Skip to content

Commit

Permalink
swc
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Jun 25, 2024
1 parent 2d4a21d commit b66b869
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 63 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Injector, Logger } from "replugged";
export const PluginLogger = Logger.plugin("HideDisabledEmojis");
export const PluginLogger = Logger.plugin("Double Click to VC");
export const PluginInjector = new Injector();

import Injections from "./injections/index";

export const start = (): void => {
void Injections.applyInjections();
void Injections.applyInjections().catch((err) => PluginLogger.error(err));
};

export const stop = (): void => {
Expand Down
5 changes: 3 additions & 2 deletions src/injections/ChannelItem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { util } from "replugged";
import { util, webpack } from "replugged";
import { PluginInjector } from "../index";
import Modules from "../lib/requiredModules";
import Types from "../types";
export default (): void => {
const { ChannelButtonClasses, ChannelItem } = Modules;
PluginInjector.after(ChannelItem, "default", (_args, res: React.ReactElement & Types.Tree) => {
const loader = webpack.getFunctionKeyBySource(ChannelItem, ".ALL_MESSAGES");
PluginInjector.after(ChannelItem, loader, (_args, res: React.ReactElement & Types.Tree) => {
const button = util.findInReactTree(res, (n: React.ReactElement & Types.Tree) =>
n?.props?.className?.includes(ChannelButtonClasses?.link),
) as (React.ReactElement & Types.Tree) | undefined;
Expand Down
8 changes: 7 additions & 1 deletion src/injections/IconMod.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { webpack } from "replugged";
import { PluginInjector } from "../index";
import Modules from "../lib/requiredModules";
import Types from "../types";
export default (): void => {
const { Interactive } = Modules;
const InteractiveDefault = webpack.getExportsForProps<{ Icon: Types.DefaultTypes.AnyFunction }>(
Interactive,
["Icon"],
);

PluginInjector.after(
Interactive.default,
InteractiveDefault,
"Icon",
(
[{ onDoubleClick }]: [{ onDoubleClick: Types.DefaultTypes.AnyFunction }],
Expand Down
29 changes: 23 additions & 6 deletions src/lib/requiredModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ import Types from "../types";
export const Modules: Types.Modules = {};

Modules.loadModules = async (): Promise<void> => {
Modules.ChannelItem = await webpack.waitForProps<Types.ChannelItem>("ChannelItemIcon");
Modules.ChannelButtonClasses = await webpack.waitForProps<Types.ChannelButtonClasses>(
"modeMuted",
"linkBottom",
);
Modules.Interactive = await webpack.waitForProps<Types.Interactive>("Icon", "default");
Modules.ChannelButtonClasses = await webpack
.waitForProps<Types.ChannelButtonClasses>(["modeMuted", "linkBottom"], {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find ChannelButtonClasses Module");
});

Modules.ChannelItem ??= await webpack
.waitForModule<Types.GenericModule>(webpack.filters.bySource(".iconContainerWithGuildIcon,"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find ChannelItem Module");
});

Modules.Interactive = await webpack
.waitForModule<Types.GenericModule>(webpack.filters.bySource(/\.Title=.=>/), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find Interactive Module");
});
};

export default Modules;
2 changes: 1 addition & 1 deletion src/plaintextPatches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Types from "./types";
import Types from "./types";
export default [
{
find: ".renderVoiceCallButton",
Expand Down
103 changes: 53 additions & 50 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,54 @@
export { types as DefaultTypes } from "replugged";
import { types as DefaultTypes } from "replugged";
export { Channel } from "discord-types/general";
export { Tree } from "replugged/dist/renderer/util";
export interface ChannelButtonClasses {
channelEmoji: string;
channelEmojiLeftOfIcon: string;
channelEmojiRightOfIcon: string;
children: string;
emojiColorFill: string;
favoritesSuggestion: string;
icon: string;
iconContainer: string;
link: string;
linkBottom: string;
linkTop: string;
linkWithChannelEmoji: string;
modeConnected: string;
modeLocked: string;
modeMuted: string;
modeSelected: string;
modeUnread: string;
name: string;
newBadge: string;
notInteractive: string;
numberBadge: string;
responsiveWidthMobile: string;
ripple: string;
subtitle: string;
topContent: string;
twemoji: string;
typeThread: string;
unread: string;
unreadRelevant: string;
wrapper: string;
import { types } from "replugged";
import type util from "replugged/util";

export namespace Types {
export import DefaultTypes = types;
export type Tree = util.Tree;
export type GenericModule = Record<string, DefaultTypes.AnyFunction> & {
default: DefaultTypes.AnyFunction;
};
export interface GenericExport {
exports?: GenericModule;
id: string;
loaded: boolean;
}
export interface ChannelButtonClasses {
channelEmoji: string;
channelEmojiLeftOfIcon: string;
channelEmojiRightOfIcon: string;
children: string;
emojiColorFill: string;
favoritesSuggestion: string;
icon: string;
iconContainer: string;
link: string;
linkBottom: string;
linkTop: string;
linkWithChannelEmoji: string;
modeConnected: string;
modeLocked: string;
modeMuted: string;
modeSelected: string;
modeUnread: string;
name: string;
newBadge: string;
notInteractive: string;
numberBadge: string;
responsiveWidthMobile: string;
ripple: string;
subtitle: string;
topContent: string;
twemoji: string;
typeThread: string;
unread: string;
unreadRelevant: string;
wrapper: string;
}
export interface Modules {
loadModules?: () => Promise<void>;
ChannelButtonClasses?: ChannelButtonClasses;
ChannelItem?: GenericModule;
Interactive?: GenericModule;
}
}
export interface ChannelItem {
default: DefaultTypes.AnyFunction;
ChannelItemIcon: DefaultTypes.AnyFunction;
}
export interface Interactive {
Icon: DefaultTypes.AnyFunction;
default: { Icon: DefaultTypes.AnyFunction } & DefaultTypes.AnyFunction;
}
export interface Modules {
loadModules?: () => Promise<void>;
ChannelItem?: ChannelItem;
ChannelButtonClasses?: ChannelButtonClasses;
Interactive?: Interactive;
}
export * as default from "./types";
export default Types;

0 comments on commit b66b869

Please sign in to comment.