79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
|
//@ts-check
|
||
|
|
||
|
import JadefinIntegrity from '../JadefinIntegrity.js';
|
||
|
|
||
|
import Jadefin from "../Jadefin.js";
|
||
|
import JadefinMod from "../JadefinMod.js";
|
||
|
import JadefinModules from "../JadefinModules.js";
|
||
|
import JadefinUtils from "../JadefinUtils.js";
|
||
|
|
||
|
import { rd, rdom, rd$, RDOMListHelper } from "../utils/rdom.js";
|
||
|
|
||
|
export default JadefinIntegrity("VersionCheck", import.meta.url, () => new (class VersionCheck extends JadefinMod {
|
||
|
_promptedUpdate = false;
|
||
|
|
||
|
constructor() {
|
||
|
super();
|
||
|
}
|
||
|
|
||
|
async init(name, modUrl) {
|
||
|
await super.init(name, modUrl);
|
||
|
|
||
|
await this.initStyle();
|
||
|
|
||
|
const parser = new DOMParser();
|
||
|
const url = `${window.location.origin}${window.location.pathname}?cachev=${Date.now()}`;
|
||
|
const data = await fetch(url).then(r => r.text());
|
||
|
const doc = parser.parseFromString(data, "text/html");
|
||
|
|
||
|
const srcOld = this.srcOld = this.storage.get("src");
|
||
|
const srcCurr = this.srcCurr = document.querySelector("[data-main-jellyfin-bundle]")?.getAttribute("src");
|
||
|
const srcNew = this.srcNew = doc.querySelector("[data-main-jellyfin-bundle]")?.getAttribute("src");
|
||
|
|
||
|
if (srcOld != srcCurr) {
|
||
|
this.storage.set("src", srcCurr);
|
||
|
JadefinModules.toast("Jadefin updated.");
|
||
|
}
|
||
|
|
||
|
const canUpdate = this.canUpdate = srcCurr != srcNew;
|
||
|
if (!canUpdate) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this.promptUpdate();
|
||
|
}
|
||
|
|
||
|
promptUpdate() {
|
||
|
if (this._promptedUpdate) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this._promptedUpdate = true;
|
||
|
|
||
|
JadefinModules.toast("Jadefin update available.");
|
||
|
|
||
|
const ExtrasMenu = /** @type {import("./ExtrasMenu.js").default} */ (Jadefin.getMod("ExtrasMenu"));
|
||
|
|
||
|
ExtrasMenu.headerExtrasEl.appendChild(rd$()`<span class="versionCheck"></span>`);
|
||
|
|
||
|
const item = ExtrasMenu.items.find(i => i.name == "Reload" && i.icon == "update");
|
||
|
const orig = item.cbEl;
|
||
|
|
||
|
item.cbEl = (/** @type {HTMLElement} */ el, current, alive) => {
|
||
|
orig?.(el, current, alive);
|
||
|
|
||
|
if (!alive) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
const icon = el.querySelector(".actionsheetMenuItemIcon");
|
||
|
if (!icon) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
icon.classList.add("hasVersionCheck");
|
||
|
icon.appendChild(rd$()`<span class="versionCheck"></span>`);
|
||
|
};
|
||
|
}
|
||
|
})());
|