Get version from build VERSION variable (#19857)

* Fetch version from VERSION set during build
* When polling for new versions, compare to VERSION set during build
* Strip leading v from version, matching package.sh
This commit is contained in:
James Salter 2021-11-23 18:42:24 +11:00 committed by GitHub
parent 9746517ef7
commit 194aeac19e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,8 +33,6 @@ import { logger } from "matrix-js-sdk/src/logger";
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
export default class WebPlatform extends VectorBasePlatform { export default class WebPlatform extends VectorBasePlatform {
private runningVersion: string = null;
constructor() { constructor() {
super(); super();
// Register service worker if available on this platform // Register service worker if available on this platform
@ -102,7 +100,7 @@ export default class WebPlatform extends VectorBasePlatform {
return notification; return notification;
} }
private getVersion(): Promise<string> { private getMostRecentVersion(): Promise<string> {
// We add a cachebuster to the request to make sure that we know about // We add a cachebuster to the request to make sure that we know about
// the most recent version on the origin server. That might not // the most recent version on the origin server. That might not
// actually be the version we'd get on a reload (particularly in the // actually be the version we'd get on a reload (particularly in the
@ -131,10 +129,15 @@ export default class WebPlatform extends VectorBasePlatform {
} }
getAppVersion(): Promise<string> { getAppVersion(): Promise<string> {
if (this.runningVersion !== null) { let ver = process.env.VERSION;
return Promise.resolve(this.runningVersion);
// if version looks like semver with leading v, strip it
// (matches scripts/package.sh)
const semVerRegex = new RegExp("^v[0-9]+.[0-9]+.[0-9]+(-.+)?$");
if (semVerRegex.test(process.env.VERSION)) {
ver = process.env.VERSION.substr(1);
} }
return this.getVersion(); return Promise.resolve(ver);
} }
startUpdater() { startUpdater() {
@ -147,12 +150,10 @@ export default class WebPlatform extends VectorBasePlatform {
} }
pollForUpdate = () => { pollForUpdate = () => {
return this.getVersion().then((ver) => { return this.getMostRecentVersion().then((mostRecentVersion) => {
if (this.runningVersion === null) { if (process.env.VERSION !== mostRecentVersion) {
this.runningVersion = ver; if (this.shouldShowUpdate(mostRecentVersion)) {
} else if (this.runningVersion !== ver) { showUpdateToast(process.env.VERSION, mostRecentVersion);
if (this.shouldShowUpdate(ver)) {
showUpdateToast(this.runningVersion, ver);
} }
return { status: UpdateCheckStatus.Ready }; return { status: UpdateCheckStatus.Ready };
} else { } else {