Skip to content

Commit 6865f67

Browse files
committed
[enh] Display warning when new release available - fix #80
1 parent 1b071b2 commit 6865f67

File tree

12 files changed

+223
-68
lines changed

12 files changed

+223
-68
lines changed

www/i18n/locale-en-GB.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
"ABOUT": {
9999
"TITLE": "About",
100100
"LICENSE": "<b>Free/libre software</b> (License GNU GPLv3).",
101+
"LATEST_RELEASE": "There is a <b>newer version</ b> of {{'COMMON.APP_NAME' | translate}} (<b>v{{version}}</b>)",
102+
"PLEASE_UPDATE": "Please update {{'COMMON.APP_NAME' | translate}} (latest version: <b>v{{version}}</b>)",
101103
"CODE": "Source code:",
102104
"DEVELOPERS": "Developers:",
103105
"FORUM": "Forum:",
104-
"DEV_WARNING": "Warning",
105-
"DEV_WARNING_MESSAGE": "This application is still in active development.<br/>Please report any issue to us!",
106-
"DEV_WARNING_MESSAGE_SHORT": "This App is still unstable (still under development).",
106+
"PLEASE_REPORT_ISSUE": "Please report any issue to us!",
107107
"REPORT_ISSUE": "Report an issue"
108108
},
109109
"HOME": {

www/i18n/locale-en.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
"ABOUT": {
9999
"TITLE": "About",
100100
"LICENSE": "<b>Free/libre software</b> (License GNU GPLv3).",
101+
"LATEST_RELEASE": "There is a <b>newer version</ b> of {{'COMMON.APP_NAME' | translate}} (<b>v{{version}}</b>)",
102+
"PLEASE_UPDATE": "Please update {{'COMMON.APP_NAME' | translate}} (latest version: <b>v{{version}}</b>)",
101103
"CODE": "Source code:",
102104
"DEVELOPERS": "Developers:",
103105
"FORUM": "Forum:",
104-
"DEV_WARNING": "Warning",
105-
"DEV_WARNING_MESSAGE": "This application is still in active development.<br/>Please report any issue to us!",
106-
"DEV_WARNING_MESSAGE_SHORT": "This App is still unstable (still under development).",
106+
"PLEASE_REPORT_ISSUE": "Please report any issue to us!",
107107
"REPORT_ISSUE": "Report an issue"
108108
},
109109
"HOME": {
@@ -342,6 +342,9 @@
342342
"NO_PENDING": "No pending registrations.",
343343
"NO_NEWCOMERS": "No members."
344344
},
345+
"CONTACTS": {
346+
"TITLE": "Contacts"
347+
},
345348
"MODAL": {
346349
"TITLE": "Search"
347350
},

www/i18n/locale-es-ES.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
"ABOUT": {
9999
"TITLE": "A propósito ",
100100
"LICENSE": "Aplicación <b>libre</b> (licencia GNU GPLv3).",
101+
"LATEST_RELEASE": "Hay una <b>versión más nueva</b> de {{'COMMON.APP_NAME' | translate}} (<b>v{{version}}</b>)",
102+
"PLEASE_UPDATE": "Por favor actualice {{'COMMON.APP_NAME' | translate}} (última versión: <b>v{{version}}</b>)",
101103
"CODE": "Codigo fuente :",
102104
"DEVELOPERS": "Desarrollado por :",
103105
"FORUM": "Foro :",
104-
"DEV_WARNING": "Advertencia",
105-
"DEV_WARNING_MESSAGE": "Esta applicación ya no es estabilizada (Desarrollo en proceso).<br/>No duda a informarnos de las anomalías encontradas !",
106-
"DEV_WARNING_MESSAGE_SHORT": "Esta Ap ya no es estabilizada (Desarrollo en proceso).",
106+
"PLEASE_REPORT_ISSUE": "No duda a informarnos de las anomalías encontradas",
107107
"REPORT_ISSUE": "Informar de un problema"
108108
},
109109
"HOME": {
@@ -342,6 +342,9 @@
342342
"NO_PENDING": "Ninguna inscripción en espera.",
343343
"NO_NEWCOMERS": "Ningun miembro."
344344
},
345+
"CONTACTS": {
346+
"TITLE": "Contactos"
347+
},
345348
"MODAL": {
346349
"TITLE": "Búsqueda"
347350
},

www/i18n/locale-fr-FR.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@
9898
"ABOUT": {
9999
"TITLE": "À propos",
100100
"LICENSE": "Application <b>libre</b> (licence GNU GPLv3).",
101+
"LATEST_RELEASE": "Il existe une <b>version plus récente</b> de {{'COMMON.APP_NAME'|translate}} (<b>v{{version}}</b>)",
102+
"PLEASE_UPDATE": "Veuillez mettre à jour {{'COMMON.APP_NAME'|translate}} (dernière version : <b>v{{version}}</b>)",
101103
"CODE": "Code source :",
102104
"DEVELOPERS": "Développé par :",
103105
"FORUM": "Forum :",
104-
"DEV_WARNING": "Avertissement",
105-
"DEV_WARNING_MESSAGE": "Cette application est encore en plein développement.<br/>N'hésitez pas à nous remonter les anomalies rencontrées !",
106-
"DEV_WARNING_MESSAGE_SHORT": "Cette App est en plein développement.",
106+
"PLEASE_REPORT_ISSUE": "N'hésitez pas à nous remonter les anomalies rencontrées",
107107
"REPORT_ISSUE": "Remonter un problème"
108108
},
109109
"HOME": {

www/js/controllers/app-controllers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
411411
$scope.doMotion = function(options) {
412412
return $scope.motion.show(options);
413413
};
414+
414415
}
415416

416417

www/js/platform.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,30 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
161161
return started;
162162
}
163163

164+
165+
function getLatestRelease() {
166+
var latestRelease = csSettings.data.latestReleaseUrl && csHttp.uri.parse(csSettings.data.latestReleaseUrl);
167+
if (latestRelease) {
168+
return csHttp.get(latestRelease.host, latestRelease.port, "/" + latestRelease.pathname)()
169+
.then(function (json) {
170+
//console.debug(json);
171+
if (json && json.name && json.tag_name && json.html_url) {
172+
return {
173+
version: json.name,
174+
url: json.html_url,
175+
isNewer: (csHttp.version.compare(csConfig.version, json.name) < 0)
176+
};
177+
}
178+
})
179+
.catch(function(err) {
180+
// silent (just log it)
181+
console.error('[platform] Failed to get latest version', err);
182+
})
183+
;
184+
}
185+
return $q.when();
186+
}
187+
164188
function addListeners() {
165189
listeners = [
166190
// Listen if node changed
@@ -254,7 +278,10 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
254278
ready: ready,
255279
restart: restart,
256280
start: start,
257-
stop: stop
281+
stop: stop,
282+
version: {
283+
latest: getLatestRelease
284+
}
258285
};
259286
})
260287

@@ -318,6 +345,18 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
318345
StatusBar.styleDefault();
319346
}
320347

348+
// Get latest release
349+
csPlatform.version.latest()
350+
.then(function(release) {
351+
if (release.isNewer) {
352+
console.info('[app] New release detected: {0}'.format(release.version));
353+
$rootScope.newRelease = release;
354+
}
355+
else {
356+
console.info('[app] Already use latest release {0}'.format(csConfig.version));
357+
}
358+
});
359+
321360
// Make sure platform is started
322361
return csPlatform.ready();
323362
});

www/js/services/device-services.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ angular.module('cesium.device.services', ['cesium.utils.services', 'cesium.setti
1919
// workaround to quickly no is device or not (even before the ready() event)
2020
enable: true
2121
},
22+
cache = {},
2223
started = false,
2324
startPromise;
2425

@@ -204,12 +205,19 @@ angular.module('cesium.device.services', ['cesium.utils.services', 'cesium.setti
204205
};
205206

206207
exports.isDesktop = function() {
207-
try {
208-
// Has NodeJs + NW ?
209-
return !!process && !!App;
210-
} catch (err) {
211-
return false;
208+
if (!angular.isDefined(cache.isDesktop)) {
209+
try {
210+
// Should have NodeJs and NW
211+
cache.isDesktop = !exports.enable && !!process && !!App;
212+
} catch (err) {
213+
cache.isDesktop = false;
214+
}
212215
}
216+
return cache.isDesktop;
217+
};
218+
219+
exports.isWeb = function() {
220+
return !exports.enable && !exports.isDesktop();
213221
};
214222

215223
exports.ready = function() {

www/js/services/http-services.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,71 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
346346
return Math.floor(moment().utc().valueOf() / 1000);
347347
}
348348

349+
function isPositiveInteger(x) {
350+
// http://stackoverflow.com/a/1019526/11236
351+
return /^\d+$/.test(x);
352+
}
353+
354+
/**
355+
* Compare two software version numbers (e.g. 1.7.1)
356+
* Returns:
357+
*
358+
* 0 if they're identical
359+
* negative if v1 < v2
360+
* positive if v1 > v2
361+
* Nan if they in the wrong format
362+
*
363+
* E.g.:
364+
*
365+
* assert(version_number_compare("1.7.1", "1.6.10") > 0);
366+
* assert(version_number_compare("1.7.1", "1.7.10") < 0);
367+
*
368+
* "Unit tests": http://jsfiddle.net/ripper234/Xv9WL/28/
369+
*
370+
* Taken from http://stackoverflow.com/a/6832721/11236
371+
*/
372+
function compareVersionNumbers(v1, v2){
373+
var v1parts = v1.split('.');
374+
var v2parts = v2.split('.');
375+
376+
// First, validate both numbers are true version numbers
377+
function validateParts(parts) {
378+
for (var i = 0; i < parts.length; ++i) {
379+
if (!isPositiveInteger(parts[i])) {
380+
return false;
381+
}
382+
}
383+
return true;
384+
}
385+
if (!validateParts(v1parts) || !validateParts(v2parts)) {
386+
return NaN;
387+
}
388+
389+
for (var i = 0; i < v1parts.length; ++i) {
390+
if (v2parts.length === i) {
391+
return 1;
392+
}
393+
394+
if (v1parts[i] === v2parts[i]) {
395+
continue;
396+
}
397+
if (v1parts[i] > v2parts[i]) {
398+
return 1;
399+
}
400+
return -1;
401+
}
402+
403+
if (v1parts.length != v2parts.length) {
404+
return -1;
405+
}
406+
407+
return 0;
408+
}
409+
349410
function isVersionCompatible(minVersion, actualVersion) {
350411
// TODO: add implementation
351412
console.debug('[http] TODO: implement check version [{0}] compatible with [{1}]'.format(actualVersion, minVersion));
352-
return true;
413+
return compareVersionNumbers(minVersion, actualVersion) <= 0;
353414
}
354415

355416
var cache = angular.copy(csCache.constants);
@@ -374,6 +435,7 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
374435
now: getDateNow
375436
},
376437
version: {
438+
compare: compareVersionNumbers,
377439
isCompatible: isVersionCompatible
378440
},
379441
cache: cache

www/js/services/modal-services.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
angular.module('cesium.modal.services', [])
22

33
// Useful for modal with no controller
4-
.controller('EmptyModalCtrl', function ($scope, parameters) {
4+
.controller('EmptyModalCtrl', function () {
55
'ngInject';
66

77
})
88

9+
.controller('AboutModalCtrl', function ($scope, UIUtils, csHttp) {
10+
'ngInject';
11+
12+
$scope.openLink = function(event, uri, options) {
13+
options = options || {};
14+
15+
// If unable to open, just copy value
16+
options.onError = function() {
17+
return UIUtils.popover.copy(event, uri);
18+
};
19+
20+
return csHttp.uri.open(uri, options);
21+
};
22+
})
23+
924
.factory('ModalUtils', function($ionicModal, $rootScope, $q, $injector, $controller, $timeout) {
1025
'ngInject';
1126

@@ -164,7 +179,7 @@ angular.module('cesium.modal.services', [])
164179
}
165180

166181
function showAbout(parameters) {
167-
return ModalUtils.show('templates/modal_about.html','EmptyModalCtrl',
182+
return ModalUtils.show('templates/modal_about.html','AboutModalCtrl',
168183
parameters);
169184
}
170185

www/js/services/settings-services.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
6868
uiEffects: true,
6969
minVersion: '1.1.0',
7070
newIssueUrl: "https://git.duniter.org/clients/cesium/cesium/issues/new",
71+
latestReleaseUrl: "https://api.github.com/repos/duniter/cesium/releases/latest",
7172
helptip: {
7273
enable: true,
7374
installDocUrl: "https://duniter.org/en/wiki/duniter/install/",
@@ -191,6 +192,8 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
191192
data.timeWarningExpireMembership = defaultSettings.timeWarningExpireMembership;
192193
data.cacheTimeMs = defaultSettings.cacheTimeMs;
193194
data.timeout = defaultSettings.timeout;
195+
data.minVersion = defaultSettings.minVersion;
196+
data.latestReleaseUrl = defaultSettings.latestReleaseUrl;
194197

195198
// Apply the new locale (only if need)
196199
if (localeChanged) {

0 commit comments

Comments
 (0)