fix(window-provider): maximize avoiding loop detection

This commit is contained in:
Tunglies 2026-03-09 06:46:36 +08:00
parent ffc2419afd
commit 0e89afb01f
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8

View File

@ -25,13 +25,21 @@ export const WindowProvider: React.FC<{ children: React.ReactNode }> = ({
useEffect(() => { useEffect(() => {
let isUnmounted = false; let isUnmounted = false;
let lastWidth = -1;
let lastHeight = -1;
const checkMaximized = debounce(async () => { const checkMaximized = debounce(
if (!isUnmounted) { async (event: { payload: { width: number; height: number } }) => {
if (isUnmounted) return;
const { width, height } = event.payload;
if (width === lastWidth && height === lastHeight) return;
lastWidth = width;
lastHeight = height;
const value = await currentWindow.isMaximized(); const value = await currentWindow.isMaximized();
setMaximized(value); setMaximized(value);
} },
}, 300); 300,
);
const unlistenPromise = currentWindow.onResized(checkMaximized); const unlistenPromise = currentWindow.onResized(checkMaximized);