From c10ef381cbc10fe1db31bcc7d1a9f04636e1bd50 Mon Sep 17 00:00:00 2001 From: Yu Peng Zheng <151984457+Felix201209@users.noreply.github.com> Date: Thu, 25 Jun 2026 13:39:58 +0800 Subject: [PATCH] fix(ui): clean up late Tauri listener subscriptions Immediately unsubscribe Tauri listeners if their async listen() call resolves after component unmount, preventing leaked handlers in AudioCue and Linux window chrome. --- openless-all/app/src/components/AudioCue.tsx | 4 ++-- openless-all/app/src/components/WindowChrome.tsx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/openless-all/app/src/components/AudioCue.tsx b/openless-all/app/src/components/AudioCue.tsx index e3f5f4ad..128f2647 100644 --- a/openless-all/app/src/components/AudioCue.tsx +++ b/openless-all/app/src/components/AudioCue.tsx @@ -46,7 +46,7 @@ export function AudioCueListener() { listen('prefs:changed', (event) => { const next = event.payload; if (next) audioCueEnabledRef.current = next.audioCueOnRecord !== false; - }).then(fn => { if (!cancelled) unlisten = fn; }).catch(() => {}); + }).then(fn => { if (cancelled) fn(); else unlisten = fn; }).catch(() => {}); })(); return () => { cancelled = true; unlisten?.(); }; }, [audioCueRuntimeEnabled]); @@ -73,7 +73,7 @@ export function AudioCueListener() { } else if (state !== 'recording' && prev === 'recording') { stopAudioCue(); } - }).then(fn => { if (!cancelled) unlisten = fn; }).catch(() => {}); + }).then(fn => { if (cancelled) fn(); else unlisten = fn; }).catch(() => {}); })(); return () => { cancelled = true; unlisten?.(); }; }, [audioCueRuntimeEnabled]); diff --git a/openless-all/app/src/components/WindowChrome.tsx b/openless-all/app/src/components/WindowChrome.tsx index a6e6c6e4..0c8fa084 100644 --- a/openless-all/app/src/components/WindowChrome.tsx +++ b/openless-all/app/src/components/WindowChrome.tsx @@ -113,7 +113,8 @@ function LinuxTitlebar() { if (!cancelled) setMaximized(m); }).catch(() => {}); }).then((fn) => { - if (!cancelled) unlisten = fn; + if (cancelled) fn(); + else unlisten = fn; }).catch(() => {}); }).catch(() => {}); return () => {