Updating the pack in Manager restarts ComfyUI and reloads the workflow, but not the page. The tab kept running the old AusBoss scripts and nothing said so: the update guard only looked once, when the page loaded. The guard now looks again every time the server comes back, asks once per installed version, and its message stays until it is closed instead of going away after 30 seconds. Follow-up to issue #108. The missing LoRA Loader panel reported there was old browser copies of the shared modules, fixed in 2.5.2.
81 lines
2.9 KiB
JavaScript
81 lines
2.9 KiB
JavaScript
// Notices when this tab is still running old AusBoss files after an update,
|
|
// refreshes them, and asks for a reload. A reload alone is not always enough:
|
|
// browsers may keep reusing the old shared modules (.mjs) for hours.
|
|
//
|
|
// Imports nothing from ../shared on purpose. Old cached copies of those files
|
|
// are the problem this entry has to survive.
|
|
import { api } from "/scripts/api.js";
|
|
import { app } from "/scripts/app.js";
|
|
|
|
const PACK_URL = new URL("../", import.meta.url).href;
|
|
const PARALLEL = 6;
|
|
|
|
async function runningVersion() {
|
|
try {
|
|
return (await import("../shared/index.mjs")).AUSBOSS_JS_VERSION;
|
|
} catch (_error) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Fetching with cache "reload" replaces the browser's stored copy with a
|
|
// fresh one, so the next page load uses the new files.
|
|
async function refreshModules(paths) {
|
|
const queue = [...paths];
|
|
const worker = async () => {
|
|
while (queue.length) {
|
|
const path = queue.pop();
|
|
try {
|
|
await fetch(PACK_URL + path, { cache: "reload" });
|
|
} catch (_error) {
|
|
// One file failing to refresh must not stop the rest.
|
|
}
|
|
}
|
|
};
|
|
await Promise.all(Array.from({ length: PARALLEL }, worker));
|
|
}
|
|
|
|
function askForReload(installed) {
|
|
const detail =
|
|
`AusBoss v${installed} is installed, but this page is still running an older copy. ` +
|
|
"Press F5 to reload the page.";
|
|
const toast = app.extensionManager?.toast;
|
|
if (typeof toast?.add === "function") {
|
|
// No `life`: the message stays until it is closed. The page keeps running
|
|
// the old files until it is reloaded, however long that takes.
|
|
toast.add({ severity: "warn", summary: "AusBoss was updated", detail });
|
|
} else {
|
|
console.warn(`[AusBoss] ${detail}`);
|
|
}
|
|
}
|
|
|
|
// The installed version this page already asked a reload for. A server that
|
|
// drops and comes back several times must not stack the same message.
|
|
let asked = null;
|
|
|
|
async function check() {
|
|
// Advice, not a feature: any network or route failure stays silent.
|
|
try {
|
|
const installed = (await (await api.fetchApi("/ausboss/pack_version")).json())?.version;
|
|
const running = await runningVersion();
|
|
if (!installed || installed === "unknown" || !running || installed === running || installed === asked) return;
|
|
asked = installed;
|
|
const listing = await (await api.fetchApi("/ausboss/pack_modules")).json();
|
|
await refreshModules(Array.isArray(listing?.modules) ? listing.modules : []);
|
|
askForReload(installed);
|
|
} catch (_error) {
|
|
// Old backend without the routes, offline, or a non-JSON reply.
|
|
}
|
|
}
|
|
|
|
app.registerExtension({
|
|
name: "ausboss.cache_guard",
|
|
async setup() {
|
|
await check();
|
|
// An update from the Manager restarts the server and reloads the workflow,
|
|
// not the page, so an open tab keeps the scripts it started with. Look
|
|
// again every time the server comes back.
|
|
api.addEventListener("reconnected", check);
|
|
},
|
|
});
|