From 0c8a73b099946595e0872b58bab04d8e2d60d1d3 Mon Sep 17 00:00:00 2001 From: Antelle Date: Sun, 7 Feb 2016 14:49:31 +0300 Subject: [PATCH] check local version in updater --- app/scripts/comp/updater.js | 36 +++++++++++-------- .../views/settings/settings-general-view.js | 3 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/scripts/comp/updater.js b/app/scripts/comp/updater.js index 41640331..f68b895b 100644 --- a/app/scripts/comp/updater.js +++ b/app/scripts/comp/updater.js @@ -122,7 +122,7 @@ var Updater = { } if (!startedByUser && that.getAutoUpdateType() === 'install') { that.update(startedByUser); - } else if (UpdateModel.instance.get('lastVersion') !== RuntimeInfo.version) { + } else if (that.compareVersions(UpdateModel.instance.get('lastVersion'), RuntimeInfo.version) > 0) { UpdateModel.instance.set('updateStatus', 'found'); } }, @@ -140,32 +140,40 @@ var Updater = { }, canAutoUpdate: function() { - var launcherVersion = Launcher.version.split('.'); var minLauncherVersion = UpdateModel.instance.get('lastCheckUpdMin'); if (minLauncherVersion) { - minLauncherVersion = minLauncherVersion.split('.'); - for (var num = 0; num < minLauncherVersion.length; num++) { - var min = minLauncherVersion[num] | 0, - actual = launcherVersion[num] | 0; - if (min < actual) { - return true; - } - if (min > actual) { - UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true }); - return false; - } + var cmp = this.compareVersions(Launcher.version, minLauncherVersion); + if (cmp < 0) { + UpdateModel.instance.set({ updateStatus: 'ready', updateManual: true }); + return false; } } return true; }, + compareVersions: function(left, right) { + left = left.split('.'); + right = right.split('.'); + for (var num = 0; num < left.length; num++) { + var partLeft = left[num] | 0, + partRight = right[num] | 0; + if (partLeft < partRight) { + return -1; + } + if (partLeft > partRight) { + return 1; + } + } + return 0; + }, + update: function(startedByUser, successCallback) { var ver = UpdateModel.instance.get('lastVersion'); if (!this.enabled) { logger.info('Updater is disabled'); return; } - if (ver === RuntimeInfo.version) { + if (this.compareVersions(RuntimeInfo.version, ver) >= 0) { logger.info('You are using the latest version'); return; } diff --git a/app/scripts/views/settings/settings-general-view.js b/app/scripts/views/settings/settings-general-view.js index 26be49aa..846ea1cc 100644 --- a/app/scripts/views/settings/settings-general-view.js +++ b/app/scripts/views/settings/settings-general-view.js @@ -91,7 +91,8 @@ var SettingsGeneralView = Backbone.View.extend({ return errMsg; case 'ok': var msg = Locale.setGenCheckedAt + ' ' + Format.dtStr(UpdateModel.instance.get('lastCheckDate')) + ': '; - if (RuntimeInfo.version === UpdateModel.instance.get('lastVersion')) { + var cmp = Updater.compareVersions(RuntimeInfo.version, UpdateModel.instance.get('lastVersion')); + if (cmp >= 0) { msg += Locale.setGenLatestVer; } else { msg += Locale.setGenNewVer.replace('{}', UpdateModel.instance.get('lastVersion')) + ' ' +