Skip to content

An open-source cross-platform alternative to AirDrop

fix: correctly set the background flag

Tien Do Nam276bd39b1c27
diff --git a/app/lib/pages/tabs/send_tab_vm.dart b/app/lib/pages/tabs/send_tab_vm.dart
index 177cbdc5..ed4a7cf9 100644
--- a/app/lib/pages/tabs/send_tab_vm.dart
+++ b/app/lib/pages/tabs/send_tab_vm.dart
@@ -162,7 +162,12 @@ final sendTabVmProvider = ViewProvider((ref) {
() => SendPage(showAppBar: true, closeSessionOnClose: false, sessionId: session.sessionId),
transition: RouterinoTransition.fade(),
);
- ref.notifier(sendProvider).setBackground(session.sessionId, true);
+ // Only restore background mode if the user actually backed out.
+ // When the receiver accepts, the provider replaces this page with the ProgressPage,
+ // which also resolves this future; the ProgressPage then owns the background flag.
+ if (ref.read(sendProvider)[session.sessionId]?.status == SessionStatus.waiting) {
+ ref.notifier(sendProvider).setBackground(session.sessionId, true);
+ }
return;
} else if (session.status == SessionStatus.sending || session.status == SessionStatus.finishedWithErrors) {
ref.notifier(sendProvider).setBackground(session.sessionId, false);
diff --git a/app/lib/provider/network/send_provider.dart b/app/lib/provider/network/send_provider.dart
index 24ed8420..0630831a 100644
--- a/app/lib/provider/network/send_provider.dart
+++ b/app/lib/provider/network/send_provider.dart
@@ -410,16 +410,26 @@ class SendNotifier extends Notifier<Map<String, SendSessionState>> {
if (state[sessionId]?.background == false) {
final background = ref.read(settingsProvider).sendMode == SendMode.multiple;
- // ignore: use_build_context_synchronously, unawaited_futures
- Routerino.context.pushAndRemoveUntil(
- removeUntil: HomePage,
- transition: RouterinoTransition.fade(),
- // immediately is not possible: https://github.com/flutter/flutter/issues/121910
- builder: () => ProgressPage(
- showAppBar: background,
- closeSessionOnClose: !background,
- sessionId: sessionId,
- ),
+ unawaited(
+ // ignore: use_build_context_synchronously
+ Routerino.context
+ .pushAndRemoveUntil(
+ removeUntil: HomePage,
+ transition: RouterinoTransition.fade(),
+ // immediately is not possible: https://github.com/flutter/flutter/issues/121910
+ builder: () => ProgressPage(
+ showAppBar: background,
+ closeSessionOnClose: !background,
+ sessionId: sessionId,
+ ),
+ )
+ .then((_) {
+ if (background) {
+ // The page was popped (e.g. backing out mid-transfer), so the session
+ // runs in background again and is removed silently on success.
+ setBackground(sessionId, true);
+ }
+ }),
);
}