aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-01-29 19:08:36 +0100
committer0neGal <mail@0negal.com>2024-01-29 19:12:47 +0100
commitbd36343fd6f419a6a504ea536cbd3813771e3004 (patch)
treef43d593a9b481b5bf8017190a00f663f91ae3d25 /src
parent7703f1214a903fa8e3d8a8590ca2333c751494bf (diff)
downloadViper-bd36343fd6f419a6a504ea536cbd3813771e3004.tar.gz
Viper-bd36343fd6f419a6a504ea536cbd3813771e3004.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/app/main.js45
1 files 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);
}