From 558ef98614b8ad34ba4fb35a8f0b6fe94211f938 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 4 Aug 2024 14:27:54 +0200 Subject: handle onLine event dynamically, don't enable buttons when going offline --- src/app/js/browser.js | 1 - src/app/js/request.js | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/app') diff --git a/src/app/js/browser.js b/src/app/js/browser.js index 3415ebf..c559031 100644 --- a/src/app/js/browser.js +++ b/src/app/js/browser.js @@ -524,7 +524,6 @@ ipcRenderer.on("legacy-duped-mod", (_, modname) => { }) ipcRenderer.on("no-internet", () => { - set_buttons(true); toasts.show({ timeout: 10000, scheme: "error", diff --git a/src/app/js/request.js b/src/app/js/request.js index 29b8883..aeea35a 100644 --- a/src/app/js/request.js +++ b/src/app/js/request.js @@ -1,10 +1,16 @@ const ipcRenderer = require("electron").ipcRenderer; -// show a toast message if no Internet connection has been detected. -if (! navigator.onLine) { - ipcRenderer.send("no-internet"); +const updateOnlineStatus = () => { + // show a toast message if no Internet connection has been detected. + if (!navigator.onLine) { + ipcRenderer.send("no-internet"); + } } +window.addEventListener('online', updateOnlineStatus); +window.addEventListener('offline', updateOnlineStatus); +updateOnlineStatus(); + // invokes `requests.get()` from `src/modules/requests.js` through the // main process, and returns the output let request = async (...args) => { -- cgit v1.2.3