From 0f5dc2184d00f67ad65236fe99e4939a80cc06fa Mon Sep 17 00:00:00 2001 From: tianqijiuyun-latiao <69459608+tianqijiuyun-latiao@users.noreply.github.com> Date: Fri, 6 Mar 2026 20:27:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(window-scale):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=A0=8F=E5=88=87=E6=8D=A2=E5=90=8E=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E5=BC=82=E5=B8=B8=E6=94=BE=E5=A4=A7=20refs=20#193?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 47 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index be49c41..f1cd093 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -283,6 +283,7 @@ function App() { let inFlight = false; let lastRatio = Number(window.devicePixelRatio) || 1; let lastFixAt = 0; + let activationTimer: number | null = null; const wait = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms)); @@ -334,17 +335,55 @@ function App() { void fixWindowScaleIfNeeded(); }; + const scheduleActivationFix = () => { + if (cancelled) return; + if (activationTimer !== null) { + window.clearTimeout(activationTimer); + } + activationTimer = window.setTimeout(() => { + activationTimer = null; + if (cancelled) return; + void fixWindowScaleIfNeeded(); + }, 80); + }; + + const handleWindowFocus = () => { + if (cancelled) return; + checkDevicePixelRatio(); + scheduleActivationFix(); + }; + + const handleVisibilityChange = () => { + if (cancelled) return; + if (document.visibilityState !== 'visible') { + return; + } + checkDevicePixelRatio(); + scheduleActivationFix(); + }; + + const handlePageShow = () => { + if (cancelled) return; + checkDevicePixelRatio(); + scheduleActivationFix(); + }; + const pollTimer = window.setInterval(checkDevicePixelRatio, 900); window.addEventListener('resize', checkDevicePixelRatio); - window.addEventListener('focus', checkDevicePixelRatio); - document.addEventListener('visibilitychange', checkDevicePixelRatio); + window.addEventListener('focus', handleWindowFocus); + window.addEventListener('pageshow', handlePageShow); + document.addEventListener('visibilitychange', handleVisibilityChange); return () => { cancelled = true; + if (activationTimer !== null) { + window.clearTimeout(activationTimer); + } window.clearInterval(pollTimer); window.removeEventListener('resize', checkDevicePixelRatio); - window.removeEventListener('focus', checkDevicePixelRatio); - document.removeEventListener('visibilitychange', checkDevicePixelRatio); + window.removeEventListener('focus', handleWindowFocus); + window.removeEventListener('pageshow', handlePageShow); + document.removeEventListener('visibilitychange', handleVisibilityChange); }; }, []);