From 830d53203882143924e91461735f8b8bc29d96e4 Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Mon, 31 Jul 2023 18:30:27 +0200 Subject: [PATCH] fix(settings) Force using an existing timeout (e.g. for version < 1.7.4) --- dist/desktop | 2 +- www/js/controllers/settings-controllers.js | 12 +-- www/js/services/settings-services.js | 91 +++++++++++++--------- www/templates/settings/settings.html | 2 +- 4 files changed, 56 insertions(+), 51 deletions(-) diff --git a/dist/desktop b/dist/desktop index 947b8c830..89e7db0fb 160000 --- a/dist/desktop +++ b/dist/desktop @@ -1 +1 @@ -Subproject commit 947b8c830926aeba77680b6f82914dd687d539ed +Subproject commit 89e7db0fb8b42f13789ff2175c3bb622d0438831 diff --git a/www/js/controllers/settings-controllers.js b/www/js/controllers/settings-controllers.js index be091f4bd..ef8b90b90 100644 --- a/www/js/controllers/settings-controllers.js +++ b/www/js/controllers/settings-controllers.js @@ -34,17 +34,7 @@ function SettingsController($scope, $q, $window, $ionicHistory, $ionicPopup, $ti loading: !csPlatform.isStarted(), loadingMessage: 'COMMON.LOADING' }; - // Fill timeout - $scope.timeouts = [ - {label: 'SETTINGS.NETWORK_ANALYZE_TIMEOUT_AUTO', value: -1}, - {value: 500}, - {value: 1000}, - {value: 5000}, - {value: 10000}, - {value: 30000}, - {value: 60000}, - {value: 300000} - ]; + $scope.timeouts = csSettings.timeouts; $scope.keepAuthIdleLabels = { /*0: { labelKey: 'SETTINGS.KEEP_AUTH_OPTION.NEVER' diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index 2e9059ba1..b13990725 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -5,19 +5,31 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) 'ngInject'; // Define app locales - var locales = [ - {id:'en', label:'English', flag: 'us'}, - {id:'en-GB', label:'English (UK)', flag: 'gb'}, - {id:'eo-EO', label:'Esperanto', flag: 'eo'}, - {id:'fr-FR', label:'Français', flag: 'fr'}, - {id:'nl-NL', label:'Nederlands', flag: 'nl'}, - {id:'es-ES', label:'Español', flag: 'es'}, - {id:'ca', label:'Català ', flag: 'ca'}, - {id:'it-IT', label:'Italiano', flag: 'it'}, - {id:'pt-PT', label:'Português', flag: 'pt'}, - {id:'de-DE', label:'Deutsch', flag: 'de'} - ]; - var fallbackLocale = csConfig.fallbackLanguage ? fixLocale(csConfig.fallbackLanguage) : 'en'; + var + locales = [ + {id:'en', label:'English', flag: 'us'}, + {id:'en-GB', label:'English (UK)', flag: 'gb'}, + {id:'eo-EO', label:'Esperanto', flag: 'eo'}, + {id:'fr-FR', label:'Français', flag: 'fr'}, + {id:'nl-NL', label:'Nederlands', flag: 'nl'}, + {id:'es-ES', label:'Español', flag: 'es'}, + {id:'ca', label:'Català ', flag: 'ca'}, + {id:'it-IT', label:'Italiano', flag: 'it'}, + {id:'pt-PT', label:'Português', flag: 'pt'}, + {id:'de-DE', label:'Deutsch', flag: 'de'} + ], + timeouts = [ + -1, + 500, + 1000, + 5000, + 10000, + 30000, + 60000, + 300000 + ], + fallbackLocale = csConfig.fallbackLanguage ? fixLocale(csConfig.fallbackLanguage) : 'en' + ; // Convert browser locale to app locale (fix #140) function fixLocale (locale) { @@ -70,7 +82,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) httpsMode: false }, defaultSettings = angular.merge({ - timeout : -1, // -1 = auto + timeout: -1, // -1 = auto useRelative: false, useLocalStorage: !!$window.localStorage, // override to false if no device useLocalStorageEncryption: false, @@ -136,8 +148,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) defaultSettings.walletHistoryAutoRefresh = false; // endRemoveIf(no-device) - var - reset = function() { + function reset() { _.keys(data).forEach(function(key){ delete data[key]; }); @@ -146,9 +157,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) return api.data.raisePromise.reset(data) .then(store); - }, + } - getByPath = function(path, defaultValue) { + function getByPath(path, defaultValue) { var obj = data; _.each(path.split('.'), function(key) { obj = obj[key]; @@ -159,17 +170,17 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) }); return obj; - }, + } - emitChangedEvent = function() { + function emitChangedEvent() { var hasChanged = angular.isUndefined(previousData) || !angular.equals(previousData, data); if (hasChanged) { previousData = angular.copy(data); return api.data.raise.changed(data); } - }, + } - store = function() { + function store() { if (!started) { console.debug('[settings] Waiting start finished...'); return (startPromise || start()).then(store); @@ -207,13 +218,13 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) // Emit event on store .then(emitChangedEvent); - }, + } /** * Apply new settings (can be partial) * @param newData */ - applyData = function(newData) { + function applyData(newData) { if (!newData) return; // skip empty // DEBUG @@ -232,6 +243,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) newData[key] = defaultSettings[key]; // This will apply fixed value (override by config.js file) }); + // Force using an existing timeout (e.g. for version < 1.7.4) + newData.timeout = newData.timeout && timeouts.includes(newData.timeout) ? newData.timeout : -1 /* auto */; + // If need select a random peer, from the config if (!data.node && !newData.node && _.size(csConfig.fallbackNodes) > 0) { newData.node = _.sample(csConfig.fallbackNodes); @@ -252,9 +266,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) if (localeChanged) { $translate.use(data.locale.id); } - }, + } - restore = function() { + function restore() { var now = Date.now(); return localStorage.getObject(constants.STORAGE_KEY) @@ -274,22 +288,22 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) emitChangedEvent(); }); - }, + } - getLicenseUrl = function() { + function getLicenseUrl() { var locale = data.locale && data.locale.id || csConfig.defaultLanguage || 'en'; return (csConfig.license) ? (csConfig.license[locale] ? csConfig.license[locale] : defaultSettings.license[csConfig.defaultLanguage || 'en'] || csConfig.license) : undefined; - }, + } - getFeedUrl = function() { + function getFeedUrl() { var locale = data.locale && data.locale.id || csConfig.defaultLanguage || 'en'; return (csConfig.feed && csConfig.feed.jsonFeed) ? (csConfig.feed.jsonFeed[locale] ? csConfig.feed.jsonFeed[locale] : defaultSettings.feed.jsonFeed[csConfig.defaultLanguage || 'en'] || csConfig.feed) : undefined; - }, + } // Detect locale successful changes, then apply to vendor libs - onLocaleChange = function() { + function onLocaleChange() { var locale = $translate.use(); console.debug('[settings] Locale ['+locale+']'); @@ -323,18 +337,18 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) // Emit event api.locale.raise.changed(locale); - }, + } - isStarted = function() { + function isStarted() { return started; - }, + } - ready = function() { + function ready() { if (started) return $q.when(); return startPromise || start(); - }, + } - start = function() { + function start() { console.debug('[settings] Starting...'); startPromise = localStorage.ready() @@ -386,6 +400,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) // api extension api: api, locales: locales, + timeouts: timeouts, constants: constants }; }); diff --git a/www/templates/settings/settings.html b/www/templates/settings/settings.html index d2aca0530..c778bfced 100644 --- a/www/templates/settings/settings.html +++ b/www/templates/settings/settings.html @@ -273,7 +273,7 @@ <h4 class="gray text-wrap hidden-xs" ng-bind-html="'SETTINGS.NETWORK_ANALYZE_TIMEOUT_HELP' | translate"></h4> <select ng-model="formData.timeout" - ng-options="t as ((t.label|translate) || (t.value|formatDurationMs)) for t in timeouts track by t.value"> + ng-options="t as (t === -1 ? ('SETTINGS.NETWORK_ANALYZE_TIMEOUT_AUTO'|translate) : (t|formatDurationMs)) for t in timeouts track by t"> </select> </label> -- GitLab