aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2024-08-04 18:44:53 +0200
committerJan200101 <sentrycraft123@gmail.com>2024-08-04 18:44:53 +0200
commit56f2cb84412252ae0a90076b861f3b1be32be01d (patch)
treea84aef1744f4117489e69cdaac29c137d035b61c /src/modules
parent09b7d16086595b1ba039ecf1c1b904a6e0948d12 (diff)
downloadViper-56f2cb84412252ae0a90076b861f3b1be32be01d.tar.gz
Viper-56f2cb84412252ae0a90076b861f3b1be32be01d.zip
feat: support thunderstore ror2mm protocol for installing mods
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/packages.js2
-rw-r--r--src/modules/protocol.js66
2 files changed, 68 insertions, 0 deletions
diff --git a/src/modules/packages.js b/src/modules/packages.js
index 8df6665..f7e7d62 100644
--- a/src/modules/packages.js
+++ b/src/modules/packages.js
@@ -16,6 +16,7 @@ var packages = {};
// lets renderer install packages
ipcMain.on("install-from-url", (event, url, author, package_name, version) => {
+ console.log(url);
packages.install(url, author, package_name, version);
})
@@ -194,6 +195,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..8b6cfc6
--- /dev/null
+++ b/src/modules/protocol.js
@@ -0,0 +1,66 @@
+const { app, ipcMain } = require("electron");
+
+const requests = require("./requests");
+const version = require("./version");
+
+async function install_mod(domain, author, package_name, version) {
+ let package_data = JSON.parse(await requests.get(
+ domain, `/api/experimental/package/${author}/${package_name}/${version}/`
+ ));
+
+ 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;
+
+ const args = process.argv.slice(app.isPackaged ? 1 : 2);
+
+ 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 mod = 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;
+
+ try {
+ if (term == "install") {
+ await install_mod(domain, author, mod, version);
+ }
+ }catch(err) {
+ console.error(err);
+ continue;
+ }
+ }
+ }
+}