aboutsummaryrefslogtreecommitdiff
path: root/src/modules/gamepath.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-02-04 15:40:23 +0100
committer0neGal <mail@0negal.com>2024-02-04 15:46:55 +0100
commite8e502cc574fdd6eaa54a3a25c2d975596c13026 (patch)
treed193b02d9f37afe109a497b99b6bffc54a5cab64 /src/modules/gamepath.js
parentceda605611c9ec2fbe858f3ae29942d56a06ac66 (diff)
downloadViper-e8e502cc574fdd6eaa54a3a25c2d975596c13026.tar.gz
Viper-e8e502cc574fdd6eaa54a3a25c2d975596c13026.zip
move IPC events into their respective modules
I've not been able to find anything that breaks from this, as I've gone through every IPC event that got moved, to ensure it still functions, and all the breakage I found has since been fixed. IPC events that dont fit in any particular module is also now in the new file named `src/app/modules/ipc.js` There's also another module `src/win.js`, which lets you get the `BrowserWindow` outside of `src/index.js` I also took the oppertunity to clean up some of the code when moving it around, and adding a couple comments, as some of it was quite horrid.
Diffstat (limited to 'src/modules/gamepath.js')
-rw-r--r--src/modules/gamepath.js61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/modules/gamepath.js b/src/modules/gamepath.js
index 8d28c29..9d12854 100644
--- a/src/modules/gamepath.js
+++ b/src/modules/gamepath.js
@@ -1,18 +1,77 @@
const path = require("path");
const fs = require("fs-extra");
+const win = require("../win");
const { dialog, ipcMain } = require("electron");
const cli = require("../cli");
const lang = require("../lang");
+const version = require("./version");
const win_show = require("./window");
const settings = require("./settings");
const findgame = require("./findgame");
-
let gamepath = {};
+ipcMain.on("setpath-cli", () => {gamepath.set()});
+ipcMain.on("setpath", (event, value, force_dialog) => {
+ if (! value) {
+ if (! win().isVisible()) {
+ gamepath.set(win(), force_dialog);
+ } else {
+ gamepath.set(win(), force_dialog || true);
+ }
+ } else if (! win().isVisible()) {
+ win().show();
+ }
+})
+
+
+// allows renderer to set a new renderer
+ipcMain.on("newpath", (event, newpath) => {
+ if (newpath === false && ! win().isVisible()) {
+ win().send("no-path-selected");
+ } else {
+ version.send_info();
+
+ if (! win().isVisible()) {
+ win().show();
+ }
+ }
+})
+
+ipcMain.on("wrong-path", () => {
+ win().send("wrong-path");
+})
+
+ipcMain.on("found-missing-perms", async (e, selected_gamepath) => {
+ await win_show.alert(lang("gui.gamepath.found_missing_perms") + selected_gamepath);
+ ipcMain.emit("setpath", null, false, true);
+})
+
+ipcMain.on("missing-perms", async (e, selected_gamepath) => {
+ await win_show.alert(lang("gui.gamepath.missing_perms") + selected_gamepath);
+ ipcMain.emit("setpath");
+})
+
+ipcMain.on("gamepath-lost-perms", async (e, selected_gamepath) => {
+ if (! gamepath.setting) {
+ gamepath.setting = true;
+ await win_show.alert(lang("gui.gamepath.lost_perms") + selected_gamepath);
+ ipcMain.emit("setpath");
+ }
+})
+
+// ensures gamepath still exists and is valid on startup
+let gamepathlost = false;
+ipcMain.on("gamepath-lost", (event, ...args) => {
+ if (! gamepathlost) {
+ gamepathlost = true;
+ win().send("gamepath-lost");
+ }
+})
+
// returns true/false depending on if the gamepath currently exists/is
// mounted, used to avoid issues...
gamepath.exists = (folder) => {