mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
This commit is contained in:
1 parent
773846d803
commit
44cc5c88fd
2 files changed
+31
-5
No files matched your search
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user