aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-07-22 01:23:04 +0200
committer0neGal <mail@0negal.com>2023-07-22 01:23:04 +0200
commitc3652b72b7bb3bcce207139ebc718e15f6746e43 (patch)
treef3ba70e7ccbee09c1f61a7100886be1a75e93c8c
parent73a651b63c29e24774c1ba3952a2d6c977101047 (diff)
downloadViper-c3652b72b7bb3bcce207139ebc718e15f6746e43.tar.gz
Viper-c3652b72b7bb3bcce207139ebc718e15f6746e43.zip
mostly support installing packages through GUI
Install toasts, installing overall, dependencies and so forth, all seem to be fully functional, however more bug testing is probably required to concluce whether that is actually the case or not... This also doesn't break `src/modules/mods.js`, i.e dragging mods in to manually install them still functions the same as always.
-rw-r--r--src/app/js/browser.js18
-rw-r--r--src/app/main.js8
-rw-r--r--src/index.js6
-rw-r--r--src/modules/packages.js10
4 files changed, 30 insertions, 12 deletions
diff --git a/src/app/js/browser.js b/src/app/js/browser.js
index 3c3786f..b95b0a7 100644
--- a/src/app/js/browser.js
+++ b/src/app/js/browser.js
@@ -115,7 +115,11 @@ var Browser = {
return installFromURL(
package_obj.download || package_obj.versions[0].download_url,
package_obj.dependencies || package_obj.versions[0].dependencies,
- clear_queue, package_obj.owner
+ clear_queue,
+
+ package_obj.author || package_obj.owner,
+ package_obj.name || package_obj.pkg.name,
+ package_obj.version || package_obj.versions[0].version_number
)
},
add_pkg_properties: () => {
@@ -463,7 +467,7 @@ ipcRenderer.on("failed-mod", (event, modname) => {
})
})
-ipcRenderer.on("duped-mod", (event, modname) => {
+ipcRenderer.on("legacy-duped-mod", (event, modname) => {
if (recent_toasts["duped" + modname]) {return}
add_recent_toast("duped" + modname);
@@ -490,28 +494,30 @@ ipcRenderer.on("installed-mod", (event, mod) => {
if (recent_toasts["installed" + mod.name]) {return}
add_recent_toast("installed" + mod.name);
+ let name = mod.fancy_name || mod.name;
+
setButtons(true);
- Browser.setbutton(mod.name, lang("gui.browser.reinstall"));
+ Browser.setbutton(name, lang("gui.browser.reinstall"));
if (mod.malformed) {
new Toast({
timeout: 8000,
scheme: "warning",
title: lang("gui.toast.title.malformed"),
- description: mod.name + " " + lang("gui.toast.desc.malformed")
+ description: name + " " + lang("gui.toast.desc.malformed")
})
}
new Toast({
scheme: "success",
title: lang("gui.toast.title.installed"),
- description: mod.name + " " + lang("gui.toast.desc.installed")
+ description: name + " " + lang("gui.toast.desc.installed")
})
if (installqueue.length != 0) {
installFromURL(
"https://thunderstore.io/package/download/" + installqueue[0].pkg,
- false, false, installqueue[0].author
+ false, false, installqueue[0].author, installqueue[0].package_name, installqueue[0].version
)
installqueue.shift();
diff --git a/src/app/main.js b/src/app/main.js
index 26410cc..51d9e73 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -173,7 +173,7 @@ function installFromPath(path) {
}
// Tells the main process to install a mod from a URL
-function installFromURL(url, dependencies, clearqueue, author) {
+function installFromURL(url, dependencies, clearqueue, author, package_name, version) {
if (clearqueue) {installqueue = []};
let prettydepends = [];
@@ -188,7 +188,9 @@ function installFromURL(url, dependencies, clearqueue, author) {
if (! isModInstalled(pkg[1])) {
newdepends.push({
pkg: depend,
- author: pkg[0]
+ author: pkg[0],
+ version: pkg[2],
+ package_name: pkg[1]
});
prettydepends.push(`${pkg[1]} v${pkg[2]} - ${lang("gui.browser.madeby")} ${pkg[0]}`);
@@ -207,7 +209,7 @@ function installFromURL(url, dependencies, clearqueue, author) {
}
setButtons(false);
- ipcRenderer.send("install-from-url", url, author);
+ ipcRenderer.send("install-from-url", url, author, package_name, version);
if (dependencies) {
installqueue = dependencies;
diff --git a/src/index.js b/src/index.js
index eb258a5..9e2f31f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -19,9 +19,9 @@ const version = require("./modules/version");
const gamepath = require("./modules/gamepath");
const settings = require("./modules/settings");
const requests = require("./modules/requests");
+const packages = require("./modules/packages");
const is_running = require("./modules/is_running");
-const plugins = require("./modules/packages");
var log = console.log;
@@ -113,7 +113,9 @@ function start() {
// install calls
ipcMain.on("install-from-path", (event, path) => {mods.install(path)});
- ipcMain.on("install-from-url", (event, url, author) => {mods.installFromURL(url, author)});
+ ipcMain.on("install-from-url", (event, url, author, package_name, version) => {
+ packages.install(url, author, package_name, version);
+ });
win.webContents.on("dom-ready", () => {
send("mods", mods.list());
diff --git a/src/modules/packages.js b/src/modules/packages.js
index 12659fe..317f0b0 100644
--- a/src/modules/packages.js
+++ b/src/modules/packages.js
@@ -1,7 +1,7 @@
const path = require("path");
const fs = require("fs-extra");
const unzip = require("unzipper");
-const app = require("electron").app;
+const { app, ipcMain } = require("electron");
const https = require("follow-redirects").https;
const json = require("./json");
@@ -203,6 +203,8 @@ packages.install = async (url, author, package_name, version) => {
}
break;
default:
+ ipcMain.emit("failed-mod", name);
+
// other unhandled error
return console.log(
"Verification of package failed:", name,
@@ -233,10 +235,16 @@ packages.install = async (url, author, package_name, version) => {
let moved = packages.move(package_path);
if (! moved) {
+ ipcMain.emit("failed-mod", name);
console.log("Moving package failed:", name);
return false;
}
+ ipcMain.emit("installed-mod", "", {
+ name: name,
+ fancy_name: package_name
+ })
+
console.log("Installed package:", name);
return true;
}