Fix InstantScreenshare, WigglyText, ExitSounds

This commit is contained in:
thororen1234 2026-06-06 19:59:19 -04:00
parent b8673bbab2
commit a31c80ba50
No known key found for this signature in database
3 changed files with 64 additions and 52 deletions

View file

@ -14,7 +14,7 @@ import { Devs } from "@utils/constants";
import { classNameFactory } from "@utils/css";
import definePlugin, { OptionType } from "@utils/types";
import { findComponentByCodeLazy } from "@webpack";
import { ChannelActions, Constants, GuildStore, IconUtils, MediaEngineStore, Menu, RestAPI, SearchableSelect, SelectedChannelStore, TextInput, Toasts } from "@webpack/common";
import { Constants, GuildStore, IconUtils, MediaEngineStore, Menu, RestAPI, SearchableSelect, SelectedChannelStore, TextInput, Toasts } from "@webpack/common";
const cl = classNameFactory("vc-exitsounds-");
@ -99,8 +99,6 @@ const SoundButtonContext: NavContextMenuPatchCallback = (children, { sound }: {
);
};
let original: typeof ChannelActions.selectVoiceChannel;
export default definePlugin({
name: "ExitSounds",
description: "Play soundboard sounds when you disconnect from voice.",
@ -108,41 +106,39 @@ export default definePlugin({
authors: [Devs.prism],
dependencies: ["AudioPlayerAPI"],
settings,
contextMenus: {
"sound-button-context": SoundButtonContext
},
start() {
original = ChannelActions.selectVoiceChannel;
ChannelActions.selectVoiceChannel = async (id: string | null, ...args: unknown[]) => {
const { soundGuildId, soundId } = settings.store;
const voiceId = SelectedChannelStore.getVoiceChannelId();
if (soundGuildId && soundId && voiceId !== id && !MediaEngineStore.isDeaf()) {
try {
await RestAPI.post({
url: Constants.Endpoints.SEND_SOUNDBOARD_SOUND(voiceId),
body: {
sound_id: soundId,
source_guild_id: soundGuildId
}
});
await new Promise(r => setTimeout(r, 500));
} catch {
Toasts.show({
message: "Oops! Something went wrong.",
id: Toasts.genId(),
type: Toasts.Type.FAILURE
});
}
patches: [
{
find: 'type:"VOICE_CHANNEL_SHOW_FEEDBACK"',
replacement: {
match: /disconnect\(\)\{/,
replace: "async $& await $self.onDisconnect();"
}
}
],
async onDisconnect() {
const { soundGuildId, soundId } = settings.store;
if (!soundGuildId || !soundId || MediaEngineStore.isDeaf()) return;
return original(id, ...args);
};
},
const voiceId = SelectedChannelStore.getVoiceChannelId();
if (!voiceId) return;
stop() {
ChannelActions.selectVoiceChannel = original;
try {
await RestAPI.post({
url: Constants.Endpoints.SEND_SOUNDBOARD_SOUND(voiceId),
body: {
sound_id: soundId,
source_guild_id: soundGuildId
}
});
} catch {
Toasts.show({
message: "Oops! Something went wrong.",
id: Toasts.genId(),
type: Toasts.Type.FAILURE
});
}
}
});

View file

@ -8,6 +8,7 @@ import { definePluginSettings } from "@api/Settings";
import { Heading } from "@components/Heading";
import { Margins } from "@components/margins";
import { Paragraph } from "@components/Paragraph";
import { IS_WINDOWS } from "@utils/constants";
import { Logger } from "@utils/Logger";
import { OptionType } from "@utils/types";
import { findByCodeLazy, findByPropsLazy } from "@webpack";
@ -68,7 +69,7 @@ export const settings = definePluginSettings({
export async function getCurrentMedia() {
const media = MediaEngineStore.getMediaEngine();
const sources = await getDesktopSources(media, ["screen", "window"], null) ?? [];
const sources = await getDesktopSources(media, IS_WINDOWS, ["screen", "window"], null) ?? [];
if (settings.store.includeVideoDevices) {
try {
@ -122,7 +123,7 @@ function ScreenSetting() {
let active = true;
async function fetchMedia() {
setLoading(true);
const sources = await getDesktopSources(media, ["screen", "window"], null) ?? [];
const sources = await getDesktopSources(media, IS_WINDOWS, ["screen", "window"], null) ?? [];
if (includeVideoDevices) {
try {

View file

@ -128,33 +128,48 @@ export default definePlugin({
patches: [
{
find: "parseToAST:",
find: "AUTO_MODERATION_SYSTEM_MESSAGE_RULES:",
replacement: {
match: /(parse[\w]*):(.*?)\((\i)\),/g,
replace: "$1:$2({...$3,wiggly:$self.wigglyRule}),",
match: /staticRouteLink:\{order:(\i\.\i\.order)/,
replace: "wiggly:$self.wigglyRule($1),$&",
},
},
{
find: 'before:"@silent"',
replacement: [
{
match: /staticRouteLink:{type:/,
replace: 'wiggly:{type:"inlineObject"},$&',
},
{
match: /case"roleMention":/,
replace: '$&case "wiggly":'
}
]
},
],
wigglyRule: {
order: 24,
match: (source: string) => classMap.map(({ chars }) => source.match(new RegExp(`^(\\${chars[0]})~([\\s\\S]+?)~(\\${chars[1]})(?!_)`))).find(x => x !== null),
parse: (
capture: RegExpMatchArray,
transform: (...args: any[]) => any,
state: any
) => {
const className = classMap.find(({ chars }) => chars[0] === capture[1] && chars[1] === capture[3])?.className ?? "";
wigglyRule: (order: number) => ({
order: order,
requiredFirstCharacters: ["<~", "^~", ")~"],
match(source: string) {
return classMap
.map(({ chars }) => source.match(
new RegExp(`^(\\${chars[0]})~([\\s\\S]+?)~(\\${chars[1]})(?!_)`)
))
.find(x => x !== null);
},
parse(capture: RegExpMatchArray, transform: (...args: any[]) => any, state: any) {
const className = classMap
.find(({ chars }) => chars[0] === capture[1] && chars[1] === capture[3])?.className
?? "";
return {
content: transform(capture[2], state),
className
};
},
react: (
data: { content: any[]; className: string; },
output: (...args: any[]) => ReactNode[]
) => {
react(data: { content: any[]; className: string; }, output: (...args: any[]) => ReactNode[]) {
let offset = 0;
const traverse = (raw: any) => {
const children = !Array.isArray(raw) ? [raw] : raw;
@ -186,7 +201,7 @@ export default definePlugin({
return traverse(output(data.content));
},
},
}),
start: () => {
styles = document.createElement("style");