Simplified configurator version checking (#3346)
parent
ad5b94cd2a
commit
6618378e8d
|
@ -160,4 +160,9 @@ export default class BuildApi {
|
|||
const url = `${this._url}/api/releases/${release}/commits`;
|
||||
this.load(url, onSuccess, onFailure);
|
||||
}
|
||||
|
||||
loadConfiguratorRelease(type, onSuccess, onFailure) {
|
||||
const url = `${this._url}/api/configurator/releases/${type}`;
|
||||
this.load(url, onSuccess, onFailure);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
import { gui_log } from "./gui_log";
|
||||
import { i18n } from "./localization";
|
||||
import { get as getStorage, set as setStorage } from "./SessionStorage";
|
||||
|
||||
const ReleaseChecker = function (releaseName, releaseUrl) {
|
||||
const self = this;
|
||||
|
||||
self._releaseName = releaseName;
|
||||
self._releaseDataTag = `${self._releaseName}ReleaseData`;
|
||||
self._releaseLastUpdateTag = `${self._releaseName}ReleaseLastUpdate`;
|
||||
self._releaseUrl = releaseUrl;
|
||||
};
|
||||
|
||||
ReleaseChecker.prototype.loadReleaseData = function (processFunction) {
|
||||
const self = this;
|
||||
const result = getStorage([self._releaseLastUpdateTag, self._releaseDataTag]);
|
||||
const releaseDataTimestamp = $.now();
|
||||
const cacheReleaseData = result[self._releaseDataTag];
|
||||
const cachedReleaseLastUpdate = result[self._releaseLastUpdateTag];
|
||||
|
||||
if (!cacheReleaseData || !cachedReleaseLastUpdate || releaseDataTimestamp - cachedReleaseLastUpdate > 3600 * 1000) {
|
||||
$.get(self._releaseUrl, function (releaseData) {
|
||||
gui_log(i18n.getMessage('releaseCheckLoaded',[self._releaseName]));
|
||||
|
||||
const data = {};
|
||||
data[self._releaseDataTag] = releaseData;
|
||||
data[self._releaseLastUpdateTag] = releaseDataTimestamp;
|
||||
setStorage(data);
|
||||
|
||||
self._processReleaseData(releaseData, processFunction);
|
||||
}).fail(function (data) {
|
||||
let message = '';
|
||||
if (data['responseJSON']) {
|
||||
message = data['responseJSON'].message;
|
||||
}
|
||||
gui_log(i18n.getMessage('releaseCheckFailed',[self._releaseName,message]));
|
||||
|
||||
self._processReleaseData(cacheReleaseData, processFunction);
|
||||
});
|
||||
} else {
|
||||
if (cacheReleaseData) {
|
||||
gui_log(i18n.getMessage('releaseCheckCached',[self._releaseName]));
|
||||
}
|
||||
|
||||
self._processReleaseData(cacheReleaseData, processFunction);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ReleaseChecker.prototype._processReleaseData = function (releaseData, processFunction) {
|
||||
if (releaseData) {
|
||||
processFunction(releaseData);
|
||||
} else {
|
||||
gui_log(i18n.getMessage('releaseCheckNoInfo',[self._releaseName]));
|
||||
|
||||
processFunction();
|
||||
}
|
||||
};
|
||||
|
||||
export default ReleaseChecker;
|
|
@ -1,43 +1,21 @@
|
|||
import semver from "semver";
|
||||
import ReleaseChecker from "../release_checker";
|
||||
import BuildApi from "../BuildApi";
|
||||
import { get as getConfig } from "../ConfigStorage";
|
||||
import CONFIGURATOR from "../data_storage";
|
||||
import { i18n } from "../localization";
|
||||
import { gui_log } from "../gui_log";
|
||||
|
||||
function notifyOutdatedVersion(releaseData) {
|
||||
const result = getConfig('checkForConfiguratorUnstableVersions');
|
||||
let showUnstableReleases = false;
|
||||
if (result.checkForConfiguratorUnstableVersions) {
|
||||
showUnstableReleases = true;
|
||||
}
|
||||
function notifyOutdatedVersion(data) {
|
||||
|
||||
if (releaseData === undefined) {
|
||||
if (data === undefined) {
|
||||
console.log('No releaseData');
|
||||
return false;
|
||||
}
|
||||
|
||||
const versions = releaseData.filter(function (version) {
|
||||
const semVerVersion = semver.parse(version.tag_name);
|
||||
if (semVerVersion && (showUnstableReleases || semVerVersion.prerelease.length === 0)) {
|
||||
return version;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}).sort(function (v1, v2) {
|
||||
try {
|
||||
return semver.compare(v2.tag_name, v1.tag_name);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (data.isCurrent === false && data.updatedVersion !== undefined) {
|
||||
|
||||
if (versions.length > 0) {
|
||||
CONFIGURATOR.latestVersion = versions[0].tag_name;
|
||||
CONFIGURATOR.latestVersionReleaseUrl = versions[0].html_url;
|
||||
}
|
||||
CONFIGURATOR.latestVersion = data.UpdatedVersion.Version;
|
||||
CONFIGURATOR.latestVersionReleaseUrl = data.UpdatedVersion.Url;
|
||||
|
||||
if (semver.lt(CONFIGURATOR.version, CONFIGURATOR.latestVersion)) {
|
||||
const message = i18n.getMessage('configuratorUpdateNotice', [CONFIGURATOR.latestVersion, CONFIGURATOR.latestVersionReleaseUrl]);
|
||||
gui_log(message);
|
||||
|
||||
|
@ -60,7 +38,13 @@ function notifyOutdatedVersion(releaseData) {
|
|||
}
|
||||
|
||||
export function checkForConfiguratorUpdates() {
|
||||
const releaseChecker = new ReleaseChecker('configurator', 'https://api.github.com/repos/betaflight/betaflight-configurator/releases');
|
||||
|
||||
releaseChecker.loadReleaseData(notifyOutdatedVersion);
|
||||
const result = getConfig('checkForConfiguratorUnstableVersions');
|
||||
let type = "Stable";
|
||||
if (result.checkForConfiguratorUnstableVersions) {
|
||||
type = "Unstable";
|
||||
}
|
||||
|
||||
const buildApi = new BuildApi();
|
||||
buildApi.loadConfiguratorRelease(type, notifyOutdatedVersion);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue