mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: maximized window optimization (#5622)
This commit is contained in:
parent
f59b8a2e5c
commit
c996c9c28e
@ -18,6 +18,13 @@ class KVKeys {
|
|||||||
/// {'dx': 10.0, 'dy': 10.0}
|
/// {'dx': 10.0, 'dy': 10.0}
|
||||||
static const String windowPosition = 'windowPosition';
|
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 =
|
static const String kDocumentAppearanceFontSize =
|
||||||
'kDocumentAppearanceFontSize';
|
'kDocumentAppearanceFontSize';
|
||||||
static const String kDocumentAppearanceFontFamily =
|
static const String kDocumentAppearanceFontFamily =
|
||||||
|
@ -83,4 +83,19 @@ class WindowSizeManager {
|
|||||||
'${scaleFactor.clamp(minScaleFactor, maxScaleFactor)}',
|
'${scaleFactor.clamp(minScaleFactor, maxScaleFactor)}',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the window maximized status
|
||||||
|
Future<void> setWindowMaximized(bool isMaximized) async {
|
||||||
|
await getIt<KeyValueStorage>()
|
||||||
|
.set(KVKeys.windowMaximized, isMaximized.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the window maximized status
|
||||||
|
Future<bool> getWindowMaximized() async {
|
||||||
|
return await getIt<KeyValueStorage>().getWithFormat<bool>(
|
||||||
|
KVKeys.windowMaximized,
|
||||||
|
(v) => bool.tryParse(v) ?? false,
|
||||||
|
) ??
|
||||||
|
false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,9 @@ import 'package:scaled_app/scaled_app.dart';
|
|||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
class InitAppWindowTask extends LaunchTask with WindowListener {
|
class InitAppWindowTask extends LaunchTask with WindowListener {
|
||||||
InitAppWindowTask({
|
InitAppWindowTask({this.title = 'AppFlowy'});
|
||||||
this.title = 'AppFlowy',
|
|
||||||
});
|
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
final windowSizeManager = WindowSizeManager();
|
final windowSizeManager = WindowSizeManager();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -48,7 +45,7 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
|
|||||||
final position = await windowSizeManager.getPosition();
|
final position = await windowSizeManager.getPosition();
|
||||||
|
|
||||||
if (PlatformExtension.isWindows) {
|
if (PlatformExtension.isWindows) {
|
||||||
doWhenWindowReady(() {
|
doWhenWindowReady(() async {
|
||||||
appWindow.minSize = windowOptions.minimumSize;
|
appWindow.minSize = windowOptions.minimumSize;
|
||||||
appWindow.maxSize = windowOptions.maximumSize;
|
appWindow.maxSize = windowOptions.maximumSize;
|
||||||
appWindow.size = windowSize;
|
appWindow.size = windowSize;
|
||||||
@ -58,6 +55,13 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appWindow.show();
|
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 {
|
} else {
|
||||||
await windowManager.waitUntilReadyToShow(windowOptions, () async {
|
await windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
@ -78,16 +82,20 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onWindowResize() async {
|
Future<void> onWindowMaximize() async {
|
||||||
super.onWindowResize();
|
super.onWindowMaximize();
|
||||||
|
await windowSizeManager.setWindowMaximized(true);
|
||||||
final currentWindowSize = await windowManager.getSize();
|
|
||||||
return windowSizeManager.setSize(currentWindowSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onWindowMaximize() async {
|
Future<void> onWindowUnmaximize() async {
|
||||||
super.onWindowMaximize();
|
super.onWindowUnmaximize();
|
||||||
|
await windowSizeManager.setWindowMaximized(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onWindowResize() async {
|
||||||
|
super.onWindowResize();
|
||||||
|
|
||||||
final currentWindowSize = await windowManager.getSize();
|
final currentWindowSize = await windowManager.getSize();
|
||||||
return windowSizeManager.setSize(currentWindowSize);
|
return windowSizeManager.setSize(currentWindowSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user