code refactor, remove angular-notification, and add icon in notification
This commit is contained in:
parent
325e16e299
commit
6119b8e54e
|
@ -27,7 +27,6 @@
|
|||
"angular-websocket": "^2.0.0",
|
||||
"angular-utf8-base64": "^0.0.5",
|
||||
"angular-local-storage": "^0.7.1",
|
||||
"angular-notification": "git://github.com/neoziro/angular-notification#775ee861c1737b284588bcb878ba1f4e43c70c97",
|
||||
"angular-ui-notification": "^0.3.6",
|
||||
"angular-bittorrent-peerid": "^1.2.0",
|
||||
"angular-busy": "^4.1.4",
|
||||
|
|
|
@ -128,8 +128,8 @@
|
|||
ariaNgSettingService.setBrowserNotification(value);
|
||||
|
||||
if (value && !ariaNgNotificationService.hasBrowserPermission()) {
|
||||
ariaNgNotificationService.requestBrowserPermission(function (permission) {
|
||||
if (!ariaNgNotificationService.isPermissionGranted(permission)) {
|
||||
ariaNgNotificationService.requestBrowserPermission(function (result) {
|
||||
if (!result.granted) {
|
||||
$scope.context.settings.browserNotification = false;
|
||||
ariaNgLocalizationService.showError('You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.');
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
'ngWebSocket',
|
||||
'utf8-base64',
|
||||
'LocalStorageModule',
|
||||
'notification',
|
||||
'ui-notification',
|
||||
'angularBittorrentPeerid',
|
||||
'cgBusy',
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
|
||||
ariaNgCommonService.confirm(title, text, type, callback, notClose, extendSettings);
|
||||
},
|
||||
notifyViaBrowser: function (title, content) {
|
||||
notifyViaBrowser: function (title, content, options) {
|
||||
if (title) {
|
||||
title = this.getLocalizedText(title);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@
|
|||
content = this.getLocalizedText(content);
|
||||
}
|
||||
|
||||
return ariaNgNotificationService.notifyViaBrowser(title, content);
|
||||
return ariaNgNotificationService.notifyViaBrowser(title, content, options);
|
||||
},
|
||||
notifyInPage: function (title, content, options) {
|
||||
if (!options) {
|
||||
|
|
|
@ -1,47 +1,87 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', 'Notification', 'ariaNgSettingService', function ($notification, Notification, ariaNgSettingService) {
|
||||
var isSupportBrowserNotification = $notification.isSupported;
|
||||
angular.module('ariaNg').factory('ariaNgNotificationService', ['$window', 'Notification', 'ariaNgSettingService', function ($window, Notification, ariaNgSettingService) {
|
||||
var isSupportBrowserNotification = !!$window.Notification;
|
||||
|
||||
var isPermissionGranted = function (permission) {
|
||||
var isBrowserNotifactionGranted = function (permission) {
|
||||
return permission === 'granted';
|
||||
};
|
||||
|
||||
var getBrowserNotifactionPermission = function () {
|
||||
if (!$window.Notification) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $window.Notification.permission;
|
||||
};
|
||||
|
||||
var requestBrowserNotifactionPermission = function (callback) {
|
||||
if (!$window.Notification) {
|
||||
return;
|
||||
}
|
||||
|
||||
$window.Notification.requestPermission(function (permission) {
|
||||
if (callback) {
|
||||
callback({
|
||||
granted: isBrowserNotifactionGranted(permission),
|
||||
permission: permission
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var showBrowserNotifaction = function (title, options) {
|
||||
if (!$window.Notification) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isBrowserNotifactionGranted(getBrowserNotifactionPermission())) {
|
||||
return;
|
||||
}
|
||||
|
||||
options = angular.extend({
|
||||
icon: 'tileicon.png'
|
||||
}, options);
|
||||
|
||||
new $window.Notification(title, options);
|
||||
};
|
||||
|
||||
return {
|
||||
isSupportBrowserNotification: function () {
|
||||
return isSupportBrowserNotification;
|
||||
},
|
||||
isPermissionGranted: function (permission) {
|
||||
return isPermissionGranted(permission);
|
||||
},
|
||||
hasBrowserPermission: function () {
|
||||
if (!isSupportBrowserNotification) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isPermissionGranted($notification.getPermission());
|
||||
return isBrowserNotifactionGranted(getBrowserNotifactionPermission());
|
||||
},
|
||||
requestBrowserPermission: function (callback) {
|
||||
if (!isSupportBrowserNotification) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification.requestPermission().then(function (permission) {
|
||||
if (!isPermissionGranted(permission)) {
|
||||
requestBrowserNotifactionPermission(function (result) {
|
||||
if (!result.granted) {
|
||||
ariaNgSettingService.setBrowserNotification(false);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(permission);
|
||||
callback(result);
|
||||
}
|
||||
});
|
||||
},
|
||||
notifyViaBrowser: function (title, content) {
|
||||
notifyViaBrowser: function (title, content, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
options.body = content;
|
||||
|
||||
if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) {
|
||||
$notification(title, {
|
||||
body: content
|
||||
});
|
||||
showBrowserNotifaction(title, options);
|
||||
}
|
||||
},
|
||||
notifyInPage: function (title, content, options) {
|
||||
|
|
Reference in a new issue