Browse Source

merge https://github.com/mayswind/AriaNg/commit/ce1c2fed4b080b0184ad877d4b8072f595f87229

MaysWind 6 years ago
parent
commit
628492503f

+ 2 - 1
app/langs/zh_Hans.txt

@@ -200,8 +200,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 版本

+ 2 - 1
app/langs/zh_Hant.txt

@@ -200,8 +200,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 版本

+ 2 - 1
app/scripts/config/defaultLanguage.js

@@ -204,8 +204,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',

+ 5 - 1
app/scripts/core/root.js

@@ -1,7 +1,7 @@
 (function () {
     'use strict';
 
-    angular.module('ariaNg').run(['$rootScope', '$location', '$window', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', 'ariaNgNativeElectronService', function ($rootScope, $location, $window, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService, ariaNgNativeElectronService) {
+    angular.module('ariaNg').run(['$window', '$rootScope', '$location', '$document', 'ariaNgCommonService', 'ariaNgLocalizationService', 'ariaNgLogService', 'ariaNgSettingService', 'aria2TaskService', 'ariaNgNativeElectronService', function ($window, $rootScope, $location, $document, ariaNgCommonService, ariaNgLocalizationService, ariaNgLogService, ariaNgSettingService, aria2TaskService, ariaNgNativeElectronService) {
         var isUrlMatchUrl2 = function (url, url2) {
             if (url === url2) {
                 return true;
@@ -397,6 +397,10 @@
             }
         };
 
+        $rootScope.refreshPage = function () {
+            $window.location.reload();
+        };
+
         $rootScope.nativeWindowContext = {
             maximized: false
         };

+ 46 - 1
app/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();
 
@@ -106,7 +133,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');

+ 6 - 0
app/views/notification-reloadable.html

@@ -0,0 +1,6 @@
+<div class="ui-notification custom-template">
+    <div class="message" ng-bind-html="message"></div>
+    <div class="message">
+        <a class="btn btn-small btn-primary close-notification" ng-click="refreshPage()" translate>Reload AriaNg</a>
+    </div>
+</div>