An open-source cross-platform alternative to AirDrop
fix: share handler regression
Tien Do Namfb2e8afb6b9a
diff --git a/lib/init.dart b/lib/init.dartindex ec1903d4..b3017789 100644--- a/lib/init.dart+++ b/lib/init.dart@@ -57,7 +57,7 @@ Future<PersistenceService> preInit(List<String> args) async {StreamSubscription? _sharedMediaSubscription;/// Will be called when home page has been initialized-Future<void> postInit(BuildContext context, WidgetRef ref, void Function(int) goToPage) async {+Future<void> postInit(BuildContext context, WidgetRef ref, bool appStart, void Function(int) goToPage) async {updateSystemOverlayStyle(context);final settings = ref.read(settingsProvider);@@ -74,11 +74,14 @@ Future<void> postInit(BuildContext context, WidgetRef ref, void Function(int) goif (checkPlatformCanReceiveShareIntent()) {final shareHandler = ShareHandlerPlatform.instance;- final initialSharedPayload = await shareHandler.getInitialSharedMedia();- if (initialSharedPayload != null) {- hasInitialShare = true;- _handleSharedIntent(initialSharedPayload, ref);- goToPage(HomeTab.send.index);++ if (appStart) {+ final initialSharedPayload = await shareHandler.getInitialSharedMedia();+ if (initialSharedPayload != null) {+ hasInitialShare = true;+ _handleSharedIntent(initialSharedPayload, ref);+ goToPage(HomeTab.send.index);+ }}_sharedMediaSubscription?.cancel();@@ -88,7 +91,7 @@ Future<void> postInit(BuildContext context, WidgetRef ref, void Function(int) go});}- if (!hasInitialShare && (checkPlatformWithGallery() || checkPlatformCanReceiveShareIntent())) {+ if (appStart && !hasInitialShare && (checkPlatformWithGallery() || checkPlatformCanReceiveShareIntent())) {// Clear cache on every app start.// If we received a share intent, then don't clear it, otherwise the shared file will be lost.clearCache();diff --git a/lib/main.dart b/lib/main.dartindex 91b79eed..c1023823 100644--- a/lib/main.dart+++ b/lib/main.dart@@ -72,7 +72,7 @@ class LocalSendApp extends ConsumerWidget {darkTheme: getTheme(Brightness.dark),themeMode: themeMode,navigatorKey: Routerino.navigatorKey,- home: const HomePage(doPostInit: true),+ home: const HomePage(appStart: true),),),),diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dartindex 6156e79b..53995b32 100644--- a/lib/pages/home_page.dart+++ b/lib/pages/home_page.dart@@ -33,10 +33,11 @@ enum HomeTab {}class HomePage extends ConsumerStatefulWidget {- /// Only do post init when the app started- final bool doPostInit;+ /// It is important for the initializing step+ /// because the first init clears the cache+ final bool appStart;- const HomePage({required this.doPostInit, super.key});+ const HomePage({required this.appStart, super.key});@overrideConsumerState<HomePage> createState() => _HomePageState();@@ -52,11 +53,9 @@ class _HomePageState extends ConsumerState<HomePage> {void initState() {super.initState();- if (widget.doPostInit) {- WidgetsBinding.instance.addPostFrameCallback((_) {- postInit(context, ref, _goToPage);- });- }+ WidgetsBinding.instance.addPostFrameCallback((_) {+ postInit(context, ref, widget.appStart, _goToPage);+ });}void _goToPage(int index) {diff --git a/lib/pages/progress_page.dart b/lib/pages/progress_page.dartindex 5d1bc2e5..99e76141 100644--- a/lib/pages/progress_page.dart+++ b/lib/pages/progress_page.dart@@ -291,7 +291,7 @@ class _ProgressPageState extends ConsumerState<ProgressPage> {onPressed: () async {final result = await _askCancelConfirmation(status);if (result && mounted) {- context.pushRootImmediately(() => const HomePage(doPostInit: false));+ context.pushRootImmediately(() => const HomePage(appStart: false));}},icon: Icon(status == SessionStatus.sending ? Icons.close : Icons.check_circle),diff --git a/lib/provider/network/send_provider.dart b/lib/provider/network/send_provider.dartindex 734de175..d1186591 100644--- a/lib/provider/network/send_provider.dart+++ b/lib/provider/network/send_provider.dart@@ -102,7 +102,7 @@ class SendNotifier extends StateNotifier<SendState?> {// receiver has nothing selected// ignore: use_build_context_synchronously- Routerino.context.pushRootImmediately(() => const HomePage(doPostInit: false));+ Routerino.context.pushRootImmediately(() => const HomePage(appStart: false));state = null;return;}