Notifications were hardcoded disabled for mobile.
This commit is contained in:
djmaze 2020-11-10 09:28:33 +01:00
parent 542d9c91e9
commit f706e14a2f
2 changed files with 10 additions and 8 deletions

View file

@ -8,6 +8,8 @@ import * as Links from 'Common/Links';
*/
const HTML5Notification = window.Notification ? Notification : null,
HTML5NotificationStatus = () => (HTML5Notification && HTML5Notification.permission) || 'denied',
NotificationsDenied = () => 'denied' === HTML5NotificationStatus(),
NotificationsGranted = () => 'granted' === HTML5NotificationStatus(),
dispatchMessage = data => {
focus();
if (data.Folder && data.Uid) {
@ -20,7 +22,6 @@ let DesktopNotifications = false,
// Are Notifications supported in the service worker?
if (WorkerNotifications && ServiceWorkerRegistration && ServiceWorkerRegistration.prototype.showNotification) {
console.log('ServiceWorker supported');
/* Listen for close requests from the ServiceWorker */
WorkerNotifications.addEventListener('message', event => {
const obj = JSON.parse(event.data);
@ -28,7 +29,7 @@ if (WorkerNotifications && ServiceWorkerRegistration && ServiceWorkerRegistratio
});
} else {
WorkerNotifications = null;
console.log('WorkerNotifications not supported');
console.log('ServiceWorker Notifications not supported');
}
class NotificationUserStore {
@ -37,13 +38,13 @@ class NotificationUserStore {
this.enableDesktopNotification = ko.observable(false)/*.extend({ notify: 'always' })*/;
this.isDesktopNotificationDenied = ko.observable('denied' === HTML5NotificationStatus());
this.isDesktopNotificationDenied = ko.observable(NotificationsDenied());
this.enableDesktopNotification.subscribe(value => {
DesktopNotifications = !!value;
if (value && HTML5Notification && 'granted' !== HTML5Notification.permission) {
if (value && HTML5Notification && !NotificationsGranted()) {
HTML5Notification.requestPermission(() =>
this.isDesktopNotificationDenied('denied' === HTML5Notification.permission)
this.isDesktopNotificationDenied(NotificationsDenied())
);
}
});
@ -62,12 +63,15 @@ class NotificationUserStore {
* Used with DesktopNotifications setting
*/
displayDesktopNotification(title, text, messageData, imageSrc) {
if (DesktopNotifications && 'granted' === HTML5NotificationStatus()) {
if (DesktopNotifications && NotificationsGranted()) {
const options = {
body: text,
icon: imageSrc || Links.notificationMailIcon(),
data: messageData
};
if (messageData && messageData.Uid) {
options.tag = messageData.Uid;
}
if (WorkerNotifications) {
// Service-Worker-Allowed HTTP header to allow the scope.
WorkerNotifications.register('/serviceworker.js')

View file

@ -1480,8 +1480,6 @@ NewThemeLink IncludeCss TemplatesLink LangLink IncludeBackground PluginsLink Aut
{
$aResult['Layout'] = Enumerations\Layout::NO_PREVIW;
$aResult['SoundNotification'] = false;
$aResult['DesktopNotifications'] = false;
$aResult['UseCheckboxesInList'] = true;
$aResult['UserBackgroundName'] = '';