summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorflawedworld <38294951+flawedworld@users.noreply.github.com>2021-04-07 00:14:57 +0100
committerDaniel Micay <danielmicay@gmail.com>2021-04-06 22:14:59 -0400
commitd7ed02a28fb03a74fe6757356ab9ff25c54fdcd0 (patch)
tree355db628d2a619fcf05b6a5c206c0449b6e73954 /static
parentd7bec67cccacb4b66e5c9f5ed1a7a1eb0e6220b8 (diff)
Create an alert if user tries to leave during download or installation.
Diffstat (limited to 'static')
-rw-r--r--static/js/web-install.js40
1 files changed, 30 insertions, 10 deletions
diff --git a/static/js/web-install.js b/static/js/web-install.js
index 5d6362e1..64f2114b 100644
--- a/static/js/web-install.js
+++ b/static/js/web-install.js
@@ -7,6 +7,8 @@ const RELEASES_URL = "https://releases.grapheneos.org";
const CACHE_DB_NAME = "BlobStore";
const CACHE_DB_VERSION = 1;
+let safeToLeave = true;
+
// This wraps XHR because getting progress updates with fetch() is overly complicated.
function fetchBlobWithProgress(url, onProgress) {
let xhr = new XMLHttpRequest();
@@ -155,11 +157,16 @@ async function downloadRelease(setProgress) {
let latestZip = await getLatestRelease();
// Download and cache the zip as a blob
+ safeToLeave = false;
setProgress(`Downloading ${latestZip}...`);
await blobStore.init();
- await blobStore.download(`${RELEASES_URL}/${latestZip}`, (progress) => {
- setProgress(`Downloading ${latestZip}...`, progress);
- });
+ try {
+ await blobStore.download(`${RELEASES_URL}/${latestZip}`, (progress) => {
+ setProgress(`Downloading ${latestZip}...`, progress);
+ });
+ } finally {
+ safeToLeave = true;
+ }
setProgress(`Downloaded ${latestZip} release.`, 1.0);
}
@@ -196,13 +203,18 @@ async function flashRelease(setProgress) {
}
setProgress("Flashing release...");
- await device.flashFactoryZip(blob, true, reconnectCallback,
- (action, item, progress) => {
- let userAction = fastboot.USER_ACTION_MAP[action];
- let userItem = item === "avb_custom_key" ? "verified boot key" : item;
- setProgress(`${userAction} ${userItem}...`, progress);
- }
- );
+ safeToLeave = false;
+ try {
+ await device.flashFactoryZip(blob, true, reconnectCallback,
+ (action, item, 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.`;
}
@@ -299,4 +311,12 @@ if ("usb" in navigator) {
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