opt: add preventClose to handle close event manually

This commit is contained in:
Kingtous
2022-11-06 17:39:19 +08:00
parent ddeaf7fb92
commit 0b167493cc
5 changed files with 28 additions and 13 deletions

View File

@@ -33,7 +33,7 @@ class DesktopHomePage extends StatefulWidget {
const borderColor = Color(0xFF2F65BA);
class _DesktopHomePageState extends State<DesktopHomePage>
with TrayListener, WindowListener, AutomaticKeepAliveClientMixin {
with TrayListener, AutomaticKeepAliveClientMixin {
final _leftPaneScrollController = ScrollController();
@override
@@ -41,14 +41,6 @@ class _DesktopHomePageState extends State<DesktopHomePage>
var updateUrl = '';
StreamSubscription? _uniLinksSubscription;
@override
void onWindowClose() async {
super.onWindowClose();
// hide window on close
await windowManager.hide();
rustDeskWinManager.unregisterActiveWindow(0);
}
@override
Widget build(BuildContext context) {
super.build(context);
@@ -425,7 +417,6 @@ class _DesktopHomePageState extends State<DesktopHomePage>
// disable this tray because we use tray function provided by rust now
// initTray();
trayManager.addListener(this);
windowManager.addListener(this);
rustDeskWinManager.registerActiveWindowListener(onActiveWindowChanged);
rustDeskWinManager.registerActiveWindow(0);
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
@@ -471,9 +462,9 @@ class _DesktopHomePageState extends State<DesktopHomePage>
@override
void dispose() {
// destoryTray();
rustDeskWinManager.unregisterActiveWindowListener(onActiveWindowChanged);
// fix: disable unregister to prevent from receiving events from other windows
// rustDeskWinManager.unregisterActiveWindowListener(onActiveWindowChanged);
trayManager.removeListener(this);
windowManager.removeListener(this);
_uniLinksSubscription?.cancel();
super.dispose();
}

View File

@@ -498,6 +498,21 @@ class WindowActionPanelState extends State<WindowActionPanel>
super.onWindowUnmaximize();
}
@override
void onWindowClose() async {
// hide window on close
if (widget.isMainWindow) {
await windowManager.hide();
rustDeskWinManager.unregisterActiveWindow(0);
} else {
widget.onClose?.call();
WindowController.fromWindowId(windowId!).hide();
rustDeskWinManager
.call(WindowType.Main, kWindowEventHide, {"id": windowId!});
}
super.onWindowClose();
}
@override
Widget build(BuildContext context) {
return Row(