aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/js/browser.js10
-rw-r--r--src/app/js/request.js23
-rw-r--r--src/app/js/update.js10
-rw-r--r--src/lang/en.json2
4 files changed, 43 insertions, 2 deletions
diff --git a/src/app/js/browser.js b/src/app/js/browser.js
index 10428bc..f306da8 100644
--- a/src/app/js/browser.js
+++ b/src/app/js/browser.js
@@ -107,7 +107,15 @@ var browser = {
browser.filters.toggle(false);
}
},
- install: (package_obj, clear_queue = false) => {
+ install: async (package_obj, clear_queue = false) => {
+ let can_connect = await request.check_with_toasts(
+ "Thunderstore", "https://thunderstore.io"
+ )
+
+ if (! can_connect) {
+ return;
+ }
+
return mods.install_from_url(
package_obj.download || package_obj.versions[0].download_url,
package_obj.dependencies || package_obj.versions[0].dependencies,
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;
diff --git a/src/app/js/update.js b/src/app/js/update.js
index d03db02..3732f89 100644
--- a/src/app/js/update.js
+++ b/src/app/js/update.js
@@ -125,7 +125,15 @@ let update = {
// updates Northstar, `force_update` forcefully updates Northstar,
// causing it to update, even if its already up-to-date
- ns: (force_update) => {
+ ns: async (force_update) => {
+ let can_connect = await request.check_with_toasts(
+ "GitHub", "https://github.com"
+ )
+
+ if (! can_connect) {
+ return;
+ }
+
update.ns.last_checked = new Date().getTime();
ipcRenderer.send("update-northstar", force_update);
update.ns.should_install = false;
diff --git a/src/lang/en.json b/src/lang/en.json
index 28e4ecb..9540ad2 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -267,6 +267,7 @@
"malformed": "Incorrect folder structure!",
"unknown_error": "Unknown Error!",
"no_internet": "No Internet",
+ "failed_to_connect": "Failed to connect",
"failed_launch_command": "Failed running launch command",
"missing_launch_command": "Missing launch command",
"missing_steam": "Missing Steam",
@@ -281,6 +282,7 @@
"duped": "has multiple mod folders in it, with the same name, causing duplicate folders, if you're the developer, you should fix this.",
"unknown_error": "An unknown error occurred, click for more details. You may want to take a screenshot of the detailed error when filing a bug report.",
"no_internet": "Viper may not work properly.",
+ "failed_to_connect": "A connection could not be established to %s, check your internet, firewall or whether %s is currently down",
"failed_launch_command": "Something went wrong whilst running the custom launch command",
"missing_launch_command": "There's currently no custom launch command set, one has to be configured to launch",
"missing_steam": "Can't launch with Steam directly, as it doesn't seem to be installed",