Skip to content

Commit 0eebe80

Browse files
committed
Fix mac desktop notification sounds overlapping with our custom sounds
1 parent 93554ad commit 0eebe80

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

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 = false): 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().optional().default(false),
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: 12 additions & 3 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 = false,
19+
): void {
20+
trpcVanilla.notification.send.mutate({ title, body, silent }).catch((err) => {
1721
log.error("Failed to send notification", err);
1822
});
1923
}
@@ -40,10 +44,15 @@ export function notifyPromptComplete(
4044
const isWindowFocused = document.hasFocus();
4145
if (isWindowFocused) return;
4246

47+
const hasCustomSound = 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+
hasCustomSound,
55+
);
4756
}
4857
if (dockBadgeNotifications) {
4958
showDockBadge();

0 commit comments

Comments
 (0)