aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-05 00:37:38 +0100
committer0neGal <mail@0negal.com>2022-01-05 00:37:38 +0100
commita898d6866a912abceb78832bc1b3fe2ff56d1335 (patch)
tree9067a550a1f110b37cfa8cd99ce7a80b156c442d
parentdce0f68e7f9095ffa400112f03968251999a92dc (diff)
parent89d8d1986b62d5686160f28359383ccd0c67f77d (diff)
downloadViper-a898d6866a912abceb78832bc1b3fe2ff56d1335.tar.gz
Viper-a898d6866a912abceb78832bc1b3fe2ff56d1335.zip
Merge branch 'main' of 0neGal/viper into mod-support
-rw-r--r--build/langs.js18
-rw-r--r--package.json3
-rw-r--r--src/app/main.js23
-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.js7
7 files changed, 66 insertions, 9 deletions
diff --git a/build/langs.js b/build/langs.js
new file mode 100644
index 0000000..0e82022
--- /dev/null
+++ b/build/langs.js
@@ -0,0 +1,18 @@
+const fs = require("fs");
+
+let lang = require("../src/lang/en.json");
+
+langs = fs.readdirSync("src/lang")
+langs.forEach((localefile) => {
+ let missing = [];
+ let locale = require("../src/lang/" + localefile)
+ for (let i in lang) {
+ if (! locale[i]) {
+ missing.push(i);
+ }
+ }
+
+ if (missing.length > 0) {
+ console.error(`${localefile} is missing: ${missing}`)
+ }
+})
diff --git a/package.json b/package.json
index 45eb7fc..97823ff 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "viper",
"productName": "Viper",
- "version": "0.9.0",
+ "version": "0.9.1",
"description": "Launcher+Updater for TF|2 Northstar",
"main": "src/index.js",
"build": {
@@ -26,6 +26,7 @@
}
},
"scripts": {
+ "langs": "node build/langs.js",
"start": "npx electron src/index.js",
"debug": "npx electron src/index.js --debug",
"man": "npx marked-man docs/viper.1.md > docs/viper.1",
diff --git a/src/app/main.js b/src/app/main.js
index 6f2493a..a5c0a37 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -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.missinggamepath"));
+ 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")}
@@ -145,6 +159,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 a723622..1a9f660 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")})
@@ -74,6 +70,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 401e98f..406ee79 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -54,6 +54,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 5be9cfe..fc62f01 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -31,7 +31,7 @@ if (fs.existsSync("viper.json")) {
settings = {...settings, ...JSON.parse(fs.readFileSync("viper.json", "utf8"))};
settings.zip = path.join(settings.gamepath + "/northstar.zip");
} else {
- console.log(lang("general.missinggamepath"));
+ console.log(lang("general.missingpath"));
}
function setpath(win) {
@@ -39,10 +39,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)})
}