Skip to content

Commit

Permalink
Merge pull request #343 from le-jeu/check_version
Browse files Browse the repository at this point in the history
Check version + warn on new version
  • Loading branch information
le-jeu authored Feb 22, 2022
2 parents 2f7d1f8 + 886148a commit 10732bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/code/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import WasabeeMe from "./model/me";
import WasabeeOp from "./model/operation";
import db from "./db";
import polyfill from "./polyfill";
import { displayError } from "./error";
import { displayError, displayWarning } from "./error";
import { deleteJWT } from "./auth";

import type { FeatureGroup, LayerEvent, LayerGroup } from "leaflet";
Expand All @@ -34,6 +34,8 @@ import type { WLMarker } from "./ui/marker";
import type { WLAgent } from "./ui/agent";
import type { WLZone } from "./ui/zone";
import type { ButtonsControl } from "./leafletClasses";
import { checkVersion } from "./version";
import wX from "./wX";

type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
export interface Wasabee {
Expand Down Expand Up @@ -258,6 +260,12 @@ window.plugin.wasabee.init = async () => {
window.map.on("wdialog", (event) => {
postToFirebase({ id: "analytics", action: event.dialogType });
});

checkVersion().then((v) => {
if (v) {
displayWarning(wX("dialog.update_warning"));
}
});
};

// this can be moved to auth dialog, no need to init it for people who never log in
Expand Down
1 change: 1 addition & 0 deletions src/code/translations/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"dialog.team_members.location": "Sharing Location",
"dialog.team_members.wd_keys": "Sharing W-D Keys",
"dialog.team_message": "Team announcement: “{message}” from {sender}",
"dialog.update_warning": "Wasabee is out of date. Please update using your plugin manager or by going to <a href='https://wasabee.rocks'>https://wasabee.rocks</a>",
"dialog.zone_color.title": "Zone Color",
"dialog.zone_color.text": "Set the color of all links in zone {zoneName}",
"dialog.zones.color": "Color",
Expand Down
23 changes: 23 additions & 0 deletions src/code/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const metaURL = "https://cdn2.wasabee.rocks/iitcplugin/prod/wasabee.meta.js";

function getCurrentVersion() {
return window.plugin.wasabee.info.version;
}

function simpleSemVer(a: string, b: string) {
const av = a.split(".", 3);
const bv = b.split(".", 3);
return +av[0] < +bv[0] || (+av[0] == +bv[0] && +av[1] < +bv[1]);
}

export async function checkVersion() {
const data = await (await fetch(metaURL)).text();
for (const line of data.split("\n")) {
if (line.startsWith("// @version")) {
const version = line.slice(11).trim();
const curVer = getCurrentVersion();
return simpleSemVer(curVer, version);
}
}
return false;
}

0 comments on commit 10732bd

Please sign in to comment.