优化事件处理

This commit is contained in:
xintaofei
2026-03-08 17:08:31 +08:00
parent 7a4cbcb73e
commit c1220e1a8f
12 changed files with 178 additions and 64 deletions

View File

@@ -11,6 +11,7 @@ import {
} from "react"
import { useTranslations } from "next-intl"
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
import { disposeTauriListener } from "@/lib/tauri-listener"
import {
acpConnect,
acpListAgents,
@@ -1420,11 +1421,7 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
})
.then((fn) => {
if (cancelled) {
try {
fn()
} catch {
// ignore
}
disposeTauriListener(fn, "AcpConnectionsProvider.globalEvent")
} else {
unlisten = fn
listenerReadyRef.current = true
@@ -1444,7 +1441,7 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
clearTimeout(flushTimerRef.current)
flushTimerRef.current = null
}
unlisten?.()
disposeTauriListener(unlisten, "AcpConnectionsProvider.globalEvent")
}
}, [bufferUnmappedEvent, handleMappedEvent, resolveListenerReadyWaiters])