aboutsummaryrefslogtreecommitdiff
path: root/src/app/main.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-05-02 21:49:20 +0200
committerGitHub <noreply@github.com>2022-05-02 21:49:20 +0200
commitc40e331bdc4b2375d3802a515c9b7a032118dea7 (patch)
tree77c8d84c0fc9d0fbb742cfeeb80efa4762784a9d /src/app/main.js
parent9f2f77558238c28ceb8ff4fca2096602671779e5 (diff)
parent847a2178e7823749e3096daf24dfcd3df8b236cb (diff)
downloadViper-c40e331bdc4b2375d3802a515c9b7a032118dea7.tar.gz
Viper-c40e331bdc4b2375d3802a515c9b7a032118dea7.zip
Merge branch 'main' into enabledmods
Diffstat (limited to 'src/app/main.js')
-rw-r--r--src/app/main.js78
1 files changed, 75 insertions, 3 deletions
diff --git a/src/app/main.js b/src/app/main.js
index 169f86f..95b6f4c 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -8,7 +8,11 @@ let shouldInstallNorthstar = false;
// Base settings
var settings = {
+ nsargs: "",
gamepath: "",
+ nsupdate: true,
+ autolang: true,
+ forcedlang: "en",
autoupdate: true,
zip: "/northstar.zip",
lang: navigator.language,
@@ -23,7 +27,24 @@ ipcRenderer.send("setlang", settings.lang);
// Loads the settings
if (fs.existsSync("viper.json")) {
- settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))};
+ let conf = fs.readFileSync("viper.json", "utf8");
+ let json = {};
+
+ // Validates viper.json
+ try {
+ json = JSON.parse(conf);
+ }catch (e) {
+ let reset = confirm(lang("general.invalidconfig", navigator.language) + e);
+ if (! reset) {
+ ipcRenderer.send("exit")
+ } else {
+ fs.writeFileSync("viper.json", "{}")
+ ipcRenderer.send("relaunch");
+ }
+
+ }
+
+ settings = {...settings, ...json};
settings.zip = path.join(settings.gamepath + "/northstar.zip");
if (settings.gamepath.length === 0) {
@@ -31,6 +52,11 @@ if (fs.existsSync("viper.json")) {
} else {
setpath(true);
}
+
+ let args = path.join(settings.gamepath, "ns_startup_args.txt");
+ if (fs.existsSync(args)) {
+ settings.nsargs = fs.readFileSync(args, "utf8");
+ }
} else {
setpath();
}
@@ -74,14 +100,22 @@ function setButtons(state) {
}
}
+ disablearray(document.querySelectorAll(".playBtnContainer .playBtn"))
disablearray(document.querySelectorAll("#nsMods .buttons.modbtns button"))
disablearray(document.querySelectorAll("#browser #browserEntries .text button"))
}
+ipcRenderer.on("setbuttons", (event, state) => {setButtons(state)})
+ipcRenderer.on("gamepathlost", (event, state) => {
+ page(0);
+ setButtons(false);
+ alert(lang("gui.gamepath.lost"));
+})
+
// Frontend part of updating Northstar
ipcRenderer.on("ns-update-event", (event, key) => {
document.getElementById("update").innerText = `(${lang(key)})`;
- console.log(key);
+ console.log(lang(key));
switch(key) {
case "cli.update.uptodate.short":
setButtons(true);
@@ -156,12 +190,18 @@ function selected(all) {
}
}
-// Tells the main process to install a mod
+// Tells the main process to install a mod through the file selector
function installmod() {
setButtons(false);
ipcRenderer.send("installmod")
}
+// Tells the main process to directly install a mod from this path
+function installFromPath(path) {
+ setButtons(false);
+ ipcRenderer.send("installfrompath", path)
+}
+
// Tells the main process to install a mod from a URL
function installFromURL(url) {
setButtons(false);
@@ -242,6 +282,38 @@ ipcRenderer.on("wrongpath", () => {
setlang();
+let dragtimer;
+document.addEventListener("dragover", (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ dragUI.classList.add("shown");
+
+ clearTimeout(dragtimer);
+ dragtimer = setTimeout(() => {
+ dragUI.classList.remove("shown");
+ }, 5000)
+});
+
+document.addEventListener("mouseover", (e) => {
+ clearTimeout(dragtimer);
+ dragUI.classList.remove("shown");
+});
+
+document.addEventListener("drop", (e) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ dragUI.classList.remove("shown");
+ installFromPath(event.dataTransfer.files[0].path)
+});
+
+document.body.addEventListener("keyup", (e) => {
+ if (e.key == "Escape") {
+ Browser.toggle(false);
+ Settings.toggle(false);
+ }
+})
+
document.body.addEventListener("click", event => {
if (event.target.tagName.toLowerCase() === "a" && event.target.protocol != "file:") {
event.preventDefault();