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.
This commit is contained in:
Yu Peng Zheng authored and GitHub committed 2026-06-25 13:39:58 +08:00
1 parent b4636f9620
commit c10ef381cb
2 files changed
+4 -3

No files matched your search

+2 -2
View File
@@ -46,7 +46,7 @@ export function AudioCueListener() {
listen<UserPreferences>('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]);
@@ -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 () => {