Skip to content

Commit

Permalink
add current rpc alias placeholder in title
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Feb 21, 2019
1 parent 767cdd9 commit 03609c9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/langs/zh_Hans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Invalid settings data format!=无效的设置数据格式!
Data has been copied to clipboard.=数据已经复制到剪贴板中.
Supported Placeholder=支持的占位符
AriaNg Title=AriaNg 标题
Current RPC Alias=当前 RPC 别名
Downloading Count=正在下载数量
Waiting Count=正在等待数量
Stopped Count=已停止数量
Expand Down
1 change: 1 addition & 0 deletions src/langs/zh_Hant.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Data has been copied to clipboard.=資料已經複製到剪貼簿中.
Supported Placeholder=支援的預留位置
AriaNg Title=AriaNg 標題
Downloading Count=正在下載數量
Current RPC Alias=目前 RPC 別名
Waiting Count=正在等待數量
Stopped Count=已停止數量
You have disabled notification in your browser. You should change your browser's settings before you enable this function.=您已經在瀏覽器中停用通知功能. 如需使用此功能, 請修改您瀏覽器的設定.
Expand Down
1 change: 1 addition & 0 deletions src/scripts/config/defaultLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
'Data has been copied to clipboard.': 'Data has been copied to clipboard.',
'Supported Placeholder': 'Supported Placeholder',
'AriaNg Title': 'AriaNg Title',
'Current RPC Alias': 'Current RPC Alias',
'Downloading Count': 'Downloading Count',
'Waiting Count': 'Waiting Count',
'Stopped Count': 'Stopped Count',
Expand Down
20 changes: 19 additions & 1 deletion src/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
var globalStatRefreshPromise = null;

var refreshPageTitle = function () {
$document[0].title = ariaNgTitleService.getFinalTitleByGlobalStat($scope.globalStat);
$document[0].title = ariaNgTitleService.getFinalTitleByGlobalStat({
globalStat: $scope.globalStat,
currentRpcProfile: getCurrentRPCProfile()
});
};

var refreshGlobalStat = function (silent, callback) {
Expand All @@ -27,6 +30,21 @@
}, silent);
};

var getCurrentRPCProfile = function () {
if (!$scope.rpcSettings || $scope.rpcSettings.length < 1) {
return null;
}

for (var i = 0; i < $scope.rpcSettings.length; i++) {
var rpcSetting = $scope.rpcSettings[i];
if (rpcSetting.isDefault) {
return rpcSetting;
}
}

return null;
};

if (ariaNgSettingService.getBrowserNotification()) {
ariaNgNotificationService.requestBrowserPermission();
}
Expand Down
21 changes: 20 additions & 1 deletion src/scripts/controllers/settings-ariang.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,25 @@
var lastRefreshPageNotification = null;

var getFinalTitle = function () {
return ariaNgTitleService.getFinalTitleByGlobalStat(ariaNgMonitorService.getCurrentGlobalStat());
return ariaNgTitleService.getFinalTitleByGlobalStat({
globalStat: ariaNgMonitorService.getCurrentGlobalStat(),
currentRpcProfile: getCurrentRPCProfile()
});
};

var getCurrentRPCProfile = function () {
if (!$scope.context || !$scope.context.rpcSettings || $scope.context.rpcSettings.length < 1) {
return null;
}

for (var i = 0; i < $scope.context.rpcSettings.length; i++) {
var rpcSetting = $scope.context.rpcSettings[i];
if (rpcSetting.isDefault) {
return rpcSetting;
}
}

return null;
};

var setNeedRefreshPage = function () {
Expand Down Expand Up @@ -50,6 +68,7 @@
exportSettingsCopied: false
};

$scope.context.titlePreview = getFinalTitle();
$scope.context.showDebugMode = $scope.context.sessionSettings.debugMode || extendType === 'debug';

$scope.changeGlobalTab = function () {
Expand Down
20 changes: 14 additions & 6 deletions src/scripts/services/ariaNgTitleService.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
return title;
};

var replaceCurrentRPCAlias = function (title, value) {
return replacePlaceholders(title, 'rpcprofile', {
value: value
});
};

var replaceDownloadingCount = function (title, value) {
return replacePlaceholders(title, 'downloading', {
prefix: ariaNgLocalizationService.getLocalizedText('Downloading') + ': ',
Expand Down Expand Up @@ -118,6 +124,7 @@
uploadSpeed: 0
}, context);

title = replaceCurrentRPCAlias(title, context.currentRPCAlias);
title = replaceDownloadingCount(title, context.downloadingCount);
title = replaceWaitingCount(title, context.waitingCount);
title = replaceStoppedCount(title, context.stoppedCount);
Expand All @@ -127,13 +134,14 @@

return title;
},
getFinalTitleByGlobalStat: function (globalStat) {
getFinalTitleByGlobalStat: function (params) {
var context = {
downloadingCount: (globalStat ? globalStat.numActive : 0),
waitingCount: (globalStat ? globalStat.numWaiting : 0),
stoppedCount: (globalStat ? globalStat.numStopped : 0),
downloadSpeed: (globalStat ? globalStat.downloadSpeed : 0),
uploadSpeed: (globalStat ? globalStat.uploadSpeed : 0)
currentRPCAlias: (params && params.currentRpcProfile ? (params.currentRpcProfile.rpcAlias || (params.currentRpcProfile.rpcHost + ':' + params.currentRpcProfile.rpcPort)) : ''),
downloadingCount: (params && params.globalStat ? params.globalStat.numActive : 0),
waitingCount: (params && params.globalStat ? params.globalStat.numWaiting : 0),
stoppedCount: (params && params.globalStat ? params.globalStat.numStopped : 0),
downloadSpeed: (params && params.globalStat ? params.globalStat.downloadSpeed : 0),
uploadSpeed: (params && params.globalStat ? params.globalStat.uploadSpeed : 0)
};

return this.getFinalTitle(context);
Expand Down
1 change: 1 addition & 0 deletions src/views/settings-ariang.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
data-trigger="hover" data-placement="auto right" data-container="body" data-html="true"
data-content="{{('Supported Placeholder' | translate) + ':<br/>' +
('AriaNg Title' | translate) + ': ${title}<br/>' +
('Current RPC Alias' | translate) + ': ${rpcprofile}<br/>' +
('Downloading Count' | translate) + ': ${downloading}<br/>' +
('Waiting Count' | translate) + ': ${waiting}<br/>' +
('Stopped Count' | translate) + ': ${stopped}<br/>' +
Expand Down

0 comments on commit 03609c9

Please sign in to comment.