From e9ae8c93ae0f36b034a497e7914d12880a91a2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E9=98=BF=E6=B1=9F=28Relakkes?= =?UTF-8?q?=29?= Date: Fri, 17 Apr 2026 20:26:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(desktop):=20haha-oauth=20store=20=E2=80=94?= =?UTF-8?q?=20logout=20=E5=81=9C=20polling=20+=20recursive=20setTimeout=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=20overlap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code review follow-ups on f10396e: - logout() 首行调 stopPolling, 避免登出后 poll timer 还在跑 - setInterval 改为 recursive setTimeout, fetchStatus >2s 时不会产生 parallel 请求 Co-Authored-By: Claude Opus 4.7 (1M context) --- desktop/src/stores/hahaOAuthStore.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/desktop/src/stores/hahaOAuthStore.ts b/desktop/src/stores/hahaOAuthStore.ts index d6f3e49a..df6f9f98 100644 --- a/desktop/src/stores/hahaOAuthStore.ts +++ b/desktop/src/stores/hahaOAuthStore.ts @@ -19,7 +19,7 @@ type HahaOAuthState = { } export const useHahaOAuthStore = create((set, get) => { - let pollTimer: ReturnType | null = null + let pollTimer: ReturnType | null = null return { status: null, @@ -53,6 +53,7 @@ export const useHahaOAuthStore = create((set, get) => { }, logout: async () => { + get().stopPolling() set({ isLoading: true }) try { await hahaOAuthApi.logout() @@ -69,18 +70,26 @@ export const useHahaOAuthStore = create((set, get) => { startPolling: () => { if (pollTimer) return set({ isPolling: true }) - pollTimer = setInterval(async () => { - await get().fetchStatus() - const cur = get().status - if (cur && cur.loggedIn) { - get().stopPolling() - } - }, POLL_INTERVAL_MS) + + const scheduleNext = () => { + pollTimer = setTimeout(async () => { + await get().fetchStatus() + const cur = get().status + if (cur && cur.loggedIn) { + get().stopPolling() + return + } + if (get().isPolling) { + scheduleNext() + } + }, POLL_INTERVAL_MS) + } + scheduleNext() }, stopPolling: () => { if (pollTimer) { - clearInterval(pollTimer) + clearTimeout(pollTimer) pollTimer = null } set({ isPolling: false })