support browser notification
This commit is contained in:
parent
c526d323be
commit
5abcf35e56
|
@ -44,9 +44,10 @@
|
|||
"angular-websocket": "^1.1.0",
|
||||
"angular-utf8-base64": "^0.0.5",
|
||||
"angular-local-storage": "^0.2.7",
|
||||
"angular-notification": "775ee861c1737b284588bcb878ba1f4e43c70c97",
|
||||
"angular-busy": "^4.1.3",
|
||||
"angular-promise-buttons": "^0.1.14",
|
||||
"angular-dragula": "^1.2.7",
|
||||
"ngSweetAlert": "https://github.com/oitozero/ngSweetAlert.git#8df6c30b0996f09cb4cf5e90a41115a6c09fa852"
|
||||
"ngSweetAlert": "8df6c30b0996f09cb4cf5e90a41115a6c09fa852"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -264,6 +264,7 @@
|
|||
<script src="../bower_components/angular-websocket/angular-websocket.min.js"></script>
|
||||
<script src="../bower_components/angular-utf8-base64/angular-utf8-base64.min.js"></script>
|
||||
<script src="../bower_components/angular-local-storage/dist/angular-local-storage.min.js"></script>
|
||||
<script src="../bower_components/angular-notification/angular-notification.js"></script>
|
||||
<script src="../bower_components/angular-busy/dist/angular-busy.min.js"></script>
|
||||
<script src="../bower_components/angular-promise-buttons/dist/angular-promise-buttons.min.js"></script>
|
||||
<script src="../bower_components/angular-dragula/dist/angular-dragula.min.js"></script>
|
||||
|
@ -306,8 +307,9 @@
|
|||
<script src="scripts/filters/volumn.js"></script>
|
||||
<script src="scripts/services/ariaNgCommonService.js"></script>
|
||||
<script src="scripts/services/ariaNgFileService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
<script src="scripts/services/ariaNgMonitorService.js"></script>
|
||||
<script src="scripts/services/ariaNgNotificationService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
<script src="scripts/services/aria2TaskService.js"></script>
|
||||
<script src="scripts/services/aria2SettingService.js"></script>
|
||||
<script src="scripts/services/aria2RpcService.js"></script>
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
"OK": "确定",
|
||||
"Confirm": "确认",
|
||||
"Cancel": "取消",
|
||||
"True": "是",
|
||||
"False": "否",
|
||||
"New": "新建",
|
||||
"Start": "开始下载任务",
|
||||
"Pause": "暂停下载任务",
|
||||
|
@ -101,6 +103,7 @@
|
|||
"More Options": "更多选项",
|
||||
"Language": "语言",
|
||||
"Page Title": "页面标题",
|
||||
"Enable Browser Notification": "启用浏览器通知",
|
||||
"Aria2 RPC Host": "Aria2 RPC 主机",
|
||||
"Aria2 RPC Port": "Aria2 RPC 端口",
|
||||
"Aria2 RPC Protocol": "Aria2 RPC 协议",
|
||||
|
@ -108,6 +111,7 @@
|
|||
"Global Stat Refresh Interval": "全局状态刷新间隔",
|
||||
"Download Task Refresh Interval": "下载任务刷新间隔",
|
||||
"Supported Placeholder: AriaNg Title ${title}, Downloading Count ${downloading}, Waiting Count ${waiting}, Stopped Count ${stopped}, Download Speed ${downspeed}, Upload Speed ${upspeed}.": "支持的占位符: AriaNg 标题 ${title}, 正在下载数量 ${downloading}, 正在等待数量 ${waiting}, 已停止数量 ${stopped}, 下载速度 ${downspeed}, 上传速度: ${upspeed}.",
|
||||
"You have disabled notification in your browser. You should change your browser's settings before you enable this function.": "您已经在浏览器中禁用通知功能. 如需使用此功能, 请修改您浏览器的设置.",
|
||||
"Aria2 Version": "Aria2 版本",
|
||||
"Enabled Features": "已启用的功能",
|
||||
"Functions": "方法",
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
}).constant('ariaNgDefaultOptions', {
|
||||
language: 'en',
|
||||
title: '${downspeed}, ${upspeed} - ${title}',
|
||||
browserNotification: false,
|
||||
rpcHost: '',
|
||||
rpcPort: '6800',
|
||||
protocol: 'http',
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
'OK': 'OK',
|
||||
'Confirm': 'Confirm',
|
||||
'Cancel': 'Cancel',
|
||||
'True': 'True',
|
||||
'False': 'False',
|
||||
'New': 'New',
|
||||
'Start': 'Start',
|
||||
'Pause': 'Pause',
|
||||
|
@ -105,6 +107,7 @@
|
|||
'More Options': 'More Options',
|
||||
'Language': 'Language',
|
||||
'Page Title': 'Page Title',
|
||||
'Enable Browser Notification': 'Enable Browser Notification',
|
||||
'Aria2 RPC Host': 'Aria2 RPC Host',
|
||||
'Aria2 RPC Port': 'Aria2 RPC Port',
|
||||
'Aria2 RPC Protocol': 'Aria2 RPC Protocol',
|
||||
|
@ -112,6 +115,7 @@
|
|||
'Global Stat Refresh Interval': 'Global Stat Refresh Interval',
|
||||
'Download Task Refresh Interval': 'Download Task Refresh Interval',
|
||||
'Supported Placeholder: AriaNg Title ${title}, Downloading Count ${downloading}, Waiting Count ${waiting}, Stopped Count ${stopped}, Download Speed ${downspeed}, Upload Speed ${upspeed}.': 'Supported Placeholder: AriaNg Title ${title}, Downloading Count ${downloading}, Waiting Count ${waiting}, Stopped Count ${stopped}, Download Speed ${downspeed}, Upload Speed ${upspeed}.',
|
||||
'You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.': 'You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.',
|
||||
'Aria2 Version': 'Aria2 Version',
|
||||
'Enabled Features': 'Enabled Features',
|
||||
'Functions': 'Functions',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$location', '$document', '$interval', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $location, $document, $interval, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, aria2TaskService, aria2SettingService) {
|
||||
angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$location', '$document', '$interval', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'ariaNgNotificationService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $location, $document, $interval, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, ariaNgNotificationService, aria2TaskService, aria2SettingService) {
|
||||
var globalStatRefreshPromise = null;
|
||||
|
||||
var refreshGlobalStat = function (silent) {
|
||||
|
@ -24,6 +24,10 @@
|
|||
}
|
||||
}, silent);
|
||||
};
|
||||
|
||||
if (ariaNgSettingService.getBrowserNotification()) {
|
||||
ariaNgNotificationService.requestBrowserPermission();
|
||||
}
|
||||
|
||||
$scope.globalStatusContext = {
|
||||
data: ariaNgMonitorService.getGlobalStatsData()
|
||||
|
|
|
@ -1,15 +1,30 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', function ($rootScope, $scope, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService) {
|
||||
angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgNotificationService', function ($rootScope, $scope, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService, ariaNgNotificationService) {
|
||||
$scope.context = {
|
||||
languages: ariaNgLanguages,
|
||||
availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true),
|
||||
settings: ariaNgSettingService.getAllOptions()
|
||||
trueFalseOptions: [{name: 'True', value: true}, {name: 'False', value: false}],
|
||||
settings: ariaNgSettingService.getAllOptions(),
|
||||
supportBrowserNotification: ariaNgNotificationService.isSupportBrowserNotification()
|
||||
};
|
||||
|
||||
|
||||
$scope.settingService = ariaNgSettingService;
|
||||
|
||||
$scope.setEnableBrowserNotification = function (value) {
|
||||
ariaNgSettingService.setBrowserNotification(value);
|
||||
|
||||
if (value && !ariaNgNotificationService.hasBrowserPermission()) {
|
||||
ariaNgNotificationService.requestBrowserPermission(function (permission) {
|
||||
if (!ariaNgNotificationService.isPermissionGranted(permission)) {
|
||||
$scope.context.settings.browserNotification = false;
|
||||
ariaNgCommonService.showError('You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.loadPromise = $timeout(function () {
|
||||
;//Do Nothing
|
||||
}, 100);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
'ngWebSocket',
|
||||
'ab-base64',
|
||||
'LocalStorageModule',
|
||||
'notification',
|
||||
'cgBusy',
|
||||
'angularPromiseButtons',
|
||||
'oitozero.ngSweetAlert',
|
||||
|
|
49
src/scripts/services/ariaNgNotificationService.js
Normal file
49
src/scripts/services/ariaNgNotificationService.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', 'ariaNgSettingService', function ($notification, ariaNgSettingService) {
|
||||
var isSupportBrowserNotification = $notification.isSupported;
|
||||
|
||||
var isPermissionGranted = function (permission) {
|
||||
return permission == 'granted';
|
||||
};
|
||||
|
||||
return {
|
||||
isSupportBrowserNotification: function () {
|
||||
return isSupportBrowserNotification;
|
||||
},
|
||||
isPermissionGranted: function (permission) {
|
||||
return isPermissionGranted(permission);
|
||||
},
|
||||
hasBrowserPermission: function () {
|
||||
if (!isSupportBrowserNotification) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isPermissionGranted($notification.getPermission());
|
||||
},
|
||||
requestBrowserPermission: function (callback) {
|
||||
if (!isSupportBrowserNotification) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification.requestPermission().then(function (permission) {
|
||||
if (!isPermissionGranted(permission)) {
|
||||
ariaNgSettingService.setBrowserNotification(false);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(permission);
|
||||
}
|
||||
});
|
||||
},
|
||||
notify: function (title, content) {
|
||||
if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) {
|
||||
$notification(title, {
|
||||
body: content
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}]);
|
||||
})();
|
|
@ -89,6 +89,12 @@
|
|||
setTitle: function (value) {
|
||||
setOption('title', value);
|
||||
},
|
||||
getBrowserNotification: function () {
|
||||
return getOption('browserNotification');
|
||||
},
|
||||
setBrowserNotification: function (value) {
|
||||
setOption('browserNotification', value);
|
||||
},
|
||||
getJsonRpcUrl: function () {
|
||||
var protocol = getOption('protocol');
|
||||
var rpcHost = getOption('rpcHost');
|
||||
|
|
|
@ -21,6 +21,17 @@
|
|||
<input class="form-control" type="text" ng-model="context.settings.title" ng-change="settingService.setTitle(context.settings.title)"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" ng-if="context.supportBrowserNotification">
|
||||
<div class="setting-key setting-key-without-desc col-sm-4">
|
||||
<span translate>Enable Browser Notification</span>
|
||||
</div>
|
||||
<div class="setting-value col-sm-8">
|
||||
<select class="form-control" style="width: 100%;" ng-model="context.settings.browserNotification"
|
||||
ng-change="setEnableBrowserNotification(context.settings.browserNotification)"
|
||||
ng-options="option.value as (option.name | translate) for option in context.trueFalseOptions">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="setting-key setting-key-without-desc col-sm-4">
|
||||
<span translate>Aria2 RPC Host</span>
|
||||
|
|
Reference in a new issue