mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-28 23:05:54 +00:00
Put sound notifications in SMAudio
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'External/User/ko';
|
||||
|
||||
import { SMAudio } from 'Common/Audio';
|
||||
import { isArray, pString, changeTheme } from 'Common/Utils';
|
||||
import { mailToHelper, setLayoutResizer, dropdownsDetectVisibility } from 'Common/UtilsUser';
|
||||
|
||||
@@ -289,8 +290,8 @@ export class AppUser extends AbstractApp {
|
||||
if (SettingsGet('Auth')) {
|
||||
rl.setWindowTitle(i18n('GLOBAL/LOADING'));
|
||||
|
||||
NotificationUserStore.enableSoundNotification(!!SettingsGet('SoundNotification'));
|
||||
NotificationUserStore.enableDesktopNotification(!!SettingsGet('DesktopNotifications'));
|
||||
SMAudio.notifications(!!SettingsGet('SoundNotification'));
|
||||
NotificationUserStore.enabled(!!SettingsGet('DesktopNotifications'));
|
||||
|
||||
AccountUserStore.email(SettingsGet('Email'));
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as Links from 'Common/Links';
|
||||
import { doc, SettingsGet, fireEvent, addEventsListener } from 'Common/Globals';
|
||||
import { addObservablesTo } from 'External/ko';
|
||||
|
||||
let notificator = null,
|
||||
player = null,
|
||||
@@ -50,7 +51,7 @@ let notificator = null,
|
||||
audioCtx.resume();
|
||||
}
|
||||
unlockEvents.forEach(type => doc.removeEventListener(type, unlock, true));
|
||||
// setTimeout(()=>Audio.playNotification(1),1);
|
||||
// setTimeout(()=>SMAudio.playNotification(0,1),1);
|
||||
};
|
||||
|
||||
if (audioCtx) {
|
||||
@@ -76,6 +77,10 @@ export const SMAudio = new class {
|
||||
addEventsListener(player, ['ended','error'], stopFn);
|
||||
addEventListener('audio.api.stop', stopFn);
|
||||
}
|
||||
|
||||
addObservablesTo(this, {
|
||||
notifications: false
|
||||
});
|
||||
}
|
||||
|
||||
paused() {
|
||||
@@ -103,18 +108,23 @@ export const SMAudio = new class {
|
||||
this.supportedWav && play(url, name);
|
||||
}
|
||||
|
||||
playNotification(silent) {
|
||||
if ('running' == audioCtx.state && (this.supportedMp3 || this.supportedOgg)) {
|
||||
notificator = notificator || createNewObject();
|
||||
if (notificator) {
|
||||
notificator.src = Links.staticLink('sounds/'
|
||||
+ SettingsGet('NotificationSound')
|
||||
+ (this.supportedMp3 ? '.mp3' : '.ogg'));
|
||||
notificator.volume = silent ? 0.01 : 1;
|
||||
notificator.play();
|
||||
/**
|
||||
* Used with SoundNotification setting
|
||||
*/
|
||||
playNotification(force, silent) {
|
||||
if (force || this.notifications()) {
|
||||
if ('running' == audioCtx.state && (this.supportedMp3 || this.supportedOgg)) {
|
||||
notificator = notificator || createNewObject();
|
||||
if (notificator) {
|
||||
notificator.src = Links.staticLink('sounds/'
|
||||
+ SettingsGet('NotificationSound')
|
||||
+ (this.supportedMp3 ? '.mp3' : '.ogg'));
|
||||
notificator.volume = silent ? 0.01 : 1;
|
||||
notificator.play();
|
||||
}
|
||||
} else {
|
||||
console.log('No audio: ' + audioCtx.state);
|
||||
}
|
||||
} else {
|
||||
console.log('No audio: ' + audioCtx.state);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import ko from 'ko';
|
||||
|
||||
import { SMAudio } from 'Common/Audio';
|
||||
import { SaveSettingsStep } from 'Common/Enums';
|
||||
import { EditorDefaultType, Layout } from 'Common/EnumsUser';
|
||||
import { Settings, SettingsGet } from 'Common/Globals';
|
||||
@@ -35,12 +36,12 @@ export class UserSettingsGeneral extends AbstractViewSettings {
|
||||
this.editorDefaultType = SettingsUserStore.editorDefaultType;
|
||||
this.layout = SettingsUserStore.layout;
|
||||
|
||||
this.soundNotification = NotificationUserStore.enableSoundNotification;
|
||||
this.soundNotification = SMAudio.notifications;
|
||||
this.notificationSound = ko.observable(SettingsGet('NotificationSound'));
|
||||
this.notificationSounds = ko.observableArray(SettingsGet('NewMailSounds'));
|
||||
|
||||
this.desktopNotification = NotificationUserStore.enableDesktopNotification;
|
||||
this.isDesktopNotificationAllowed = NotificationUserStore.isDesktopNotificationAllowed;
|
||||
this.desktopNotification = NotificationUserStore.enabled;
|
||||
this.isDesktopNotificationAllowed = NotificationUserStore.allowed;
|
||||
|
||||
this.viewHTML = SettingsUserStore.viewHTML;
|
||||
this.showImages = SettingsUserStore.showImages;
|
||||
@@ -133,11 +134,11 @@ export class UserSettingsGeneral extends AbstractViewSettings {
|
||||
}
|
||||
|
||||
testSoundNotification() {
|
||||
NotificationUserStore.playSoundNotification(true);
|
||||
SMAudio.playNotification(true);
|
||||
}
|
||||
|
||||
testSystemNotification() {
|
||||
NotificationUserStore.displayDesktopNotification('SnappyMail', 'Test notification');
|
||||
NotificationUserStore.display('SnappyMail', 'Test notification');
|
||||
}
|
||||
|
||||
selectLanguage() {
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user