feat: add custom sound for notification so it works for Linux too

This commit is contained in:
Audric Ackermann 2022-10-07 12:04:59 +11:00
parent c4fcac7ddf
commit 4271e66fb6
4 changed files with 12 additions and 3 deletions

BIN
sound/new_message.mp3 Normal file

Binary file not shown.

View File

@ -63,7 +63,7 @@ describe('Settings', () => {
});
it('should return true', () => {
assert.isFalse(Settings.isAudioNotificationSupported());
assert.isTrue(Settings.isAudioNotificationSupported());
});
});
});

View File

@ -2,7 +2,8 @@ import * as OS from '../OS';
const MIN_WINDOWS_VERSION = '8.0.0';
export const isAudioNotificationSupported = () => OS.isWindows(MIN_WINDOWS_VERSION) || OS.isMacOS(); // currently, only linux does not support audio notification natively
export const isAudioNotificationSupported = () =>
OS.isWindows(MIN_WINDOWS_VERSION) || OS.isMacOS() || OS.isLinux();
// Using `Notification::tag` has a bug on Windows 7:
// https://github.com/electron/electron/issues/11189

View File

@ -22,6 +22,8 @@ function filter(text?: string) {
.replace(/>/g, '>');
}
let sound: any;
export type SessionNotification = {
conversationId: string;
iconUrl: string | null;
@ -218,10 +220,16 @@ function update(forceRefresh = false) {
}
window.drawAttention();
if (status.shouldPlayNotificationSound) {
if (!sound) {
sound = new Audio('sound/new_message.mp3');
}
void sound.play();
}
lastNotificationDisplayed = new Notification(title || '', {
body: window.platform === 'linux' ? filter(message) : message,
icon: iconUrl || undefined,
silent: !status.shouldPlayNotificationSound,
silent: true,
});
lastNotificationDisplayed.onclick = () => {
window.openFromNotification(lastNotification.conversationId);