diff --git a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart b/frontend/appflowy_flutter/lib/core/config/kv_keys.dart index bd4d68fa5a3c..91249f769fc5 100644 --- a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart +++ b/frontend/appflowy_flutter/lib/core/config/kv_keys.dart @@ -18,6 +18,13 @@ class KVKeys { /// {'dx': 10.0, 'dy': 10.0} static const String windowPosition = 'windowPosition'; + /// The key for saving the window status + /// + /// The value is a json string with the following format: + /// { 'windowMaximized': true } + /// + static const String windowMaximized = 'windowMaximized'; + static const String kDocumentAppearanceFontSize = 'kDocumentAppearanceFontSize'; static const String kDocumentAppearanceFontFamily = diff --git a/frontend/appflowy_flutter/lib/startup/tasks/app_window_size_manager.dart b/frontend/appflowy_flutter/lib/startup/tasks/app_window_size_manager.dart index 6c5bea392ccb..a783e835a2e1 100644 --- a/frontend/appflowy_flutter/lib/startup/tasks/app_window_size_manager.dart +++ b/frontend/appflowy_flutter/lib/startup/tasks/app_window_size_manager.dart @@ -83,4 +83,19 @@ class WindowSizeManager { '${scaleFactor.clamp(minScaleFactor, maxScaleFactor)}', ); } + + /// Set the window maximized status + Future setWindowMaximized(bool isMaximized) async { + await getIt() + .set(KVKeys.windowMaximized, isMaximized.toString()); + } + + /// Get the window maximized status + Future getWindowMaximized() async { + return await getIt().getWithFormat( + KVKeys.windowMaximized, + (v) => bool.tryParse(v) ?? false, + ) ?? + false; + } } diff --git a/frontend/appflowy_flutter/lib/startup/tasks/windows.dart b/frontend/appflowy_flutter/lib/startup/tasks/windows.dart index 78486e332077..9cc2b5b765b5 100644 --- a/frontend/appflowy_flutter/lib/startup/tasks/windows.dart +++ b/frontend/appflowy_flutter/lib/startup/tasks/windows.dart @@ -13,12 +13,9 @@ import 'package:scaled_app/scaled_app.dart'; import 'package:window_manager/window_manager.dart'; class InitAppWindowTask extends LaunchTask with WindowListener { - InitAppWindowTask({ - this.title = 'AppFlowy', - }); + InitAppWindowTask({this.title = 'AppFlowy'}); final String title; - final windowSizeManager = WindowSizeManager(); @override @@ -48,7 +45,7 @@ class InitAppWindowTask extends LaunchTask with WindowListener { final position = await windowSizeManager.getPosition(); if (PlatformExtension.isWindows) { - doWhenWindowReady(() { + doWhenWindowReady(() async { appWindow.minSize = windowOptions.minimumSize; appWindow.maxSize = windowOptions.maximumSize; appWindow.size = windowSize; @@ -58,6 +55,13 @@ class InitAppWindowTask extends LaunchTask with WindowListener { } appWindow.show(); + + /// on Windows we maximize the window if it was previously closed + /// from a maximized state. + final isMaximized = await windowSizeManager.getWindowMaximized(); + if (isMaximized) { + appWindow.maximize(); + } }); } else { await windowManager.waitUntilReadyToShow(windowOptions, () async { @@ -78,16 +82,20 @@ class InitAppWindowTask extends LaunchTask with WindowListener { } @override - Future onWindowResize() async { - super.onWindowResize(); + Future onWindowMaximize() async { + super.onWindowMaximize(); + await windowSizeManager.setWindowMaximized(true); + } - final currentWindowSize = await windowManager.getSize(); - return windowSizeManager.setSize(currentWindowSize); + @override + Future onWindowUnmaximize() async { + super.onWindowUnmaximize(); + await windowSizeManager.setWindowMaximized(false); } @override - void onWindowMaximize() async { - super.onWindowMaximize(); + Future onWindowResize() async { + super.onWindowResize(); final currentWindowSize = await windowManager.getSize(); return windowSizeManager.setSize(currentWindowSize);