diff --git a/src/langs/zh_CN.json b/src/langs/zh_CN.json index 22c62d3..9277d6b 100644 --- a/src/langs/zh_CN.json +++ b/src/langs/zh_CN.json @@ -103,6 +103,7 @@ "More Options": "更多选项", "Language": "语言", "Page Title": "页面标题", + "Page Title Refresh Interval": "页面标题刷新间隔", "Enable Browser Notification": "启用浏览器通知", "Aria2 RPC Host": "Aria2 RPC 主机", "Aria2 RPC Port": "Aria2 RPC 端口", diff --git a/src/scripts/config/constants.js b/src/scripts/config/constants.js index 61f9d0c..2b50b9e 100644 --- a/src/scripts/config/constants.js +++ b/src/scripts/config/constants.js @@ -109,7 +109,8 @@ }).constant('ariaNgDefaultOptions', { language: 'en', title: '${downspeed}, ${upspeed} - ${title}', - browserNotification: false, + titleRefreshInterval: 5000, + browserNotification: false, rpcHost: '', rpcPort: '6800', protocol: 'http', diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index fe30372..8addcaa 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -107,6 +107,7 @@ 'More Options': 'More Options', 'Language': 'Language', 'Page Title': 'Page Title', + 'Page Title Refresh Interval': 'Page Title Refresh Interval', 'Enable Browser Notification': 'Enable Browser Notification', 'Aria2 RPC Host': 'Aria2 RPC Host', 'Aria2 RPC Port': 'Aria2 RPC Port', diff --git a/src/scripts/controllers/main.js b/src/scripts/controllers/main.js index 191b166..178d1a6 100644 --- a/src/scripts/controllers/main.js +++ b/src/scripts/controllers/main.js @@ -2,9 +2,28 @@ 'use strict'; 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 pageTitleRefreshPromise = null; var globalStatRefreshPromise = null; - var refreshGlobalStat = function (silent) { + var refreshPageTitle = function () { + var context = (function (globalStat) { + if (!globalStat) { + return null; + } + + return { + downloadingCount: globalStat.numActive, + waitingCount: globalStat.numWaiting, + stoppedCount: globalStat.numStopped, + downloadSpeed: globalStat.downloadSpeed, + uploadSpeed: globalStat.uploadSpeed + } + })($scope.globalStat); + + $document[0].title = ariaNgSettingService.getFinalTitle(context); + }; + + var refreshGlobalStat = function (silent, callback) { return aria2SettingService.getGlobalStat(function (response) { if (!response.success && response.data.message == aria2RpcErrors.Unauthorized.message) { $interval.cancel(globalStatRefreshPromise); @@ -13,18 +32,15 @@ if (response.success) { $scope.globalStat = response.data; - $document[0].title = ariaNgSettingService.getFinalTitle({ - downloadingCount: $scope.globalStat.numActive, - waitingCount: $scope.globalStat.numWaiting, - stoppedCount: $scope.globalStat.numStopped, - downloadSpeed: $scope.globalStat.downloadSpeed, - uploadSpeed: $scope.globalStat.uploadSpeed - }); ariaNgMonitorService.recordGlobalStat(response.data); } + + if (callback) { + callback(response); + } }, silent); }; - + if (ariaNgSettingService.getBrowserNotification()) { ariaNgNotificationService.requestBrowserPermission(); } @@ -187,6 +203,12 @@ return orderType.equals(targetType); }; + if (ariaNgSettingService.getTitleRefreshInterval() > 0) { + pageTitleRefreshPromise = $interval(function () { + refreshPageTitle(); + }, ariaNgSettingService.getTitleRefreshInterval()); + } + if (ariaNgSettingService.getGlobalStatRefreshInterval() > 0) { globalStatRefreshPromise = $interval(function () { refreshGlobalStat(true); @@ -194,11 +216,17 @@ } $scope.$on('$destroy', function () { + if (pageTitleRefreshPromise) { + $interval.cancel(pageTitleRefreshPromise); + } + if (globalStatRefreshPromise) { $interval.cancel(globalStatRefreshPromise); } }); - refreshGlobalStat(true); + refreshGlobalStat(true, function () { + refreshPageTitle(); + }); }]); })(); diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 59ce717..c925ee1 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -77,6 +77,14 @@ getFinalTitle: function (context) { var title = this.getTitle(); + context = angular.extend({ + downloadingCount: 0, + waitingCount: 0, + stoppedCount: 0, + downloadSpeed: 0, + uploadSpeed: 0 + }, context); + title = title.replace(/\$\{downloading\}/g, $translate.instant('Downloading') + ': ' + context.downloadingCount); title = title.replace(/\$\{waiting\}/g, $translate.instant('Waiting') + ': ' + context.waitingCount); title = title.replace(/\$\{stopped\}/g, $translate.instant('Downloaded / Stopped') + ': ' + context.stoppedCount); @@ -89,6 +97,12 @@ setTitle: function (value) { setOption('title', value); }, + getTitleRefreshInterval: function () { + return getOption('titleRefreshInterval'); + }, + setTitleRefreshInterval: function (value) { + setOption('titleRefreshInterval', Math.max(parseInt(value), 0)); + }, getBrowserNotification: function () { return getOption('browserNotification'); }, diff --git a/src/views/settings-ariang.html b/src/views/settings-ariang.html index 48a98e8..d3b9137 100644 --- a/src/views/settings-ariang.html +++ b/src/views/settings-ariang.html @@ -21,6 +21,18 @@ +