mirror of
https://github.com/MathMan05/Fermi.git
synced 2026-10-16 19:40:09 +00:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import {I18n} from "./i18n";
|
|
import {Dialog} from "./settings";
|
|
|
|
export class Versions {
|
|
private ver: number;
|
|
constructor(ver?: number) {
|
|
this.ver = ver ?? -1;
|
|
}
|
|
private static warned = false;
|
|
private showWarn(text: string) {
|
|
//TODO enable this once the version endpoint is up and running
|
|
if (Versions.warned) return;
|
|
Versions.warned = true;
|
|
const d = new Dialog("");
|
|
d.options.addText(text);
|
|
d.options.addButtonInput("", I18n.yes(), () => {
|
|
d.hide();
|
|
});
|
|
d.show();
|
|
d.background.deref()!.style.zIndex = "10000";
|
|
}
|
|
private onRegi() {
|
|
if (this.ver === -1) {
|
|
this.showWarn(I18n.sbWarns.regi());
|
|
}
|
|
}
|
|
private onStart() {
|
|
if (this.ver === -1) {
|
|
this.showWarn(I18n.sbWarns.in());
|
|
}
|
|
}
|
|
static async makeVersion(api: string, place: "regi" | "start"): Promise<Versions> {
|
|
if (!api.includes("spacebar.chat")) return new Versions();
|
|
const p = await fetch(api + "/harmony/version");
|
|
if (!p.ok) {
|
|
const v = new Versions();
|
|
if (place === "regi") {
|
|
v.onRegi();
|
|
} else if (place === "start") {
|
|
v.onStart();
|
|
}
|
|
return v;
|
|
}
|
|
const v = await p.json();
|
|
return new Versions(v.version);
|
|
}
|
|
}
|