Create an alert if user tries to leave during download or installation.
This commit is contained in:
parent
d7bec67ccc
commit
d7ed02a28f
@ -7,6 +7,8 @@ const RELEASES_URL = "https://releases.grapheneos.org";
|
|||||||
const CACHE_DB_NAME = "BlobStore";
|
const CACHE_DB_NAME = "BlobStore";
|
||||||
const CACHE_DB_VERSION = 1;
|
const CACHE_DB_VERSION = 1;
|
||||||
|
|
||||||
|
let safeToLeave = true;
|
||||||
|
|
||||||
// This wraps XHR because getting progress updates with fetch() is overly complicated.
|
// This wraps XHR because getting progress updates with fetch() is overly complicated.
|
||||||
function fetchBlobWithProgress(url, onProgress) {
|
function fetchBlobWithProgress(url, onProgress) {
|
||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
@ -155,11 +157,16 @@ async function downloadRelease(setProgress) {
|
|||||||
let latestZip = await getLatestRelease();
|
let latestZip = await getLatestRelease();
|
||||||
|
|
||||||
// Download and cache the zip as a blob
|
// Download and cache the zip as a blob
|
||||||
|
safeToLeave = false;
|
||||||
setProgress(`Downloading ${latestZip}...`);
|
setProgress(`Downloading ${latestZip}...`);
|
||||||
await blobStore.init();
|
await blobStore.init();
|
||||||
await blobStore.download(`${RELEASES_URL}/${latestZip}`, (progress) => {
|
try {
|
||||||
setProgress(`Downloading ${latestZip}...`, progress);
|
await blobStore.download(`${RELEASES_URL}/${latestZip}`, (progress) => {
|
||||||
});
|
setProgress(`Downloading ${latestZip}...`, progress);
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
safeToLeave = true;
|
||||||
|
}
|
||||||
setProgress(`Downloaded ${latestZip} release.`, 1.0);
|
setProgress(`Downloaded ${latestZip} release.`, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,13 +203,18 @@ async function flashRelease(setProgress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setProgress("Flashing release...");
|
setProgress("Flashing release...");
|
||||||
await device.flashFactoryZip(blob, true, reconnectCallback,
|
safeToLeave = false;
|
||||||
(action, item, progress) => {
|
try {
|
||||||
let userAction = fastboot.USER_ACTION_MAP[action];
|
await device.flashFactoryZip(blob, true, reconnectCallback,
|
||||||
let userItem = item === "avb_custom_key" ? "verified boot key" : item;
|
(action, item, progress) => {
|
||||||
setProgress(`${userAction} ${userItem}...`, progress);
|
let userAction = fastboot.USER_ACTION_MAP[action];
|
||||||
}
|
let userItem = item === "avb_custom_key" ? "verified boot key" : item;
|
||||||
);
|
setProgress(`${userAction} ${userItem}...`, progress);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
safeToLeave = true;
|
||||||
|
}
|
||||||
|
|
||||||
return `Flashed ${latestZip} to device.`;
|
return `Flashed ${latestZip} to device.`;
|
||||||
}
|
}
|
||||||
@ -299,4 +311,12 @@ if ("usb" in navigator) {
|
|||||||
console.log("WebUSB unavailable");
|
console.log("WebUSB unavailable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This will create an alert box to stop the user from leaving the page during actions
|
||||||
|
window.addEventListener("beforeunload", event => {
|
||||||
|
if (!safeToLeave) {
|
||||||
|
console.log("User tried to leave the page whilst unsafe to leave!");
|
||||||
|
event.returnValue = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// @license-end
|
// @license-end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user