From 35dd9dee5f91169e47413f26f11153b7bbb3b46c Mon Sep 17 00:00:00 2001 From: wgh19 Date: Mon, 27 May 2024 14:48:07 +0800 Subject: [PATCH] fix window placement --- lib/utils/window.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/utils/window.dart b/lib/utils/window.dart index 1235f96..4cb263f 100644 --- a/lib/utils/window.dart +++ b/lib/utils/window.dart @@ -15,6 +15,10 @@ class WindowPlacement { Future applyToWindow() async { await windowManager.setBounds(rect); + if(!validate(rect)){ + await windowManager.center(); + } + if (isMaximized) { await windowManager.maximize(); } @@ -55,10 +59,17 @@ class WindowPlacement { static void loop() async { var placement = await WindowPlacement.current; + if(!validate(placement.rect)){ + return; + } if (placement.rect != cache.rect || placement.isMaximized != cache.isMaximized) { cache = placement; await placement.writeToFile(); } } + + static bool validate(Rect rect){ + return rect.topLeft.dx >= 0 && rect.topLeft.dy >= 0; + } }