Skip to content

Commit 830d532

Browse files
committed
fix(settings) Force using an existing timeout (e.g. for version < 1.7.4)
1 parent d5d5aa0 commit 830d532

File tree

4 files changed

+56
-51
lines changed

4 files changed

+56
-51
lines changed

dist/desktop

Submodule desktop updated from 947b8c8 to 89e7db0

www/js/controllers/settings-controllers.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@ function SettingsController($scope, $q, $window, $ionicHistory, $ionicPopup, $ti
3434
loading: !csPlatform.isStarted(),
3535
loadingMessage: 'COMMON.LOADING'
3636
};
37-
// Fill timeout
38-
$scope.timeouts = [
39-
{label: 'SETTINGS.NETWORK_ANALYZE_TIMEOUT_AUTO', value: -1},
40-
{value: 500},
41-
{value: 1000},
42-
{value: 5000},
43-
{value: 10000},
44-
{value: 30000},
45-
{value: 60000},
46-
{value: 300000}
47-
];
37+
$scope.timeouts = csSettings.timeouts;
4838
$scope.keepAuthIdleLabels = {
4939
/*0: {
5040
labelKey: 'SETTINGS.KEEP_AUTH_OPTION.NEVER'

www/js/services/settings-services.js

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
55
'ngInject';
66

77
// Define app locales
8-
var locales = [
9-
{id:'en', label:'English', flag: 'us'},
10-
{id:'en-GB', label:'English (UK)', flag: 'gb'},
11-
{id:'eo-EO', label:'Esperanto', flag: 'eo'},
12-
{id:'fr-FR', label:'Français', flag: 'fr'},
13-
{id:'nl-NL', label:'Nederlands', flag: 'nl'},
14-
{id:'es-ES', label:'Español', flag: 'es'},
15-
{id:'ca', label:'Català', flag: 'ca'},
16-
{id:'it-IT', label:'Italiano', flag: 'it'},
17-
{id:'pt-PT', label:'Português', flag: 'pt'},
18-
{id:'de-DE', label:'Deutsch', flag: 'de'}
19-
];
20-
var fallbackLocale = csConfig.fallbackLanguage ? fixLocale(csConfig.fallbackLanguage) : 'en';
8+
var
9+
locales = [
10+
{id:'en', label:'English', flag: 'us'},
11+
{id:'en-GB', label:'English (UK)', flag: 'gb'},
12+
{id:'eo-EO', label:'Esperanto', flag: 'eo'},
13+
{id:'fr-FR', label:'Français', flag: 'fr'},
14+
{id:'nl-NL', label:'Nederlands', flag: 'nl'},
15+
{id:'es-ES', label:'Español', flag: 'es'},
16+
{id:'ca', label:'Català', flag: 'ca'},
17+
{id:'it-IT', label:'Italiano', flag: 'it'},
18+
{id:'pt-PT', label:'Português', flag: 'pt'},
19+
{id:'de-DE', label:'Deutsch', flag: 'de'}
20+
],
21+
timeouts = [
22+
-1,
23+
500,
24+
1000,
25+
5000,
26+
10000,
27+
30000,
28+
60000,
29+
300000
30+
],
31+
fallbackLocale = csConfig.fallbackLanguage ? fixLocale(csConfig.fallbackLanguage) : 'en'
32+
;
2133

2234
// Convert browser locale to app locale (fix #140)
2335
function fixLocale (locale) {
@@ -70,7 +82,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
7082
httpsMode: false
7183
},
7284
defaultSettings = angular.merge({
73-
timeout : -1, // -1 = auto
85+
timeout: -1, // -1 = auto
7486
useRelative: false,
7587
useLocalStorage: !!$window.localStorage, // override to false if no device
7688
useLocalStorageEncryption: false,
@@ -136,8 +148,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
136148
defaultSettings.walletHistoryAutoRefresh = false;
137149
// endRemoveIf(no-device)
138150

139-
var
140-
reset = function() {
151+
function reset() {
141152
_.keys(data).forEach(function(key){
142153
delete data[key];
143154
});
@@ -146,9 +157,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
146157

147158
return api.data.raisePromise.reset(data)
148159
.then(store);
149-
},
160+
}
150161

151-
getByPath = function(path, defaultValue) {
162+
function getByPath(path, defaultValue) {
152163
var obj = data;
153164
_.each(path.split('.'), function(key) {
154165
obj = obj[key];
@@ -159,17 +170,17 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
159170
});
160171

161172
return obj;
162-
},
173+
}
163174

164-
emitChangedEvent = function() {
175+
function emitChangedEvent() {
165176
var hasChanged = angular.isUndefined(previousData) || !angular.equals(previousData, data);
166177
if (hasChanged) {
167178
previousData = angular.copy(data);
168179
return api.data.raise.changed(data);
169180
}
170-
},
181+
}
171182

172-
store = function() {
183+
function store() {
173184
if (!started) {
174185
console.debug('[settings] Waiting start finished...');
175186
return (startPromise || start()).then(store);
@@ -207,13 +218,13 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
207218

208219
// Emit event on store
209220
.then(emitChangedEvent);
210-
},
221+
}
211222

212223
/**
213224
* Apply new settings (can be partial)
214225
* @param newData
215226
*/
216-
applyData = function(newData) {
227+
function applyData(newData) {
217228
if (!newData) return; // skip empty
218229

219230
// DEBUG
@@ -232,6 +243,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
232243
newData[key] = defaultSettings[key]; // This will apply fixed value (override by config.js file)
233244
});
234245

246+
// Force using an existing timeout (e.g. for version < 1.7.4)
247+
newData.timeout = newData.timeout && timeouts.includes(newData.timeout) ? newData.timeout : -1 /* auto */;
248+
235249
// If need select a random peer, from the config
236250
if (!data.node && !newData.node && _.size(csConfig.fallbackNodes) > 0) {
237251
newData.node = _.sample(csConfig.fallbackNodes);
@@ -252,9 +266,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
252266
if (localeChanged) {
253267
$translate.use(data.locale.id);
254268
}
255-
},
269+
}
256270

257-
restore = function() {
271+
function restore() {
258272
var now = Date.now();
259273

260274
return localStorage.getObject(constants.STORAGE_KEY)
@@ -274,22 +288,22 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
274288

275289
emitChangedEvent();
276290
});
277-
},
291+
}
278292

279-
getLicenseUrl = function() {
293+
function getLicenseUrl() {
280294
var locale = data.locale && data.locale.id || csConfig.defaultLanguage || 'en';
281295
return (csConfig.license) ?
282296
(csConfig.license[locale] ? csConfig.license[locale] : defaultSettings.license[csConfig.defaultLanguage || 'en'] || csConfig.license) : undefined;
283-
},
297+
}
284298

285-
getFeedUrl = function() {
299+
function getFeedUrl() {
286300
var locale = data.locale && data.locale.id || csConfig.defaultLanguage || 'en';
287301
return (csConfig.feed && csConfig.feed.jsonFeed) ?
288302
(csConfig.feed.jsonFeed[locale] ? csConfig.feed.jsonFeed[locale] : defaultSettings.feed.jsonFeed[csConfig.defaultLanguage || 'en'] || csConfig.feed) : undefined;
289-
},
303+
}
290304

291305
// Detect locale successful changes, then apply to vendor libs
292-
onLocaleChange = function() {
306+
function onLocaleChange() {
293307
var locale = $translate.use();
294308
console.debug('[settings] Locale ['+locale+']');
295309

@@ -323,18 +337,18 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
323337

324338
// Emit event
325339
api.locale.raise.changed(locale);
326-
},
340+
}
327341

328-
isStarted = function() {
342+
function isStarted() {
329343
return started;
330-
},
344+
}
331345

332-
ready = function() {
346+
function ready() {
333347
if (started) return $q.when();
334348
return startPromise || start();
335-
},
349+
}
336350

337-
start = function() {
351+
function start() {
338352
console.debug('[settings] Starting...');
339353

340354
startPromise = localStorage.ready()
@@ -386,6 +400,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
386400
// api extension
387401
api: api,
388402
locales: locales,
403+
timeouts: timeouts,
389404
constants: constants
390405
};
391406
});

www/templates/settings/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ <h4 class="gray text-italic">
273273
<h4 class="gray text-wrap hidden-xs" ng-bind-html="'SETTINGS.NETWORK_ANALYZE_TIMEOUT_HELP' | translate"></h4>
274274

275275
<select ng-model="formData.timeout"
276-
ng-options="t as ((t.label|translate) || (t.value|formatDurationMs)) for t in timeouts track by t.value">
276+
ng-options="t as (t === -1 ? ('SETTINGS.NETWORK_ANALYZE_TIMEOUT_AUTO'|translate) : (t|formatDurationMs)) for t in timeouts track by t">
277277
</select>
278278
</label>
279279

0 commit comments

Comments
 (0)