Skip to content

Commit

Permalink
Merge pull request #191 from 0neGal/packages-dir
Browse files Browse the repository at this point in the history
feat: Support for the new packages folder
  • Loading branch information
0neGal authored Jul 24, 2023
2 parents 1126109 + 55040f6 commit b180388
Show file tree
Hide file tree
Showing 10 changed files with 687 additions and 101 deletions.
39 changes: 22 additions & 17 deletions src/app/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ var Browser = {
browser.classList.toggle("shown");
},
install: (package_obj, clear_queue = false) => {
console.log(package_obj)
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: () => {
Expand All @@ -133,9 +136,9 @@ var Browser = {
for (let ii = 0; ii < modsobj.all.length; ii++) {
let mod = modsobj.all[ii];

if (normalize(mod.Name) === normalized) {
local_name = mod.Name;
local_version = version.format(mod.Version);
if (normalize(mod.name) === normalized) {
local_name = mod.name;
local_version = version.format(mod.version);
if (version.is_newer(remote_version, local_version)) {
has_update = true;
}
Expand Down Expand Up @@ -270,13 +273,13 @@ var Browser = {

setTimeout(() => {
for (let i = 0; i < modsobj.all.length; i++) {
let modname = normalize(modsobj.all[i].Name);
let modfolder = normalize(modsobj.all[i].FolderName);
let modname = normalize(modsobj.all[i].name);
let modfolder = normalize(modsobj.all[i].folder_name);

if (mod.includes(modname)) {
if (! make(modname)) {
if (modsobj.all[i].ManifestName) {
make(normalize(modsobj.all[i].ManifestName));
if (modsobj.all[i].manifest_name) {
make(normalize(modsobj.all[i].manifest_name));
}
}
}
Expand Down Expand Up @@ -386,7 +389,7 @@ function BrowserEl(properties) {
let normalized_mods = [];

for (let i = 0; i < modsobj.all; i++) {
normalized_mods.push(normalize(mods_list[i].Name));
normalized_mods.push(normalize(mods_list[i].name));
}

if (properties.pkg.local_version) {
Expand Down Expand Up @@ -445,8 +448,8 @@ function add_recent_toast(name, timeout = 3000) {
ipcRenderer.on("removed-mod", (event, mod) => {
setButtons(true);
Browser.setbutton(mod.name, lang("gui.browser.install"));
if (mod.manifestname) {
Browser.setbutton(mod.manifestname, lang("gui.browser.install"));
if (mod.manifest_name) {
Browser.setbutton(mod.manifest_name, lang("gui.browser.install"));
}
})

Expand All @@ -463,7 +466,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);

Expand All @@ -490,28 +493,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();
Expand Down
83 changes: 63 additions & 20 deletions src/app/js/mods.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ mods.load = (mods_obj) => {
let normalized_names = [];

let set_mod = (mod) => {
let normalized_name = "mod-list-" + normalize(mod.Name);
let name = mod.name;
if (mod.package) {
name = mod.package.package_name;
}

let normalized_name = "mod-list-" + normalize(name);

normalized_names.push(normalized_name);

let el = document.getElementById(normalized_name);
if (el) {
if (mod.Disabled) {
if (mod.disabled) {
el.querySelector(".switch").classList.remove("on");
} else {
el.querySelector(".switch").classList.add("on");
Expand All @@ -25,36 +30,67 @@ mods.load = (mods_obj) => {
div.classList.add("el");
div.id = normalized_name;

let mod_details = {
name: mod.name,
version: mod.version,
description: mod.description
}

if (mod.package) {
mod_details = {
image: mod.package.icon,
name: mod.package.manifest.name,
version: mod.package.manifest.version_number,
description: mod.package.manifest.description
}
}

div.innerHTML += `
<div class="image">
<img src="">
<img src="${mod_details.image || ""}">
<img class="blur" src="">
</div>
<div class="text">
<div class="title">${mod.Name}</div>
<div class="description">${mod.Description}</div>
<div class="title">${mod_details.name}</div>
<div class="description">${mod_details.description}</div>
<button class="switch on orange"></button>
<button class="update bg-blue">
${lang("gui.browser.update")}
</button>
<button class="bg-red" onclick="mods.remove('${mod.Name}')">
<button class="bg-red remove">
${lang("gui.mods.remove")}
</button>
<button class="visual">${version.format(mod.Version)}</button>
<button class="visual">${version.format(mod_details.version)}</button>
<button class="visual">
${lang("gui.browser.madeby")}
${mod.Author || lang("gui.mods.unknown_author")}
${mod.author || lang("gui.mods.unknown_author")}
</button>
</div>
`;

if (mod.Disabled) {
div.querySelector(".remove").onclick = () => {
if (! mod.package) {
return mods.remove(mod.name);
}

for (let i = 0; i < mod.packaged_mods.length; i++) {
mods.remove(mod.packaged_mods[i]);
}
}

if (mod.disabled) {
div.querySelector(".switch").classList.remove("on");
}

div.querySelector(".switch").addEventListener("click", () => {
mods.toggle(mod.Name);
if (! mod.package) {
return mods.toggle(mod.name);
}

for (let i = 0; i < mod.packaged_mods.length; i++) {
mods.toggle(mod.packaged_mods[i]);
}
})

div.querySelector(".image").style.display = "none";
Expand Down Expand Up @@ -87,20 +123,23 @@ mods.load = (mods_obj) => {
return;
}

let image_container = mod_els[i].querySelector(".image");
let image_el = image_container.querySelector("img")
let image_blur_el = image_container.querySelector("img.blur")

if (mod_versions[mod]) {
let image_url = mod_versions[mod].package.versions[0].icon;
image_el.src = mod_versions[mod].package.versions[0].icon;
}

let image_container = mod_els[i].querySelector(".image");
let image_el = image_container.querySelector("img")
let image_blur_el = image_container.querySelector("img.blur")
if (image_el.getAttribute("src") &&
! image_container.parentElement.classList.contains("has-icon")) {

if (image_url && ! image_el.getAttribute("src")) {
image_container.style.display = null;
image_el.src = image_url;
image_blur_el.src = image_url;
let image_src = image_el.getAttribute("src");

image_container.parentElement.classList.add("has-icon");
}
image_blur_el.src = image_src;
image_container.style.display = null;

image_container.parentElement.classList.add("has-icon");
}

if (mod_versions[mod]
Expand All @@ -118,6 +157,10 @@ mods.load = (mods_obj) => {

let mod_el = mod_els[i].cloneNode(true);

// copy click event of the remove button to the new button
mod_el.querySelector(".remove").onclick =
mod_els[i].querySelector(".remove").onclick;

mod_el.classList.add("no-animation");

mod_el.querySelector(".switch").addEventListener("click", () => {
Expand Down
21 changes: 14 additions & 7 deletions src/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const path = require("path");
const { app, ipcRenderer, shell } = require("electron");

const lang = require("../lang");
var modsobj = {};
var modsobj = {
all: [],
enabled: [],
disabled: []
}

let shouldInstallNorthstar = false;

// Base settings
Expand Down Expand Up @@ -168,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 = [];
Expand All @@ -183,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]}`);
Expand All @@ -202,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;
Expand All @@ -212,11 +219,11 @@ function installFromURL(url, dependencies, clearqueue, author) {
function isModInstalled(modname) {
for (let i = 0; i < modsobj.all.length; i++) {
let mod = modsobj.all[i];
if (mod.ManifestName) {
if (mod.ManifestName.match(modname)) {
if (mod.manifest_name) {
if (mod.manifest_name.match(modname)) {
return true;
}
} else if (mod.Name.match(modname)) {
} else if (mod.name.match(modname)) {
return true;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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");

console = require("./modules/console");
Expand Down Expand Up @@ -112,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());
Expand Down Expand Up @@ -238,13 +241,13 @@ ipcMain.on("getmods", () => {
log(`${lang("general.mods.installed")} ${mods.all.length}`);
log(`${lang("general.mods.enabled")} ${mods.enabled.length}`);
for (let i = 0; i < mods.enabled.length; i++) {
log(` ${mods.enabled[i].Name} ${mods.enabled[i].Version}`);
log(` ${mods.enabled[i].name} ${mods.enabled[i].version}`);
}

if (mods.disabled.length > 0) {
log(`${lang("general.mods.disabled")} ${mods.disabled.length}`);
for (let i = 0; i < mods.disabled.length; i++) {
log(` ${mods.disabled[i].Name} ${mods.disabled[i].Version}`);
log(` ${mods.disabled[i].name} ${mods.disabled[i].version}`);
}
}
cli.exit(0);
Expand Down
2 changes: 2 additions & 0 deletions src/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"gui.mods.installedmod": "Mod installiert!",
"gui.mods.dragdrop": "Drag and drop den Mod um ihn zu installieren!",
"gui.mods.confirmdependencies": "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",
"gui.mods.confirm_plugins_title": "Das folgende Packet hat native plugins::",
"gui.mods.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.",

"gui.browser.info": "Info",
"gui.browser.view": "Anschauen",
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"gui.mods.installedmod": "Installed mod!",
"gui.mods.dragdrop": "Drag and drop a mod to install",
"gui.mods.confirmdependencies": "This package has dependencies, shown below, clicking \"Ok\" will install the package and the dependencies.\n\n",
"gui.mods.confirm_plugins_title": "The following package has native plugins:",
"gui.mods.confirm_plugins_description": "Native plugins have far more system access than a regular mod, and because of this they're inherently less secure to have installed, as a malicious plugin could do far more harm this way. If this plugin is one from a trusted developer or similar or you know what you're doing, then you can disregard this message completely.",

"gui.browser.info": "Info",
"gui.browser.view": "View",
Expand Down
2 changes: 2 additions & 0 deletions src/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"gui.mods.confirmdependencies": "Este paquete tiene dependencias, se muestran abajo. Presionar \"Ok\" instalará el paquete y las dependencias.\n\n",
"gui.mods.remove": "Remover",
"gui.mods.unknown_author": "Desconocido",
"gui.mods.confirm_plugins_title": "El siguiente paquete tiene complementos nativos:",
"gui.mods.confirm_plugins_description": "Los complementos nativos tienen mucho más acceso al sistema que un mod regular y, por lo tanto, son inherentemente menos seguros de instalar, ya que un complemento malicioso podría causar mucho más daño de esta manera. Si este complemento es de un desarrollador confiable o similar o si sabe lo que está haciendo, entonces puede ignorar completamente este mensaje.",

"gui.browser.info": "Información",
"gui.browser.madeby": "hecho por",
Expand Down
2 changes: 2 additions & 0 deletions src/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
"gui.mods.installedmod": "Mod installé !",
"gui.mods.dragdrop": "Glissez/déposez un mod pour l'installer",
"gui.mods.confirmdependencies": "Ce mod a des dépendances (affichées ci-dessous), cliquer \"Ok\" les installera en même temps que le mod.\n\n",
"gui.mods.confirm_plugins_title": "Ce mod contient des plugins :",
"gui.mods.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.",

"gui.browser.info": "Info",
"gui.browser.view": "Voir",
Expand Down
Loading

0 comments on commit b180388

Please sign in to comment.