Skip to content

Commit

Permalink
[enh] Display warning when new release available - fix #80
Browse files Browse the repository at this point in the history
  • Loading branch information
blavenie committed Jan 9, 2018
1 parent 1b071b2 commit 6865f67
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 68 deletions.
6 changes: 3 additions & 3 deletions www/i18n/locale-en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
"ABOUT": {
"TITLE": "About",
"LICENSE": "<b>Free/libre software</b> (License GNU GPLv3).",
"LATEST_RELEASE": "There is a <b>newer version</ b> of {{'COMMON.APP_NAME' | translate}} (<b>v{{version}}</b>)",
"PLEASE_UPDATE": "Please update {{'COMMON.APP_NAME' | translate}} (latest version: <b>v{{version}}</b>)",
"CODE": "Source code:",
"DEVELOPERS": "Developers:",
"FORUM": "Forum:",
"DEV_WARNING": "Warning",
"DEV_WARNING_MESSAGE": "This application is still in active development.<br/>Please report any issue to us!",
"DEV_WARNING_MESSAGE_SHORT": "This App is still unstable (still under development).",
"PLEASE_REPORT_ISSUE": "Please report any issue to us!",
"REPORT_ISSUE": "Report an issue"
},
"HOME": {
Expand Down
9 changes: 6 additions & 3 deletions www/i18n/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
"ABOUT": {
"TITLE": "About",
"LICENSE": "<b>Free/libre software</b> (License GNU GPLv3).",
"LATEST_RELEASE": "There is a <b>newer version</ b> of {{'COMMON.APP_NAME' | translate}} (<b>v{{version}}</b>)",
"PLEASE_UPDATE": "Please update {{'COMMON.APP_NAME' | translate}} (latest version: <b>v{{version}}</b>)",
"CODE": "Source code:",
"DEVELOPERS": "Developers:",
"FORUM": "Forum:",
"DEV_WARNING": "Warning",
"DEV_WARNING_MESSAGE": "This application is still in active development.<br/>Please report any issue to us!",
"DEV_WARNING_MESSAGE_SHORT": "This App is still unstable (still under development).",
"PLEASE_REPORT_ISSUE": "Please report any issue to us!",
"REPORT_ISSUE": "Report an issue"
},
"HOME": {
Expand Down Expand Up @@ -342,6 +342,9 @@
"NO_PENDING": "No pending registrations.",
"NO_NEWCOMERS": "No members."
},
"CONTACTS": {
"TITLE": "Contacts"
},
"MODAL": {
"TITLE": "Search"
},
Expand Down
9 changes: 6 additions & 3 deletions www/i18n/locale-es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
"ABOUT": {
"TITLE": "A propósito ",
"LICENSE": "Aplicación <b>libre</b> (licencia GNU GPLv3).",
"LATEST_RELEASE": "Hay una <b>versión más nueva</b> de {{'COMMON.APP_NAME' | translate}} (<b>v{{version}}</b>)",
"PLEASE_UPDATE": "Por favor actualice {{'COMMON.APP_NAME' | translate}} (última versión: <b>v{{version}}</b>)",
"CODE": "Codigo fuente :",
"DEVELOPERS": "Desarrollado por :",
"FORUM": "Foro :",
"DEV_WARNING": "Advertencia",
"DEV_WARNING_MESSAGE": "Esta applicación ya no es estabilizada (Desarrollo en proceso).<br/>No duda a informarnos de las anomalías encontradas !",
"DEV_WARNING_MESSAGE_SHORT": "Esta Ap ya no es estabilizada (Desarrollo en proceso).",
"PLEASE_REPORT_ISSUE": "No duda a informarnos de las anomalías encontradas",
"REPORT_ISSUE": "Informar de un problema"
},
"HOME": {
Expand Down Expand Up @@ -342,6 +342,9 @@
"NO_PENDING": "Ninguna inscripción en espera.",
"NO_NEWCOMERS": "Ningun miembro."
},
"CONTACTS": {
"TITLE": "Contactos"
},
"MODAL": {
"TITLE": "Búsqueda"
},
Expand Down
6 changes: 3 additions & 3 deletions www/i18n/locale-fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@
"ABOUT": {
"TITLE": "À propos",
"LICENSE": "Application <b>libre</b> (licence GNU GPLv3).",
"LATEST_RELEASE": "Il existe une <b>version plus récente</b> de {{'COMMON.APP_NAME'|translate}} (<b>v{{version}}</b>)",
"PLEASE_UPDATE": "Veuillez mettre à jour {{'COMMON.APP_NAME'|translate}} (dernière version : <b>v{{version}}</b>)",
"CODE": "Code source :",
"DEVELOPERS": "Développé par :",
"FORUM": "Forum :",
"DEV_WARNING": "Avertissement",
"DEV_WARNING_MESSAGE": "Cette application est encore en plein développement.<br/>N'hésitez pas à nous remonter les anomalies rencontrées !",
"DEV_WARNING_MESSAGE_SHORT": "Cette App est en plein développement.",
"PLEASE_REPORT_ISSUE": "N'hésitez pas à nous remonter les anomalies rencontrées",
"REPORT_ISSUE": "Remonter un problème"
},
"HOME": {
Expand Down
1 change: 1 addition & 0 deletions www/js/controllers/app-controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $
$scope.doMotion = function(options) {
return $scope.motion.show(options);
};

}


Expand Down
41 changes: 40 additions & 1 deletion www/js/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
return started;
}


function getLatestRelease() {
var latestRelease = csSettings.data.latestReleaseUrl && csHttp.uri.parse(csSettings.data.latestReleaseUrl);
if (latestRelease) {
return csHttp.get(latestRelease.host, latestRelease.port, "/" + latestRelease.pathname)()
.then(function (json) {
//console.debug(json);
if (json && json.name && json.tag_name && json.html_url) {
return {
version: json.name,
url: json.html_url,
isNewer: (csHttp.version.compare(csConfig.version, json.name) < 0)
};
}
})
.catch(function(err) {
// silent (just log it)
console.error('[platform] Failed to get latest version', err);
})
;
}
return $q.when();
}

function addListeners() {
listeners = [
// Listen if node changed
Expand Down Expand Up @@ -254,7 +278,10 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
ready: ready,
restart: restart,
start: start,
stop: stop
stop: stop,
version: {
latest: getLatestRelease
}
};
})

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

// Get latest release
csPlatform.version.latest()
.then(function(release) {
if (release.isNewer) {
console.info('[app] New release detected: {0}'.format(release.version));
$rootScope.newRelease = release;
}
else {
console.info('[app] Already use latest release {0}'.format(csConfig.version));
}
});

// Make sure platform is started
return csPlatform.ready();
});
Expand Down
18 changes: 13 additions & 5 deletions www/js/services/device-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ angular.module('cesium.device.services', ['cesium.utils.services', 'cesium.setti
// workaround to quickly no is device or not (even before the ready() event)
enable: true
},
cache = {},
started = false,
startPromise;

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

exports.isDesktop = function() {
try {
// Has NodeJs + NW ?
return !!process && !!App;
} catch (err) {
return false;
if (!angular.isDefined(cache.isDesktop)) {
try {
// Should have NodeJs and NW
cache.isDesktop = !exports.enable && !!process && !!App;
} catch (err) {
cache.isDesktop = false;
}
}
return cache.isDesktop;
};

exports.isWeb = function() {
return !exports.enable && !exports.isDesktop();
};

exports.ready = function() {
Expand Down
64 changes: 63 additions & 1 deletion www/js/services/http-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,71 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
return Math.floor(moment().utc().valueOf() / 1000);
}

function isPositiveInteger(x) {
// http://stackoverflow.com/a/1019526/11236
return /^\d+$/.test(x);
}

/**
* Compare two software version numbers (e.g. 1.7.1)
* Returns:
*
* 0 if they're identical
* negative if v1 < v2
* positive if v1 > v2
* Nan if they in the wrong format
*
* E.g.:
*
* assert(version_number_compare("1.7.1", "1.6.10") > 0);
* assert(version_number_compare("1.7.1", "1.7.10") < 0);
*
* "Unit tests": http://jsfiddle.net/ripper234/Xv9WL/28/
*
* Taken from http://stackoverflow.com/a/6832721/11236
*/
function compareVersionNumbers(v1, v2){
var v1parts = v1.split('.');
var v2parts = v2.split('.');

// First, validate both numbers are true version numbers
function validateParts(parts) {
for (var i = 0; i < parts.length; ++i) {
if (!isPositiveInteger(parts[i])) {
return false;
}
}
return true;
}
if (!validateParts(v1parts) || !validateParts(v2parts)) {
return NaN;
}

for (var i = 0; i < v1parts.length; ++i) {
if (v2parts.length === i) {
return 1;
}

if (v1parts[i] === v2parts[i]) {
continue;
}
if (v1parts[i] > v2parts[i]) {
return 1;
}
return -1;
}

if (v1parts.length != v2parts.length) {
return -1;
}

return 0;
}

function isVersionCompatible(minVersion, actualVersion) {
// TODO: add implementation
console.debug('[http] TODO: implement check version [{0}] compatible with [{1}]'.format(actualVersion, minVersion));
return true;
return compareVersionNumbers(minVersion, actualVersion) <= 0;
}

var cache = angular.copy(csCache.constants);
Expand All @@ -374,6 +435,7 @@ angular.module('cesium.http.services', ['cesium.cache.services'])
now: getDateNow
},
version: {
compare: compareVersionNumbers,
isCompatible: isVersionCompatible
},
cache: cache
Expand Down
19 changes: 17 additions & 2 deletions www/js/services/modal-services.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
angular.module('cesium.modal.services', [])

// Useful for modal with no controller
.controller('EmptyModalCtrl', function ($scope, parameters) {
.controller('EmptyModalCtrl', function () {
'ngInject';

})

.controller('AboutModalCtrl', function ($scope, UIUtils, csHttp) {
'ngInject';

$scope.openLink = function(event, uri, options) {
options = options || {};

// If unable to open, just copy value
options.onError = function() {
return UIUtils.popover.copy(event, uri);
};

return csHttp.uri.open(uri, options);
};
})

.factory('ModalUtils', function($ionicModal, $rootScope, $q, $injector, $controller, $timeout) {
'ngInject';

Expand Down Expand Up @@ -164,7 +179,7 @@ angular.module('cesium.modal.services', [])
}

function showAbout(parameters) {
return ModalUtils.show('templates/modal_about.html','EmptyModalCtrl',
return ModalUtils.show('templates/modal_about.html','AboutModalCtrl',
parameters);
}

Expand Down
3 changes: 3 additions & 0 deletions www/js/services/settings-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
uiEffects: true,
minVersion: '1.1.0',
newIssueUrl: "https://git.duniter.org/clients/cesium/cesium/issues/new",
latestReleaseUrl: "https://api.github.com/repos/duniter/cesium/releases/latest",
helptip: {
enable: true,
installDocUrl: "https://duniter.org/en/wiki/duniter/install/",
Expand Down Expand Up @@ -191,6 +192,8 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config'])
data.timeWarningExpireMembership = defaultSettings.timeWarningExpireMembership;
data.cacheTimeMs = defaultSettings.cacheTimeMs;
data.timeout = defaultSettings.timeout;
data.minVersion = defaultSettings.minVersion;
data.latestReleaseUrl = defaultSettings.latestReleaseUrl;

// Apply the new locale (only if need)
if (localeChanged) {
Expand Down
16 changes: 13 additions & 3 deletions www/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,24 @@ <h4 ng-if="!login">
<ion-footer-bar class="bar-stable footer hidden-xs hidden-sm" >
<a class="pull-left icon-help" menu-toggle="left" title="{{:locale:'HOME.BTN_HELP'|translate}}" ui-sref="app.help"></a>

<a class="title gray" ng-click="showAboutModal()" title="{{:locale:'HOME.BTN_ABOUT'|translate}}">
<a class="title gray" ng-click="showAboutModal()" >

<!-- version -->
{{:locale:'COMMON.APP_VERSION'|translate:{version: config.version} }}
<span title="{{:locale:'HOME.BTN_ABOUT'|translate}}"
ng-class="{'assertive': $root.newRelease}">
<!-- warning icon, if new version available -->
<i ng-if="$root.newRelease" class="ion-alert-circled assertive"></i>

{{:locale:'COMMON.APP_VERSION'|translate:{version: config.version} }}
</span>
|
<!-- about -->
{{:locale:'HOME.BTN_ABOUT'|translate}}
<span title="{{:locale:'HOME.BTN_ABOUT'|translate}}">
{{:locale:'HOME.BTN_ABOUT'|translate}}
</span>
</a>


</ion-footer-bar>
<!-- endRemoveIf(device) -->
</ion-side-menu>
Expand Down
Loading

0 comments on commit 6865f67

Please sign in to comment.