2024-11-01 10:53:33 -04:00
|
|
|
import { Notices } from "@api/index";
|
|
|
|
import { addAccessory } from "@api/MessageAccessories";
|
|
|
|
import { Devs } from "@utils/constants";
|
2024-11-01 13:10:56 -04:00
|
|
|
import definePlugin, { PluginNative } from "@utils/types";
|
|
|
|
import { Button, ChannelStore, Forms, Toasts } from "@webpack/common";
|
2024-11-01 10:53:33 -04:00
|
|
|
import { Message } from "discord-types/general";
|
2024-11-01 13:10:56 -04:00
|
|
|
import { clone } from "lodash";
|
|
|
|
import UserpluginInstallButton from "./UserpluginInstallButton";
|
2024-11-01 15:36:58 -04:00
|
|
|
import { showInstallModal } from "./UserpluginInstallModal";
|
2024-11-01 10:53:33 -04:00
|
|
|
|
2024-11-01 15:36:58 -04:00
|
|
|
import "./style.css";
|
|
|
|
|
|
|
|
export let plugins: any[] = [];
|
2024-11-01 13:10:56 -04:00
|
|
|
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)?(?:\/)?/;
|
2024-11-01 10:53:33 -04:00
|
|
|
|
2024-11-01 13:10:56 -04:00
|
|
|
// @ts-ignore
|
2024-11-01 15:36:58 -04:00
|
|
|
export const Native = VencordNative.pluginHelpers.UserpluginInstaller as PluginNative<typeof import("./native")>;
|
2024-11-01 13:10:56 -04:00
|
|
|
|
|
|
|
export async function clonePlugin(gitLink: RegExpMatchArray) {
|
|
|
|
Toasts.show({
|
|
|
|
message: "Cloning plugin...",
|
|
|
|
id: Toasts.genId(),
|
|
|
|
type: Toasts.Type.MESSAGE
|
|
|
|
});
|
|
|
|
try {
|
2024-11-01 15:36:58 -04:00
|
|
|
const path = `${VesktopNative.fileManager.getVencordDir().replace("\\", "/")}/../src/userplugins/${gitLink[1]}`;
|
|
|
|
const clonedRepo = await Native.cloneRepo(gitLink[0], path);
|
|
|
|
const meta = await Native.getPluginMeta(path);
|
|
|
|
console.log(meta);
|
|
|
|
showInstallModal(meta, path);
|
2024-11-01 13:10:56 -04:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Toasts.pop();
|
|
|
|
return Toasts.show({
|
|
|
|
message: "Something bad has happened while cloning the plugin, try again later and make sure that the plugin link is valid.",
|
|
|
|
id: Toasts.genId(),
|
|
|
|
type: Toasts.Type.FAILURE
|
|
|
|
});
|
|
|
|
}
|
2024-11-01 10:53:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
name: "UserpluginInstaller",
|
|
|
|
description: "Install userplugins with a simple button click",
|
|
|
|
authors: [Devs.nin0dev],
|
2024-11-01 15:36:58 -04:00
|
|
|
async start() {
|
|
|
|
plugins = await Native.getPlugins(`${VesktopNative.fileManager.getVencordDir().replace("\\", "/")}/../src/userplugins/`);
|
|
|
|
console.log(plugins);
|
2024-11-01 10:53:33 -04:00
|
|
|
addAccessory("userpluginInstallButton", (props: Record<string, any>) => (
|
|
|
|
<UserpluginInstallButton props={props} />
|
|
|
|
), 4);
|
|
|
|
}
|
|
|
|
});
|