mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 19:12:09 +08:00
fix(ws): assign websocket after onConnected succeeds (#7639)
* feat(layout): add logging of MihomoWebSocket instances in dev mode * refactor(hooks): defer ws assignment in use-mihomo-ws-subscription * chore: update tauri-plugin-mihomo-api dependency source to use github protocol * docs: update changelog with websocket connection fix
This commit is contained in:
@@ -97,17 +97,11 @@ const createSharedSubscriptionEntry = (
|
||||
return
|
||||
}
|
||||
|
||||
entry.ws = ws
|
||||
syncSharedWsRefs(entry)
|
||||
clearReconnectTimer()
|
||||
|
||||
const owner = pickActiveOwner(entry)
|
||||
if (owner?.onConnected) {
|
||||
await owner.onConnected(ws)
|
||||
if (entry.closed) {
|
||||
await ws.close()
|
||||
return
|
||||
}
|
||||
await owner?.onConnected?.(ws)
|
||||
if (entry.closed) {
|
||||
await ws.close()
|
||||
return
|
||||
}
|
||||
|
||||
ws.addListener((msg: Message) => {
|
||||
@@ -117,6 +111,10 @@ const createSharedSubscriptionEntry = (
|
||||
|
||||
activeOwner.handleMessage(msg.data)
|
||||
})
|
||||
|
||||
entry.ws = ws
|
||||
syncSharedWsRefs(entry)
|
||||
clearReconnectTimer()
|
||||
} catch (ignoreError) {
|
||||
if (!entry.closed && !entry.ws) {
|
||||
clearReconnectTimer()
|
||||
|
||||
@@ -27,6 +27,7 @@ import type { CSSProperties } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Outlet, useNavigate } from 'react-router'
|
||||
import { MihomoWebSocket } from 'tauri-plugin-mihomo-api'
|
||||
|
||||
import iconDark from '@/assets/image/icon_dark.svg?react'
|
||||
import iconLight from '@/assets/image/icon_light.svg?react'
|
||||
@@ -122,6 +123,24 @@ const Layout = () => {
|
||||
const navigate = useNavigate()
|
||||
const themeReady = useMemo(() => Boolean(theme), [theme])
|
||||
|
||||
// 开发环境下检测 MihomoWebSocket 的所有实例
|
||||
useEffect(() => {
|
||||
let id: number
|
||||
if (import.meta.env.DEV) {
|
||||
id = setInterval(() => {
|
||||
MihomoWebSocket.get_all_instances().then((list) => {
|
||||
console.log('Mihomo ws instances', list)
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (id) {
|
||||
clearInterval(id)
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
const [menuUnlocked, setMenuUnlocked] = useState(false)
|
||||
const [menuContextPosition, setMenuContextPosition] =
|
||||
useState<MenuContextPosition | null>(null)
|
||||
|
||||
Reference in New Issue
Block a user