Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Oct 7, 2024
1 parent b33e0d0 commit 6dc54f1
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 109 deletions.
3 changes: 1 addition & 2 deletions src/Components/AccountDetailsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defaultSettings } from "../lib/consts";
import FakeDeafenContextMenu from "./ContextMenu";
import Icons from "../Components/Icons";
import Utils from "../lib/utils";
export const AccountDetailsButton = () => {
export default () => {
if (
!SettingValues.get("userPanel", defaultSettings.userPanel) ||
plugins.getDisabled().includes("dev.tharki.FakeDeafen")
Expand Down Expand Up @@ -43,4 +43,3 @@ export const AccountDetailsButton = () => {
/>
);
};
export default () => (Modules.PanelButton ? <AccountDetailsButton /> : <></>);
48 changes: 48 additions & 0 deletions src/Components/AccountProfileItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { SettingValues } from "../index";
import { defaultSettings } from "../lib/consts";
import ContextMenu from "./ContextMenu";
import Icons from "./Icons";
import Utils from "../lib/utils";
import Types from "../types";

export default ({ ProfileItem }: { ProfileItem: Types.ProfileItem }): React.ReactElement | null => {
if (!SettingValues.get("statusPicker", defaultSettings.statusPicker)) return null;
const [status, toogleStatus] = Utils.useSoundStatus();
const Icon = (
<Icons.sound
width="16"
height="16"
style={{
marginLeft: "-2px",
}}
/>
);
const DisabledIcon = (
<Icons.sound
width="16"
height="16"
style={{
marginLeft: "-2px",
}}>
<polygon
style={{
fill: "#a61616",
}}
points="22.6,2.7 22.6,2.8 19.3,6.1 16,9.3 16,9.4 15,10.4 15,10.4 10.3,15 2.8,22.5 1.4,21.1 21.2,1.3 "
/>
</Icons.sound>
);

return (
<div>
<ProfileItem
label={`${status ? "Unfake" : "Fake"} VC Status`}
id="fake-deafen"
icon={() => (status ? DisabledIcon : Icon)}
onClick={() => toogleStatus()}
renderSubmenu={({ closePopout }) => <ContextMenu onClose={closePopout} />}
/>
<div id="profileDivider" />
</div>
);
};
2 changes: 1 addition & 1 deletion src/Components/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default (props: Types.MenuProps | { onClose: Types.DefaultTypes.AnyFuncti
return (
<ContextMenu.ContextMenu
{...props}
navId="yofukashino"
navId="yofukashino-fake-deafen-submenu"
onClose={props.onClose ?? ContextMenuApi.close}>
<ContextMenu.MenuGroup label="What to fake?">
<ContextMenu.MenuSeparator />
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export const stop = (): void => {
Listeners.removeListeners();
};

export { default as _addPanelButton } from "./Components/AccountDetailsButton";

export { Settings } from "./Components/Settings.jsx";

export { _addPanelButton, _addProfileItem } from "./plaintextFunctions";
102 changes: 0 additions & 102 deletions src/injections/AccountContextMenu.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/injections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import Modules from "../lib/requiredModules";
import injectAudioResolver from "./AudioResolver";
import injectCenterControlTray from "./CenterControlTray";
import injectGatewayConnection from "./GatewayConnection";
import injectAccountContextMenu from "./AccountContextMenu";
import injectSettingSetter from "./SettingValues";
export const applyInjections = async (): Promise<void> => {
await Modules.loadModules();
void injectAudioResolver();
injectCenterControlTray();
injectGatewayConnection();
injectAccountContextMenu();
injectSettingSetter();
};

Expand Down
11 changes: 11 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ export const toggleSoundStatus = (enabled: boolean): void => {
PluginLogger.log(enabled ? "Disabled Fake Voice State" : "Enabled Fake Voice State");
SettingValues.set("enabled", !enabled);
};
export const useSoundStatus = (): [boolean, () => void] => {
const [enabled, setEnabled] = React.useState(
SettingValues.get("enabled", defaultSettings.enabled),
);
const toogleEnabled = (): void => {
toggleSoundStatus(enabled);
setEnabled(SettingValues.get("enabled", defaultSettings.enabled));
};
return [enabled, toogleEnabled];
};
export const useSetting = <
T extends Record<string, Types.Jsonifiable>,
D extends keyof T,
Expand Down Expand Up @@ -130,6 +140,7 @@ export default {
forceRerenderElement,
updateSoundStatus,
toggleSoundStatus,
useSoundStatus,
useSetting,
useSettingArray,
};
7 changes: 7 additions & 0 deletions src/plaintextFunctions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Modules from "./lib/requiredModules";
import AccountDetailsButton from "./Components/AccountDetailsButton";
import AccountProfileItem from "./Components/AccountProfileItem";

export const _addPanelButton = () => (Modules.PanelButton ? <AccountDetailsButton /> : <></>);

export const _addProfileItem = (props) => <AccountProfileItem {...props} />;
10 changes: 10 additions & 0 deletions src/plaintextPatches.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Types from "./types";

export default [
{
find: "AccountProfilePopout",
replacements: [
{
match: /\(0,\w+\.jsx\)\((\w+\.\w+),{id:"switch-accounts/,
replace: (suffix: string, ProfileItem: string) =>
`replugged.plugins.getExports("dev.tharki.FakeDeafen")?._addProfileItem?.({ProfileItem: ${ProfileItem}}),${suffix}`,
},
],
},
{
find: "isCopiedStreakGodlike",
replacements: [
Expand Down
6 changes: 6 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@
color: var(----interactive-hover);
display: none;
}

#profileDivider {
background-color: var(--profile-body-divider-color);
height: 1px;
margin: 8px 4px;
}
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ export namespace Types {
default: DefaultTypes.AnyFunction;
handleToggleVideo: DefaultTypes.AnyFunction;
}
export type ProfileItem = React.ComponentType<{
label: string;
id: string;
icon: () => React.ReactElement;
onClick: () => void;
renderSubmenu?: ({ closePopout }: { closePopout: () => void }) => React.ReactElement;
}>;
export interface AccountDetailsClasses {
accountProfilePopoutWrapper: string;
avatar: string;
Expand Down

0 comments on commit 6dc54f1

Please sign in to comment.