Skip to content

Commit

Permalink
fix platform indicators (#437)
Browse files Browse the repository at this point in the history
Co-authored-by: Kaan <[email protected]>
Co-authored-by: domi-btnr <[email protected]>
  • Loading branch information
3 people authored Feb 2, 2025
1 parent 15ff80c commit 71b01da
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 40 deletions.
19 changes: 11 additions & 8 deletions PlatformIndicators/components/indicators.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React from "react";
import { Components } from "@api";

import * as Icons from "./icons/Icons";
import Styles from "./indicators.scss";
import {ModulesLibrary, buildClassName} from "../modules/shared";

import { buildClassName } from "../modules/shared";
import usePlatformStores from "../modules/usePlatformStores";
import * as Icons from "./icons/Icons";
import {getStatusText, getStatusColor} from "../modules/utils";
import { getStatusText, getStatusColor } from "../modules/utils";

export default function StatusIndicators({type, userId, size = 18, separator = false}) {
export default function StatusIndicators({ type, userId, size = 18, separator = false }) {
const state = usePlatformStores(userId, type);

if (!Object.keys(state.clients).length || !state.shouldShow) return null;

return (
<React.Fragment>
{separator && <span className={Styles.badge_separator} />}
Expand All @@ -20,18 +23,18 @@ export default function StatusIndicators({type, userId, size = 18, separator = f
const Icon = Icons[key];

return (
<ModulesLibrary.Tooltip text={getStatusText(key, status)}>
<Components.Tooltip text={getStatusText(key, status)}>
{props => (
<Icon
text={getStatusText(key, status)}
style={{color: getStatusColor(status)}}
style={{ color: getStatusColor(status) }}
width={size}
height={size}
data-status={status}
{...props}
/>
)}
</ModulesLibrary.Tooltip>
</Components.Tooltip>
);
})
}
Expand Down
38 changes: 21 additions & 17 deletions PlatformIndicators/components/settings.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import React from "react";
import { Components } from "@api";

import Settings from "../modules/settings";
import {useStateFromStores} from "../modules/shared";
import { useStateFromStores } from "../modules/shared";
import { getStatusColor } from "../modules/utils";

import * as Icons from "./icons/Icons";
import Styles from "./settings.scss";
import {Webpack} from "@api";
import React from "react";
import { Checkbox } from "./icons/checkbox";
import SettingsItems from "./settings.json";
import {Checkbox} from "./icons/checkbox";
import {getStatusColor} from "../modules/utils";
import Styles from "./settings.scss";

const {FormSwitch} = Webpack.getByKeys("FormSwitch");
const { SettingItem, SwitchInput } = Components;

function SwitchItem(props) {
const value = useStateFromStores([Settings], () => Settings.get(props.id, props.value));

return (
<FormSwitch
<SettingItem
{...props}
value={value}
children={props.name}
onChange={value => {
Settings.set(props.id, value);
}}
/>
inline={true}
>
<SwitchInput
value={value}
onChange={v => {
Settings.set(props.id, v);
}}
/>
</SettingItem>
);
}

Expand All @@ -42,9 +46,9 @@ function SmartDisable(props) {
<div className={Styles.body}>
{props.items.map(item => (
<div key={item.id} className={Styles.item} onClick={() => handleClick(item.id)}>
{["online", "dnd", "idle", "offline"].map(status =>
{["online", "dnd", "idle", "offline"].map(status =>
React.createElement(Icons[item.icon], {
style: {color: getStatusColor(status)},
style: { color: getStatusColor(status) },
width: iconSize,
height: iconSize
})
Expand Down
20 changes: 13 additions & 7 deletions PlatformIndicators/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { DOM, Patcher, ReactUtils, Webpack, Utils } from "@api";
import {DOM, Patcher, ReactUtils, Webpack, Utils} from "@api";
import manifest from "@manifest";
import Styles from "@styles";

Expand All @@ -8,7 +8,7 @@ import showChangelog from "../common/Changelog";
import StatusIndicators from "./components/indicators";
import SettingsPanel from "./components/settings";
import Settings from "./modules/settings";
import { findInReactTree } from "./modules/utils";
import {findInReactTree} from "./modules/utils";

export default class PlatformIndicators {
getSettingsPanel() {
Expand All @@ -18,24 +18,25 @@ export default class PlatformIndicators {
start() {
Styles.load();
showChangelog(manifest);
this.patchDMs();
this.patchDMList();
this.patchMemberList();
this.patchChat();
this.patchBadges();
this.patchFriendList();
}

patchDMs() {
patchDMList() {
const UserContext = React.createContext(null);
const [ChannelWrapper, Key_CW] = Webpack.getWithKey(Webpack.Filters.byStrings("isGDMFacepileEnabled"));
const [NameWrapper, Key_NW] = Webpack.getWithKey(x => x.toString().includes(".nameAndDecorators") && !x.toString().includes("FocusRing"));
const [NameWrapper, Key_NW] = Webpack.getWithKey(x => x.toString().includes(".nameAndDecorators") && !x.toString().includes('"listitem"'));
const ChannelClasses = Webpack.getByKeys("channel", "decorator");

Patcher.after(ChannelWrapper, Key_CW, (_, __, res) => {
if (!Settings.get("showInDmsList", true)) return;
Patcher.after(res, "type", (_, [props], res) => {
if (!props.user) return; // Its a group DM
if (Settings.get("ignoreBots", true) && props.user.bot) return;

return (
<UserContext.Provider value={props.user}>
{res}
Expand All @@ -52,10 +53,13 @@ export default class PlatformIndicators {

Patcher.after(NameWrapper, Key_NW, (_, __, res) => {
if (!Settings.get("showInDmsList", true)) return;

const user = React.useContext(UserContext);
if (!user) return;

const child = Utils.findInTree(res, e => e?.className?.includes("nameAndDecorators"));
if (!child) return;

child.children.push(
<StatusIndicators
userId={user.id}
Expand All @@ -74,8 +78,9 @@ export default class PlatformIndicators {
if (Settings.get("ignoreBots", true) && props.user.bot) return;
const children = ret.props.children();
const obj = findInReactTree(children, e => e?.avatar && e?.name);

if (obj)
children.props.decorators?.props?.children.push(
children?.props?.children?.props?.decorators?.props?.children.push(
<StatusIndicators
userId={props.user.id}
type="MemberList"
Expand Down Expand Up @@ -151,7 +156,8 @@ export default class PlatformIndicators {
if (!Settings.get("showInFriendsList", true)) return;
const unpatch = Patcher.after(res.props.children[1].props.children[0], "type", (_, [props], res) => {
unpatch();
Patcher.after(res, "type", (_, __, res) => {
const unpatch_ = Patcher.after(res, "type", (_, __, res) => {
unpatch_();
res.props.children.push(
<StatusIndicators
userId={props.user.id}
Expand Down
2 changes: 1 addition & 1 deletion PlatformIndicators/modules/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useStateFromStores = Webpack.getByStrings("useStateFromStores", { s
export const Dispatcher = UserStore._dispatcher;

export const Flux = Webpack.getByKeys("Store");
export const ModulesLibrary = Webpack.getByKeys("Anchor");
export const StatusTypes = Webpack.getModule(x => x.DND && x.OFFLINE, { searchExports: true })
export const Colors = Webpack.getByKeys("RED_400");

export const Messages = { "STATUS_DND": "Do Not Disturb", "STATUS_OFFLINE": "Offline", "STATUS_ONLINE": "Online", "STATUS_STEAMING": "Streaming", "STATUS_IDLE": "Idle", "STATUS_MOBILE": "Mobile" };
Expand Down
5 changes: 1 addition & 4 deletions PlatformIndicators/modules/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Utils} from "@api";
import {Messages} from "./shared";
import {Colors, ModulesLibrary} from "./shared";
import {Colors, StatusTypes} from "./shared";

export const findInReactTree = (tree, filter) => Utils.findInTree(tree, filter, {walkable: ["props", "children", "type"]});

Expand All @@ -11,9 +11,6 @@ export function getStatusText(key, status) {
}

export function getStatusColor(status) {
const {
StatusTypes
} = ModulesLibrary;
switch (status) {
case StatusTypes.ONLINE:
return Colors.GREEN_360;
Expand Down
6 changes: 3 additions & 3 deletions PlatformIndicators/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "APlatformIndicators",
"version": "1.5.11",
"version": "1.5.12",
"author": "Strencher",
"authorId": "415849376598982656",
"description": "Adds indicators for every platform that the user is using.",
Expand All @@ -11,9 +11,9 @@
"title": "Fixed",
"type": "fixed",
"items": [
"Fixed Badges not showing up"
"Plugin fixed for the latest Discord update"
]
}
],
"changelogDate": "2025-01-16"
"changelogDate": "2025-02-02"
}

0 comments on commit 71b01da

Please sign in to comment.