Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/desktop/src/ipc/channels.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
11 changes: 10 additions & 1 deletion apps/desktop/src/ipc/methods/notificationBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })),
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/threadNotifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
7 changes: 5 additions & 2 deletions apps/web/src/threadNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ export interface DesktopBridge {
getClientPlatform: () => string;
setNotificationBadge: (badge: { count: number; image: string | null }) => Promise<void>;
onNotificationBadgeClear: (listener: () => void) => () => void;
/** Whether the OS session is locked (incl. a display asleep behind a password), so notification sounds stay quiet. */
isScreenLocked?: () => Promise<boolean>;
onTrackpadScrollBegin: (listener: () => void) => () => void;
onTrackpadScrollEnd: (listener: () => void) => () => void;
/**
Expand Down
6 changes: 6 additions & 0 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading