diff options
-rw-r--r-- | src/app/index.html | 6 | ||||
-rw-r--r-- | src/app/js/browser.js | 4 | ||||
-rw-r--r-- | src/app/js/mods.js | 2 | ||||
-rw-r--r-- | src/app/js/request.js | 25 | ||||
-rw-r--r-- | src/app/js/set_buttons.js | 12 |
5 files changed, 36 insertions, 13 deletions
diff --git a/src/app/index.html b/src/app/index.html index f9d3d51..5421a3f 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -38,7 +38,7 @@ <div id="overlay" onclick="popups.set_all(false)"></div> <div class="popup" id="options"> <div class="misc"> - <input class="search default-selection" placeholder="%%gui.search%%"> + <input class="search default-selection requires-internet" placeholder="%%gui.search%%"> <button id="apply" onclick="settings.popup.apply();settings.popup.toggle(false)"> <img src="icons/apply.png"> %%gui.settings.save%% @@ -341,7 +341,7 @@ <button id="playNsBtn" class="playBtn" onclick="launch('northstar')">%%gui.launch%%</button> <div class="inline"> <div id="nsversion"></div> - <a id="update" href="#" onclick="update.ns()" class="disable-when-installing">(%%gui.update.check%%)</a> + <a id="update" href="#" onclick="update.ns()" class="disable-when-installing requires-internet">(%%gui.update.check%%)</a> <div id="serverstatus" class="checking"></div> </div> </div> @@ -363,7 +363,7 @@ <img src="icons/downloads.png"> %%gui.mods.install%% </button> - <button id="findmod" class="bg-blue2" onclick="browser.toggle(true)"> + <button id="findmod" class="requires-internet bg-blue2" onclick="browser.toggle(true)"> <img src="icons/search.png"> %%gui.mods.find%% </button> diff --git a/src/app/js/browser.js b/src/app/js/browser.js index d30ad9f..10428bc 100644 --- a/src/app/js/browser.js +++ b/src/app/js/browser.js @@ -489,11 +489,11 @@ browser.mod_el = (properties) => { <div class="text"> <div class="title">${properties.title}</div> <div class="description">${properties.description}</div> - <button class="install bg-blue" onclick=''> + <button class="install bg-blue requires-internet" onclick=''> <img src="icons/${installicon}.png"> <span>${installstr}</span> </button> - <button class="info" onclick="browser.preview.set('${properties.url}')"> + <button class="info requires-internet" onclick="browser.preview.set('${properties.url}')"> <img src="icons/open.png"> <span>${lang('gui.browser.view')}</span> </button> diff --git a/src/app/js/mods.js b/src/app/js/mods.js index 755aad1..9eb528b 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -74,7 +74,7 @@ mods.load = (mods_obj) => { <div class="title">${mod_details.name}</div> <div class="description">${mod_details.description}</div> <button class="switch on orange"></button> - <button class="update bg-blue"> + <button class="update bg-blue requires-internet"> <img src="icons/downloads.png"> <span>${lang("gui.browser.update")}</span> </button> 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); diff --git a/src/app/js/set_buttons.js b/src/app/js/set_buttons.js index 9cb9d3e..4a0e1b2 100644 --- a/src/app/js/set_buttons.js +++ b/src/app/js/set_buttons.js @@ -6,22 +6,24 @@ ipcRenderer.on("set-buttons", (_, state) => { // disables or enables certain buttons when for example // updating/installing Northstar. -module.exports = (state, enable_gamepath_btns) => { - playNsBtn.disabled = ! state; +module.exports = (state, enable_gamepath_btns, elements) => { + if (! elements) { + playNsBtn.disabled = ! state; + } let disable_array = (array) => { for (let i = 0; i < array.length; i++) { array[i].disabled = ! state; if (state) { - array[i].classList.remove("disabled") + array[i].classList.remove("disabled"); } else { - array[i].classList.add("disabled") + array[i].classList.add("disabled"); } } } - disable_array(document.querySelectorAll([ + disable_array(elements || document.querySelectorAll([ "#modsdiv .el button", ".disable-when-installing", ".playBtnContainer .playBtn", |