From 64107e982faf196537b403eb6319796914d7585e Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 13 Aug 2024 22:44:24 +0200 Subject: chore: rework protocol mod installs to use renderer package list This is achieved by sending an IPC event to the renderer and waiting for a reply once Since this is async we return from the function after sending the event and recursively invoke it once the reply arrives The package data is returned a a JSON String because Electron is unable to copy the Object over IPC --- src/app/js/browser.js | 2 ++ src/app/js/mods.js | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'src/app/js') diff --git a/src/app/js/browser.js b/src/app/js/browser.js index 3415ebf..153c7b5 100644 --- a/src/app/js/browser.js +++ b/src/app/js/browser.js @@ -477,6 +477,8 @@ browser.mod_el = (properties) => { browserEntries.appendChild(entry); } +browser.packages = () => { 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..b257753 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -328,4 +328,10 @@ ipcRenderer.on("mods", (event, mods_obj) => { mods.load(mods_obj); }) +ipcRenderer.on("packages", (event) => { + // Its not possible to send over the package object directly, so we serialize it + const packages = JSON.stringify(browser.packages()); + event.sender.send("packages-reply", [packages]); +}) + module.exports = mods; -- cgit v1.2.3 From 05d9c0acd4c87d34ed31edc6683e2932058a30dd Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 13 Aug 2024 23:02:34 +0200 Subject: chore: use existing mod installation logic for r2mm protocol --- src/app/js/browser.js | 5 ++++- src/app/js/mods.js | 35 +++++++++++++++++++++++++++++++---- src/modules/protocol.js | 49 +++---------------------------------------------- 3 files changed, 38 insertions(+), 51 deletions(-) (limited to 'src/app/js') diff --git a/src/app/js/browser.js b/src/app/js/browser.js index 153c7b5..b2e0493 100644 --- a/src/app/js/browser.js +++ b/src/app/js/browser.js @@ -477,7 +477,10 @@ browser.mod_el = (properties) => { browserEntries.appendChild(entry); } -browser.packages = () => { return packages; } +browser.packages = async () => { + await browser.loadfront(); + return packages; +} let recent_toasts = {}; function add_recent_toast(name, timeout = 3000) { diff --git a/src/app/js/mods.js b/src/app/js/mods.js index b257753..349f5b9 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -328,10 +328,37 @@ ipcRenderer.on("mods", (event, mods_obj) => { mods.load(mods_obj); }) -ipcRenderer.on("packages", (event) => { - // Its not possible to send over the package object directly, so we serialize it - const packages = JSON.stringify(browser.packages()); - event.sender.send("packages-reply", [packages]); +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) { + console.error("Couldn't find package") + return; + } + + const package_obj = package.versions.find((package_version) => { return package_version.version_number == version; }) + if (!package_obj) { + console.error("Couldn't find package_version") + return; + } + + console.log(package_obj); + + mods.install_from_url( + package_obj.download_url, + package_obj.dependencies, + false, + + author, + package_name, + version + ); }) module.exports = mods; diff --git a/src/modules/protocol.js b/src/modules/protocol.js index e8701b2..a40b67e 100644 --- a/src/modules/protocol.js +++ b/src/modules/protocol.js @@ -1,51 +1,8 @@ -const { app, ipcMain } = require("electron"); +const { app } = require("electron"); const win = require("../win"); -const requests = require("./requests"); const version = require("./version"); -var packages = undefined; -async function install_mod(domain, author, package_name, version) { - if (packages == undefined) - { - ipcMain.once("packages-reply", (event, packages_string) => { - packages = JSON.parse(packages_string); - install_mod(domain, author, package_name, version); - }); - - win().send("packages"); - return; - } - - const package = packages.find((package) => { return package.owner == author && package.name == package_name; }) - if (!package) { - console.error("Couldn't find package") - return; - } - - const package_data = package.versions.find((package_version) => { return package_version.version_number == version; }) - if (!package_data) { - console.error("Couldn't find package_version") - return; - } - - for (const dep of package_data.dependencies) { - let fragments = dep.split("-"); - if (fragments.length != 3) { - console.error("bad dep") - return; - } - - if (fragments[0] != "northstar") - await install_mod(domain, ...fragments); - } - - let result = ipcMain.emit("install-from-url", null, package_data.download_url, author, package_name, version); - if (!result) { - console.error("no install-from-url handler") - } -} - module.exports = async () => { if (version.northstar() == "unknown") return; @@ -63,7 +20,7 @@ module.exports = async () => { const term = fragments[1]; const domain = fragments[2]; const author = fragments[3]; - const mod = fragments[4]; + const package_name = fragments[4]; const version = fragments[5]; // There is only v1 @@ -76,7 +33,7 @@ module.exports = async () => { try { if (term == "install") { - await install_mod(domain, author, mod, version); + win().send("protocol-install-mod", [domain, author, package_name, version]); } }catch(err) { console.error(err); -- cgit v1.2.3 From b578362de216142959ef9511510c06d5446e355f Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 14 Aug 2024 19:57:47 +0200 Subject: chore: display alert when mod install via protocol cannot be resolved --- src/app/js/mods.js | 5 +++-- src/lang/en.json | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/app/js') diff --git a/src/app/js/mods.js b/src/app/js/mods.js index 349f5b9..bca417e 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -1,3 +1,4 @@ +const util = require('util'); const ipcRenderer = require("electron").ipcRenderer; const lang = require("../../lang"); @@ -338,13 +339,13 @@ ipcRenderer.on("protocol-install-mod", async (event, data) => { const package = packages.find((package) => { return package.owner == author && package.name == package_name; }) if (!package) { - console.error("Couldn't find 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) { - console.error("Couldn't find package_version") + alert(util.format(lang("gui.mods.cant_find_version"), version, author, package_name)) return; } diff --git a/src/lang/en.json b/src/lang/en.json index d07d60f..0c44198 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -101,6 +101,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:", -- cgit v1.2.3 From 9c97e16b85a55cb770d74fa7e44d338a3ad9ce88 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Wed, 14 Aug 2024 20:05:11 +0200 Subject: feat: show toast when installing mod through ror2mm protocol --- src/app/js/mods.js | 8 +++++++- src/app/js/toasts.js | 4 ++++ src/lang/en.json | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/app/js') diff --git a/src/app/js/mods.js b/src/app/js/mods.js index bca417e..326b8b9 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -4,6 +4,7 @@ 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 = {}; @@ -349,7 +350,12 @@ ipcRenderer.on("protocol-install-mod", async (event, data) => { return; } - console.log(package_obj); + toasts.show({ + timeout: 3000, + scheme: "info", + title: lang("gui.mods.installing"), + description: lang("gui.toast.desc.installing") + " " + package_obj.full_name + }) mods.install_from_url( package_obj.download_url, diff --git a/src/app/js/toasts.js b/src/app/js/toasts.js index 83ddf6a..3fd6899 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/lang/en.json b/src/lang/en.json index 0c44198..1c3b4b4 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -268,6 +268,7 @@ "desc": { "installed": "has been installed successfully!", + "installing": "Installing", "malformed": "has an incorrect folder structure, if you're the developer, you should fix this.", "failed": "An unknown error occurred while trying to install the mod. This may be the author's fault, and it may also be Viper's fault.", "duped": "has multiple mod folders in it, with the same name, causing duplicate folders, if you're the developer, you should fix this.", -- cgit v1.2.3 From 7fb97f07c1f6e3818edf8651d26d9600849e5521 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 15 Aug 2024 22:41:18 +0200 Subject: chore: remove installing translation description its a bit redundant since the title already states that we are installing --- src/app/js/mods.js | 2 +- src/lang/en.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/app/js') diff --git a/src/app/js/mods.js b/src/app/js/mods.js index 326b8b9..2408548 100644 --- a/src/app/js/mods.js +++ b/src/app/js/mods.js @@ -354,7 +354,7 @@ ipcRenderer.on("protocol-install-mod", async (event, data) => { timeout: 3000, scheme: "info", title: lang("gui.mods.installing"), - description: lang("gui.toast.desc.installing") + " " + package_obj.full_name + description: package_obj.full_name }) mods.install_from_url( diff --git a/src/lang/en.json b/src/lang/en.json index 1c3b4b4..0c44198 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -268,7 +268,6 @@ "desc": { "installed": "has been installed successfully!", - "installing": "Installing", "malformed": "has an incorrect folder structure, if you're the developer, you should fix this.", "failed": "An unknown error occurred while trying to install the mod. This may be the author's fault, and it may also be Viper's fault.", "duped": "has multiple mod folders in it, with the same name, causing duplicate folders, if you're the developer, you should fix this.", -- cgit v1.2.3