From cda9868a1f68fd866411af82881b405264e3600a Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Wed, 30 Sep 2026 20:58:36 +0700 Subject: [PATCH] fix(startup): keep shared backend alive across activity recreation --- .../src/main/kotlin/com/zarz/spotiflac/MainActivity.kt | 8 +++----- lib/main.dart | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/kotlin/com/zarz/spotiflac/MainActivity.kt b/android/app/src/main/kotlin/com/zarz/spotiflac/MainActivity.kt index 3aa24419..bb010daf 100644 --- a/android/app/src/main/kotlin/com/zarz/spotiflac/MainActivity.kt +++ b/android/app/src/main/kotlin/com/zarz/spotiflac/MainActivity.kt @@ -946,11 +946,9 @@ class MainActivity: FlutterFragmentActivity() { } catch (_: Exception) {} } libraryStorageReceiver = null - try { - coreBackend.cleanupExtensions() - } catch (e: Exception) { - android.util.Log.w("SpotiFLAC", "Failed to cleanup extensions on destroy: ${e.message}") - } + // The backend belongs to the process/shared Flutter engine and download + // service. Activity recreation must not shut it down (or wait for its + // active scans/downloads on the UI thread). stopDownloadProgressStream() stopLibraryScanProgressStream() closeAllSafPlaybackLeases() diff --git a/lib/main.dart b/lib/main.dart index 9e266643..26e2e45e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -243,7 +243,7 @@ Future _detectInitialSafAccessLoss(AppSettings settings) async { try { return !await PlatformBridge.validateSafTreeAccess( settings.downloadTreeUri, - ); + ).timeout(const Duration(seconds: 2)); } catch (e) { // A transient bridge failure must not trap the user at launch. Download // preflight validates strictly again before any write starts.