Added legacy Notifications

Closes #379
This commit is contained in:
Igor Zhukov 2014-07-13 23:58:22 +04:00
parent 0e658af1e3
commit 45823dd045

View File

@ -3236,7 +3236,7 @@ angular.module('myApp.services', [])
.service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, MtpApiManager, AppPeersManager, IdleManager, Storage) { .service('NotificationsManager', function ($rootScope, $window, $timeout, $interval, $q, MtpApiManager, AppPeersManager, IdleManager, Storage) {
var notificationsUiSupport = 'Notification' in window; var notificationsUiSupport = ('Notification' in window) || ('mozNotification' in navigator);
var notificationsShown = {}; var notificationsShown = {};
var notificationIndex = 0; var notificationIndex = 0;
var notificationsCount = 0; var notificationsCount = 0;
@ -3359,7 +3359,7 @@ angular.module('myApp.services', [])
return false; return false;
} }
if (Notification.permission !== 'granted' && Notification.permission !== 'denied') { if ('Notification' in window && Notification.permission !== 'granted' && Notification.permission !== 'denied') {
$($window).on('click', requestPermission); $($window).on('click', requestPermission);
} }
@ -3388,7 +3388,7 @@ angular.module('myApp.services', [])
notificationsCount++; notificationsCount++;
if (!notificationsUiSupport || if (!notificationsUiSupport ||
Notification.permission !== 'granted') { 'Notification' in window && Notification.permission !== 'granted') {
return false; return false;
} }
@ -3403,13 +3403,22 @@ angular.module('myApp.services', [])
return; return;
} }
var idx = ++notificationIndex, var idx = ++notificationIndex,
key = data.key || 'k' + idx; key = data.key || 'k' + idx,
notification;
var notification = new Notification(data.title, { if ('Notification' in window) {
icon: data.image || '', notification = new Notification(data.title, {
body: data.message || '', icon: data.image || '',
tag: data.tag || '' body: data.message || '',
}); tag: data.tag || ''
});
}
else if ('mozNotification' in navigator) {
notification = navigator.mozNotification.createNotification(data.title, data.message || '', data.image || '');
}
else {
return;
}
notification.onclick = function () { notification.onclick = function () {
notification.close(); notification.close();