Custom new mail notification sounds

This commit is contained in:
djmaze 2021-07-21 11:19:52 +02:00
parent ee540097b4
commit 7ab832e854
9 changed files with 20 additions and 5 deletions

BIN
assets/sounds/alert.mp3 Normal file

Binary file not shown.

BIN
assets/sounds/alert.ogg Normal file

Binary file not shown.

BIN
assets/sounds/ping.mp3 Normal file

Binary file not shown.

BIN
assets/sounds/ping.ogg Normal file

Binary file not shown.

View file

@ -1,5 +1,5 @@
import * as Links from 'Common/Links';
import { doc } from 'Common/Globals';
import { doc, SettingsGet } from 'Common/Globals';
let notificator = null,
player = null,
@ -106,11 +106,11 @@ export const SMAudio = new class {
playNotification(silent) {
if ('running' == audioCtx.state && (this.supportedMp3 || this.supportedOgg)) {
if (!notificator) {
notificator = createNewObject();
notificator.src = Links.staticLink('sounds/new-mail.'+ (this.supportedMp3 ? 'mp3' : 'ogg'));
}
notificator = notificator || createNewObject();
if (notificator) {
notificator.src = Links.staticLink('sounds/'
+ SettingsGet('NotificationSound')
+ (this.supportedMp3 ? '.mp3' : '.ogg'));
notificator.volume = silent ? 0.01 : 1;
notificator.play();
}

View file

@ -32,6 +32,8 @@ export class GeneralUserSettings {
this.layout = SettingsUserStore.layout;
this.enableSoundNotification = NotificationUserStore.enableSoundNotification;
this.notificationSound = ko.observable(SettingsGet('NotificationSound'));
this.notificationSounds = ko.observableArray(SettingsGet('NewMailSounds'));
this.enableDesktopNotification = NotificationUserStore.enableDesktopNotification;
this.isDesktopNotificationDenied = NotificationUserStore.isDesktopNotificationDenied;
@ -115,6 +117,10 @@ export class GeneralUserSettings {
enableDesktopNotification: value => Remote.saveSetting('DesktopNotifications', value ? 1 : 0),
enableSoundNotification: value => Remote.saveSetting('SoundNotification', value ? 1 : 0),
notificationSound: value => {
Remote.saveSetting('NotificationSound', value);
rl.settings.set('NotificationSound', value);
},
replySameFolder: value => Remote.saveSetting('ReplySameFolder', value ? 1 : 0),

View file

@ -1060,6 +1060,7 @@ class Actions
'RemoveColors' => (bool) $oConfig->Get('defaults', 'remove_colors', false),
'MPP' => (int) $oConfig->Get('webmail', 'messages_per_page', 25),
'SoundNotification' => false,
'NotificationSound' => 'new-mail',
'DesktopNotifications' => false,
'Layout' => (int) $oConfig->Get('defaults', 'view_layout', Enumerations\Layout::SIDE_PREVIEW),
'EditorDefaultType' => (string) $oConfig->Get('defaults', 'view_editor_type', ''),
@ -1165,6 +1166,7 @@ class Actions
$aResult['ContactsAutosave'] = (bool)$oSettings->GetConf('ContactsAutosave', $aResult['ContactsAutosave']);
$aResult['MPP'] = (int)$oSettings->GetConf('MPP', $aResult['MPP']);
$aResult['SoundNotification'] = (bool)$oSettings->GetConf('SoundNotification', $aResult['SoundNotification']);
$aResult['NotificationSound'] = (string)$oSettings->GetConf('NotificationSound', $aResult['NotificationSound']);
$aResult['DesktopNotifications'] = (bool)$oSettings->GetConf('DesktopNotifications', $aResult['DesktopNotifications']);
$aResult['UseCheckboxesInList'] = (bool)$oSettings->GetConf('UseCheckboxesInList', $aResult['UseCheckboxesInList']);
$aResult['AllowDraftAutosave'] = (bool)$oSettings->GetConf('AllowDraftAutosave', $aResult['AllowDraftAutosave']);
@ -1186,6 +1188,10 @@ class Actions
$aResult['ReplySameFolder'] = (bool)$oSettingsLocal->GetConf('ReplySameFolder', $aResult['ReplySameFolder']);
}
}
$aResult['NewMailSounds'] = [];
foreach (\glob(APP_VERSION_ROOT_PATH.'static/sounds/*.mp3') as $file) {
$aResult['NewMailSounds'][] = \basename($file, '.mp3');
}
}
else {
if ($oConfig->Get('login', 'allow_languages_on_login', true)

View file

@ -347,6 +347,7 @@ trait User
$this->setSettingsFromParams($oSettings, 'ContactsAutosave', 'bool');
$this->setSettingsFromParams($oSettings, 'DesktopNotifications', 'bool');
$this->setSettingsFromParams($oSettings, 'SoundNotification', 'bool');
$this->setSettingsFromParams($oSettings, 'NotificationSound', 'string');
$this->setSettingsFromParams($oSettings, 'UseCheckboxesInList', 'bool');
$this->setSettingsFromParams($oSettings, 'AllowDraftAutosave', 'bool');
$this->setSettingsFromParams($oSettings, 'AutoLogout', 'int');

View file

@ -132,6 +132,8 @@
}
}"></div>
&nbsp;
<select data-bind="options: notificationSounds, value: notificationSound"></select>
&nbsp;
<span class="fontastic" data-bind="click: testSoundNotification" style="color:green;cursor:pointer">▶️</span>
</div>
</div>