mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-25 07:48:32 +00:00
Updated contextmenus
This commit is contained in:
parent
3e7032b188
commit
96b6ac67ae
1 changed files with 34 additions and 84 deletions
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { addContextMenuPatch, type NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu";
|
import { type NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||||
import { DataStore, Notifications } from "@api/index";
|
import { DataStore, Notifications } from "@api/index";
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
|
@ -37,73 +37,25 @@ function icon(enabled?: boolean) {
|
||||||
</svg>;
|
</svg>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GuildContext: NavContextMenuPatchCallback = (children, { guild }: ContextProps) => () => {
|
function ContextCallback(name: "guild" | "user" | "channel"): NavContextMenuPatchCallback {
|
||||||
const enabled = bypasses.guilds.includes(guild.id);
|
return (children, props) => {
|
||||||
|
const type = props[name];
|
||||||
|
if (!type) return;
|
||||||
|
const enabled = bypasses[`${name}s`].includes(type.id);
|
||||||
|
if (name === "user" && type.id === UserStore.getCurrentUser().id) return;
|
||||||
children.splice(-1, 0, (
|
children.splice(-1, 0, (
|
||||||
<Menu.MenuGroup>
|
<Menu.MenuGroup>
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="dnd-guild-bypass"
|
id={`dnd-${name}-bypass`}
|
||||||
label={`${enabled ? "Remove" : "Add"} DND Bypass`}
|
label={`${enabled ? "Remove" : "Add"} DND Bypass`}
|
||||||
icon={() => icon(enabled)}
|
icon={() => icon(enabled)}
|
||||||
action={() => {
|
action={() => {
|
||||||
if (enabled) bypasses.guilds = bypasses.guilds.filter(id => id !== guild.id);
|
if (enabled) bypasses[`${name}s`] = bypasses[`${name}s`].filter(id => id !== type.id);
|
||||||
else bypasses.guilds.push(guild.id);
|
else bypasses[`${name}s`].push(type.id);
|
||||||
DataStore.set("bypassdnd", bypasses)
|
|
||||||
.then(() => {
|
|
||||||
settings.store.guilds = bypasses.guilds.join(", ");
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
|
|
||||||
/>
|
|
||||||
</Menu.MenuGroup>
|
|
||||||
));
|
|
||||||
};
|
|
||||||
|
|
||||||
const ChannelContext: NavContextMenuPatchCallback = (children, { channel }: ContextProps) => () => {
|
|
||||||
const enabled = bypasses.channels.includes(channel.id);
|
|
||||||
children.splice(-1, 0, (
|
|
||||||
<Menu.MenuGroup>
|
|
||||||
<Menu.MenuItem
|
|
||||||
id="dnd-channel-bypass"
|
|
||||||
label={`${enabled ? "Remove" : "Add"} DND Bypass`}
|
|
||||||
icon={() => icon(enabled)}
|
|
||||||
action={() => {
|
|
||||||
if (enabled) bypasses.channels = bypasses.channels.filter(id => id !== channel.id);
|
|
||||||
else bypasses.channels.push(channel.id);
|
|
||||||
|
|
||||||
DataStore.set("bypassdnd", bypasses)
|
DataStore.set("bypassdnd", bypasses)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
settings.store.channels = bypasses.channels.join(", ");
|
settings.store[`${name}s`] = bypasses[`${name}s`].join(", ");
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
|
|
||||||
/>
|
|
||||||
</Menu.MenuGroup>
|
|
||||||
));
|
|
||||||
};
|
|
||||||
|
|
||||||
const UserContext: NavContextMenuPatchCallback = (children, { user }: ContextProps) => () => {
|
|
||||||
const enabled = bypasses.users.includes(user.id);
|
|
||||||
if (user.id === UserStore.getCurrentUser().id) return;
|
|
||||||
children.splice(-1, 0, (
|
|
||||||
<Menu.MenuGroup>
|
|
||||||
<Menu.MenuItem
|
|
||||||
id="dnd-user-bypass"
|
|
||||||
label={`${enabled ? "Remove" : "Add"} DND Bypass`}
|
|
||||||
icon={() => icon(enabled)}
|
|
||||||
action={() => {
|
|
||||||
if (enabled) bypasses.users = bypasses.users.filter(id => id !== user.id);
|
|
||||||
else bypasses.users.push(user.id);
|
|
||||||
|
|
||||||
DataStore.set("bypassdnd", bypasses)
|
|
||||||
.then(() => {
|
|
||||||
settings.store.users = bypasses.users.join(", ");
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -113,6 +65,7 @@ const UserContext: NavContextMenuPatchCallback = (children, { user }: ContextPro
|
||||||
</Menu.MenuGroup>
|
</Menu.MenuGroup>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
interface Bypasses {
|
interface Bypasses {
|
||||||
guilds: string[];
|
guilds: string[];
|
||||||
|
@ -201,16 +154,13 @@ export default definePlugin({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
settings,
|
settings,
|
||||||
|
contextMenus: {
|
||||||
|
"guild-context": ContextCallback("guild"),
|
||||||
|
"channel-context": ContextCallback("channel"),
|
||||||
|
"user-context": ContextCallback("user"),
|
||||||
|
},
|
||||||
async start() {
|
async start() {
|
||||||
addContextMenuPatch("guild-context", GuildContext);
|
|
||||||
addContextMenuPatch("channel-context", ChannelContext);
|
|
||||||
addContextMenuPatch("user-context", UserContext);
|
|
||||||
bypasses = (await DataStore.get("bypassdnd")) ?? { guilds: [], channels: [], users: [] };
|
bypasses = (await DataStore.get("bypassdnd")) ?? { guilds: [], channels: [], users: [] };
|
||||||
await DataStore.set("bypassdnd", bypasses);
|
await DataStore.set("bypassdnd", bypasses);
|
||||||
},
|
|
||||||
stop() {
|
|
||||||
removeContextMenuPatch("guild-context", GuildContext);
|
|
||||||
removeContextMenuPatch("channel-context", ChannelContext);
|
|
||||||
removeContextMenuPatch("user-context", UserContext);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue