From b19f4290a674917aeb4740c2d8a6edae72b1f7af Mon Sep 17 00:00:00 2001 From: franzap <_@franzap.com> Date: Fri, 22 Nov 2024 17:39:31 -0300 Subject: [PATCH] Initializer: Preload updates and curation set in background --- lib/navigation/app_initializer.dart | 31 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/navigation/app_initializer.dart b/lib/navigation/app_initializer.dart index 7a93942..86af6d4 100644 --- a/lib/navigation/app_initializer.dart +++ b/lib/navigation/app_initializer.dart @@ -27,26 +27,31 @@ final appInitializer = FutureProvider((ref) async { // Initialize Flutter Data await ref.read(initializeFlutterData(adapterProvidersMap).future); - _lifecycleListener = AppLifecycleListener( - onStateChange: (state) async { - if (state == AppLifecycleState.resumed) { - await ref.localApps.localAppAdapter.refreshUpdateStatus(); - } - }, - ); - - // Preload curation sets - // Do not use ignoreReturn here + // NOTE: Do not use ignoreReturn here if (ref.appCurationSets.countLocal == 0) { + // If we are here, local storage is empty + // Preload curation sets await ref.appCurationSets.findAll(); - // Take opportunity to preload updates - await ref.apps.appAdapter.checkForUpdates(); + // Preload updates in the background (no await) + ref.apps.appAdapter.checkForUpdates(); } else { + // Preload curation sets in the background (no await) ref.appCurationSets.findAll(); } // Preload zapstore's nostr curation set - await ref.read(appCurationSetProvider(kNostrCurationSet).notifier).fetch(); + ref.read(appCurationSetProvider(kNostrCurationSet).notifier).fetch(); + + // App-wide listeners + + // Register app lifecycle listener + _lifecycleListener = AppLifecycleListener( + onStateChange: (state) { + if (state == AppLifecycleState.resumed) { + ref.localApps.localAppAdapter.refreshUpdateStatus(); + } + }, + ); // Handle deep links final appLinksSub = appLinks.uriLinkStream.listen((uri) async {