support modify page title refresh interval
This commit is contained in:
parent
5abcf35e56
commit
ba4d540d03
|
@ -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 端口",
|
||||
|
|
|
@ -109,7 +109,8 @@
|
|||
}).constant('ariaNgDefaultOptions', {
|
||||
language: 'en',
|
||||
title: '${downspeed}, ${upspeed} - ${title}',
|
||||
browserNotification: false,
|
||||
titleRefreshInterval: 5000,
|
||||
browserNotification: false,
|
||||
rpcHost: '',
|
||||
rpcPort: '6800',
|
||||
protocol: 'http',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}]);
|
||||
})();
|
||||
|
|
|
@ -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');
|
||||
},
|
||||
|
|
|
@ -21,6 +21,18 @@
|
|||
<input class="form-control" type="text" ng-model="context.settings.title" ng-change="settingService.setTitle(context.settings.title)"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="setting-key setting-key-without-desc col-sm-4">
|
||||
<span translate>Page Title Refresh Interval</span>
|
||||
<span class="asterisk">*</span>
|
||||
</div>
|
||||
<div class="setting-value col-sm-8">
|
||||
<select class="form-control" style="width: 100%;" ng-model="context.settings.titleRefreshInterval"
|
||||
ng-change="settingService.setTitleRefreshInterval(context.settings.titleRefreshInterval)"
|
||||
ng-options="time.optionValue as (time.name | translate: {value: time.value}) for time in context.availableTime">
|
||||
</select>
|
||||
</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>
|
||||
|
|
Reference in a new issue