aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-12-20 13:09:12 +0100
committerGitHub <noreply@github.com>2024-12-20 13:09:12 +0100
commit28130f46eb9c167671994b47b77b926386002ac2 (patch)
tree26185cbcba747df98e6de6d7e225777093c6720c
parent8fddf38701f50015ee8f61ce7bc8978f1dcebfd3 (diff)
parentb9c0243d6433550784116fac7eec462cc5ae2a79 (diff)
downloadViper-28130f46eb9c167671994b47b77b926386002ac2.tar.gz
Viper-28130f46eb9c167671994b47b77b926386002ac2.zip
Merge pull request #248 from Jan200101/PR/protocol
feat: support thunderstore ror2mm protocol for installing mods
-rw-r--r--src/app/js/browser.js5
-rw-r--r--src/app/js/mods.js40
-rw-r--r--src/app/js/toasts.js4
-rw-r--r--src/index.js26
-rw-r--r--src/lang/de.json3
-rw-r--r--src/lang/en.json4
-rw-r--r--src/lang/fr.json3
-rw-r--r--src/lang/zh.json3
-rw-r--r--src/modules/packages.js1
-rw-r--r--src/modules/protocol.js39
10 files changed, 127 insertions, 1 deletions
diff --git a/src/app/js/browser.js b/src/app/js/browser.js
index bd9506f..aaca6a8 100644
--- a/src/app/js/browser.js
+++ b/src/app/js/browser.js
@@ -475,6 +475,11 @@ browser.mod_el = (properties) => {
browserEntries.appendChild(entry);
}
+browser.packages = async () => {
+ await browser.loadfront();
+ return packages;
+}
+
let recent_toasts = {};
function add_recent_toast(name, timeout = 3000) {
if (recent_toasts[name]) {return}
diff --git a/src/app/js/mods.js b/src/app/js/mods.js
index f463ddb..2408548 100644
--- a/src/app/js/mods.js
+++ b/src/app/js/mods.js
@@ -1,8 +1,10 @@
+const util = require('util');
const ipcRenderer = require("electron").ipcRenderer;
const lang = require("../../lang");
const version = require("./version");
+const toasts = require("./toasts");
const set_buttons = require("./set_buttons");
let mods = {};
@@ -328,4 +330,42 @@ ipcRenderer.on("mods", (event, mods_obj) => {
mods.load(mods_obj);
})
+ipcRenderer.on("protocol-install-mod", async (event, data) => {
+ const domain = data[0];
+ const author = data[1];
+ const package_name = data[2];
+ const version = data[3];
+
+ const packages = await browser.packages();
+
+ const package = packages.find((package) => { return package.owner == author && package.name == package_name; })
+ if (!package) {
+ alert(util.format(lang("gui.mods.cant_find_specific"), author, package_name));
+ return;
+ }
+
+ const package_obj = package.versions.find((package_version) => { return package_version.version_number == version; })
+ if (!package_obj) {
+ alert(util.format(lang("gui.mods.cant_find_version"), version, author, package_name))
+ return;
+ }
+
+ toasts.show({
+ timeout: 3000,
+ scheme: "info",
+ title: lang("gui.mods.installing"),
+ description: package_obj.full_name
+ })
+
+ mods.install_from_url(
+ package_obj.download_url,
+ package_obj.dependencies,
+ false,
+
+ author,
+ package_name,
+ version
+ );
+})
+
module.exports = mods;
diff --git a/src/app/js/toasts.js b/src/app/js/toasts.js
index bd9d03a..c5cdd40 100644
--- a/src/app/js/toasts.js
+++ b/src/app/js/toasts.js
@@ -24,6 +24,10 @@ toasts.show = (properties) => {
toast.fg = "#FFFFFF";
toast.bg = "#FF9B85";
break
+ case "info":
+ toast.fg = "#FFFFFF";
+ toast.bg = "rgb(var(--blue))";
+ break
}
diff --git a/src/index.js b/src/index.js
index 9321598..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,11 +10,13 @@ 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");
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 +90,7 @@ function start() {
// load list of mods on initial load
win.webContents.on("dom-ready", () => {
+ protocol();
send("mods", mods.list());
})
@@ -103,6 +106,7 @@ function start() {
}
}
+
// starts the GUI or CLI
if (cli.hasArgs()) {
if (cli.hasParam("update-viper")) {
@@ -112,9 +116,29 @@ if (cli.hasArgs()) {
cli.init();
}
} else {
+ app.setAsDefaultProtocolClient("ror2mm");
+
+ const app_lock = app.requestSingleInstanceLock()
+
// 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();
})
+
+ app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
+ protocol(commandLine);
+ })
+
}
diff --git a/src/lang/de.json b/src/lang/de.json
index 5a5ab4d..0a22a68 100644
--- a/src/lang/de.json
+++ b/src/lang/de.json
@@ -96,6 +96,8 @@
"install": "Installieren",
"launch": "Starten",
"mods": {
+ "cant_find_specific": "Mod %s-%s kann nicht gefunden werden!",
+ "cant_find_version": "Version %s von Mod %s-%s kann nicht gefunden werden!",
"confirm_dependencies": "Dieser Mod benötigt weitere Mods, diese werden unter dieser Nachricht angezeigt. Beim drücken auf \"Ok\" stimmst du zu da diese Installiert werden.\n\n",
"confirm_plugins": {
"description": "Native plugins haben sehr viel mehr Rechte als reguläre Mods, da durch ist das nutzen dieser um einiges unsicherer denn es ist einfacher ihnen zuschaden! Bitte installieren sie nur native plugins von vertrauten Entwicklern oder ähnliches, falls dir bewusst ist was du machst kannst du diese Nachricht ignorieren.",
@@ -284,6 +286,7 @@
"settings": "Einstellungen"
},
"viper": {
+ "already_running": "Viper läuft bereits",
"info": {
"credits": "Credits",
"discord": "Tritt dem Discord bei:",
diff --git a/src/lang/en.json b/src/lang/en.json
index bf147ab..c6a4946 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -102,6 +102,8 @@
"installed_mod": "Installed mod!",
"drag_n_drop": "Drag and drop a mod to install",
"confirm_dependencies": "This package has dependencies, shown below, clicking \"Ok\" will install the package and the dependencies.\n\n",
+ "cant_find_specific": "Can't find mod %s-%s!",
+ "cant_find_version": "Can't find version %s of mod %s-%s!",
"confirm_plugins": {
"title": "The following package has native plugins:",
@@ -282,6 +284,8 @@
},
"viper": {
+ "already_running": "Viper is already running",
+
"menu": {
"main": "Viper",
"release": "Release Notes",
diff --git a/src/lang/fr.json b/src/lang/fr.json
index c98e143..491e400 100644
--- a/src/lang/fr.json
+++ b/src/lang/fr.json
@@ -96,6 +96,8 @@
"install": "Installer",
"launch": "Jouer",
"mods": {
+ "cant_find_specific": "Incapable de trouver le mod %s-%s!",
+ "cant_find_version": "Incapable de trouver la version %s du mod %s-%s!",
"confirm_dependencies": "Ce mod a des dépendances (affichées ci-dessous), cliquer \"Ok\" les installera en même temps que le mod.\n\n",
"confirm_plugins": {
"description": "Les plugins ont des accès à votre système, comparés aux mods classiques, et sont de fait plus dangereux à l'installation, comme pourrait l'être un plugin contenant un malware. Si ce plugin provient d'un tiers de confiance ou si vous savez ce que vous faites, ne tenez pas compte de ce message.",
@@ -284,6 +286,7 @@
"settings": "Paramètres"
},
"viper": {
+ "already_running": "Viper est déjà en cours d'éxecution",
"info": {
"credits": "Remerciements",
"discord": "Rejoingnez le serveur Discord :",
diff --git a/src/lang/zh.json b/src/lang/zh.json
index be8cfbb..43df3b0 100644
--- a/src/lang/zh.json
+++ b/src/lang/zh.json
@@ -96,6 +96,8 @@
"install": "安装",
"launch": "启动",
"mods": {
+ "cant_find_specific": "无法找到模组%s-%s!",
+ "cant_find_version": "无法找到%s版的模组%s-%s!",
"confirm_dependencies": "此包含有依赖项, 以下展示, 点击 \"Ok\" 将会安装此包和它的依赖项.\n\n",
"confirm_plugins": {
"description": "Native插件比普通的模组拥有更多对系统的访问权限, 如果安装了恶意插件可能会导致您的计算机受到损害. 如果这个插件是来自于一位信任的开发者或您知道自己在干什么, 那么请忽略这条信息.",
@@ -284,6 +286,7 @@
"settings": "设置"
},
"viper": {
+ "already_running": "Viper已在运行中",
"info": {
"credits": "鸣谢",
"discord": "加入Discord:",
diff --git a/src/modules/packages.js b/src/modules/packages.js
index 8df6665..125705a 100644
--- a/src/modules/packages.js
+++ b/src/modules/packages.js
@@ -194,6 +194,7 @@ packages.install = async (url, author, package_name, version) => {
return false;
}
+
let name = packages.format_name(author, package_name, version);
// removes zip's and folders
diff --git a/src/modules/protocol.js b/src/modules/protocol.js
new file mode 100644
index 0000000..1aeb7f9
--- /dev/null
+++ b/src/modules/protocol.js
@@ -0,0 +1,39 @@
+const { app } = require("electron");
+
+const win = require("../win");
+const version = require("./version");
+
+module.exports = async (argv) => {
+ if (version.northstar() == "unknown")
+ return;
+
+ const args = argv || process.argv;
+
+ for (const key of args) {
+ if (key.startsWith("ror2mm://")) {
+ let fragments = key.slice(9).split("/");
+
+ if (fragments.length < 6)
+ return;
+
+ const ver = fragments[0];
+ const term = fragments[1];
+ const domain = fragments[2];
+ const author = fragments[3];
+ const package_name = fragments[4];
+ const version = fragments[5];
+
+ // There is only v1
+ if (ver != "v1")
+ continue;
+
+ // No support for custom thunderstore instances
+ if (domain != "thunderstore.io")
+ continue;
+
+ if (term == "install") {
+ win().send("protocol-install-mod", [domain, author, package_name, version]);
+ }
+ }
+ }
+}