Skip to content

Commit

Permalink
fix: No game path (#24)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>
  • Loading branch information
Alystrasz and 0neGal authored Jan 4, 2022
1 parent 0c30429 commit 145baa0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
21 changes: 20 additions & 1 deletion src/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@ 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();
}

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")}
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 17 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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")})
Expand All @@ -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", {
Expand Down
1 change: 1 addition & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
}

Expand Down

0 comments on commit 145baa0

Please sign in to comment.