feat(前端界面): 新增联网更新提示,离线使用不受影响
build.yaml / build (push) Successful in 36s

This commit is contained in:
xiaoqidun committed 2026-09-14 00:34:00 +08:00
1 parent 773846d803
commit 44cc5c88fd
2 files changed
+31 -5

No files matched your search

+24
View File
@@ -421,6 +421,7 @@ async function prepareOffline() {
return false;
}
el.offlineStatus.textContent = "可离线";
watchApplicationUpdates(result.checksum);
} catch {
el.offlineStatus.textContent = "未就绪";
}
@@ -428,6 +429,29 @@ async function prepareOffline() {
return true;
}
function watchApplicationUpdates(checksum) {
let checking = false;
async function check() {
if (checking || document.hidden || !navigator.onLine) {
return;
}
checking = true;
try {
const response = await fetch("./", { method: "HEAD", cache: "no-store", signal: AbortSignal.timeout(10000) });
const latest = response.headers.get("X-OFDGo-Checksum");
if (response.ok && !response.redirected && latest) {
el.offlineStatus.textContent = latest === checksum ? "可离线" : "可更新";
}
} catch {
} finally {
checking = false;
}
}
window.addEventListener("online", check);
document.addEventListener("visibilitychange", check);
check();
}
function waitForWorker(worker, target) {
return new Promise((resolve, reject) => {
function changed() {