From 6dc54f13f7e77ba91d8cbd94857733b8df9c3e98 Mon Sep 17 00:00:00 2001 From: yofukashino Date: Tue, 8 Oct 2024 03:27:25 +0530 Subject: [PATCH] fix --- src/Components/AccountDetailsButton.tsx | 3 +- src/Components/AccountProfileItem.tsx | 48 +++++++++++ src/Components/ContextMenu.tsx | 2 +- src/index.ts | 4 +- src/injections/AccountContextMenu.tsx | 102 ------------------------ src/injections/index.ts | 2 - src/lib/utils.ts | 11 +++ src/plaintextFunctions.tsx | 7 ++ src/plaintextPatches.ts | 10 +++ src/style.css | 6 ++ src/types.ts | 7 ++ 11 files changed, 93 insertions(+), 109 deletions(-) create mode 100644 src/Components/AccountProfileItem.tsx delete mode 100644 src/injections/AccountContextMenu.tsx create mode 100644 src/plaintextFunctions.tsx diff --git a/src/Components/AccountDetailsButton.tsx b/src/Components/AccountDetailsButton.tsx index edcb35c..44999ee 100644 --- a/src/Components/AccountDetailsButton.tsx +++ b/src/Components/AccountDetailsButton.tsx @@ -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") @@ -43,4 +43,3 @@ export const AccountDetailsButton = () => { /> ); }; -export default () => (Modules.PanelButton ? : <>); diff --git a/src/Components/AccountProfileItem.tsx b/src/Components/AccountProfileItem.tsx new file mode 100644 index 0000000..de037b7 --- /dev/null +++ b/src/Components/AccountProfileItem.tsx @@ -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 = ( + + ); + const DisabledIcon = ( + + + + ); + + return ( +
+ (status ? DisabledIcon : Icon)} + onClick={() => toogleStatus()} + renderSubmenu={({ closePopout }) => } + /> +
+
+ ); +}; diff --git a/src/Components/ContextMenu.tsx b/src/Components/ContextMenu.tsx index fe4ab5b..3726e39 100644 --- a/src/Components/ContextMenu.tsx +++ b/src/Components/ContextMenu.tsx @@ -23,7 +23,7 @@ export default (props: Types.MenuProps | { onClose: Types.DefaultTypes.AnyFuncti return ( diff --git a/src/index.ts b/src/index.ts index df8fee9..5e50350 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; diff --git a/src/injections/AccountContextMenu.tsx b/src/injections/AccountContextMenu.tsx deleted file mode 100644 index 6d39098..0000000 --- a/src/injections/AccountContextMenu.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { React } from "replugged/common"; -import { ContextMenu } from "replugged/components"; -import { PluginInjectorUtils, SettingValues } from "../index"; -import { defaultSettings } from "../lib/consts"; -import Icons from "../Components/Icons"; -import Utils from "../lib/utils"; -import Types from "../types"; - -export default (): void => { - PluginInjectorUtils.addMenuItem(Types.DefaultTypes.ContextMenuTypes.Account, (_data, menu) => { - if (!SettingValues.get("statusPicker", defaultSettings.statusPicker)) return; - const [muteValue, muteOnChange] = Utils.useSettingArray( - SettingValues, - "soundStatus.mute", - defaultSettings.soundStatus.mute, - ); - const [deafValue, deafOnChange] = Utils.useSettingArray( - SettingValues, - "soundStatus.deaf", - defaultSettings.soundStatus.deaf, - ); - const [videoValue, videoOnChange] = Utils.useSettingArray( - SettingValues, - "soundStatus.video", - defaultSettings.soundStatus.video, - ); - const [enabled, setEnabled] = React.useState( - SettingValues.get("enabled", defaultSettings.enabled), - ); - React.useEffect(() => { - setEnabled(SettingValues.get("enabled", defaultSettings.enabled)); - }, [SettingValues.get("enabled", defaultSettings.enabled)]); - const Icon = ( - - ); - const DisabledIcon = ( - - - - ); - const { children } = menu as { children: React.ReactElement[] }; - const switchAccount = children.find((c) => c?.props?.children?.key === "switch-account"); - if (!children.find((c) => c?.props?.className === "yofukashino")) - children.splice( - children.indexOf(switchAccount!), - 0, - , - ); - const section = children.find((c) => c?.props?.className === "yofukashino"); - if (!section) return; - section.props.children = section.props.children.filter( - (m: React.ReactElement) => m?.props?.id !== "fake-deafen", - ); - if (!section.props.children.find((m: React.ReactElement) => m?.props?.id === "fake-deafen")) - section.props.children.push( - Utils.toggleSoundStatus(enabled)} - icon={() => (enabled ? DisabledIcon : Icon)} - showIconFirst={true}> - - - muteOnChange(!muteValue)} - /> - deafOnChange(!deafValue)} - /> - videoOnChange(!videoValue)} - /> - - , - ); - }); -}; diff --git a/src/injections/index.ts b/src/injections/index.ts index 82948c0..671791b 100644 --- a/src/injections/index.ts +++ b/src/injections/index.ts @@ -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 => { await Modules.loadModules(); void injectAudioResolver(); injectCenterControlTray(); injectGatewayConnection(); - injectAccountContextMenu(); injectSettingSetter(); }; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index b927b40..5b145e2 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -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, D extends keyof T, @@ -130,6 +140,7 @@ export default { forceRerenderElement, updateSoundStatus, toggleSoundStatus, + useSoundStatus, useSetting, useSettingArray, }; diff --git a/src/plaintextFunctions.tsx b/src/plaintextFunctions.tsx new file mode 100644 index 0000000..e13112d --- /dev/null +++ b/src/plaintextFunctions.tsx @@ -0,0 +1,7 @@ +import Modules from "./lib/requiredModules"; +import AccountDetailsButton from "./Components/AccountDetailsButton"; +import AccountProfileItem from "./Components/AccountProfileItem"; + +export const _addPanelButton = () => (Modules.PanelButton ? : <>); + +export const _addProfileItem = (props) => ; diff --git a/src/plaintextPatches.ts b/src/plaintextPatches.ts index 29ed0d7..5f9e030 100644 --- a/src/plaintextPatches.ts +++ b/src/plaintextPatches.ts @@ -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: [ diff --git a/src/style.css b/src/style.css index 6c102b0..d869a0a 100644 --- a/src/style.css +++ b/src/style.css @@ -15,3 +15,9 @@ color: var(----interactive-hover); display: none; } + +#profileDivider { + background-color: var(--profile-body-divider-color); + height: 1px; + margin: 8px 4px; +} diff --git a/src/types.ts b/src/types.ts index ce376c4..a99dc47 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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;