diff options
author | 0neGal <mail@0negal.com> | 2024-12-20 20:21:28 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-12-20 20:21:28 +0100 |
commit | 00d04db553eb53abb48f0b4e3649a6912fdc10df (patch) | |
tree | 9e4d4ac04b01010b4c2faa71543440114308be86 /src/app/js/request.js | |
parent | 01da499a2cc510536aa7cfa38ffa96ba50adb540 (diff) | |
download | Viper-00d04db553eb53abb48f0b4e3649a6912fdc10df.tar.gz Viper-00d04db553eb53abb48f0b4e3649a6912fdc10df.zip |
added request.check_with_toasts() and use it
This makes it very simple to check if some endpoints are available, and
show a toast if not, with an error message saying exactly what isn't
available. Currently made use for updates with GitHub and installs with
Thunderstore.
Diffstat (limited to 'src/app/js/request.js')
-rw-r--r-- | src/app/js/request.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/app/js/request.js b/src/app/js/request.js index ad8c25b..81e10b1 100644 --- a/src/app/js/request.js +++ b/src/app/js/request.js @@ -1,3 +1,5 @@ +const lang = require("../../lang"); +const toasts = require("./toasts"); const launcher = require("./launcher"); const set_buttons = require("./set_buttons"); const ipcRenderer = require("electron").ipcRenderer; @@ -18,6 +20,27 @@ request.delete_cache = () => { ipcRenderer.send("delete-request-cache"); } +// does `request.check(...args)` and shows toast if the check failed, +// using `name` inside the toast message +request.check_with_toasts = async (name, ...args) => { + // perform check + let can_connect = ( + await request.check(...args) + ).succeeded.length; + + // show toast, as the check failed + if (! can_connect) { + toasts.show({ + timeout: 10000, + scheme: "error", + title: lang("gui.toast.title.failed_to_connect"), + description: lang("gui.toast.desc.failed_to_connect").replaceAll("%s", name) + }) + } + + return can_connect; +} + // keeps track of whether we've already sent a toast since we last went // offline, to prevent multiple toasts let sent_error_toast = false; |