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
19 changes: 19 additions & 0 deletions plugins/push-notifications/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ afterEach(() => {
});

describe("client system notifications", () => {
it.each([
{ platform: "macos", icon: undefined },
{ platform: "linux", icon: "http://localhost:3000/icon-192.png" },
{ platform: "web", icon: "http://localhost:3000/icon-192.png" },
])(
"uses the appropriate notification icon on $platform",
async ({ platform, icon }) => {
if (platform !== "web") vi.stubGlobal("bbDesktop", { platform });
const delivery = createClientDelivery(vi.fn());
await delivery.deliver(
{ ...message, channels: [platform === "web" ? "web" : "desktop"] },
true,
);
expect(TestNotification.instances).toHaveLength(1);
expect(TestNotification.instances[0]?.options.icon).toBe(icon);
delivery.dispose();
},
);

it("deduplicates windows, navigates on click, and cleans up on disposal", async () => {
const navigate = vi.fn();
const first = createClientDelivery(navigate);
Expand Down
10 changes: 9 additions & 1 deletion plugins/push-notifications/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ export function createClientDelivery(navigate: (threadId: string) => void) {

function display(message: ClientNotification): void {
if (disposed || notificationPermission() !== "granted") return;
const isMacDesktop =
"bbDesktop" in window &&
typeof window.bbDesktop === "object" &&
window.bbDesktop !== null &&
"platform" in window.bbDesktop &&
window.bbDesktop.platform === "macos";
const notification = new Notification(message.title, {
body: message.body,
icon: new URL("/icon-192.png", window.location.origin).href,
...(isMacDesktop
? {}
: { icon: new URL("/icon-192.png", window.location.origin).href }),
tag: `bb-${message.threadId ?? message.id}`,
});
active.add(notification);
Expand Down
Loading