diff options
author | 0neGal <mail@0negal.com> | 2024-12-20 19:29:48 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-12-20 19:29:48 +0100 |
commit | 957e8a9ad0b7bfe33079ca2d6a5dc097fdc2daa9 (patch) | |
tree | efae3014e6a97207adbddbb2dbd4b52a7210056f /src/app/js/request.js | |
parent | ada511f0c2f86a0a28e9d2129a1ebdd1edb19f3d (diff) | |
download | Viper-957e8a9ad0b7bfe33079ca2d6a5dc097fdc2daa9.tar.gz Viper-957e8a9ad0b7bfe33079ca2d6a5dc097fdc2daa9.zip |
if offline close browser and disable some buttons
Diffstat (limited to 'src/app/js/request.js')
-rw-r--r-- | src/app/js/request.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/app/js/request.js b/src/app/js/request.js index d0ef39b..bec9d7c 100644 --- a/src/app/js/request.js +++ b/src/app/js/request.js @@ -1,3 +1,4 @@ +const set_buttons = require("./set_buttons"); const ipcRenderer = require("electron").ipcRenderer; // invokes `requests.get()` from `src/modules/requests.js` through the @@ -26,6 +27,12 @@ let state_action = (is_online) => { // hide offline icon sent_error_toast = false; offline.classList.add("hidden"); + + // re-enable buttons that require internet + set_buttons( + true, false, + document.querySelectorAll(".requires-internet") + ) } else { // show toast if (! sent_error_toast) { @@ -35,10 +42,21 @@ let state_action = (is_online) => { // show offline icon offline.classList.remove("hidden"); + + // disable buttons that require internet + set_buttons( + false, false, + document.querySelectorAll(".requires-internet") + ) + + // close mod browser + try { + require("./browser").toggle(false); + } catch(err) {} } } -state_action(navigator.onLine); +setTimeout(() => state_action(navigator.onLine), 100); window.addEventListener("online", () => state_action(navigator.onLine)); window.addEventListener("offline", () => state_action(navigator.onLine)); @@ -60,7 +78,10 @@ let check_endpoints = async () => { // handle result of check state_action(!! status.succeeded.length); -}; check_endpoints(); +} + +// check endpoints on startup +setTimeout(check_endpoints, 100); // check endpoints every 30 seconds setInterval(check_endpoints, 30000); |