From a28e3812f95fd301201733bc2e7de24bb555ddb8 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 17 Jan 2022 14:47:03 +0100 Subject: documented: index.js, cli.js, lang.js app/lang.js --- src/index.js | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 333b1c9..98de132 100644 --- a/src/index.js +++ b/src/index.js @@ -10,12 +10,20 @@ const utils = require("./utils"); const cli = require("./cli"); const requests = require("./requests"); +// Starts the actual BrowserWindow, which is only run when using the +// GUI, for the CLI this function is never called. function start() { win = new BrowserWindow({ width: 1000, height: 600, + + // Hides the window initially, it'll be shown when the DOM is + // loaded, as to not cause visual issues. show: false, title: "Viper", + + // In the future we may want to allow the user to resize the window, + // as it's fairly responsive, but for now we won't allow that. resizable: false, titleBarStyle: "hidden", frame: false, @@ -26,8 +34,10 @@ function start() { }, }); + // When --debug is added it'll open the dev tools if (cli.hasParam("debug")) {win.openDevTools()} + // General setup win.removeMenu(); win.loadFile(__dirname + "/app/index.html"); @@ -47,11 +57,15 @@ function start() { win.webContents.send("updateavailable") }); + // Updates and restarts Viper, if user says yes to do so. + // Otherwise it'll do it on the next start up. ipcMain.on("updatenow", () => { autoUpdater.quitAndInstall(); }) } +// General events used to handle utils.js stuff without requiring the +// module inside the file that sent the event. { ipcMain.on("installmod", () => { if (cli.hasArgs()) { utils.mods.install(cli.param("installmod")) @@ -79,19 +93,6 @@ ipcMain.on("setpath", (event, value) => { } }); -ipcMain.on("newpath", (event, newpath) => { - if (newpath === false && !win.isVisible()) { - win.webContents.send("nopathselected"); - } else { - _sendVersionsInfo(); - if (!win.isVisible()) { - win.show(); - } - } -}); ipcMain.on("wrongpath", (event) => { - win.webContents.send("wrongpath"); -}); - function _sendVersionsInfo() { win.webContents.send("version", { ns: utils.getNSVersion(), @@ -100,8 +101,10 @@ function _sendVersionsInfo() { }); } -ipcMain.on("getversion", () => _sendVersionsInfo()); +// Sends the version info back to the renderer +ipcMain.on("getversion", () => {_sendVersionsInfo()}); +// Prints out version info for the CLI ipcMain.on("versioncli", () => { console.log("Viper: v" + require("../package.json").version); console.log("Northstar: " + utils.getNSVersion()); @@ -131,9 +134,25 @@ ipcMain.on("getmods", (event) => { cli.exit(0); } }) +// } +ipcMain.on("newpath", (event, newpath) => { + if (newpath === false && !win.isVisible()) { + win.webContents.send("nopathselected"); + } else { + _sendVersionsInfo(); + if (!win.isVisible()) { + win.show(); + } + } +}); ipcMain.on("wrongpath", (event) => { + win.webContents.send("wrongpath"); +}); + +// Ensures ./ is the config folder where viper.json is located. process.chdir(app.getPath("appData")); +// Starts the GUI or CLI if (cli.hasArgs()) { if (cli.hasParam("updatevp")) { utils.updatevp(true); @@ -147,9 +166,11 @@ if (cli.hasArgs()) { }) } +// Returns cached requests ipcMain.on("get-ns-notes", async () => { win.webContents.send("ns-notes", await requests.getNsReleaseNotes()); }); + ipcMain.on("get-vp-notes", async () => { win.webContents.send("vp-notes", await requests.getVpReleaseNotes()); }); -- cgit v1.2.3