implement missing features

This commit is contained in:
nin0 2025-03-08 23:47:04 -05:00
parent 39750cb2b5
commit 911ffd9794
Signed by: nin0
SSH key fingerprint: SHA256:NOoDnFVvZNFvqfXCIhzr6oCTDImZAbTTuyAysZ8Ufk8
3 changed files with 48 additions and 6 deletions

View file

@ -7,7 +7,7 @@
import { exec, spawn } from "child_process";
import { BrowserView, BrowserWindow, dialog, shell } from "electron";
import { existsSync, readdirSync, readFileSync } from "fs";
import { rm } from "fs/promises";
import { readdir, rm } from "fs/promises";
import { join } from "path";
// @ts-ignore fuck off
@ -16,6 +16,29 @@ import pluginValidateContent from "./pluginValidate.txt"; // i would use HTML bu
const PLUGIN_META_REGEX = /export default definePlugin\((?:\s|\/(?:\/|\*).*)*{\s*(?:\s|\/(?:\/|\*).*)*name:\s*(?:"|'|`)(.*)(?:"|'|`)(?:\s|\/(?:\/|\*).*)*,(?:\s|\/(?:\/|\*).*)*(?:\s|\/(?:\/|\*).*)*description:\s*(?:"|'|`)(.*)(?:"|'|`)(?:\s|\/(?:\/|\*).*)*/;
const CLONE_LINK_REGEX = /https:\/\/((?:git(?:hub|lab)\.com|git\.(?:[a-zA-Z0-9]|\.)+|codeberg\.org))\/(?!user-attachments)((?:[a-zA-Z0-9]|-)+)\/((?:[a-zA-Z0-9]|-)+)(?:\.git)?(?:\/)?/;
export async function rmPlugin(_, name: string): Promise<string> {
// eslint-disable-next-line
return new Promise(async (resolve, reject) => {
const pluginPath = join(__dirname, "..", "src", "userplugins", name);
if (!existsSync(pluginPath)) {
throw new Error("Plugin does not exist");
}
const deleteReqDialog = await dialog.showMessageBox({
title: "Uninstall plugin",
message: `Uninstall ${name}`,
type: "error",
detail: `The uninstall of the userplugin ${name} has been requested. Would you like to do so?\n\nIf you did not initiate this, press No.`,
buttons: ["No", "Yes"]
});
if (deleteReqDialog.response !== 1) return reject("User rejected");
await rm(pluginPath, { recursive: true });
await build();
resolve("Done");
});
}
export async function initPluginInstall(_, link: string, source: string, owner: string, repo: string): Promise<string> {
// eslint-disable-next-line
return new Promise(async (resolve, reject) => {
@ -173,3 +196,8 @@ function generateReviewPluginContent(meta: {
const buf = Buffer.from(template).toString("base64");
return `data:text/html;base64,${buf}`;
}
export async function getUserplugins() {
return await readdir(join(__dirname, "..", "src", "userplugins"));
}