Mac: Keep app running on window hide().

This commit is contained in:
Dain Nilsson 2023-02-17 13:19:33 +01:00
parent 6ead9860fb
commit f4f48f8158
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
2 changed files with 12 additions and 4 deletions

View File

@ -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<Widget> initialize(List<String> argv) async {
@ -78,7 +85,7 @@ Future<Widget> initialize(List<String> 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.

View File

@ -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
}
}