diff options
author | 0neGal <mail@0negal.com> | 2022-01-17 14:47:03 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2022-01-17 14:47:03 +0100 |
commit | a28e3812f95fd301201733bc2e7de24bb555ddb8 (patch) | |
tree | 163d5da537e9dd35bf867ed13df7b298f34ddba2 /src/index.js | |
parent | d92c4523ec92fb46b092308d9b1f3e38aff3a7d9 (diff) | |
download | Viper-a28e3812f95fd301201733bc2e7de24bb555ddb8.tar.gz Viper-a28e3812f95fd301201733bc2e7de24bb555ddb8.zip |
documented: index.js, cli.js, lang.js app/lang.js
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 49 |
1 files changed, 35 insertions, 14 deletions
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()); }); |