Files
native/android/app/src/main/java/com/anonymous/bulwarkmobile/BulwarkWidgetRefreshService.kt
T
Linus Rath c5143975db fix: finish the widget refresh after leaving the app #52
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.
2026-10-02 12:01:31 +02:00

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)
}