aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/index.html2
-rw-r--r--src/app/main.js13
-rw-r--r--src/index.js12
3 files changed, 23 insertions, 4 deletions
diff --git a/src/app/index.html b/src/app/index.html
index 97a14ab..263a903 100644
--- a/src/app/index.html
+++ b/src/app/index.html
@@ -9,7 +9,7 @@
<div class="text">Welcome to Viper!</div>
<div class="buttons">
<button id="update" onclick="update()">Update</button>
- <button id="setpath">Game Path</button>
+ <button id="setpath" onclick="setpath()">Game Path</button>
</div>
</div>
<div class="line">
diff --git a/src/app/main.js b/src/app/main.js
index b7071ec..352e654 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -2,7 +2,7 @@ const fs = require("fs");
const path = require("path");
const unzip = require("unzipper");
const request = require("request");
-const { dialog } = require("electron");
+const { ipcRenderer } = require("electron");
const { https } = require("follow-redirects");
var settings = {
@@ -14,6 +14,9 @@ var settings = {
if (fs.existsSync(settings.file)) {
settings.gamepath = JSON.parse(fs.readFileSync(settings.file, "utf8")).path;
settings.zip = path.join(settings.gamepath + "/northstar.zip");
+} else {
+ alert("Game path is not set! Please select the path!");
+ setpath();
}
function update() {
@@ -36,3 +39,11 @@ function update() {
})
})
}
+
+function setpath() {
+ ipcRenderer.send("setpath");
+}
+
+ipcRenderer.on("newpath", (event, newpath) => {
+ settings.gamepath = newpath;
+})
diff --git a/src/index.js b/src/index.js
index ebea48f..0babcea 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,5 +1,6 @@
+const fs = require("fs");
const path = require("path");
-const { app, BrowserWindow } = require("electron");
+const { app, dialog, ipcMain, BrowserWindow } = require("electron");
function start() {
win = new BrowserWindow({
@@ -16,6 +17,14 @@ function start() {
win.removeMenu();
win.loadFile(__dirname + "/app/index.html");
win.webContents.once("dom-ready", () => {win.show()});
+
+ ipcMain.on("setpath", (event) => {
+ dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
+ fs.writeFileSync(app.getPath("appData") + "/viper.json", JSON.stringify({path: res.filePaths[0]}))
+
+ win.webContents.send("newpath", res.filePaths[0]);
+ }).catch(err => {console.error(err)})
+ })
}
app.on("ready", () => {
@@ -23,4 +32,3 @@ app.on("ready", () => {
app.setPath("userData", path.join(app.getPath("cache"), app.name));
start();
})
-