fix window placement

This commit is contained in:
wgh19
2024-05-27 14:48:07 +08:00
parent b34a8342d2
commit 35dd9dee5f

View File

@@ -15,6 +15,10 @@ class WindowPlacement {
Future<void> applyToWindow() async { Future<void> applyToWindow() async {
await windowManager.setBounds(rect); await windowManager.setBounds(rect);
if(!validate(rect)){
await windowManager.center();
}
if (isMaximized) { if (isMaximized) {
await windowManager.maximize(); await windowManager.maximize();
} }
@@ -55,10 +59,17 @@ class WindowPlacement {
static void loop() async { static void loop() async {
var placement = await WindowPlacement.current; var placement = await WindowPlacement.current;
if(!validate(placement.rect)){
return;
}
if (placement.rect != cache.rect || if (placement.rect != cache.rect ||
placement.isMaximized != cache.isMaximized) { placement.isMaximized != cache.isMaximized) {
cache = placement; cache = placement;
await placement.writeToFile(); await placement.writeToFile();
} }
} }
static bool validate(Rect rect){
return rect.topLeft.dx >= 0 && rect.topLeft.dy >= 0;
}
} }