From ac172c633b838bd97d3e79c0a81755bd9e62996f Mon Sep 17 00:00:00 2001 From: Lei OT Date: Wed, 11 Dec 2024 10:51:09 +0800 Subject: [PATCH] =?UTF-8?q?revert:=20requestAnimationFrame=20=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=20setInternal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/DesktopApp.jsx | 42 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/src/views/DesktopApp.jsx b/src/views/DesktopApp.jsx index 33281dc..ae00a71 100644 --- a/src/views/DesktopApp.jsx +++ b/src/views/DesktopApp.jsx @@ -88,43 +88,25 @@ function DesktopApp() { * 标签页标题闪烁 */ const [isTitleVisible, setIsTitleVisible] = useState(true) - - const start = useRef(); - + const step = useCallback(() => { + document.title = isTitleVisible + ? `🔔🔥💬【${totalNotify}条新消息】` + : '______________'; + setIsTitleVisible(!isTitleVisible); + }, [isTitleVisible, totalNotify]); useEffect(() => { - let animationFrameId; - - const step = (timestamp) => { - if (start.current === undefined) { - start.current = timestamp; - } - const elapsed = timestamp - start.current; - - if (elapsed > 1000) { // 2000ms = 2s - document.title = isTitleVisible - ? `🔔🔥💬【${totalNotify}条新消息】` - : '______________'; - setIsTitleVisible(!isTitleVisible); - start.current = timestamp; - } - - if (totalNotify > 0) { - animationFrameId = requestAnimationFrame(step); - } else { - document.title = '销售平台'; - } - }; - + let intervalId; if (totalNotify > 0) { if ('setAppBadge' in navigator) { navigator.setAppBadge(totalNotify).catch(() => {}); } - animationFrameId = requestAnimationFrame(step); + intervalId = setInterval(step, 1000); // 1000ms = 1s + } else { + document.title = '销售平台'; } - return () => { - if (animationFrameId) { - cancelAnimationFrame(animationFrameId); + if (intervalId) { + clearInterval(intervalId); } }; }, [totalNotify, isTitleVisible]);