From 40fe13feda16e0a32806dd090e3039491da919bf Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 15 Nov 2025 13:39:36 +0100 Subject: [PATCH] LastFMRichPresence: fix duplicating spotify presence --- .../discord-types/src/common/Activity.d.ts | 1 + .../src/stores/PresenceStore.d.ts | 26 +++++++++++++++++++ packages/discord-types/src/stores/index.d.ts | 1 + src/plugins/lastfmRichPresence/index.tsx | 6 ++--- src/plugins/platformIndicators/index.tsx | 15 +++++------ src/webpack/common/stores.ts | 2 +- 6 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 packages/discord-types/src/stores/PresenceStore.d.ts diff --git a/packages/discord-types/src/common/Activity.d.ts b/packages/discord-types/src/common/Activity.d.ts index 42de8136..5f7b9037 100644 --- a/packages/discord-types/src/common/Activity.d.ts +++ b/packages/discord-types/src/common/Activity.d.ts @@ -40,3 +40,4 @@ export interface Activity { }; } +export type OnlineStatus = "online" | "idle" | "dnd" | "invisible" | "offline" | "unknown" | "streaming"; diff --git a/packages/discord-types/src/stores/PresenceStore.d.ts b/packages/discord-types/src/stores/PresenceStore.d.ts new file mode 100644 index 00000000..3f245aca --- /dev/null +++ b/packages/discord-types/src/stores/PresenceStore.d.ts @@ -0,0 +1,26 @@ +import { Activity, OnlineStatus } from "../common"; +import { FluxStore } from "./FluxStore"; + +export interface UserAndActivity { + userId: string; + activity: Activity; +} + +export type DiscordPlatform = "desktop" | "mobile" | "web" | "embedded"; + +export class PresenceStore extends FluxStore { + findActivity(userId: string, predicate: (activity: Activity) => boolean, guildId?: string): Activity | undefined; + getActivities(userId: string, guildId?: string): Activity[]; + getActivityMetadata(userId: string): any; + getAllApplicationActivities(applicationId: string): UserAndActivity[]; + getApplicationActivity(userId: string, applicationId: string, guildId?: string): Activity | null; + getClientStatus(userId: string): Record; + getHiddenActivities(): any; + /** literally just getActivities(...)[0] */ + getPrimaryActivity(userId: string, guildId?: string): Activity | null; + getState(): any; + getStatus(userId: string, guildId?: string | null, defaultStatus?: OnlineStatus): OnlineStatus; + getUnfilteredActivities(userId: string, guildId?: string): Activity[]; + getUserIds(): string[]; + isMobileOnline(userId: string): boolean; +} diff --git a/packages/discord-types/src/stores/index.d.ts b/packages/discord-types/src/stores/index.d.ts index a843445b..756021a5 100644 --- a/packages/discord-types/src/stores/index.d.ts +++ b/packages/discord-types/src/stores/index.d.ts @@ -8,6 +8,7 @@ export * from "./GuildMemberStore"; export * from "./GuildRoleStore"; export * from "./GuildStore"; export * from "./MessageStore"; +export * from "./PresenceStore"; export * from "./RelationshipStore"; export * from "./SelectedChannelStore"; export * from "./SelectedGuildStore"; diff --git a/src/plugins/lastfmRichPresence/index.tsx b/src/plugins/lastfmRichPresence/index.tsx index e355c361..fdfa3f3e 100644 --- a/src/plugins/lastfmRichPresence/index.tsx +++ b/src/plugins/lastfmRichPresence/index.tsx @@ -22,7 +22,7 @@ import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { Activity, ActivityAssets, ActivityButton } from "@vencord/discord-types"; import { ActivityFlags, ActivityStatusDisplayType, ActivityType } from "@vencord/discord-types/enums"; -import { ApplicationAssetUtils, FluxDispatcher, PresenceStore } from "@webpack/common"; +import { ApplicationAssetUtils, AuthenticationStore, FluxDispatcher, PresenceStore } from "@webpack/common"; interface TrackData { name: string; @@ -243,13 +243,13 @@ export default definePlugin({ async getActivity(): Promise { if (settings.store.hideWithActivity) { - if (PresenceStore.getActivities().some(a => a.application_id !== DISCORD_APP_ID)) { + if (PresenceStore.getActivities(AuthenticationStore.getId()).some(a => a.application_id !== DISCORD_APP_ID)) { return null; } } if (settings.store.hideWithSpotify) { - if (PresenceStore.getActivities().some(a => a.type === ActivityType.LISTENING && a.application_id !== DISCORD_APP_ID)) { + if (PresenceStore.getActivities(AuthenticationStore.getId()).some(a => a.type === ActivityType.LISTENING && a.application_id !== DISCORD_APP_ID)) { // there is already music status because of Spotify or richerCider (probably more) return null; } diff --git a/src/plugins/platformIndicators/index.tsx b/src/plugins/platformIndicators/index.tsx index add93064..eb51b5e7 100644 --- a/src/plugins/platformIndicators/index.tsx +++ b/src/plugins/platformIndicators/index.tsx @@ -24,7 +24,7 @@ import { addMessageDecoration, removeMessageDecoration } from "@api/MessageDecor import { Settings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { User } from "@vencord/discord-types"; +import { DiscordPlatform, User } from "@vencord/discord-types"; import { filters, findStoreLazy, mapMangledModuleLazy } from "@webpack"; import { AuthenticationStore, PresenceStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; @@ -66,14 +66,13 @@ const Icons = { web: Icon("M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2Zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93Zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39Z"), mobile: Icon("M 187 0 L 813 0 C 916.277 0 1000 83.723 1000 187 L 1000 1313 C 1000 1416.277 916.277 1500 813 1500 L 187 1500 C 83.723 1500 0 1416.277 0 1313 L 0 187 C 0 83.723 83.723 0 187 0 Z M 125 1000 L 875 1000 L 875 250 L 125 250 Z M 500 1125 C 430.964 1125 375 1180.964 375 1250 C 375 1319.036 430.964 1375 500 1375 C 569.036 1375 625 1319.036 625 1250 C 625 1180.964 569.036 1125 500 1125 Z", { viewBox: "0 0 1000 1500", height: 17, width: 17 }), embedded: Icon("M14.8 2.7 9 3.1V47h3.3c1.7 0 6.2.3 10 .7l6.7.6V2l-4.2.2c-2.4.1-6.9.3-10 .5zm1.8 6.4c1 1.7-1.3 3.6-2.7 2.2C12.7 10.1 13.5 8 15 8c.5 0 1.2.5 1.6 1.1zM16 33c0 6-.4 10-1 10s-1-4-1-10 .4-10 1-10 1 4 1 10zm15-8v23.3l3.8-.7c2-.3 4.7-.6 6-.6H43V3h-2.2c-1.3 0-4-.3-6-.6L31 1.7V25z", { viewBox: "0 0 50 50" }), -}; -type Platform = keyof typeof Icons; +} satisfies Record; const { useStatusFillColor } = mapMangledModuleLazy(".concat(.5625*", { useStatusFillColor: filters.byCode(".hex") }); -const PlatformIcon = ({ platform, status, small }: { platform: Platform, status: string; small: boolean; }) => { +const PlatformIcon = ({ platform, status, small }: { platform: DiscordPlatform, status: string; small: boolean; }) => { const tooltip = platform === "embedded" ? "Console" : platform[0].toUpperCase() + platform.slice(1); @@ -114,7 +113,7 @@ function getBadges({ userId }: BadgeUserArgs): ProfileBadge[] { ensureOwnStatus(user); - const status = PresenceStore.getClientStatus(user.id) as Record; + const status = PresenceStore.getClientStatus(user.id); if (!status) return []; return Object.entries(status).map(([platform, status]) => ({ @@ -122,7 +121,7 @@ function getBadges({ userId }: BadgeUserArgs): ProfileBadge[] { @@ -135,13 +134,13 @@ function getBadges({ userId }: BadgeUserArgs): ProfileBadge[] { const PlatformIndicator = ({ user, small = false }: { user: User; small?: boolean; }) => { ensureOwnStatus(user); - const status = useStateFromStores([PresenceStore], () => PresenceStore.getClientStatus(user.id) as Record); + const status = useStateFromStores([PresenceStore], () => PresenceStore.getClientStatus(user.id)); if (!status) return null; const icons = Object.entries(status).map(([platform, status]) => ( diff --git a/src/webpack/common/stores.ts b/src/webpack/common/stores.ts index 1e3e5797..725b8092 100644 --- a/src/webpack/common/stores.ts +++ b/src/webpack/common/stores.ts @@ -34,7 +34,7 @@ export let MessageStore: Omit & GenericStore & { export let PermissionStore: GenericStore; export let GuildChannelStore: GenericStore; export let ReadStateStore: GenericStore; -export let PresenceStore: GenericStore; +export let PresenceStore: t.PresenceStore; export let GuildStore: t.GuildStore; export let GuildRoleStore: t.GuildRoleStore;