From 56f2cb84412252ae0a90076b861f3b1be32be01d Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 4 Aug 2024 18:44:53 +0200 Subject: feat: support thunderstore ror2mm protocol for installing mods --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index 9321598..b26ef1e 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ const mods = require("./modules/mods"); const update = require("./modules/update"); const version = require("./modules/version"); const settings = require("./modules/settings"); +const protocol = require("./modules/protocol"); // loads `ipcMain` events that dont fit in any of the modules directly require("./modules/ipc"); @@ -88,6 +89,7 @@ function start() { // load list of mods on initial load win.webContents.on("dom-ready", () => { + protocol(); send("mods", mods.list()); }) @@ -103,6 +105,7 @@ function start() { } } + // starts the GUI or CLI if (cli.hasArgs()) { if (cli.hasParam("update-viper")) { @@ -112,9 +115,10 @@ if (cli.hasArgs()) { cli.init(); } } else { + app.setAsDefaultProtocolClient("ror2mm"); + // start the window/GUI app.on("ready", () => { - start(); }) } -- cgit v1.2.3 From 027b9dfb30d2ac09e555a3311b9ce37783c1ca9f Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 14 Aug 2024 12:12:39 +0200 Subject: feat: use instance locks to prevent multiple instances of viper --- src/index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index b26ef1e..d8107e8 100644 --- a/src/index.js +++ b/src/index.js @@ -117,6 +117,13 @@ if (cli.hasArgs()) { } else { app.setAsDefaultProtocolClient("ror2mm"); + const app_lock = app.requestSingleInstanceLock() + + if (!app_lock) { + // Viper is already running + app.quit(); + } + // start the window/GUI app.on("ready", () => { start(); -- cgit v1.2.3 From 29e7a323d26e985f47015ad8b64315fe8afa5b72 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 14 Aug 2024 12:13:14 +0200 Subject: feat: parse commandLine of secondary instances --- src/index.js | 5 +++++ src/modules/protocol.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index d8107e8..ab15039 100644 --- a/src/index.js +++ b/src/index.js @@ -128,4 +128,9 @@ if (cli.hasArgs()) { app.on("ready", () => { start(); }) + + app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => { + protocol(commandLine); + }) + } diff --git a/src/modules/protocol.js b/src/modules/protocol.js index a40b67e..7f2f7c0 100644 --- a/src/modules/protocol.js +++ b/src/modules/protocol.js @@ -3,11 +3,11 @@ const { app } = require("electron"); const win = require("../win"); const version = require("./version"); -module.exports = async () => { +module.exports = async (argv) => { if (version.northstar() == "unknown") return; - const args = process.argv.slice(app.isPackaged ? 1 : 2); + const args = argv || process.argv; for (const key of args) { if (key.startsWith("ror2mm://")) { -- cgit v1.2.3 From 60f0935e173751805634f887c9ac9640a5e51e68 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 14 Aug 2024 19:38:59 +0200 Subject: feat: display alert when Viper is already running and no args are given --- src/index.js | 20 ++++++++++++++------ src/lang/en.json | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/index.js') diff --git a/src/index.js b/src/index.js index ab15039..c6a7ba8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ const path = require("path"); -const { app, BrowserWindow } = require("electron"); +const { app, BrowserWindow, dialog } = require("electron"); // makes it so Electron cache doesn't get stored in your system's config // folder, and instead changing it over to using the system's cache @@ -10,6 +10,7 @@ app.setPath("userData", path.join(app.getPath("cache"), app.name)); process.chdir(app.getPath("appData")); const cli = require("./cli"); +const lang = require("./lang"); const mods = require("./modules/mods"); const update = require("./modules/update"); @@ -119,13 +120,20 @@ if (cli.hasArgs()) { const app_lock = app.requestSingleInstanceLock() - if (!app_lock) { - // Viper is already running - app.quit(); - } - // start the window/GUI app.on("ready", () => { + if (!app_lock) { + // Viper is already running + if (process.argv.length <= (app.isPackaged ? 1 : 2)) + { + dialog.showMessageBoxSync({ + title: lang("viper.menu.main"), + message: lang("viper.already_running") + }); + } + app.quit(); + } + start(); }) diff --git a/src/lang/en.json b/src/lang/en.json index f968f73..d07d60f 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -281,6 +281,8 @@ }, "viper": { + "already_running": "Viper is already running", + "menu": { "main": "Viper", "release": "Release Notes", -- cgit v1.2.3