Put sound notifications in SMAudio

This commit is contained in:
the-djmaze 2022-06-07 18:46:06 +02:00
parent 78a3b1a5be
commit df80ff9533
5 changed files with 40 additions and 40 deletions

View file

@ -1,5 +1,6 @@
import { koComputable } from 'External/ko';
import { SMAudio } from 'Common/Audio';
import { Notification } from 'Common/Enums';
import { MessageSetAction } from 'Common/EnumsUser';
import { $htmlCL } from 'Common/Globals';
@ -114,11 +115,11 @@ MessagelistUserStore.hasCheckedOrSelected = koComputable(() =>
MessagelistUserStore.notifyNewMessages = (folder, newMessages) => {
if (getFolderInboxName() === folder && arrayLength(newMessages)) {
NotificationUserStore.playSoundNotification();
SMAudio.playNotification();
const len = newMessages.length;
if (3 < len) {
NotificationUserStore.displayDesktopNotification(
NotificationUserStore.display(
AccountUserStore.email(),
i18n('MESSAGE_LIST/NEW_MESSAGE_NOTIFICATION', {
COUNT: len
@ -127,7 +128,7 @@ MessagelistUserStore.notifyNewMessages = (folder, newMessages) => {
);
} else {
newMessages.forEach(item => {
NotificationUserStore.displayDesktopNotification(
NotificationUserStore.display(
EmailCollectionModel.reviveFromJson(item.From).toString(),
item.subject,
{ Folder: item.Folder, Uid: item.Uid }

View file

@ -1,4 +1,3 @@
import { SMAudio } from 'Common/Audio';
import * as Links from 'Common/Links';
import { addObservablesTo } from 'External/ko';
import { fireEvent } from 'Common/Globals';
@ -37,36 +36,24 @@ if (WorkerNotifications && ServiceWorkerRegistration && ServiceWorkerRegistratio
export const NotificationUserStore = new class {
constructor() {
addObservablesTo(this, {
enableSoundNotification: false,
enableDesktopNotification: false,/*.extend({ notify: 'always' })*/
isDesktopNotificationAllowed: !NotificationsDenied()
enabled: false,/*.extend({ notify: 'always' })*/
allowed: !NotificationsDenied()
});
this.enableDesktopNotification.subscribe(value => {
this.enabled.subscribe(value => {
DesktopNotifications = !!value;
if (value && HTML5Notification && !NotificationsGranted()) {
HTML5Notification.requestPermission(() =>
this.isDesktopNotificationAllowed(!NotificationsDenied())
this.allowed(!NotificationsDenied())
);
}
});
}
/**
* Used with SoundNotification setting
*/
playSoundNotification(skipSetting) {
if (skipSetting ? true : this.enableSoundNotification()) {
SMAudio.playNotification();
}
}
/**
* Used with DesktopNotifications setting
*/
displayDesktopNotification(title, text, messageData, imageSrc) {
display(title, text, messageData, imageSrc) {
if (DesktopNotifications && NotificationsGranted()) {
const options = {
body: text,