mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-11-04 09:00:21 +00:00
feat: disable custom background button
This commit is contained in:
1 parent
b1c5b6e0a8
commit
38be1e9a10
18 files changed
+99
-99
No files matched your search
@@ -106,28 +106,15 @@ export const WebSocketProvider: React.FC<WebSocketProviderProps> = ({ url, child
|
||||
useEffect(() => {
|
||||
connect()
|
||||
|
||||
// 添加页面可见性变化监听
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.hidden) {
|
||||
// 页面隐藏时断开连接
|
||||
cleanup()
|
||||
} else {
|
||||
// 页面可见时重新连接
|
||||
connect()
|
||||
}
|
||||
}
|
||||
|
||||
// 添加页面卸载事件监听
|
||||
const handleBeforeUnload = () => {
|
||||
cleanup()
|
||||
}
|
||||
|
||||
document.addEventListener("visibilitychange", handleVisibilityChange)
|
||||
window.addEventListener("beforeunload", handleBeforeUnload)
|
||||
|
||||
return () => {
|
||||
cleanup()
|
||||
document.removeEventListener("visibilitychange", handleVisibilityChange)
|
||||
window.removeEventListener("beforeunload", handleBeforeUnload)
|
||||
}
|
||||
}, [url])
|
||||
|
||||
Reference in new issue
Block a user