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 b258453 commit 8c432f5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/Components/FluentMasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ export const stream = ({
</mask>
);

export default { online, phone, idle, dnd, offline, stream };
export const typing = ({
children,
...props
}: React.SVGProps<SVGMaskElement> & { children?: React.ReactNode }): React.ReactElement => (
<mask maskContentUnits="objectBoundingBox" viewBox="0 0 1 1" style={props.style} {...props}>
<rect fill="white" cx="0" cy="0" width="1" height="1" ry="0.5" rx="0.2" />
<rect fill="black" width="0.95" height="0.9" ry="0.5" rx="0.2" x="0.025" y="0.06" />
{children}
</mask>
);

export default { online, phone, idle, dnd, offline, stream, typing };
5 changes: 5 additions & 0 deletions src/Components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const Settings = () => {
{...util.useSetting(SettingValues, "StreamingIcon", defaultSettings.StreamingIcon)}>
Streaming Icon
</SwitchItem>
<SwitchItem
note="Fluent Typing Icon"
{...util.useSetting(SettingValues, "TypingIcon", defaultSettings.TypingIcon)}>
Typing Icon
</SwitchItem>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Injections from "./injections/index";

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

export const stop = (): void => {
Expand Down
8 changes: 8 additions & 0 deletions src/injections/MaskLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export default (): void => {
<FluentMasks.stream id={Modules.MaskManager.MaskIDs.STATUS_STREAMING} />
);
}
if (SettingValues.get("TypingIcon", defaultSettings.TypingIcon)) {
const StreamingStatusMask = masks.findIndex(
(mask: React.ReactElement) => mask.props.id === Modules.MaskManager.MaskIDs.STATUS_TYPING,
);
masks[StreamingStatusMask] = (
<FluentMasks.typing id={Modules.MaskManager.MaskIDs.STATUS_TYPING} />
);
}
return res;
},
);
Expand Down
1 change: 1 addition & 0 deletions src/lib/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const defaultSettings = {
DNDIcon: true,
IdleIcon: true,
OfflineIcon: true,
TypingIcon: true,
};
36 changes: 32 additions & 4 deletions src/lib/requiredModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,38 @@ import Types from "../types";
export const Modules: Types.Modules = {};

Modules.loadModules = async (): Promise<void> => {
Modules.Avatar ??= await webpack.waitForModule<Types.Avatar>(
webpack.filters.bySource("getMaskId()"),
);
Modules.MaskManager ??= await webpack.waitForProps<Types.MaskLibrary>("MaskLibrary");
Modules.AvatarModule ??= await webpack
.waitForModule<Types.GenericModule>(webpack.filters.bySource("getMaskId()"), {
timeout: 10000,
})
.catch(() => {
throw new Error("Failed To Find Avatar Module");
});

Modules.Avatar ??= {
Avatar: webpack.getFunctionBySource(Modules.AvatarModule, ".AVATAR_DEFAULT;"),
AnimatedAvatar: webpack.getExportsForProps(Modules.AvatarModule, ["compare", "type"]),
getStatusCoords: webpack.getFunctionBySource(Modules.AvatarModule, ".offset;"),
};

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

Modules.MaskManager ??= {
default: webpack.getFunctionBySource(Modules.MaskManagerModule, "svg"),
MaskLibrary: webpack.getExportsForProps(Modules.MaskManagerModule, ["compare", "type"]),
MaskIDs: webpack.getExportsForProps(Modules.MaskManagerModule, [
"STATUS_DND",
"STATUS_IDLE",
"STATUS_OFFLINE",
"STATUS_ONLINE",
]),
};
};

export default Modules;
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export namespace Types {
compare: null | DefaultTypes.AnyFunction;
type: DefaultTypes.AnyFunction;
};
getStatusCoords: DefaultTypes.AnyFunction;
}

export interface MaskLibrary {
Expand Down Expand Up @@ -105,7 +106,9 @@ export namespace Types {
}
export interface Modules {
loadModules?: () => Promise<void>;
AvatarModule?: GenericModule;
Avatar?: Avatar;
MaskManagerModule?: GenericModule;
MaskManager?: MaskLibrary;
}
export interface Settings {
Expand All @@ -115,6 +118,7 @@ export namespace Types {
DNDIcon: boolean;
IdleIcon: boolean;
OfflineIcon: boolean;
TypingIcon: boolean;
}
}
export default Types;

0 comments on commit 8c432f5

Please sign in to comment.