From 3fb1d96370185dee64fc22b64f8971e89a2ab6ed Mon Sep 17 00:00:00 2001 From: Kyle K Date: Sun, 11 Aug 2019 07:23:13 +0000 Subject: [PATCH] read version information from... version.json --- gulpfile.js | 5 ++++- src/js/backup_restore.js | 2 +- src/js/main.js | 39 +++++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9f86833c..1f659802 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -476,7 +476,10 @@ function getHash(cb) { function writeChangesetId() { var versionJson = new stream.Readable; - versionJson.push(JSON.stringify({ gitChangesetId: gitChangeSetId }, undefined, 2)); + versionJson.push(JSON.stringify({ + gitChangesetId: gitChangeSetId, + version: pkg.version + }, undefined, 2)); versionJson.push(null); return versionJson .pipe(source('version.json')) diff --git a/src/js/backup_restore.js b/src/js/backup_restore.js index 8c0518ea..19bb060d 100644 --- a/src/js/backup_restore.js +++ b/src/js/backup_restore.js @@ -5,7 +5,7 @@ function configuration_backup(callback) { var activeProfile = null; - var version = getManifestVersion(); + var version = CONFIGURATOR.version; if (version.indexOf(".") === -1) { version = version + ".0.0"; diff --git a/src/js/main.js b/src/js/main.js index 4a464de3..3abe0bc4 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -5,8 +5,20 @@ var analytics = undefined; $(document).ready(function () { $.getJSON('version.json', function(data) { + CONFIGURATOR.version = data.version; CONFIGURATOR.gitChangesetId = data.gitChangesetId; + // Version in the ChromeApp's manifest takes precedence. + if(chrome.runtime && chrome.runtime.getManifest) { + var manifest = chrome.runtime.getManifest(); + CONFIGURATOR.version = manifest.version; + // manifest.json for ChromeApp can't have a version + // with a prerelease tag eg 10.0.0-RC4 + // Work around is to specify the prerelease version in version_name + if (manifest.version_name) { + CONFIGURATOR.version = manifest.version_name; + } + } i18n.init(function() { startProcess(); initializeSerialBackend(); @@ -50,7 +62,7 @@ function setupAnalytics(result) { var debugMode = typeof process === "object" && process.versions['nw-flavor'] === 'sdk'; - analytics = new Analytics('UA-123002063-1', userId, 'Betaflight Configurator', getManifestVersion(), CONFIGURATOR.gitChangesetId, GUI.operating_system, checkForDebugVersions, optOut, debugMode, getBuildType()); + analytics = new Analytics('UA-123002063-1', userId, 'Betaflight Configurator', CONFIGURATOR.version, CONFIGURATOR.gitChangesetId, GUI.operating_system, checkForDebugVersions, optOut, debugMode, getBuildType()); function logException(exception) { analytics.sendException(exception.stack); @@ -79,7 +91,7 @@ function setupAnalytics(result) { // and open it in external browser GUI.nwGui.Shell.openExternal(url); }); - } else { + } else if (!GUI.isOther()) { // Looks like we're in Chrome - but the event does not actually get fired chrome.runtime.onSuspend.addListener(sendCloseEvent); } @@ -96,9 +108,9 @@ function startProcess() { // alternative - window.navigator.appVersion.match(/Chrome\/([0-9.]*)/)[1]; GUI.log(i18n.getMessage('infoVersions',{operatingSystem: GUI.operating_system, chromeVersion: window.navigator.appVersion.replace(/.*Chrome\/([0-9.]*).*/, "$1"), - configuratorVersion: getManifestVersion()})); + configuratorVersion: CONFIGURATOR.version })); - $('#logo .version').text(getManifestVersion()); + $('#logo .version').text(CONFIGURATOR.version); updateStatusBarVersion(); updateTopBarVersion(); @@ -117,7 +129,7 @@ function startProcess() { break; } - if (GUI.operating_system !== 'ChromeOS') { + if (!GUI.isOther() && GUI.operating_system !== 'ChromeOS') { checkForConfiguratorUpdates(); } @@ -557,7 +569,7 @@ function notifyOutdatedVersion(releaseData) { } }); - if (versions.length > 0 && semver.lt(getManifestVersion(), versions[0].tag_name)) { + if (versions.length > 0 && semver.lt(CONFIGURATOR.version, versions[0].tag_name)) { GUI.log(i18n.getMessage('configuratorUpdateNotice', [versions[0].tag_name, versions[0].html_url])); var dialog = $('.dialogConfiguratorUpdate')[0]; @@ -735,7 +747,7 @@ function getFirmwareVersion(firmwareVersion, firmwareId) { } function getConfiguratorVersion() { - return i18n.getMessage('versionLabelConfigurator') + ': ' + getManifestVersion(); + return i18n.getMessage('versionLabelConfigurator') + ': ' + CONFIGURATOR.version; } function updateTopBarVersion(firmwareVersion, firmwareId, hardwareId) { @@ -769,19 +781,6 @@ function updateStatusBarVersion(firmwareVersion, firmwareId, hardwareId) { $('#status-bar .version').text(versionText); } -function getManifestVersion(manifest) { - if (!manifest) { - manifest = chrome.runtime.getManifest(); - } - - var version = manifest.version_name; - if (!version) { - version = manifest.version; - } - - return version; -} - function showErrorDialog(message) { var dialog = $('.dialogError')[0];