diff --git a/src/index.html b/src/index.html index feed10b..99568a4 100644 --- a/src/index.html +++ b/src/index.html @@ -334,6 +334,7 @@ + diff --git a/src/langs/zh_CN.txt b/src/langs/zh_CN.txt index 3ebfb6f..bbf1c5b 100644 --- a/src/langs/zh_CN.txt +++ b/src/langs/zh_CN.txt @@ -122,6 +122,9 @@ Download Error=下载出错 Language=语言 Debug Mode=调试模式 Page Title=页面标题 +Preview=预览 +Tips: You can use the "noprefix" tag to ignore the prefix, "nosuffix" tag ignore the suffix, and "scale\=n" tag to set the decimal precision.=小提示: 您可以使用 "noprefix" 标签忽略前缀, "nosuffix" 标签忽略后缀, 以及 "scale\=n" 标签设置小数的精度. +Example: ${downspeed:noprefix:nosuffix:scale\=1}=示例: ${downspeed:noprefix:nosuffix:scale\=1} Page Title Refresh Interval=页面标题刷新间隔 Enable Browser Notification=启用浏览器通知 Aria2 RPC Host=Aria2 RPC 主机 diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index a11ded7..b64a6e4 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -126,6 +126,9 @@ 'Language': 'Language', 'Debug Mode': 'Debug Mode', 'Page Title': 'Page Title', + 'Preview': 'Preview', + 'Tips: You can use the "noprefix" tag to ignore the prefix, "nosuffix" tag ignore the suffix, and "scale=n" tag to set the decimal precision.': 'Tips: You can use the "noprefix" tag to ignore the prefix, "nosuffix" tag ignore the suffix, and "scale=n" tag to set the decimal precision.', + 'Example: ${downspeed:noprefix:nosuffix:scale=1}': 'Example: ${downspeed:noprefix:nosuffix:scale=1}', 'Page Title Refresh Interval': 'Page Title Refresh Interval', 'Enable Browser Notification': 'Enable Browser Notification', 'Aria2 RPC Host': 'Aria2 RPC Host', diff --git a/src/scripts/controllers/main.js b/src/scripts/controllers/main.js index 2162744..149d27a 100644 --- a/src/scripts/controllers/main.js +++ b/src/scripts/controllers/main.js @@ -1,26 +1,12 @@ (function () { '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) { + angular.module('ariaNg').controller('MainController', ['$rootScope', '$scope', '$route', '$location', '$document', '$interval', 'aria2RpcErrors', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgTitleService', 'ariaNgMonitorService', 'ariaNgNotificationService', 'aria2TaskService', 'aria2SettingService', function ($rootScope, $scope, $route, $location, $document, $interval, aria2RpcErrors, ariaNgCommonService, ariaNgSettingService, ariaNgTitleService, ariaNgMonitorService, ariaNgNotificationService, aria2TaskService, aria2SettingService) { var pageTitleRefreshPromise = null; var globalStatRefreshPromise = null; 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); + $document[0].title = ariaNgTitleService.getFinalTitleByGlobalStat($scope.globalStat); }; var refreshGlobalStat = function (silent, callback) { diff --git a/src/scripts/controllers/settings-ariang.js b/src/scripts/controllers/settings-ariang.js index 214955f..59b964e 100644 --- a/src/scripts/controllers/settings-ariang.js +++ b/src/scripts/controllers/settings-ariang.js @@ -1,13 +1,18 @@ (function () { 'use strict'; - angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$routeParams', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgNotificationService', function ($rootScope, $scope, $routeParams, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService, ariaNgNotificationService) { + angular.module('ariaNg').controller('AriaNgSettingsController', ['$rootScope', '$scope', '$routeParams', '$interval', '$timeout', 'ariaNgLanguages', 'ariaNgCommonService', 'ariaNgSettingService', 'ariaNgMonitorService', 'ariaNgNotificationService', 'ariaNgTitleService', function ($rootScope, $scope, $routeParams, $interval, $timeout, ariaNgLanguages, ariaNgCommonService, ariaNgSettingService, ariaNgMonitorService, ariaNgNotificationService, ariaNgTitleService) { var tabOrders = ['global', 'rpc']; var extendType = $routeParams.extendType; + var getFinalTitle = function () { + return ariaNgTitleService.getFinalTitleByGlobalStat(ariaNgMonitorService.getCurrentGlobalStat()); + }; + $scope.context = { currentTab: 'global', languages: ariaNgLanguages, + titlePreview: getFinalTitle(), availableTime: ariaNgCommonService.getTimeOptions([1000, 2000, 3000, 5000, 10000, 30000, 60000], true), trueFalseOptions: [{name: 'True', value: true}, {name: 'False', value: false}], showRpcSecret: false, @@ -21,6 +26,10 @@ $scope.context.currentTab = tabName; }; + $scope.updateTitlePreview = function () { + $scope.context.titlePreview = getFinalTitle(); + }; + $rootScope.swipeActions.extentLeftSwipe = function () { var tabIndex = tabOrders.indexOf($scope.context.currentTab); diff --git a/src/scripts/services/ariaNgMonitorService.js b/src/scripts/services/ariaNgMonitorService.js index 465d1cf..f3053c9 100644 --- a/src/scripts/services/ariaNgMonitorService.js +++ b/src/scripts/services/ariaNgMonitorService.js @@ -2,6 +2,7 @@ 'use strict'; angular.module('ariaNg').factory('ariaNgMonitorService', ['$filter', '$translate', 'moment', 'ariaNgConstants', function ($filter, $translate, moment, ariaNgConstants) { + var currentGlobalStat = {}; var storagesInMemory = {}; var globalStorageKey = 'global'; @@ -149,10 +150,14 @@ return this.getStatsData(key); }, recordGlobalStat: function (stat) { - return this.recordStat(globalStorageKey, stat); + this.recordStat(globalStorageKey, stat); + currentGlobalStat = stat; }, getGlobalStatsData: function () { return this.getStatsData(globalStorageKey); + }, + getCurrentGlobalStat: function () { + return currentGlobalStat; } }; }]); diff --git a/src/scripts/services/ariaNgSettingService.js b/src/scripts/services/ariaNgSettingService.js index 44834f6..b37f7e5 100644 --- a/src/scripts/services/ariaNgSettingService.js +++ b/src/scripts/services/ariaNgSettingService.js @@ -124,26 +124,6 @@ getTitle: function () { return getOption('title'); }, - 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); - title = title.replace(/\$\{downspeed\}/g, $translate.instant('Download') + ': ' + $filter('readableVolumn')(context.downloadSpeed) + '/s'); - title = title.replace(/\$\{upspeed\}/g, $translate.instant('Upload') + ': ' + $filter('readableVolumn')(context.uploadSpeed) + '/s'); - title = title.replace(/\$\{title\}/g, ariaNgConstants.title); - - return title; - }, setTitle: function (value) { setOption('title', value); }, diff --git a/src/scripts/services/ariaNgTitleService.js b/src/scripts/services/ariaNgTitleService.js new file mode 100644 index 0000000..55a6c98 --- /dev/null +++ b/src/scripts/services/ariaNgTitleService.js @@ -0,0 +1,143 @@ +(function () { + 'use strict'; + + angular.module('ariaNg').factory('ariaNgTitleService', ['$filter', '$translate', 'ariaNgConstants', 'ariaNgSettingService', function ($filter, $translate, ariaNgConstants, ariaNgSettingService) { + var parseSettings = function (placeholder) { + if (!placeholder) { + return {}; + } + + var innerText = placeholder.substring(2, placeholder.length - 1); // remove ${ and } + var items = innerText.split(':'); + + var settings = { + oldValue: placeholder + }; + + for (var i = 1; i < items.length; i++) { + var pairs = items[i].split('='); + + if (pairs.length == 1) { + settings[pairs[0]] = true; + } else if (pairs.length == 2) { + settings[pairs[0]] = pairs[1]; + } + } + + return settings; + }; + + var replacePlaerholder = function (title, context) { + var value = context.value; + + if (context.type === 'volumn') { + value = $filter('readableVolumn')(value, context.scale); + } + + if (context.prefix && !context.noprefix) { + value = context.prefix + value; + } + + if (context.suffix && !context.nosuffix) { + value = value + context.suffix; + } + + return title.replace(context.oldValue, value); + }; + + var replacePlaceholders = function (title, condition, context) { + var regex = new RegExp('\\$\\{' + condition + '(:[a-zA-Z0-9]+(=[a-zA-Z0-9]+)?)*\\}', 'g'); + var results = title.match(regex); + + if (results && results.length > 0) { + for (var i = 0; i < results.length; i++) { + var innerContext = parseSettings(results[i]); + angular.extend(innerContext, context); + + title = replacePlaerholder(title, innerContext); + } + } + + return title; + }; + + var replaceDownloadingCount = function (title, value) { + return replacePlaceholders(title, 'downloading', { + prefix: $translate.instant('Downloading') + ': ', + value: value + }); + }; + + var replaceWaitingCount = function (title, value) { + return replacePlaceholders(title, 'waiting', { + prefix: $translate.instant('Waiting') + ': ', + value: value + }); + }; + + var replaceStoppedCount = function (title, value) { + return replacePlaceholders(title, 'stopped', { + prefix: $translate.instant('Downloaded / Stopped'), + value: value + }); + }; + + var replaceDownloadSpeed = function (title, value) { + return replacePlaceholders(title, 'downspeed', { + prefix: $translate.instant('Download') + ': ', + value: value, + type: 'volumn', + suffix: '/s' + }); + }; + + var replaceUploadSpeed = function (title, value) { + return replacePlaceholders(title, 'upspeed', { + prefix: $translate.instant('Upload') + ': ', + value: value, + type: 'volumn', + suffix: '/s' + }); + }; + + var replaceAgiaNgTitle = function (title) { + return replacePlaceholders(title, 'title', { + value: ariaNgConstants.title + }); + }; + + return { + getFinalTitle: function (context) { + var title = ariaNgSettingService.getTitle(); + + context = angular.extend({ + downloadingCount: 0, + waitingCount: 0, + stoppedCount: 0, + downloadSpeed: 0, + uploadSpeed: 0 + }, context); + + title = replaceDownloadingCount(title, context.downloadingCount); + title = replaceWaitingCount(title, context.waitingCount); + title = replaceStoppedCount(title, context.stoppedCount); + title = replaceDownloadSpeed(title, context.downloadSpeed); + title = replaceUploadSpeed(title, context.uploadSpeed); + title = replaceAgiaNgTitle(title); + + return title; + }, + getFinalTitleByGlobalStat: function (globalStat) { + var context = { + downloadingCount: globalStat.numActive, + waitingCount: globalStat.numWaiting, + stoppedCount: globalStat.numStopped, + downloadSpeed: globalStat.downloadSpeed, + uploadSpeed: globalStat.uploadSpeed + }; + + return this.getFinalTitle(context); + } + }; + }]); +}()); diff --git a/src/views/settings-ariang.html b/src/views/settings-ariang.html index c4ff37d..4cfe5fb 100644 --- a/src/views/settings-ariang.html +++ b/src/views/settings-ariang.html @@ -38,11 +38,20 @@ Page Title + data-content="{{('Supported Placeholder' | translate) + ':
' + + ('AriaNg Title' | translate) + ': ${title}
' + + ('Downloading Count' | translate) + ': ${downloading}
' + + ('Waiting Count' | translate) + ': ${waiting}
' + + ('Stopped Count' | translate) + ': ${stopped}
' + + ('Download Speed' | translate) + ': ${downspeed}
' + + ('Upload Speed' | translate) + ': ${upspeed}

' + + ('Tips: You can use the "noprefix" tag to ignore the prefix, "nosuffix" tag ignore the suffix, and "scale=n" tag to set the decimal precision.' | translate) + '
' + + ('Example: ${downspeed:noprefix:nosuffix:scale=1}' | translate)}}">
+ ng-change="settingService.setTitle(context.settings.title); updateTitlePreview()"/> + [Preview]