mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-01 08:06:13 +00:00
The previous fix started the refresh as the app went to the background, but it still stopped after its first request: fetch hands every response over through a JS timer, and React Native pauses timers while the app's activity is in the background, so the answer was only read once the app came back. The widgets kept the previous account after a switch and Home, and changes made in the app reached them late. The refresh now runs as a headless task of its own, BulwarkWidgetRefresh, started through BulwarkWidgetRefreshService. A running headless task keeps the timers going, and the service keeps the process from being frozen before the widgets are redrawn. Where Android refuses to start the service the app refreshes in place as before. A refresh started for a change also no longer joins one that began before it.
21 lines
940 B
Kotlin
21 lines
940 B
Kotlin
package com.anonymous.bulwarkmobile
|
|
|
|
import android.content.Intent
|
|
import com.facebook.react.HeadlessJsTaskService
|
|
import com.facebook.react.bridge.Arguments
|
|
import com.facebook.react.jstasks.HeadlessJsTaskConfig
|
|
|
|
/**
|
|
* Runs the widgets' refresh (BulwarkWidgetRefresh, index.ts) as a headless
|
|
* task when the app goes to the background. Run from the app itself the
|
|
* refresh stalled: React Native pauses JS timers while the activity is in
|
|
* the background, and fetch resolves every response through a timer, so the
|
|
* first request went out and its answer was never read. A running headless
|
|
* task keeps timers going, and the service keeps the process from being
|
|
* frozen before the widgets are redrawn.
|
|
*/
|
|
class BulwarkWidgetRefreshService : HeadlessJsTaskService() {
|
|
override fun getTaskConfig(intent: Intent?): HeadlessJsTaskConfig =
|
|
HeadlessJsTaskConfig("BulwarkWidgetRefresh", Arguments.createMap(), 30000L, true)
|
|
}
|