Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const state = vi.hoisted(() => ({
active: { environmentId: "env-1", threadId: "other-thread" },
focused: true,
visible: "visible",
platform: "MacIntel",
live: true,
completedAt: null as string | null,
archivedAt: null as string | null,
Expand Down Expand Up @@ -160,6 +161,7 @@ function setup() {
active: { environmentId: "env-1", threadId: "other-thread" },
focused: true,
visible: "visible",
platform: "MacIntel",
live: true,
completedAt: null,
archivedAt: null,
Expand All @@ -180,6 +182,9 @@ function setup() {
.mockImplementation(() => state.visible as DocumentVisibilityState),
);
stack.use(vi.spyOn(document, "hasFocus").mockImplementation(() => state.focused));
stack.use(
vi.spyOn(Navigator.prototype, "platform", "get").mockImplementation(() => state.platform),
);
stack.use(
stubGlobal("Notification", Object.assign(state.notification, { permission: "granted" })),
);
Expand Down Expand Up @@ -290,6 +295,7 @@ describe("thread notifications", () => {
body: "Fix the login form",
tag: expect.any(String),
silent: true,
requireInteraction: false,
});
});

Expand Down Expand Up @@ -370,9 +376,37 @@ describe("thread notifications", () => {
body: "Fix the login form",
tag: expect.any(String),
silent: true,
requireInteraction: false,
});
});

it("keeps Windows completion alerts on screen so a click still reaches the app", async () => {
await using app = setup();
state.mode = "notifications";
state.focused = false;
state.platform = "Win32";
await app.render();
await app.complete();
expect(state.notification).toHaveBeenCalledWith(
"Thread completed",
expect.objectContaining({ requireInteraction: true }),
);
});

it("lets Windows attention alerts time out since another client may resolve them", async () => {
await using app = setup();
state.mode = "notifications";
state.focused = false;
state.platform = "Win32";
await app.render();
state.input = true;
await app.render();
expect(state.notification).toHaveBeenCalledWith(
"Input needed",
expect.objectContaining({ requireInteraction: false }),
);
});

it("reveals the desktop window and opens the thread when a system alert is clicked", async () => {
await using app = setup();
const revealWindow = vi.fn(() => Promise.resolve());
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/components/ThreadNotificationCoordinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { useEffect, useRef } from "react";

import { getClientSettings, useClientSettings } from "../hooks/useSettings";
import { isWindowsPlatform } from "../lib/utils";
import { useEnvironmentIds } from "../state/environments";
import { environmentShell } from "../state/shell";
import {
Expand Down Expand Up @@ -221,6 +222,10 @@ function EnvironmentNotifications({
body: thread.title,
tag: threadNotificationTag(environmentId, thread.id),
silent: true,
// Windows drops clicks once a toast times out into Notification Center, so keep
// completions on screen until clicked or cleared on focus. Attention alerts still time
// out because another client can resolve them while this window stays unfocused.
requireInteraction: kind === "completion" && isWindowsPlatform(navigator.platform),
});
onNotification(environmentId, notification);
notification.addEventListener("click", () => {
Expand Down
Loading