Merge pull request #2534 from Bilb/add-settings-audio-notifications

Add support for audio notifications Windows/MacOS/Linux
pull/2550/head
Audric Ackermann 3 years ago committed by GitHub
commit 74b706d121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -358,6 +358,7 @@
"appearanceSettingsTitle": "Appearance", "appearanceSettingsTitle": "Appearance",
"privacySettingsTitle": "Privacy", "privacySettingsTitle": "Privacy",
"notificationsSettingsTitle": "Notifications", "notificationsSettingsTitle": "Notifications",
"audioNotificationsSettingsTitle": "Audio Notifications",
"notificationsSettingsContent": "Notification Content", "notificationsSettingsContent": "Notification Content",
"notificationPreview": "Preview", "notificationPreview": "Preview",
"recoveryPhraseEmpty": "Enter your recovery phrase", "recoveryPhraseEmpty": "Enter your recovery phrase",

Binary file not shown.

@ -3,6 +3,7 @@ import React from 'react';
import useUpdate from 'react-use/lib/useUpdate'; import useUpdate from 'react-use/lib/useUpdate';
import styled from 'styled-components'; import styled from 'styled-components';
import { SettingsKey } from '../../data/settings-key'; import { SettingsKey } from '../../data/settings-key';
import { isAudioNotificationSupported } from '../../types/Settings';
import { Notifications } from '../../util/notifications'; import { Notifications } from '../../util/notifications';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
import { SessionRadioGroup } from '../basic/SessionRadioGroup'; import { SessionRadioGroup } from '../basic/SessionRadioGroup';
@ -30,10 +31,15 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean |
if (props.hasPassword === null) { if (props.hasPassword === null) {
return null; return null;
} }
const initialItem =
const initialNotificationEnabled =
window.getSettingValue(SettingsKey.settingsNotification) || NOTIFICATION.MESSAGE; window.getSettingValue(SettingsKey.settingsNotification) || NOTIFICATION.MESSAGE;
const notificationsAreEnabled = initialItem && initialItem !== NOTIFICATION.OFF; const initialAudioNotificationEnabled =
window.getSettingValue(SettingsKey.settingsAudioNotification) || false;
const notificationsAreEnabled =
initialNotificationEnabled && initialNotificationEnabled !== NOTIFICATION.OFF;
const items = [ const items = [
{ {
@ -58,7 +64,7 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean |
{ {
conversationId: `preview-notification-${Date.now()}`, conversationId: `preview-notification-${Date.now()}`,
message: message:
items.find(m => m.value === initialItem)?.label || items.find(m => m.value === initialNotificationEnabled)?.label ||
window?.i18n?.('messageBody') || window?.i18n?.('messageBody') ||
'Message body', 'Message body',
title: window.i18n('notificationPreview'), title: window.i18n('notificationPreview'),
@ -83,6 +89,19 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean |
title={window.i18n('notificationsSettingsTitle')} title={window.i18n('notificationsSettingsTitle')}
active={notificationsAreEnabled} active={notificationsAreEnabled}
/> />
{notificationsAreEnabled && isAudioNotificationSupported() && (
<SessionToggleWithDescription
onClickToggle={async () => {
await window.setSettingValue(
SettingsKey.settingsAudioNotification,
!initialAudioNotificationEnabled
);
forceUpdate();
}}
title={window.i18n('audioNotificationsSettingsTitle')}
active={initialAudioNotificationEnabled}
/>
)}
{notificationsAreEnabled ? ( {notificationsAreEnabled ? (
<SessionSettingsItemWrapper <SessionSettingsItemWrapper
title={window.i18n('notificationsSettingsContent')} title={window.i18n('notificationsSettingsContent')}
@ -90,7 +109,7 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean |
inline={false} inline={false}
> >
<SessionRadioGroup <SessionRadioGroup
initialItem={initialItem} initialItem={initialNotificationEnabled}
group={SettingsKey.settingsNotification} group={SettingsKey.settingsNotification}
items={items} items={items}
onClick={async (selectedRadioValue: string) => { onClick={async (selectedRadioValue: string) => {

@ -8,6 +8,7 @@ const settingsLinkPreview = 'link-preview-setting';
const settingsStartInTray = 'start-in-tray-setting'; const settingsStartInTray = 'start-in-tray-setting';
const settingsOpengroupPruning = 'prune-setting'; const settingsOpengroupPruning = 'prune-setting';
const settingsNotification = 'notification-setting'; const settingsNotification = 'notification-setting';
const settingsAudioNotification = 'audio-notification-setting';
export const SettingsKey = { export const SettingsKey = {
settingsReadReceipt, settingsReadReceipt,
@ -19,4 +20,5 @@ export const SettingsKey = {
settingsStartInTray, settingsStartInTray,
settingsOpengroupPruning, settingsOpengroupPruning,
settingsNotification, settingsNotification,
settingsAudioNotification,
}; };

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

@ -118,6 +118,7 @@ export type LocalizerKeys =
| 'appMenuUnhide' | 'appMenuUnhide'
| 'timerOption_30_minutes_abbreviated' | 'timerOption_30_minutes_abbreviated'
| 'pruneSettingDescription' | 'pruneSettingDescription'
| 'audioNotificationsSettingsTitle'
| 'voiceMessage' | 'voiceMessage'
| 'primaryColorPink' | 'primaryColorPink'
| 'changePasswordTitle' | 'changePasswordTitle'

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

@ -1,4 +1,5 @@
import { debounce, last } from 'lodash'; import { debounce, last } from 'lodash';
import { SettingsKey } from '../data/settings-key';
import { getStatus } from '../notifications'; import { getStatus } from '../notifications';
import { UserSetting } from '../notifications/getStatus'; import { UserSetting } from '../notifications/getStatus';
import { isMacOS } from '../OS'; import { isMacOS } from '../OS';
@ -21,6 +22,8 @@ function filter(text?: string) {
.replace(/>/g, '&gt;'); .replace(/>/g, '&gt;');
} }
let sound: any;
export type SessionNotification = { export type SessionNotification = {
conversationId: string; conversationId: string;
iconUrl: string | null; iconUrl: string | null;
@ -117,7 +120,8 @@ function update(forceRefresh = false) {
} }
const isAppFocused = isWindowFocused(); const isAppFocused = isWindowFocused();
const isAudioNotificationEnabled = (Storage.get('audio-notification') as boolean) || false; const isAudioNotificationEnabled =
(Storage.get(SettingsKey.settingsAudioNotification) as boolean) || false;
const audioNotificationSupported = isAudioNotificationSupported(); const audioNotificationSupported = isAudioNotificationSupported();
// const isNotificationGroupingSupported = Settings.isNotificationGroupingSupported(); // const isNotificationGroupingSupported = Settings.isNotificationGroupingSupported();
const numNotifications = currentNotifications.length; const numNotifications = currentNotifications.length;
@ -216,10 +220,16 @@ function update(forceRefresh = false) {
} }
window.drawAttention(); window.drawAttention();
if (status.shouldPlayNotificationSound) {
if (!sound) {
sound = new Audio('sound/new_message.mp3');
}
void sound.play();
}
lastNotificationDisplayed = new Notification(title || '', { lastNotificationDisplayed = new Notification(title || '', {
body: window.platform === 'linux' ? filter(message) : message, body: window.platform === 'linux' ? filter(message) : message,
icon: iconUrl || undefined, icon: iconUrl || undefined,
silent: !status.shouldPlayNotificationSound, silent: true,
}); });
lastNotificationDisplayed.onclick = () => { lastNotificationDisplayed.onclick = () => {
window.openFromNotification(lastNotification.conversationId); window.openFromNotification(lastNotification.conversationId);

Loading…
Cancel
Save