fix: properly close app on back gesture (#1570)

This commit is contained in:
Tien Do Nam
2024-07-27 17:00:35 +02:00
committed by GitHub
parent be0abe13ec
commit 822f429b59
3 changed files with 26 additions and 2 deletions
+4
View File
@@ -1,3 +1,7 @@
## 1.16.0 (unreleased)
- fix(android): properly close app on back gesture (@Tienisto)
## 1.15.2 (2024-07-25)
- feat: extract network scanning to separate threads, scanning should not cause UI lags anymore (@Tienisto)
+12 -2
View File
@@ -1,3 +1,4 @@
import 'package:common/isolate.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:localsend_app/gen/strings.g.dart';
@@ -38,8 +39,17 @@ class LocalSendApp extends StatelessWidget {
child: WindowWatcher(
child: LifeCycleWatcher(
onChangedState: (AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
ref.redux(localIpProvider).dispatch(InitLocalIpAction());
switch (state) {
case AppLifecycleState.resumed:
ref.redux(localIpProvider).dispatch(InitLocalIpAction());
break;
case AppLifecycleState.detached:
// The main isolate is only exited when all child isolates are exited.
// https://github.com/localsend/localsend/issues/1568
ref.redux(parentIsolateProvider).dispatch(IsolateDisposeAction());
break;
default:
break;
}
},
child: ShortcutWatcher(
@@ -96,3 +96,13 @@ class IsolateSetupAction extends AsyncReduxAction<IsolateController, ParentIsola
);
}
}
class IsolateDisposeAction extends ReduxAction<IsolateController, ParentIsolateState> {
@override
ParentIsolateState reduce() {
state.httpScanDiscovery?.isolate.kill();
state.httpTargetDiscovery?.isolate.kill();
state.multicastDiscovery?.isolate.kill();
return state;
}
}