From fdee134afbff96b8821500205431e7e3b2207572 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Thu, 24 Sep 2026 17:19:32 +0800 Subject: [PATCH] fix(webui): play completion sound in background tabs --- .../src/components/settings/overview/OverviewSettings.tsx | 2 +- webui/src/i18n/locales/en/common.json | 2 +- webui/src/i18n/locales/es/common.json | 2 +- webui/src/i18n/locales/fr/common.json | 2 +- webui/src/i18n/locales/id/common.json | 2 +- webui/src/i18n/locales/ja/common.json | 2 +- webui/src/i18n/locales/ko/common.json | 2 +- webui/src/i18n/locales/pt-BR/common.json | 2 +- webui/src/i18n/locales/vi/common.json | 2 +- webui/src/i18n/locales/zh-CN/common.json | 2 +- webui/src/i18n/locales/zh-TW/common.json | 2 +- webui/src/lib/notification-sound.ts | 8 ++------ webui/src/tests/notification-sound.test.ts | 8 +++++--- 13 files changed, 18 insertions(+), 20 deletions(-) diff --git a/webui/src/components/settings/overview/OverviewSettings.tsx b/webui/src/components/settings/overview/OverviewSettings.tsx index ba9fe3e10..b09d8222b 100644 --- a/webui/src/components/settings/overview/OverviewSettings.tsx +++ b/webui/src/components/settings/overview/OverviewSettings.tsx @@ -388,7 +388,7 @@ export function AppearanceSettings({ title={tx("settings.rows.notificationSound", "Completion sound")} description={tx( "settings.help.notificationSound", - "Play a short chime when a turn finishes while this page is in the foreground. Off by default.", + "Play a short chime when a turn finishes, even when this page is in the background. Off by default.", )} > { playTurnCompleteSound(); } - it("stays silent by default", async () => { + it.each(["visible", "hidden"] as const)("stays silent by default when %s", async (visibility) => { + setVisibility(visibility); await play(); expect(MockAudio.instances).toHaveLength(0); }); @@ -59,11 +60,12 @@ describe("playTurnCompleteSound", () => { expect(MockAudio.instances[0].play).toHaveBeenCalledTimes(1); }); - it("stays silent when the page is in the background", async () => { + it("plays when enabled and the page is in the background", async () => { writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, notificationSound: true }); setVisibility("hidden"); await play(); - expect(MockAudio.instances).toHaveLength(0); + expect(MockAudio.instances).toHaveLength(1); + expect(MockAudio.instances[0].play).toHaveBeenCalledTimes(1); }); it("reuses one audio element across turns and restarts it", async () => {