diff --git a/src/vector/platform/WebPlatform.ts b/src/vector/platform/WebPlatform.ts index bb2a52f24..b7b59826b 100644 --- a/src/vector/platform/WebPlatform.ts +++ b/src/vector/platform/WebPlatform.ts @@ -33,8 +33,6 @@ import { logger } from "matrix-js-sdk/src/logger"; const POKE_RATE_MS = 10 * 60 * 1000; // 10 min export default class WebPlatform extends VectorBasePlatform { - private runningVersion: string = null; - constructor() { super(); // Register service worker if available on this platform @@ -102,7 +100,7 @@ export default class WebPlatform extends VectorBasePlatform { return notification; } - private getVersion(): Promise { + private getMostRecentVersion(): Promise { // 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 // 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 { - if (this.runningVersion !== null) { - return Promise.resolve(this.runningVersion); + let ver = process.env.VERSION; + + // 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() { @@ -147,12 +150,10 @@ export default class WebPlatform extends VectorBasePlatform { } pollForUpdate = () => { - return this.getVersion().then((ver) => { - if (this.runningVersion === null) { - this.runningVersion = ver; - } else if (this.runningVersion !== ver) { - if (this.shouldShowUpdate(ver)) { - showUpdateToast(this.runningVersion, ver); + return this.getMostRecentVersion().then((mostRecentVersion) => { + if (process.env.VERSION !== mostRecentVersion) { + if (this.shouldShowUpdate(mostRecentVersion)) { + showUpdateToast(process.env.VERSION, mostRecentVersion); } return { status: UpdateCheckStatus.Ready }; } else {