implement missing features
This commit is contained in:
parent
39750cb2b5
commit
911ffd9794
3 changed files with 48 additions and 6 deletions
|
@ -16,7 +16,7 @@ export default function UserpluginInstallButton({ props }: any) {
|
||||||
return;
|
return;
|
||||||
const gitLink = (props.message.content as string).match(CLONE_LINK_REGEX);
|
const gitLink = (props.message.content as string).match(CLONE_LINK_REGEX);
|
||||||
if (!gitLink) return;
|
if (!gitLink) return;
|
||||||
const installed = plugins.includes(gitLink[1]);
|
const installed = plugins.includes(gitLink[3]);
|
||||||
return <>
|
return <>
|
||||||
<div style={{ display: "flex" }}>
|
<div style={{ display: "flex" }}>
|
||||||
<Button style={{
|
<Button style={{
|
||||||
|
@ -46,7 +46,7 @@ export default function UserpluginInstallButton({ props }: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
{installed ? "Reinstall" : "Install"} plugin
|
{installed ? "Update" : "Install"} plugin
|
||||||
</Button>
|
</Button>
|
||||||
{
|
{
|
||||||
installed && <Button style={{
|
installed && <Button style={{
|
||||||
|
@ -54,7 +54,18 @@ export default function UserpluginInstallButton({ props }: any) {
|
||||||
marginLeft: "10px"
|
marginLeft: "10px"
|
||||||
}}
|
}}
|
||||||
color={Button.Colors.RED}
|
color={Button.Colors.RED}
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
await Native.rmPlugin(gitLink[3]);
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
catch (e: any) {
|
||||||
|
if (e.toString().includes("silentStop")) return;
|
||||||
|
Alerts.show({
|
||||||
|
title: "Uninstall error",
|
||||||
|
body: e.toString()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}}>
|
}}>
|
||||||
Uninstall plugin
|
Uninstall plugin
|
||||||
|
|
|
@ -11,16 +11,19 @@ import definePlugin, { PluginNative } from "@utils/types";
|
||||||
|
|
||||||
import UserpluginInstallButton from "./UserpluginInstallButton";
|
import UserpluginInstallButton from "./UserpluginInstallButton";
|
||||||
|
|
||||||
export const plugins: any[] = [];
|
export let plugins: any[] = [];
|
||||||
export 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 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)?(?:\/)?/;
|
||||||
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const Native = VencordNative.pluginHelpers.UserpluginInstaller as PluginNative<typeof import("./native")>;
|
export const Native = VencordNative.pluginHelpers.UserpluginInstaller as PluginNative<typeof import("./native")>;
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "UserpluginInstaller",
|
name: "UserpluginInstaller",
|
||||||
description: "Install userplugins with a simple button click",
|
description: "Install userplugins with a simple button click",
|
||||||
|
async start() {
|
||||||
|
plugins = await Native.getUserplugins();
|
||||||
|
console.log(plugins);
|
||||||
|
},
|
||||||
authors: [Devs.nin0dev],
|
authors: [Devs.nin0dev],
|
||||||
renderMessageAccessory: props => {
|
renderMessageAccessory: props => {
|
||||||
return <UserpluginInstallButton props={props} />;
|
return <UserpluginInstallButton props={props} />;
|
||||||
|
|
30
native.ts
30
native.ts
|
@ -7,7 +7,7 @@
|
||||||
import { exec, spawn } from "child_process";
|
import { exec, spawn } from "child_process";
|
||||||
import { BrowserView, BrowserWindow, dialog, shell } from "electron";
|
import { BrowserView, BrowserWindow, dialog, shell } from "electron";
|
||||||
import { existsSync, readdirSync, readFileSync } from "fs";
|
import { existsSync, readdirSync, readFileSync } from "fs";
|
||||||
import { rm } from "fs/promises";
|
import { readdir, rm } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
// @ts-ignore fuck off
|
// @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 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)?(?:\/)?/;
|
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> {
|
export async function initPluginInstall(_, link: string, source: string, owner: string, repo: string): Promise<string> {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
@ -173,3 +196,8 @@ function generateReviewPluginContent(meta: {
|
||||||
const buf = Buffer.from(template).toString("base64");
|
const buf = Buffer.from(template).toString("base64");
|
||||||
return `data:text/html;base64,${buf}`;
|
return `data:text/html;base64,${buf}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getUserplugins() {
|
||||||
|
return await readdir(join(__dirname, "..", "src", "userplugins"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue