Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): play completion sound in background tabs
chengyongrufdee134afbff
diff --git a/webui/src/components/settings/overview/OverviewSettings.tsx b/webui/src/components/settings/overview/OverviewSettings.tsxindex 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.",)}><ToggleButtondiff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.jsonindex 51446bc83..2625033a1 100644--- a/webui/src/i18n/locales/en/common.json+++ b/webui/src/i18n/locales/en/common.json@@ -562,7 +562,7 @@"codeWrap": "Keep long code lines readable on smaller screens.","brandLogos": "Show third-party provider and CLI logos in Settings.","browserNotifications": "Notify only when this page is in the background. Off by default.",- "notificationSound": "Play a short chime when a turn finishes while this page is in the foreground. Off by default.",+ "notificationSound": "Play a short chime when a turn finishes, even when this page is in the background. Off by default.","maxResults": "Maximum number of results returned by each web search.","timeout": "How long to wait for a search request to finish.","jinaReader": "Use Jina Reader to read web pages when available.",diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.jsonindex 232a8c9e2..670e78c83 100644--- a/webui/src/i18n/locales/es/common.json+++ b/webui/src/i18n/locales/es/common.json@@ -332,7 +332,7 @@"selectedModelValue": "Definido por el modelo seleccionado.","brandLogos": "Muestra logos de proveedores de terceros y CLI en Ajustes.","browserNotifications": "Notifica solo cuando esta página está en segundo plano. Desactivado de forma predeterminada.",- "notificationSound": "Reproduce un breve sonido cuando un turno termina mientras esta página está en primer plano. Desactivado por defecto.",+ "notificationSound": "Reproduce un breve sonido cuando termina un turno, incluso si esta página está en segundo plano. Desactivado por defecto.","cliAppsCatalog": "Instala las herramientas de línea de comandos que nanobot puede usar en este equipo. Las aplicaciones de escritorio no se modifican.","cliAppsFilter": "Busca por aplicación, categoría o capacidad.","logs": "Abre la carpeta de registros de la aplicación de escritorio.",diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.jsonindex a06081c51..623f68e81 100644--- a/webui/src/i18n/locales/fr/common.json+++ b/webui/src/i18n/locales/fr/common.json@@ -332,7 +332,7 @@"selectedModelValue": "Défini par le modèle sélectionné.","brandLogos": "Affiche les logos de fournisseurs tiers et CLI dans les Réglages.","browserNotifications": "Notifier uniquement lorsque cette page est en arrière-plan. Désactivé par défaut.",- "notificationSound": "Joue un bref carillon lorsqu'un tour se termine pendant que cette page est au premier plan. Désactivé par défaut.",+ "notificationSound": "Joue un bref carillon lorsqu’un tour se termine, même si cette page est en arrière-plan. Désactivé par défaut.","cliAppsCatalog": "Installe les outils en ligne de commande que nanobot peut utiliser sur cette machine. Les applications de bureau ne sont pas modifiées.","cliAppsFilter": "Recherchez par application, catégorie ou capacité.","logs": "Ouvre le dossier des journaux de l’application de bureau.",diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.jsonindex 4e18922c1..4d00616a4 100644--- a/webui/src/i18n/locales/id/common.json+++ b/webui/src/i18n/locales/id/common.json@@ -332,7 +332,7 @@"selectedModelValue": "Ditentukan oleh model yang dipilih.","brandLogos": "Tampilkan logo penyedia pihak ketiga dan CLI di Pengaturan.","browserNotifications": "Beri tahu hanya saat halaman ini di latar belakang. Nonaktif secara bawaan.",- "notificationSound": "Putar dentang singkat saat giliran selesai ketika halaman ini berada di latar depan. Nonaktif secara default.",+ "notificationSound": "Putar dentang singkat saat giliran selesai, meskipun halaman ini berada di latar belakang. Nonaktif secara default.","cliAppsCatalog": "Memasang alat baris perintah yang dapat digunakan nanobot di komputer ini. Aplikasi desktop tidak diubah.","cliAppsFilter": "Cari berdasarkan aplikasi, kategori, atau kemampuan.","logs": "Membuka folder log aplikasi desktop.",diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.jsonindex 085d3399d..73321583b 100644--- a/webui/src/i18n/locales/ja/common.json+++ b/webui/src/i18n/locales/ja/common.json@@ -332,7 +332,7 @@"selectedModelValue": "選択したモデルによって設定されます。","brandLogos": "設定で第三者プロバイダーと CLI のロゴを表示します。","browserNotifications": "このページがバックグラウンドにある場合のみ通知します。既定ではオフです。",- "notificationSound": "このページがフォアグラウンドにあるときにターンが完了したら短いチャイムを再生します。既定ではオフです。",+ "notificationSound": "ターンが完了したら、ページがバックグラウンドにあっても短いチャイムを再生します。既定ではオフです。","cliAppsCatalog": "nanobot がこのマシンで使用できるコマンドラインツールをインストールします。デスクトップアプリは変更しません。","cliAppsFilter": "アプリ、カテゴリ、機能で検索します。","logs": "デスクトップアプリのログフォルダーを開きます。",diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.jsonindex 39145db1e..e8782c3fc 100644--- a/webui/src/i18n/locales/ko/common.json+++ b/webui/src/i18n/locales/ko/common.json@@ -332,7 +332,7 @@"selectedModelValue": "선택한 모델에 의해 설정됩니다.","brandLogos": "설정에서 타사 제공업체와 CLI 로고를 표시합니다.","browserNotifications": "이 페이지가 백그라운드에 있을 때만 알립니다. 기본값은 꺼짐입니다.",- "notificationSound": "이 페이지가 포그라운드에 있을 때 턴이 끝나면 짧은 알림음을 재생합니다. 기본적으로 꺼져 있습니다.",+ "notificationSound": "턴이 끝나면 이 페이지가 백그라운드에 있어도 짧은 알림음을 재생합니다. 기본적으로 꺼져 있습니다.","cliAppsCatalog": "nanobot이 이 컴퓨터에서 사용할 수 있는 명령줄 도구를 설치합니다. 데스크톱 앱은 변경하지 않습니다.","cliAppsFilter": "앱, 카테고리 또는 기능으로 검색합니다.","logs": "데스크톱 앱의 로그 폴더를 엽니다.",diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.jsonindex 18c05f6b8..3203d6769 100644--- a/webui/src/i18n/locales/pt-BR/common.json+++ b/webui/src/i18n/locales/pt-BR/common.json@@ -376,7 +376,7 @@"codeWrap": "Mantém linhas longas de código legíveis em telas menores.","brandLogos": "Mostra logotipos de provedores terceiros e de CLIs em Configurações.","browserNotifications": "Notifica somente quando esta página está em segundo plano. Desativado por padrão.",- "notificationSound": "Toca um breve sinal sonoro quando um turno termina enquanto esta página está em primeiro plano. Desativado por padrão.",+ "notificationSound": "Toca um breve sinal sonoro quando um turno termina, mesmo quando esta página está em segundo plano. Desativado por padrão.","maxResults": "Número máximo de resultados por busca na web.","timeout": "Segundos antes de uma requisição de busca expirar.","jinaReader": "Usa o Jina Reader para ler páginas web quando disponível.",diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.jsonindex 279aaa98d..93d346c81 100644--- a/webui/src/i18n/locales/vi/common.json+++ b/webui/src/i18n/locales/vi/common.json@@ -332,7 +332,7 @@"selectedModelValue": "Được đặt bởi mô hình đã chọn.","brandLogos": "Hiển thị logo nhà cung cấp bên thứ ba và CLI trong Cài đặt.","browserNotifications": "Chỉ thông báo khi trang này ở nền. Mặc định tắt.",- "notificationSound": "Phát một tiếng chuông ngắn khi lượt kết thúc trong lúc trang này đang ở phía trước. Tắt theo mặc định.",+ "notificationSound": "Phát một tiếng chuông ngắn khi lượt kết thúc, ngay cả khi trang này đang ở nền. Tắt theo mặc định.","cliAppsCatalog": "Cài các công cụ dòng lệnh mà nanobot có thể dùng trên máy này. Các ứng dụng trên máy tính không bị thay đổi.","cliAppsFilter": "Tìm theo ứng dụng, danh mục hoặc khả năng.","logs": "Mở thư mục nhật ký của ứng dụng trên máy tính.",diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.jsonindex d99438e52..0e3b9d086 100644--- a/webui/src/i18n/locales/zh-CN/common.json+++ b/webui/src/i18n/locales/zh-CN/common.json@@ -562,7 +562,7 @@"codeWrap": "让长代码行在小屏幕上也易读。","brandLogos": "在设置中显示提供商和命令行应用的品牌图标。","browserNotifications": "仅在页面位于后台时通知,默认关闭。",- "notificationSound": "回合结束且页面处于前台时播放短促提示音,默认关闭。",+ "notificationSound": "回合结束时播放短促提示音,页面在后台时也会播放。默认关闭。","maxResults": "每次网络搜索最多返回多少条结果。","timeout": "每次搜索请求最长等待多久。","jinaReader": "读取网页时,优先使用可用的 Jina Reader。",diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.jsonindex 8b4cf40ba..32b82fc4a 100644--- a/webui/src/i18n/locales/zh-TW/common.json+++ b/webui/src/i18n/locales/zh-TW/common.json@@ -332,7 +332,7 @@"selectedModelValue": "由選取的模型決定。","brandLogos": "在設定中顯示第三方供應商與 CLI 圖示。","browserNotifications": "僅在頁面位於背景時通知,預設關閉。",- "notificationSound": "回合結束且頁面處於前景時播放短促提示音,預設關閉。",+ "notificationSound": "回合結束時播放短促提示音,頁面在背景時也會播放。預設關閉。","cliAppsCatalog": "安裝供 nanobot 使用的命令列工具,不會安裝或修改對應的桌面應用程式。","cliAppsFilter": "依應用程式、類別或功能搜尋。","logs": "開啟原生引擎日誌資料夾。",diff --git a/webui/src/lib/notification-sound.ts b/webui/src/lib/notification-sound.tsindex e3f405abc..ae888cbbd 100644--- a/webui/src/lib/notification-sound.ts+++ b/webui/src/lib/notification-sound.ts@@ -1,8 +1,5 @@-// The short chime played when an agent turn completes while the page is-// visible (#5524). The asset ships with the WebUI's static files; playback is-// gated by the `notificationSound` local preference — off by default — and-// by page visibility: the chime is for someone actively watching the tab, so-// a background tab stays silent (browserNotifications covers that case).+// The bundled completion chime is opt-in and plays in both foreground and+// background tabs, independently of browser notification permissions.import { readLocalPreferences } from "@/lib/local-preferences";@@ -12,7 +9,6 @@ let audio: HTMLAudioElement | null = null;export function playTurnCompleteSound(): void {try {- if (document.visibilityState !== "visible") return;if (!readLocalPreferences().notificationSound) return;if (audio === null) audio = new Audio(TURN_COMPLETE_SOUND_PATH);audio.currentTime = 0;diff --git a/webui/src/tests/notification-sound.test.ts b/webui/src/tests/notification-sound.test.tsindex 143266fa8..c4973bba1 100644--- a/webui/src/tests/notification-sound.test.ts+++ b/webui/src/tests/notification-sound.test.ts@@ -46,7 +46,8 @@ describe("playTurnCompleteSound", () => {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 () => {