feat(memberListActivities): show default icon when no icons where found

This commit is contained in:
D3SOX 2024-03-18 18:03:36 +01:00
parent 896421a9fa
commit 77a3b6c96c
No known key found for this signature in database
GPG key ID: 39EC1673FC37B048

View file

@ -23,7 +23,7 @@ import { classNameFactory } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findStoreLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
import { SpotifyIcon } from "./components/SpotifyIcon"; import { SpotifyIcon } from "./components/SpotifyIcon";
import { TwitchIcon } from "./components/TwitchIcon"; import { TwitchIcon } from "./components/TwitchIcon";
@ -48,8 +48,13 @@ interface Activity {
created_at: number; created_at: number;
id: string; id: string;
name: string; name: string;
state: string;
type: number; type: number;
emoji?: {
animated: boolean;
id: string;
name: string;
}
state?: string;
flags?: number; flags?: number;
sync_id?: string; sync_id?: string;
details?: string; details?: string;
@ -100,6 +105,9 @@ const { fetchApplication }: {
fetchApplication: (id: string) => Promise<Application | null>; fetchApplication: (id: string) => Promise<Application | null>;
} = findByPropsLazy("fetchApplication"); } = findByPropsLazy("fetchApplication");
// if discord one day decides changes their icon this needs to be updated
const DefaultActivityIcon = findComponentByCodeLazy("M6,7 L2,7 L2,6 L6,6 L6,7 Z M8,5 L2,5 L2,4 L8,4 L8,5 Z M8,3 L2,3 L2,2 L8,2 L8,3 Z M8.88888889,0 L1.11111111,0 C0.494444444,0 0,0.494444444 0,1.11111111 L0,8.88888889 C0,9.50253861 0.497461389,10 1.11111111,10 L8.88888889,10 C9.50253861,10 10,9.50253861 10,8.88888889 L10,1.11111111 C10,0.494444444 9.5,0 8.88888889,0 Z");
const fetchedApplications = new Map<string, Application | null>(); const fetchedApplications = new Map<string, Application | null>();
const xboxUrl = "https://discord.com/assets/9a15d086141be29d9fcd.png"; const xboxUrl = "https://discord.com/assets/9a15d086141be29d9fcd.png";
@ -112,7 +120,7 @@ export default definePlugin({
settings, settings,
patchActivityList: (activities: Activity[]) => { patchActivityList: (activities: Activity[]): JSX.Element | null => {
const icons: JSX.Element[] = []; const icons: JSX.Element[] = [];
if (activities.some(activity => activity.name === "Spotify")) { if (activities.some(activity => activity.name === "Spotify")) {
@ -197,9 +205,16 @@ export default definePlugin({
))} ))}
</div> </div>
</ErrorBoundary>; </ErrorBoundary>;
} else {
// Show default icon when there are no custom icons
// We need to filter out custom statuses
const shouldShow = activities.filter(a => a.type !== 4).length !== icons.length;
if (shouldShow) {
return <DefaultActivityIcon />;
}
} }
return false; return null;
}, },
patches: [ patches: [