Skip to content

Commit c61cbfb

Browse files
authored
fix: Mac desktop notification sounds overlapping with our custom sounds (#766)
1 parent 93554ad commit c61cbfb

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

apps/twig/src/main/services/notification/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export class NotificationService {
1414
log.info("Notification service initialized");
1515
}
1616

17-
send(title: string, body: string): void {
17+
send(title: string, body: string, silent: boolean): void {
1818
if (!Notification.isSupported()) {
1919
log.warn("Notifications not supported on this platform");
2020
return;
2121
}
2222

23-
const notification = new Notification({ title, body });
23+
const notification = new Notification({ title, body, silent });
2424
notification.show();
25-
log.info("Notification sent", { title, body });
25+
log.info("Notification sent", { title, body, silent });
2626
}
2727

2828
showDockBadge(): void {

apps/twig/src/main/trpc/routers/notification.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ const getService = () =>
99

1010
export const notificationRouter = router({
1111
send: publicProcedure
12-
.input(z.object({ title: z.string(), body: z.string() }))
13-
.mutation(({ input }) => getService().send(input.title, input.body)),
12+
.input(
13+
z.object({
14+
title: z.string(),
15+
body: z.string(),
16+
silent: z.boolean(),
17+
}),
18+
)
19+
.mutation(({ input }) =>
20+
getService().send(input.title, input.body, input.silent),
21+
),
1422
showDockBadge: publicProcedure.mutation(() => getService().showDockBadge()),
1523
});

apps/twig/src/renderer/lib/notifications.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ function truncateTitle(title: string): string {
1212
return `${title.slice(0, MAX_TITLE_LENGTH)}...`;
1313
}
1414

15-
function sendDesktopNotification(title: string, body: string): void {
16-
trpcVanilla.notification.send.mutate({ title, body }).catch((err) => {
15+
function sendDesktopNotification(
16+
title: string,
17+
body: string,
18+
silent: boolean,
19+
): void {
20+
trpcVanilla.notification.send.mutate({ title, body, silent }).catch((err) => {
1721
log.error("Failed to send notification", err);
1822
});
1923
}
@@ -40,26 +44,39 @@ export function notifyPromptComplete(
4044
const isWindowFocused = document.hasFocus();
4145
if (isWindowFocused) return;
4246

47+
const willPlayCustomSound = completionSound !== "none";
4348
playCompletionSound(completionSound, completionVolume);
4449

4550
if (desktopNotifications) {
46-
sendDesktopNotification("Twig", `"${truncateTitle(taskTitle)}" finished`);
51+
sendDesktopNotification(
52+
"Twig",
53+
`"${truncateTitle(taskTitle)}" finished`,
54+
willPlayCustomSound,
55+
);
4756
}
4857
if (dockBadgeNotifications) {
4958
showDockBadge();
5059
}
5160
}
5261

5362
export function notifyPermissionRequest(taskTitle: string): void {
54-
const { desktopNotifications, dockBadgeNotifications } =
55-
useSettingsStore.getState();
63+
const {
64+
completionSound,
65+
completionVolume,
66+
desktopNotifications,
67+
dockBadgeNotifications,
68+
} = useSettingsStore.getState();
5669
const isWindowFocused = document.hasFocus();
5770

5871
if (!isWindowFocused) {
72+
const willPlayCustomSound = completionSound !== "none";
73+
playCompletionSound(completionSound, completionVolume);
74+
5975
if (desktopNotifications) {
6076
sendDesktopNotification(
6177
"Twig",
6278
`"${truncateTitle(taskTitle)}" needs your input`,
79+
willPlayCustomSound,
6380
);
6481
}
6582
if (dockBadgeNotifications) {

0 commit comments

Comments
 (0)