A cross platform Audiobookshelf client for Android and iOS
Dart
Fix the stuck widget and frozen splash screen after updating the app while listening
Barnabas753354f7317a
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xmlindex 4b7cb8c5..f3dbb0c9 100644--- a/android/app/src/main/AndroidManifest.xml+++ b/android/app/src/main/AndroidManifest.xml@@ -167,6 +167,16 @@android:resource="@xml/stats_widget_info" /></receiver>+ <!-- An app update kills playback but the widgets redraw from the+ stashed state, which still says playing - reset it on install. -->+ <receiver+ android:name=".PackageReplacedReceiver"+ android:exported="false">+ <intent-filter>+ <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />+ </intent-filter>+ </receiver>+<!-- Bridge to the AbsorbWear watch app: receives sync requests andsign-out events sent from the watch over the Wearable Data Layer. --><servicediff --git a/android/app/src/main/kotlin/com/barnabas/absorb/PackageReplacedReceiver.kt b/android/app/src/main/kotlin/com/barnabas/absorb/PackageReplacedReceiver.ktnew file mode 100644index 00000000..c240ffb3--- /dev/null+++ b/android/app/src/main/kotlin/com/barnabas/absorb/PackageReplacedReceiver.kt@@ -0,0 +1,36 @@+package com.barnabas.absorb++import android.appwidget.AppWidgetManager+import android.content.BroadcastReceiver+import android.content.ComponentName+import android.content.Context+import android.content.Intent+import es.antonborri.home_widget.HomeWidgetPlugin++// An app update kills the process mid-playback, but the now-playing widgets+// redraw from the stashed state, which still says playing - so they sit on a+// live squiggle with a pause button that goes nowhere. Correct the stash and+// re-render as soon as the new build is installed.+class PackageReplacedReceiver : BroadcastReceiver() {+ override fun onReceive(context: Context, intent: Intent) {+ if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return+ try {+ HomeWidgetPlugin.getData(context).edit()+ .putBoolean("widget_is_playing", false)+ .apply()+ val mgr = AppWidgetManager.getInstance(context)+ for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidget::class.java))) {+ try { NowPlayingWidget.updateWidget(context, mgr, id) } catch (_: Exception) {}+ }+ for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetCompact::class.java))) {+ try { NowPlayingWidgetCompact.updateWidget(context, mgr, id) } catch (_: Exception) {}+ }+ for (id in mgr.getAppWidgetIds(ComponentName(context, NowPlayingWidgetTiny::class.java))) {+ try { NowPlayingWidgetTiny.updateWidget(context, mgr, id) } catch (_: Exception) {}+ }+ WidgetClock.syncTicker(context)+ } catch (e: Exception) {+ android.util.Log.e("PackageReplaced", "widget reset failed", e)+ }+ }+}diff --git a/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java b/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.javaindex eb0129f7..5bfb55fd 100644--- a/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java+++ b/packages/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java@@ -47,6 +47,7 @@ import java.util.List;import java.util.Map;import io.flutter.embedding.engine.FlutterEngine;+import io.flutter.embedding.engine.FlutterEngineCache;public class AudioService extends MediaBrowserServiceCompat {public static final String CONTENT_STYLE_SUPPORTED = "android.media.browse.CONTENT_STYLE_SUPPORTED";@@ -349,8 +350,15 @@ public class AudioService extends MediaBrowserServiceCompat {}};- flutterEngine = AudioServicePlugin.getFlutterEngine(this);- System.out.println("flutterEngine warmed up");+ // Absorb patch: only adopt an engine that already exists - never+ // create one here. A headless service start (widget media-button+ // press or the system's media resumption bind after the process died,+ // e.g. an app update installed mid-listen) would run the app's full+ // main() with no activity, and that half-initialized engine gets+ // cached: the next app launch attaches to it and freezes on the+ // splash screen until the user force-stops the app. Real launches+ // create the engine through the activity before connecting.+ flutterEngine = FlutterEngineCache.getInstance().get(AudioServicePlugin.getFlutterEngineId());}@Override