mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 14:37:02 +03:00
Sound notification
Additional code refactoring
This commit is contained in:
parent
b42ce01e7e
commit
aa84077ac4
87 changed files with 1573 additions and 574 deletions
57
dev/Stores/User/App.js
Normal file
57
dev/Stores/User/App.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Globals = require('Common/Globals'),
|
||||
|
||||
Settings = require('Storage/Settings')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function AppUserStore()
|
||||
{
|
||||
// same
|
||||
this.allowLanguagesOnSettings = ko.observable(true);
|
||||
this.allowLanguagesOnLogin = ko.observable(true);
|
||||
// ----
|
||||
|
||||
this.contactsAutosave = ko.observable(false);
|
||||
this.useLocalProxyForExternalImages = ko.observable(false);
|
||||
|
||||
this.contactsIsAllowed = ko.observable(false);
|
||||
|
||||
this.interfaceAnimation = ko.observable(true);
|
||||
|
||||
this.interfaceAnimation.subscribe(function (bValue) {
|
||||
if (Globals.bMobileDevice || !bValue)
|
||||
{
|
||||
Globals.$html.removeClass('rl-anim').addClass('no-rl-anim');
|
||||
}
|
||||
else
|
||||
{
|
||||
Globals.$html.removeClass('no-rl-anim').addClass('rl-anim');
|
||||
}
|
||||
});
|
||||
|
||||
this.interfaceAnimation.valueHasMutated();
|
||||
}
|
||||
|
||||
AppUserStore.prototype.populate = function()
|
||||
{
|
||||
this.allowLanguagesOnLogin(!!Settings.settingsGet('AllowLanguagesOnLogin'));
|
||||
this.allowLanguagesOnSettings(!!Settings.settingsGet('AllowLanguagesOnSettings'));
|
||||
|
||||
this.useLocalProxyForExternalImages(!!Settings.settingsGet('UseLocalProxyForExternalImages'));
|
||||
this.contactsIsAllowed(!!Settings.settingsGet('ContactsIsAllowed'));
|
||||
this.interfaceAnimation(!!Settings.settingsGet('InterfaceAnimation'));
|
||||
};
|
||||
|
||||
module.exports = new AppUserStore();
|
||||
|
||||
}());
|
||||
28
dev/Stores/User/Filter.js
Normal file
28
dev/Stores/User/Filter.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function FilterUserStore()
|
||||
{
|
||||
this.capa = ko.observable('');
|
||||
this.modules = ko.observable({});
|
||||
|
||||
this.collection = ko.observableArray([]);
|
||||
|
||||
this.collection.loading = ko.observable(false).extend({'throttle': 200});
|
||||
this.collection.saving = ko.observable(false).extend({'throttle': 200});
|
||||
|
||||
this.raw = ko.observable('');
|
||||
}
|
||||
|
||||
module.exports = new FilterUserStore();
|
||||
|
||||
}());
|
||||
222
dev/Stores/User/Notification.js
Normal file
222
dev/Stores/User/Notification.js
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
window = require('window'),
|
||||
ko = require('ko'),
|
||||
buzz = require('buzz'),
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Links = require('Common/Links'),
|
||||
|
||||
Settings = require('Storage/Settings')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function NotificationUserStore()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.buzz = null;
|
||||
|
||||
this.enableSoundNotification = ko.observable(true);
|
||||
this.soundNotificationIsSupported = ko.observable(false);
|
||||
|
||||
this.allowDesktopNotification = ko.observable(false);
|
||||
|
||||
this.desktopNotificationPermisions = ko.computed(function () {
|
||||
|
||||
this.allowDesktopNotification();
|
||||
|
||||
var
|
||||
NotificationClass = this.notificationClass(),
|
||||
iResult = Enums.DesktopNotification.NotSupported
|
||||
;
|
||||
|
||||
if (NotificationClass && NotificationClass.permission)
|
||||
{
|
||||
switch (NotificationClass.permission.toLowerCase())
|
||||
{
|
||||
case 'granted':
|
||||
iResult = Enums.DesktopNotification.Allowed;
|
||||
break;
|
||||
case 'denied':
|
||||
iResult = Enums.DesktopNotification.Denied;
|
||||
break;
|
||||
case 'default':
|
||||
iResult = Enums.DesktopNotification.NotAllowed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (window.webkitNotifications && window.webkitNotifications.checkPermission)
|
||||
{
|
||||
iResult = window.webkitNotifications.checkPermission();
|
||||
}
|
||||
|
||||
return iResult;
|
||||
|
||||
}, this);
|
||||
|
||||
this.enableDesktopNotification = ko.computed({
|
||||
'owner': this,
|
||||
'read': function () {
|
||||
return this.allowDesktopNotification() &&
|
||||
Enums.DesktopNotification.Allowed === this.desktopNotificationPermisions();
|
||||
},
|
||||
'write': function (bValue) {
|
||||
if (bValue)
|
||||
{
|
||||
var
|
||||
NotificationClass = this.notificationClass(),
|
||||
iPermission = this.desktopNotificationPermisions()
|
||||
;
|
||||
|
||||
if (NotificationClass && Enums.DesktopNotification.Allowed === iPermission)
|
||||
{
|
||||
this.allowDesktopNotification(true);
|
||||
}
|
||||
else if (NotificationClass && Enums.DesktopNotification.NotAllowed === iPermission)
|
||||
{
|
||||
NotificationClass.requestPermission(function () {
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
if (Enums.DesktopNotification.Allowed === self.desktopNotificationPermisions())
|
||||
{
|
||||
if (self.allowDesktopNotification())
|
||||
{
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
}
|
||||
else
|
||||
{
|
||||
self.allowDesktopNotification(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self.allowDesktopNotification())
|
||||
{
|
||||
self.allowDesktopNotification(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.allowDesktopNotification(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.allowDesktopNotification(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.enableDesktopNotification.valueHasMutated)
|
||||
{
|
||||
this.enableDesktopNotification.valueHasMutated = function () {
|
||||
self.allowDesktopNotification.valueHasMutated();
|
||||
};
|
||||
}
|
||||
|
||||
this.computedProperies();
|
||||
|
||||
this.initNotificationPlayer();
|
||||
}
|
||||
|
||||
NotificationUserStore.prototype.computedProperies = function ()
|
||||
{
|
||||
this.isDesktopNotificationSupported = ko.computed(function () {
|
||||
return Enums.DesktopNotification.NotSupported !== this.desktopNotificationPermisions();
|
||||
}, this);
|
||||
|
||||
this.isDesktopNotificationDenied = ko.computed(function () {
|
||||
return Enums.DesktopNotification.NotSupported === this.desktopNotificationPermisions() ||
|
||||
Enums.DesktopNotification.Denied === this.desktopNotificationPermisions();
|
||||
}, this);
|
||||
};
|
||||
|
||||
NotificationUserStore.prototype.initNotificationPlayer = function ()
|
||||
{
|
||||
if (buzz && buzz.isSupported() && (buzz.isOGGSupported() || buzz.isMP3Supported()))
|
||||
{
|
||||
this.soundNotificationIsSupported(true);
|
||||
|
||||
this.buzz = new buzz.sound(Links.sound('new-mail'), {
|
||||
formats: ['ogg', 'mp3']
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this.enableSoundNotification(false);
|
||||
this.soundNotificationIsSupported(false);
|
||||
}
|
||||
};
|
||||
|
||||
NotificationUserStore.prototype.playSoundNotification = function (bSkipSetting)
|
||||
{
|
||||
if (this.buzz && (bSkipSetting ? true : this.enableSoundNotification()))
|
||||
{
|
||||
this.buzz.play();
|
||||
}
|
||||
};
|
||||
|
||||
NotificationUserStore.prototype.displayDesktopNotification = function (sImageSrc, sTitle, sText)
|
||||
{
|
||||
if (this.enableDesktopNotification())
|
||||
{
|
||||
var
|
||||
NotificationClass = this.notificationClass(),
|
||||
oNotification = NotificationClass ? new NotificationClass(sTitle, {
|
||||
'body': sText,
|
||||
'icon': sImageSrc
|
||||
}) : null
|
||||
;
|
||||
|
||||
if (oNotification)
|
||||
{
|
||||
if (oNotification.show)
|
||||
{
|
||||
oNotification.show();
|
||||
}
|
||||
|
||||
window.setTimeout((function (oLocalNotifications) {
|
||||
return function () {
|
||||
if (oLocalNotifications.cancel)
|
||||
{
|
||||
oLocalNotifications.cancel();
|
||||
}
|
||||
else if (oLocalNotifications.close)
|
||||
{
|
||||
oLocalNotifications.close();
|
||||
}
|
||||
};
|
||||
}(oNotification)), 7000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
NotificationUserStore.prototype.populate = function ()
|
||||
{
|
||||
this.enableSoundNotification(!!Settings.settingsGet('SoundNotification'));
|
||||
this.enableDesktopNotification(!!Settings.settingsGet('DesktopNotifications'));
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {*|null}
|
||||
*/
|
||||
NotificationUserStore.prototype.notificationClass = function ()
|
||||
{
|
||||
return window.Notification && window.Notification.requestPermission ? window.Notification : null;
|
||||
};
|
||||
|
||||
module.exports = new NotificationUserStore();
|
||||
|
||||
}());
|
||||
43
dev/Stores/User/Quota.js
Normal file
43
dev/Stores/User/Quota.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
window = require('window'),
|
||||
ko = require('ko')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function QuotaUserStore()
|
||||
{
|
||||
this.quota = ko.observable(0);
|
||||
this.usage = ko.observable(0);
|
||||
|
||||
this.percentage = ko.computed(function () {
|
||||
|
||||
var
|
||||
iQuota = this.quota(),
|
||||
iUsed = this.usage()
|
||||
;
|
||||
|
||||
return 0 < iQuota ? window.Math.ceil((iUsed / iQuota) * 100) : 0;
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} iQuota
|
||||
* @param {number} iUsage
|
||||
*/
|
||||
QuotaUserStore.prototype.populateData = function(iQuota, iUsage)
|
||||
{
|
||||
this.quota(iQuota * 1024);
|
||||
this.usage(iUsage * 1024);
|
||||
};
|
||||
|
||||
module.exports = new QuotaUserStore();
|
||||
|
||||
}());
|
||||
65
dev/Stores/User/Settings.js
Normal file
65
dev/Stores/User/Settings.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
(function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
var
|
||||
ko = require('ko'),
|
||||
|
||||
Consts = require('Common/Consts'),
|
||||
Enums = require('Common/Enums'),
|
||||
Utils = require('Common/Utils'),
|
||||
|
||||
Settings = require('Storage/Settings')
|
||||
;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function SettingsUserStore()
|
||||
{
|
||||
this.layout = ko.observable(Enums.Layout.SidePreview)
|
||||
.extend({'limitedList': [
|
||||
Enums.Layout.SidePreview, Enums.Layout.BottomPreview, Enums.Layout.NoPreview
|
||||
]});
|
||||
|
||||
this.editorDefaultType = ko.observable(Enums.EditorDefaultType.Html)
|
||||
.extend({'limitedList': [
|
||||
Enums.EditorDefaultType.Html, Enums.EditorDefaultType.Plain,
|
||||
Enums.EditorDefaultType.HtmlForced, Enums.EditorDefaultType.PlainForced
|
||||
]});
|
||||
|
||||
this.messagesPerPage = ko.observable(Consts.Defaults.MessagesPerPage)
|
||||
.extend({'limitedList': Consts.Defaults.MessagesPerPageArray});
|
||||
|
||||
this.showImages = ko.observable(false);
|
||||
this.useCheckboxesInList = ko.observable(true);
|
||||
this.useThreads = ko.observable(false);
|
||||
this.replySameFolder = ko.observable(false);
|
||||
|
||||
this.computedProperies();
|
||||
}
|
||||
|
||||
SettingsUserStore.prototype.computedProperies = function ()
|
||||
{
|
||||
this.usePreviewPane = ko.computed(function () {
|
||||
return Enums.Layout.NoPreview !== this.layout();
|
||||
}, this);
|
||||
};
|
||||
|
||||
SettingsUserStore.prototype.populate = function ()
|
||||
{
|
||||
this.layout(Utils.pInt(Settings.settingsGet('Layout')));
|
||||
this.editorDefaultType(Settings.settingsGet('EditorDefaultType'));
|
||||
|
||||
this.messagesPerPage(Settings.settingsGet('MPP'));
|
||||
|
||||
this.showImages(!!Settings.settingsGet('ShowImages'));
|
||||
this.useCheckboxesInList(!!Settings.settingsGet('UseCheckboxesInList'));
|
||||
this.useThreads(!!Settings.settingsGet('UseThreads'));
|
||||
this.replySameFolder(!!Settings.settingsGet('ReplySameFolder'));
|
||||
};
|
||||
|
||||
module.exports = new SettingsUserStore();
|
||||
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue