Skip to content

Commit

Permalink
read version information from... version.json (#1573)
Browse files Browse the repository at this point in the history
read version information from... version.json
  • Loading branch information
mikeller committed Aug 12, 2019
2 parents bac0417 + 3fb1d96 commit 6371379
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
5 changes: 4 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion src/js/backup_restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
39 changes: 19 additions & 20 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();

Expand All @@ -117,7 +129,7 @@ function startProcess() {
break;
}

if (GUI.operating_system !== 'ChromeOS') {
if (!GUI.isOther() && GUI.operating_system !== 'ChromeOS') {
checkForConfiguratorUpdates();
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 6371379

Please sign in to comment.