From bd36343fd6f419a6a504ea536cbd3813771e3004 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 29 Jan 2024 19:08:36 +0100 Subject: added artificial delay to checking updates When checking for an update whilst the latest release is already cached, it'll resolve near instantaneously, not even letting the user know what action they just performed, now however, a check for updates will visually take at least 500ms. --- src/app/main.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/app/main.js b/src/app/main.js index ad06fcf..dad4b7e 100644 --- a/src/app/main.js +++ b/src/app/main.js @@ -128,7 +128,14 @@ if (! navigator.onLine) { } function exit() {ipcRenderer.send("exit")} -function updateNorthstar() {ipcRenderer.send("update-northstar")} + +let checked_for_ns_update = new Date().getTime(); + +function updateNorthstar() { + checked_for_ns_update = new Date().getTime(); + ipcRenderer.send("update-northstar") +} + function force_update_ns() { ipcRenderer.send("update-northstar", true); } @@ -257,16 +264,44 @@ ipcRenderer.on("ns-update-event", (event, options) => { key = options; } - document.getElementById("update").innerText = `(${lang(key)})`; + // updates text in update button to `lang(key)` + let update_btn = () => { + document.getElementById("update") + .innerText = `(${lang(key)})`; + } switch(key) { case "cli.update.uptodate_short": case "cli.update.no_internet": - setButtons(true); - set_ns_progress(false); - playNsBtn.innerText = lang("gui.launch"); + // initial value + let delay = 0; + + // get current time + let now = new Date().getTime(); + + // check if `checked_for_ns_update` was less than 500ms + // since now, this variable is set when `updateNorthstar()` + // is called + if (now - checked_for_ns_update < 500) { + // if less than 500ms has passed, set `delay` to the + // amount of milliseconds missing until we've hit that + // 500ms threshold + delay = 500 - (now - checked_for_ns_update); + } + + // wait `delay`ms + setTimeout(() => { + // set buttons accordingly + update_btn(); + setButtons(true); + set_ns_progress(false); + playNsBtn.innerText = lang("gui.launch"); + }, delay) + break; default: + update_btn(); + if (options.progress) { set_ns_progress(options.progress); } -- cgit v1.2.3