diff --git a/lib/desktop/init.dart b/lib/desktop/init.dart index e8224268..346b78e3 100755 --- a/lib/desktop/init.dart +++ b/lib/desktop/init.dart @@ -54,9 +54,9 @@ final _log = Logger('desktop.init'); const String _keyWidth = 'DESKTOP_WINDOW_WIDTH'; const String _keyHeight = 'DESKTOP_WINDOW_HEIGHT'; -class _WindowResizeListener extends WindowListener { +class _WindowEventListener extends WindowListener { final SharedPreferences _prefs; - _WindowResizeListener(this._prefs); + _WindowEventListener(this._prefs); @override void onWindowResize() async { @@ -64,6 +64,13 @@ class _WindowResizeListener extends WindowListener { await _prefs.setDouble(_keyWidth, size.width); await _prefs.setDouble(_keyHeight, size.height); } + + @override + void onWindowClose() async { + if (Platform.isMacOS) { + await windowManager.destroy(); + } + } } Future initialize(List argv) async { @@ -78,7 +85,7 @@ Future initialize(List argv) async { final height = prefs.getDouble(_keyHeight) ?? 720; await windowManager.setSize(Size(width, height)); await windowManager.show(); - windowManager.addListener(_WindowResizeListener(prefs)); + windowManager.addListener(_WindowEventListener(prefs)); })); // Either use the _HELPER_PATH environment variable, or look relative to executable. diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index d53ef643..91cfe9a7 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -4,6 +4,7 @@ import FlutterMacOS @NSApplicationMain class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { - return true + // Keep app running if window closes + return false } }