From e6a3c962330289e02276b0fafe4629598933e54e Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sun, 26 Dec 2021 19:06:09 +0100 Subject: you can now set the game path in the UI --- src/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/index.js') 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(); }) - -- cgit v1.2.3