diff --git a/src/langs/zh_Hans.txt b/src/langs/zh_Hans.txt index dc8f9e6..ad3c14f 100644 --- a/src/langs/zh_Hans.txt +++ b/src/langs/zh_Hans.txt @@ -196,8 +196,9 @@ Downloading Count=正在下载数量 Waiting Count=正在等待数量 Stopped Count=已停止数量 You have disabled notification in your browser. You should change your browser's settings before you enable this function.=您已经在浏览器中禁用通知功能. 如需使用此功能, 请修改您浏览器的设置. +Language resource has been updated, please reload the page for the changes to take effect.=语言资源已经更新, 请重新加载页面使其生效. Configuration has been modified, please reload the page for the changes to take effect.=配置已经修改, 请重新加载页面使其生效. -Reload Page=重新加载页面 +Reload AriaNg=重新加载 AriaNg Show Secret=显示密钥 Hide Secret=隐藏密钥 Aria2 Version=Aria2 版本 diff --git a/src/langs/zh_Hant.txt b/src/langs/zh_Hant.txt index 7ce8d81..6adf827 100644 --- a/src/langs/zh_Hant.txt +++ b/src/langs/zh_Hant.txt @@ -196,8 +196,9 @@ 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.=您已經在瀏覽器中停用通知功能. 如需使用此功能, 請修改您瀏覽器的設定. +Language resource has been updated, please reload the page for the changes to take effect.=語言資源已經更新, 請重新載入頁面使其生效. Configuration has been modified, please reload the page for the changes to take effect.=配置已經修改, 請重新載入頁面使其生效. -Reload Page=重新載入頁面 +Reload AriaNg=重新載入 AriaNg Show Secret=顯示金鑰 Hide Secret=隱藏金鑰 Aria2 Version=Aria2 版本 diff --git a/src/scripts/config/defaultLanguage.js b/src/scripts/config/defaultLanguage.js index a066fd9..763f510 100644 --- a/src/scripts/config/defaultLanguage.js +++ b/src/scripts/config/defaultLanguage.js @@ -200,8 +200,9 @@ 'Waiting Count': 'Waiting Count', 'Stopped Count': 'Stopped Count', '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.', + 'Language resource has been updated, please reload the page for the changes to take effect.': 'Language resource has been updated, please reload the page for the changes to take effect.', 'Configuration has been modified, please reload the page for the changes to take effect.': 'Configuration has been modified, please reload the page for the changes to take effect.', - 'Reload Page': 'Reload Page', + 'Reload AriaNg': 'Reload AriaNg', 'Show Secret': 'Show Secret', 'Hide Secret': 'Hide Secret', 'Aria2 Version': 'Aria2 Version', diff --git a/src/scripts/core/root.js b/src/scripts/core/root.js index 802ee8c..2c6f66b 100644 --- a/src/scripts/core/root.js +++ b/src/scripts/core/root.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').run(['$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', function ($rootScope, $location, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService) { + angular.module('ariaNg').run(['$window', '$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', function ($window, $rootScope, $location, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService) { var isUrlMatchUrl2 = function (url, url2) { if (url === url2) { return true; @@ -324,6 +324,10 @@ } }; + $rootScope.refreshPage = function () { + $window.location.reload(); + }; + ariaNgSettingService.onFirstAccess(function () { ariaNgLocalizationService.notifyInPage('', 'Tap to configure and get started with AriaNg.', { delay: false, diff --git a/src/scripts/services/ariaNgLanguageLoader.js b/src/scripts/services/ariaNgLanguageLoader.js index a867976..dc50eeb 100644 --- a/src/scripts/services/ariaNgLanguageLoader.js +++ b/src/scripts/services/ariaNgLanguageLoader.js @@ -1,7 +1,7 @@ (function () { 'use strict'; - angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'ariaNgConstants', 'ariaNgLanguages', 'ariaNgAssetsCacheService', 'ariaNgNotificationService', 'ariaNgLogService', 'ariaNgStorageService', function ($http, $q, ariaNgConstants, ariaNgLanguages, ariaNgAssetsCacheService, ariaNgNotificationService, ariaNgLogService, ariaNgStorageService) { + angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'ariaNgConstants', 'ariaNgLanguages', 'ariaNgAssetsCacheService', 'ariaNgNotificationService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgStorageService', function ($http, $q, ariaNgConstants, ariaNgLanguages, ariaNgAssetsCacheService, ariaNgNotificationService, ariaNgLocalizationService, ariaNgLogService, ariaNgStorageService) { var getKeyValuePair = function (line) { for (var i = 0; i < line.length; i++) { if (i > 0 && line.charAt(i - 1) !== '\\' && line.charAt(i) === '=') { @@ -81,6 +81,33 @@ return langObj; }; + var isLanguageResourceEquals = function (langObj1, langObj2) { + if (!angular.isObject(langObj1) || !angular.isObject(langObj2)) { + return false; + } + + for (var key in langObj2) { + if (!langObj2.hasOwnProperty(key)) { + continue; + } + + var value = langObj2[key]; + + if (angular.isObject(value)) { + var result = isLanguageResourceEquals(langObj1[key], value); + if (!result) { + return false; + } + } else { + if (value !== langObj1[key]) { + return false; + } + } + } + + return true; + }; + return function (options) { var deferred = $q.defer(); @@ -111,7 +138,25 @@ method: 'GET' }).then(function onSuccess(response) { var languageObject = getLanguageObject(response.data); + var languageUpdated = false; + + if (languageResource) { + languageUpdated = !isLanguageResourceEquals(languageResource, languageObject); + } + ariaNgStorageService.set(languageKey, languageObject); + + if (languageUpdated) { + ariaNgLogService.info("[ariaNgLanguageLoader] load language resource successfully, and resource is updated"); + ariaNgLocalizationService.notifyInPage('', 'Language resource has been updated, please reload the page for the changes to take effect.', { + delay: false, + type: 'info', + templateUrl: 'views/notification-reloadable.html' + }); + } else { + ariaNgLogService.info("[ariaNgLanguageLoader] load language resource successfully, but resource is not updated"); + } + return deferred.resolve(languageObject); }).catch(function onError(response) { ariaNgLogService.warn('[ariaNgLanguageLoader] cannot get language resource'); diff --git a/src/views/notification-reloadable.html b/src/views/notification-reloadable.html new file mode 100644 index 0000000..e6cf8e3 --- /dev/null +++ b/src/views/notification-reloadable.html @@ -0,0 +1,6 @@ +
+
+
+ Reload AriaNg +
+