revert: requestAnimationFrame 代替 setInternal

dev/emitter
Lei OT 10 months ago
parent 11531598b0
commit ac172c633b

@ -88,43 +88,25 @@ function DesktopApp() {
* 标签页标题闪烁 * 标签页标题闪烁
*/ */
const [isTitleVisible, setIsTitleVisible] = useState(true) const [isTitleVisible, setIsTitleVisible] = useState(true)
const step = useCallback(() => {
const start = useRef();
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 document.title = isTitleVisible
? `🔔🔥💬【${totalNotify}条新消息】` ? `🔔🔥💬【${totalNotify}条新消息】`
: '______________'; : '______________';
setIsTitleVisible(!isTitleVisible); setIsTitleVisible(!isTitleVisible);
start.current = timestamp; }, [isTitleVisible, totalNotify]);
} useEffect(() => {
let intervalId;
if (totalNotify > 0) {
animationFrameId = requestAnimationFrame(step);
} else {
document.title = '销售平台';
}
};
if (totalNotify > 0) { if (totalNotify > 0) {
if ('setAppBadge' in navigator) { if ('setAppBadge' in navigator) {
navigator.setAppBadge(totalNotify).catch(() => {}); navigator.setAppBadge(totalNotify).catch(() => {});
} }
animationFrameId = requestAnimationFrame(step); intervalId = setInterval(step, 1000); // 1000ms = 1s
} else {
document.title = '销售平台';
} }
return () => { return () => {
if (animationFrameId) { if (intervalId) {
cancelAnimationFrame(animationFrameId); clearInterval(intervalId);
} }
}; };
}, [totalNotify, isTitleVisible]); }, [totalNotify, isTitleVisible]);

Loading…
Cancel
Save