cloning
This commit is contained in:
parent
7cd4dc5bdc
commit
9a83a6a012
3 changed files with 59 additions and 18 deletions
19
UserpluginInstallButton.tsx
Normal file
19
UserpluginInstallButton.tsx
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Button, ChannelStore } from "@webpack/common";
|
||||||
|
import { Message } from "discord-types/general";
|
||||||
|
import { CLONE_LINK_REGEX, clonePlugin } from ".";
|
||||||
|
|
||||||
|
const WHITELISTED_SHARE_CHANNELS = ["1256395889354997771", "1032200195582197831", "1301947896601509900"];
|
||||||
|
|
||||||
|
export default function UserpluginInstallButton({ props }: any) {
|
||||||
|
const message: Message = props.message;
|
||||||
|
if (!WHITELISTED_SHARE_CHANNELS.includes(ChannelStore.getChannel(message.channel_id).parent_id) && !WHITELISTED_SHARE_CHANNELS.includes(message.channel_id))
|
||||||
|
return;
|
||||||
|
const gitLink = (props.message.content as string).match(CLONE_LINK_REGEX);
|
||||||
|
if (!gitLink) return;
|
||||||
|
return <Button style={{
|
||||||
|
marginTop: "5px"
|
||||||
|
}}
|
||||||
|
onClick={() => clonePlugin(gitLink)}>
|
||||||
|
Install plugin
|
||||||
|
</Button>;
|
||||||
|
}
|
43
index.tsx
43
index.tsx
|
@ -1,27 +1,34 @@
|
||||||
import { Notices } from "@api/index";
|
import { Notices } from "@api/index";
|
||||||
import { addAccessory } from "@api/MessageAccessories";
|
import { addAccessory } from "@api/MessageAccessories";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { PluginNative } from "@utils/types";
|
||||||
import { Button, ChannelStore, Forms } from "@webpack/common";
|
import { Button, ChannelStore, Forms, Toasts } from "@webpack/common";
|
||||||
import { Message } from "discord-types/general";
|
import { Message } from "discord-types/general";
|
||||||
|
import { clone } from "lodash";
|
||||||
|
import UserpluginInstallButton from "./UserpluginInstallButton";
|
||||||
|
|
||||||
const WHITELISTED_SHARE_CHANNELS = ["1256395889354997771", "1032200195582197831"];
|
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)?(?:\/)?/;
|
||||||
const CLONE_LINK_REGEX = /(https:\/\/(?:git(?:hub|lab)\.com|git\.(?:[a-zA-Z0-9]|\.)+|codeberg\.org)\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+(?:\.git)?(?:\/)?)/;
|
|
||||||
|
|
||||||
function UserpluginInstallButton({ props }: any) {
|
// @ts-ignore
|
||||||
const message: Message = props.message;
|
const Native = VencordNative.pluginHelpers.UserpluginInstaller as PluginNative<typeof import("./native")>;
|
||||||
if (!WHITELISTED_SHARE_CHANNELS.includes(ChannelStore.getChannel(message.channel_id).parent_id) && !WHITELISTED_SHARE_CHANNELS.includes(message.channel_id))
|
|
||||||
return;
|
export async function clonePlugin(gitLink: RegExpMatchArray) {
|
||||||
const gitLink = (props.message.content as string).match(CLONE_LINK_REGEX);
|
Toasts.show({
|
||||||
if (!gitLink) return;
|
message: "Cloning plugin...",
|
||||||
return <Button style={{
|
id: Toasts.genId(),
|
||||||
marginTop: "5px"
|
type: Toasts.Type.MESSAGE
|
||||||
}}
|
});
|
||||||
onClick={() => {
|
try {
|
||||||
console.log(ChannelStore.getChannel(message.channel_id));
|
const clonedRepo = await Native.cloneRepo(gitLink[0], `${VesktopNative.fileManager.getVencordDir().replace("\\", "/")}/../src/userplugins/${gitLink[1]}`);
|
||||||
}}>
|
}
|
||||||
Install plugin
|
catch (e) {
|
||||||
</Button>;
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
|
|
15
native.ts
Normal file
15
native.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { exec, spawn } from "child_process";
|
||||||
|
import { IpcMainInvokeEvent } from "electron";
|
||||||
|
|
||||||
|
export async function cloneRepo(_: IpcMainInvokeEvent, repo: string, clonePath: string): Promise<any> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(`git clone ${repo} ${clonePath}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
return reject(
|
||||||
|
stderr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue