aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/js/browser.js5
-rw-r--r--src/app/js/mods.js35
-rw-r--r--src/modules/protocol.js49
3 files changed, 38 insertions, 51 deletions
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);