Skip to content

Commit 4271e66

Browse files
committed
feat: add custom sound for notification so it works for Linux too
1 parent c4fcac7 commit 4271e66

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

sound/new_message.mp3

43.5 KB
Binary file not shown.

ts/test/types/Settings_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('Settings', () => {
6363
});
6464

6565
it('should return true', () => {
66-
assert.isFalse(Settings.isAudioNotificationSupported());
66+
assert.isTrue(Settings.isAudioNotificationSupported());
6767
});
6868
});
6969
});

ts/types/Settings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as OS from '../OS';
22

33
const MIN_WINDOWS_VERSION = '8.0.0';
44

5-
export const isAudioNotificationSupported = () => OS.isWindows(MIN_WINDOWS_VERSION) || OS.isMacOS(); // currently, only linux does not support audio notification natively
5+
export const isAudioNotificationSupported = () =>
6+
OS.isWindows(MIN_WINDOWS_VERSION) || OS.isMacOS() || OS.isLinux();
67

78
// Using `Notification::tag` has a bug on Windows 7:
89
// https://github.com/electron/electron/issues/11189

ts/util/notifications.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function filter(text?: string) {
2222
.replace(/>/g, '>');
2323
}
2424

25+
let sound: any;
26+
2527
export type SessionNotification = {
2628
conversationId: string;
2729
iconUrl: string | null;
@@ -218,10 +220,16 @@ function update(forceRefresh = false) {
218220
}
219221

220222
window.drawAttention();
223+
if (status.shouldPlayNotificationSound) {
224+
if (!sound) {
225+
sound = new Audio('sound/new_message.mp3');
226+
}
227+
void sound.play();
228+
}
221229
lastNotificationDisplayed = new Notification(title || '', {
222230
body: window.platform === 'linux' ? filter(message) : message,
223231
icon: iconUrl || undefined,
224-
silent: !status.shouldPlayNotificationSound,
232+
silent: true,
225233
});
226234
lastNotificationDisplayed.onclick = () => {
227235
window.openFromNotification(lastNotification.conversationId);

0 commit comments

Comments
 (0)