aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Raes <contact@remyraes.com>2022-01-04 17:41:13 +0100
committerGitHub <noreply@github.com>2022-01-04 17:41:13 +0100
commit145baa0e1606816d7784deac8eafa58490854141 (patch)
tree923f903fe82575c5ce571453b132be0a2b9ee459
parent0c30429ab4b0a941f00b7ced79065ef05575d583 (diff)
downloadViper-145baa0e1606816d7784deac8eafa58490854141.tar.gz
Viper-145baa0e1606816d7784deac8eafa58490854141.zip
fix: No game path (#24)
* [refactor] moving main.setPath listener outside start method * [refactor] setpath tells if game path is set or not * newpath event tells if game path dialog is successful or not * [feat] main window will not show if path is not set * [feat] viper displays a dialog and exits if no game path was prompted * [fix] viper prompts for game path if viper.json:gamepath is not set * [feat] translating gui.gamepath.must key * code cleanup fixing single quotes and alike * fix gui.gamepath.must message Co-authored-by: 0neGal <mail@0negal.com>
-rw-r--r--src/app/main.js21
-rw-r--r--src/index.js22
-rw-r--r--src/lang/en.json1
-rw-r--r--src/lang/fr.json1
-rw-r--r--src/utils.js5
5 files changed, 44 insertions, 6 deletions
diff --git a/src/app/main.js b/src/app/main.js
index 8cd00a3..aa2ba68 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -20,6 +20,13 @@ ipcRenderer.send("setlang", settings.lang);
if (fs.existsSync("viper.json")) {
settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))};
settings.zip = path.join(settings.gamepath + "/northstar.zip");
+
+ if (settings.gamepath.length === 0) {
+ alert(lang("general.missingpath"));
+ setpath(false);
+ } else {
+ setpath(true);
+ }
} else {
alert(lang("general.missingpath"));
setpath();
@@ -27,7 +34,14 @@ if (fs.existsSync("viper.json")) {
function exit() {ipcRenderer.send("exit")}
function update() {ipcRenderer.send("update")}
-function setpath() {ipcRenderer.send("setpath")}
+
+/**
+ * Reports to the main thread about game path status.
+ * @param {boolean} value is game path loaded
+ */
+function setpath(value = false) {
+ ipcRenderer.send("setpath", value);
+}
function launch() {ipcRenderer.send("launch")}
function launchVanilla() {ipcRenderer.send("launchVanilla")}
@@ -65,6 +79,11 @@ ipcRenderer.on("updateavailable", () => {
}
})
+ipcRenderer.on("nopathselected", () => {
+ alert(lang("gui.gamepath.must"));
+ exit();
+});
+
setlang();
setInterval(() => {
ipcRenderer.send("setsize", document.querySelector(".lines").offsetHeight + 20);
diff --git a/src/index.js b/src/index.js
index b43611d..330b2b7 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,7 +1,7 @@
const fs = require("fs");
const path = require("path");
const { autoUpdater } = require("electron-updater");
-const { app, dialog, ipcMain, BrowserWindow, ipcRenderer } = require("electron");
+const { app, ipcMain, BrowserWindow } = require("electron");
const Emitter = require("events");
const events = new Emitter();
@@ -31,12 +31,8 @@ function start() {
win.loadFile(__dirname + "/app/index.html");
ipcMain.on("exit", () => {process.exit(0)})
- ipcMain.on("setpath", () => {utils.setpath(win)})
ipcMain.on("setsize", (event, height) => {
win.setSize(width, height);
- if (! win.isVisible()) {
- win.show();
- }
})
ipcMain.on("ns-updated", () => {win.webContents.send("ns-updated")})
@@ -61,6 +57,22 @@ ipcMain.on("launchVanilla", (event) => {utils.launch("vanilla")})
ipcMain.on("update", (event) => {utils.update()})
ipcMain.on("setpathcli", (event) => {utils.setpath()});
+ipcMain.on("setpath", (event, value) => {
+ if (!value) {
+ utils.setpath(win)
+ } else if (!win.isVisible()) {
+ win.show();
+ }
+});
+ipcMain.on("newpath", (event, newpath) => {
+ if (newpath === false && !win.isVisible()) {
+ win.webContents.send("nopathselected");
+ } else {
+ if (!win.isVisible()) {
+ win.show();
+ }
+ }
+});
ipcMain.on("getversion", () => {
win.webContents.send("version", {
diff --git a/src/lang/en.json b/src/lang/en.json
index 83f23f3..cc75268 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -36,6 +36,7 @@
"gui.launchnorthstar": "Northstar",
"gui.selectpath": "Please select the path!",
+ "gui.gamepath.must": "The game path must be set to start Viper.",
"general.launching": "Launching",
diff --git a/src/lang/fr.json b/src/lang/fr.json
index fe4d63c..870fbfe 100644
--- a/src/lang/fr.json
+++ b/src/lang/fr.json
@@ -36,6 +36,7 @@
"gui.launchnorthstar": "Northstar",
"gui.selectpath": "Veuillez sélectionner le dossier où se trouve le client Titanfall 2.",
+ "gui.gamepath.must": "Vous devez sélectionner le chemin du dossier du jeu Titanfall 2 pour pouvoir lancer Viper.",
"general.launching": "Lancement",
diff --git a/src/utils.js b/src/utils.js
index 35c8932..d2e6fe6 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -38,10 +38,15 @@ function setpath(win) {
settings.gamepath = cli.param("setpath");
} else {
dialog.showOpenDialog({properties: ["openDirectory"]}).then(res => {
+ if (res.canceled) {
+ ipcMain.emit("newpath", null, false);
+ return;
+ }
settings.gamepath = res.filePaths[0];
settings.zip = path.join(settings.gamepath + "/northstar.zip");
saveSettings();
win.webContents.send("newpath", settings.gamepath);
+ ipcMain.emit("newpath", null, settings.gamepath);
}).catch(err => {console.error(err)})
}