diff --git a/apps/desktop/src/ipc/channels.ts b/apps/desktop/src/ipc/channels.ts index b5b3e396c98e1..7f2551c72c5a8 100644 --- a/apps/desktop/src/ipc/channels.ts +++ b/apps/desktop/src/ipc/channels.ts @@ -1,5 +1,6 @@ export const PICK_FOLDER_CHANNEL = "desktop:pick-folder"; export const SET_NOTIFICATION_BADGE_CHANNEL = "desktop:set-notification-badge"; +export const IS_SCREEN_LOCKED_CHANNEL = "desktop:is-screen-locked"; export const PICK_PROJECT_FAVICON_CHANNEL = "desktop:pick-project-favicon"; export const PICK_THEME_FILES_CHANNEL = "desktop:pick-theme-files"; export const SET_THEME_CHANNEL = "desktop:set-theme"; diff --git a/apps/desktop/src/ipc/methods/notificationBadge.ts b/apps/desktop/src/ipc/methods/notificationBadge.ts index 39eeeeeb1f308..6ee6a5d5a4bc7 100644 --- a/apps/desktop/src/ipc/methods/notificationBadge.ts +++ b/apps/desktop/src/ipc/methods/notificationBadge.ts @@ -5,7 +5,7 @@ import * as HostProcess from "@t3tools/shared/HostProcess"; import * as ElectronApp from "../../electron/ElectronApp.ts"; import * as DesktopIpc from "../DesktopIpc.ts"; -import { SET_NOTIFICATION_BADGE_CHANNEL } from "../channels.ts"; +import { IS_SCREEN_LOCKED_CHANNEL, SET_NOTIFICATION_BADGE_CHANNEL } from "../channels.ts"; const NotificationBadge = Schema.Struct({ count: Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 2_147_483_647 })), @@ -64,6 +64,15 @@ export const installNotificationBadge = Effect.fn("desktop.ipc.installNotificati }), }), ); + yield* ipc.handle( + DesktopIpc.makeIpcMethod({ + channel: IS_SCREEN_LOCKED_CHANNEL, + payload: Schema.Void, + result: Schema.Boolean, + // macOS also reports "locked" once the display sleeps behind a password. + handler: () => Effect.sync(() => Electron.powerMonitor.getSystemIdleState(1) === "locked"), + }), + ); yield* app.on("browser-window-focus", clear); yield* app.on("before-quit", clear); yield* Effect.addFinalizer(() => Effect.sync(clear)); diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts index 3f8a7952514a4..7e003109943e1 100644 --- a/apps/desktop/src/preload.ts +++ b/apps/desktop/src/preload.ts @@ -107,6 +107,7 @@ contextBridge.exposeInMainWorld("desktopBridge", { getClientPlatform: () => clientPlatform, setNotificationBadge: (badge) => ipcRenderer.invoke(IpcChannels.SET_NOTIFICATION_BADGE_CHANNEL, badge), + isScreenLocked: () => ipcRenderer.invoke(IpcChannels.IS_SCREEN_LOCKED_CHANNEL), onNotificationBadgeClear: (listener) => { const handler = () => listener(); ipcRenderer.on(IpcChannels.SET_NOTIFICATION_BADGE_CHANNEL, handler); diff --git a/apps/web/src/threadNotifications.test.ts b/apps/web/src/threadNotifications.test.ts index f48267c16f318..98e37e65c4515 100644 --- a/apps/web/src/threadNotifications.test.ts +++ b/apps/web/src/threadNotifications.test.ts @@ -101,4 +101,16 @@ describe("playNotificationSound", () => { expect(audio.started).toBe(1); }); + + it("stays quiet while the desktop screen is locked", async () => { + let locked = true; + vi.stubGlobal("window", { desktopBridge: { isScreenLocked: async () => locked } }); + const { playNotificationSound } = await loadUnlocked(); + await playNotificationSound("completion", () => true); + expect(audio.started).toBe(0); + + locked = false; + await playNotificationSound("completion", () => true); + expect(audio.started).toBe(1); + }); }); diff --git a/apps/web/src/threadNotifications.ts b/apps/web/src/threadNotifications.ts index 8784f79baceef..4e7b02ec77fb3 100644 --- a/apps/web/src/threadNotifications.ts +++ b/apps/web/src/threadNotifications.ts @@ -120,8 +120,11 @@ export async function playNotificationSound( const context = audioContext; const url = kind === "completion" ? completionUrl : inputUrl; try { - const decoded = await loadNotificationBuffer(context, url); - if (!shouldPlay() || context.state !== "running") return; + const [decoded, locked] = await Promise.all([ + loadNotificationBuffer(context, url), + globalThis.window?.desktopBridge?.isScreenLocked?.().catch(() => false) ?? false, + ]); + if (locked || !shouldPlay() || context.state !== "running") return; // Coalesce same-sound bursts after decode to avoid clipping; input and completion alerts keep separate slots. if (context.currentTime < (playingUntil.get(url) ?? 0)) return; const source = context.createBufferSource(); diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index c783337127587..2ed737adfff6d 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -1087,6 +1087,8 @@ export interface DesktopBridge { getClientPlatform: () => string; setNotificationBadge: (badge: { count: number; image: string | null }) => Promise; onNotificationBadgeClear: (listener: () => void) => () => void; + /** Whether the OS session is locked (incl. a display asleep behind a password), so notification sounds stay quiet. */ + isScreenLocked?: () => Promise; onTrackpadScrollBegin: (listener: () => void) => () => void; onTrackpadScrollEnd: (listener: () => void) => () => void; /** diff --git a/spec.md b/spec.md index af9b5ef53151a..0deab4566cd75 100644 --- a/spec.md +++ b/spec.md @@ -86,6 +86,12 @@ Where: `apps/web/src/rightPanelStore.ts`, `closedViewStore.ts` (`merge`), `compo Where: `isClaudeAmbientTaskStarted` and `handleSdkMessage` in `apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts`. Check: "does not keep the thread busy for Claude's ambient artifact watch" in `ClaudeAdapterV2.test.ts`. Upstream: pingdotgg/t3code#29331 (fixes #13978). Drop this section once upstream merges it. +## 9. Quiet while the screen is locked + +- R9.1 The desktop app MUST NOT play a thread notification sound while the OS session is locked. On macOS this includes a display asleep behind a password. Desktop notifications and the badge are unchanged. Web and mobile are unchanged (a browser cannot see the lock). + +Where: `IS_SCREEN_LOCKED_CHANNEL` in `apps/desktop/src/ipc/methods/notificationBadge.ts` (`powerMonitor.getSystemIdleState(1) === "locked"`), `isScreenLocked` on the desktop bridge, checked in `playNotificationSound` (`apps/web/src/threadNotifications.ts`). Check: "stays quiet while the desktop screen is locked" in `threadNotifications.test.ts`. + ## Dropped - Claude Code mod UI (pingdotgg/t3code#15827, #17432). Upstream closed both, and this fork dropped them at 0.1.4.