From 64cb08a53fff61cd8b8484d455b9c8641d7df47f Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Sat, 20 Jul 2024 04:16:06 -0400 Subject: [PATCH] Revert "Fetch all findstorelazy from webpack" This reverts commit bf246208e922a203e5e921b5f4f3fb986de08693. --- src/equicordplugins/homeTyping/index.tsx | 8 +- .../messageLoggerEnhanced/utils/index.ts | 5 +- .../notifyUserChanges/index.tsx | 6 +- src/equicordplugins/vencordRPC/index.ts | 14 ++-- src/equicordplugins/voiceChatUtils/index.tsx | 5 +- src/equicordplugins/whosWatching/index.tsx | 10 ++- src/plugins/betterFolders/FolderSideBar.tsx | 8 +- src/plugins/betterFolders/index.tsx | 6 +- src/plugins/betterSessions/index.tsx | 5 +- src/plugins/biggerStreamPreview/index.tsx | 6 +- .../biggerStreamPreview/webpack/stores.ts | 24 ++++++ .../webpack/types/stores.ts | 77 +++++++++++++++++++ src/plugins/clientTheme/index.tsx | 7 +- src/plugins/emoteCloner/index.tsx | 8 +- src/plugins/fakeNitro/index.tsx | 12 ++- src/plugins/ignoreActivities/index.tsx | 5 +- src/plugins/implicitRelationships/index.ts | 5 +- src/plugins/memberCount/MemberCount.tsx | 4 +- src/plugins/memberCount/index.tsx | 7 ++ src/plugins/pinDms/data.ts | 4 +- src/plugins/pinDms/index.tsx | 6 +- src/plugins/platformIndicators/index.tsx | 19 ++++- src/plugins/relationshipNotifier/functions.ts | 4 +- src/plugins/relationshipNotifier/utils.ts | 11 ++- src/plugins/showConnections/index.tsx | 5 +- src/plugins/typingIndicator/index.tsx | 6 +- src/plugins/userVoiceShow/index.tsx | 5 +- src/webpack/common/types/stores.d.ts | 1 - src/webpack/common/types/utils.d.ts | 66 ---------------- src/webpack/common/utils.ts | 48 ++---------- 30 files changed, 241 insertions(+), 156 deletions(-) create mode 100644 src/plugins/biggerStreamPreview/webpack/stores.ts create mode 100644 src/plugins/biggerStreamPreview/webpack/types/stores.ts diff --git a/src/equicordplugins/homeTyping/index.tsx b/src/equicordplugins/homeTyping/index.tsx index e35936ed..f54ef98f 100644 --- a/src/equicordplugins/homeTyping/index.tsx +++ b/src/equicordplugins/homeTyping/index.tsx @@ -6,10 +6,14 @@ import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; -import { findExportedComponentLazy } from "@webpack"; -import { PrivateChannelSortStore, TypingStore, useStateFromStores } from "@webpack/common"; +import { findExportedComponentLazy, findStoreLazy } from "@webpack"; +import { useStateFromStores } from "@webpack/common"; const ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots"); +const TypingStore = findStoreLazy("TypingStore"); + +const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore") as { getPrivateChannelIds: () => string[]; }; + export default definePlugin({ name: "HomeTyping", description: "Changes the home button to a typing indicator if someone in your dms is typing", diff --git a/src/equicordplugins/messageLoggerEnhanced/utils/index.ts b/src/equicordplugins/messageLoggerEnhanced/utils/index.ts index 18298eb1..3c19b59d 100644 --- a/src/equicordplugins/messageLoggerEnhanced/utils/index.ts +++ b/src/equicordplugins/messageLoggerEnhanced/utils/index.ts @@ -17,7 +17,8 @@ */ import { Settings } from "@api/Settings"; -import { ChannelStore, SelectedChannelStore, UserGuildSettingsStore, UserStore } from "@webpack/common"; +import { findStoreLazy } from "@webpack"; +import { ChannelStore, SelectedChannelStore, UserStore } from "@webpack/common"; import { settings } from "../index"; import { loggedMessages } from "../LoggedMessageManager"; @@ -79,6 +80,8 @@ interface ShouldIgnoreArguments { const EPHEMERAL = 64; +const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore"); + /** * the function `shouldIgnore` evaluates whether a message should be ignored or kept, following a priority hierarchy: User > Channel > Server. * In this hierarchy, whitelisting takes priority; if any element (User, Channel, or Server) is whitelisted, the message is kept. diff --git a/src/equicordplugins/notifyUserChanges/index.tsx b/src/equicordplugins/notifyUserChanges/index.tsx index 5a098622..170e41bf 100644 --- a/src/equicordplugins/notifyUserChanges/index.tsx +++ b/src/equicordplugins/notifyUserChanges/index.tsx @@ -9,8 +9,8 @@ import { showNotification } from "@api/Notifications"; import { definePluginSettings, Settings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { Menu, PresenceStore, React, SelectedChannelStore, SessionsStore, Tooltip, UserStore } from "@webpack/common"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { Menu, PresenceStore, React, SelectedChannelStore, Tooltip, UserStore } from "@webpack/common"; import type { Channel, User } from "discord-types/general"; import { CSSProperties } from "react"; @@ -66,6 +66,8 @@ function shouldBeNative() { return false; } +const SessionsStore = findStoreLazy("SessionsStore"); + const StatusUtils = findByPropsLazy("useStatusFillColor", "StatusTypes"); function Icon(path: string, opts?: { viewBox?: string; width?: number; height?: number; }) { diff --git a/src/equicordplugins/vencordRPC/index.ts b/src/equicordplugins/vencordRPC/index.ts index b143e7f8..5a0cba47 100644 --- a/src/equicordplugins/vencordRPC/index.ts +++ b/src/equicordplugins/vencordRPC/index.ts @@ -8,10 +8,16 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import { isTruthy } from "@utils/guards"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { ApplicationAssetUtils, ChannelMemberStore, ChannelStore, FluxDispatcher, GuildMemberCountStore, GuildStore, PresenceStore, RelationshipStore, SelectedChannelStore, SelectedGuildStore, UserStore, useStateFromStores } from "@webpack/common"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { ApplicationAssetUtils, ChannelStore, FluxDispatcher, GuildStore, PresenceStore, RelationshipStore, SelectedChannelStore, SelectedGuildStore, UserStore } from "@webpack/common"; +import { FluxStore } from "@webpack/types"; import { Channel } from "discord-types/general"; +const presenceStore = findByPropsLazy("getLocalPresence"); +const GuildMemberCountStore = findStoreLazy("GuildMemberCountStore") as FluxStore & { getMemberCount(guildId: string): number | null; }; +const ChannelMemberStore = findStoreLazy("ChannelMemberStore") as FluxStore & { + getProps(guildId: string, channelId: string): { groups: { count: number; id: string; }[]; }; +}; const VoiceStates = findByPropsLazy("getVoiceStatesForChannel"); const chino = "https://i.imgur.com/Dsa2rQy.png"; const wysi = "https://i.imgur.com/uKtXde9.gif"; @@ -406,9 +412,7 @@ async function createActivity(): Promise { let timeout: NodeJS.Timeout | null = null; async function setRpc(disable?: boolean) { - const activities = useStateFromStores( - [PresenceStore], () => PresenceStore.getActivities() - ); + const activities: any = presenceStore.getActivities(); const activity: Activity | undefined = !activities.length || (activities.length === 1 && activities[0].application_id === settings.store.appID) ? await createActivity() : undefined; FluxDispatcher.dispatch({ diff --git a/src/equicordplugins/voiceChatUtils/index.tsx b/src/equicordplugins/voiceChatUtils/index.tsx index 601e91ed..e40d79c3 100644 --- a/src/equicordplugins/voiceChatUtils/index.tsx +++ b/src/equicordplugins/voiceChatUtils/index.tsx @@ -9,9 +9,12 @@ import { definePluginSettings } from "@api/Settings"; import { makeRange } from "@components/PluginSettings/components"; import { Devs, EquicordDevs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { GuildChannelStore, Menu, React, RestAPI, UserStore, VoiceStateStore } from "@webpack/common"; +import { findStoreLazy } from "@webpack"; +import { GuildChannelStore, Menu, React, RestAPI, UserStore } from "@webpack/common"; import type { Channel } from "discord-types/general"; +const VoiceStateStore = findStoreLazy("VoiceStateStore"); + async function runSequential(promises: Promise[]): Promise { const results: T[] = []; diff --git a/src/equicordplugins/whosWatching/index.tsx b/src/equicordplugins/whosWatching/index.tsx index 75924bd4..ae1a0627 100644 --- a/src/equicordplugins/whosWatching/index.tsx +++ b/src/equicordplugins/whosWatching/index.tsx @@ -13,8 +13,8 @@ import { openUserProfile } from "@utils/discord"; import { Margins } from "@utils/margins"; import { classes } from "@utils/misc"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; -import { ApplicationStreamingStore, Clickable, Forms, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; +import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; +import { Clickable, Forms, i18n, RelationshipStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; import { User } from "discord-types/general"; interface WatchingProps { @@ -73,6 +73,8 @@ function Watching({ userIds, guildId }: WatchingProps): JSX.Element { ); } +const ApplicationStreamingStore = findStoreLazy("ApplicationStreamingStore"); + const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); const AvatarStyles = findByPropsLazy("moreUsers", "emptyUser", "avatarContainer", "clickableAvatar"); @@ -103,7 +105,7 @@ export default definePlugin({ if (!stream) return
{props.children}
; - const userIds = ApplicationStreamingStore.getViewerIds(stream); + const userIds = ApplicationStreamingStore.getViewerIds(encodeStreamKey(stream)); let missingUsers = 0; const users = userIds.map(id => UserStore.getUser(id)).filter(user => Boolean(user) ? true : (missingUsers += 1, false)); @@ -165,7 +167,7 @@ export default definePlugin({ component: function ({ OriginalComponent }) { return ErrorBoundary.wrap((props: any) => { const stream = useStateFromStores([ApplicationStreamingStore], () => ApplicationStreamingStore.getCurrentUserActiveStream()); - const viewers = ApplicationStreamingStore.getViewerIds(stream); + const viewers = ApplicationStreamingStore.getViewerIds(encodeStreamKey(stream)); return }> {({ onMouseEnter, onMouseLeave }) => (
diff --git a/src/plugins/betterFolders/FolderSideBar.tsx b/src/plugins/betterFolders/FolderSideBar.tsx index 2fc1c237..53d24ed9 100644 --- a/src/plugins/betterFolders/FolderSideBar.tsx +++ b/src/plugins/betterFolders/FolderSideBar.tsx @@ -17,11 +17,13 @@ */ import ErrorBoundary from "@components/ErrorBoundary"; -import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; -import { ChannelRTCStore, ExpandedGuildFolderStore, useStateFromStores } from "@webpack/common"; +import { findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; +import { useStateFromStores } from "@webpack/common"; import type { CSSProperties } from "react"; -import { settings } from "."; +import { ExpandedGuildFolderStore, settings } from "."; + +const ChannelRTCStore = findStoreLazy("ChannelRTCStore"); const Animations = findByPropsLazy("a", "animated", "useTransition"); const GuildsBar = findComponentByCodeLazy('("guildsnav")'); diff --git a/src/plugins/betterFolders/index.tsx b/src/plugins/betterFolders/index.tsx index 141b116c..d0e8cf34 100644 --- a/src/plugins/betterFolders/index.tsx +++ b/src/plugins/betterFolders/index.tsx @@ -19,8 +19,8 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy, findLazy } from "@webpack"; -import { ExpandedGuildFolderStore, FluxDispatcher, i18n, SortedGuildStore, useMemo } from "@webpack/common"; +import { findByPropsLazy, findLazy, findStoreLazy } from "@webpack"; +import { FluxDispatcher, i18n, useMemo } from "@webpack/common"; import FolderSideBar from "./FolderSideBar"; @@ -31,6 +31,8 @@ enum FolderIconDisplay { } const GuildsTree = findLazy(m => m.prototype?.moveNextTo); +const SortedGuildStore = findStoreLazy("SortedGuildStore"); +export const ExpandedGuildFolderStore = findStoreLazy("ExpandedGuildFolderStore"); const FolderUtils = findByPropsLazy("move", "toggleGuildFolderExpand"); let lastGuildId = null as string | null; diff --git a/src/plugins/betterSessions/index.tsx b/src/plugins/betterSessions/index.tsx index b23ead72..598e0104 100644 --- a/src/plugins/betterSessions/index.tsx +++ b/src/plugins/betterSessions/index.tsx @@ -21,13 +21,14 @@ import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy, findExportedComponentLazy } from "@webpack"; -import { AuthSessionsStore, Constants, React, RestAPI, Tooltip } from "@webpack/common"; +import { findByPropsLazy, findExportedComponentLazy, findStoreLazy } from "@webpack"; +import { Constants, React, RestAPI, Tooltip } from "@webpack/common"; import { RenameButton } from "./components/RenameButton"; import { Session, SessionInfo } from "./types"; import { fetchNamesFromDataStore, getDefaultName, GetOsColor, GetPlatformIcon, savedSessionsCache, saveSessionsToDataStore } from "./utils"; +const AuthSessionsStore = findStoreLazy("AuthSessionsStore"); const UserSettingsModal = findByPropsLazy("saveAccountChanges", "open"); const TimestampClasses = findByPropsLazy("timestampTooltip", "blockquoteContainer"); diff --git a/src/plugins/biggerStreamPreview/index.tsx b/src/plugins/biggerStreamPreview/index.tsx index 035a316f..a86e3fca 100644 --- a/src/plugins/biggerStreamPreview/index.tsx +++ b/src/plugins/biggerStreamPreview/index.tsx @@ -21,10 +21,12 @@ import { ScreenshareIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; import { openImageModal } from "@utils/discord"; import definePlugin from "@utils/types"; -import { ApplicationStreamingStore, ApplicationStreamPreviewStore, Menu } from "@webpack/common"; -import { ApplicationStream, Stream } from "@webpack/types"; +import { Menu } from "@webpack/common"; import { Channel, User } from "discord-types/general"; +import { ApplicationStreamingStore, ApplicationStreamPreviewStore } from "./webpack/stores"; +import { ApplicationStream, Stream } from "./webpack/types/stores"; + export interface UserContextProps { channel: Channel, channelSelected: boolean, diff --git a/src/plugins/biggerStreamPreview/webpack/stores.ts b/src/plugins/biggerStreamPreview/webpack/stores.ts new file mode 100644 index 00000000..ba5227ba --- /dev/null +++ b/src/plugins/biggerStreamPreview/webpack/stores.ts @@ -0,0 +1,24 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { findStoreLazy } from "@webpack"; + +import * as t from "./types/stores"; + +export const ApplicationStreamPreviewStore: t.ApplicationStreamPreviewStore = findStoreLazy("ApplicationStreamPreviewStore"); +export const ApplicationStreamingStore: t.ApplicationStreamingStore = findStoreLazy("ApplicationStreamingStore"); diff --git a/src/plugins/biggerStreamPreview/webpack/types/stores.ts b/src/plugins/biggerStreamPreview/webpack/types/stores.ts new file mode 100644 index 00000000..0265986f --- /dev/null +++ b/src/plugins/biggerStreamPreview/webpack/types/stores.ts @@ -0,0 +1,77 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import { FluxStore } from "@webpack/types"; + +export interface ApplicationStreamPreviewStore extends FluxStore { + getIsPreviewLoading: (guildId: string | bigint | null, channelId: string | bigint, ownerId: string | bigint) => boolean; + getPreviewURL: (guildId: string | bigint | null, channelId: string | bigint, ownerId: string | bigint) => Promise; + getPreviewURLForStreamKey: (streamKey: string) => ReturnType; +} + +export interface ApplicationStream { + streamType: string; + guildId: string | null; + channelId: string; + ownerId: string; +} + +export interface Stream extends ApplicationStream { + state: string; +} + +export interface RTCStream { + region: string, + streamKey: string, + viewerIds: string[]; +} + +export interface StreamMetadata { + id: string | null, + pid: number | null, + sourceName: string | null; +} + +export interface StreamingStoreState { + activeStreams: [string, Stream][]; + rtcStreams: { [key: string]: RTCStream; }; + streamerActiveStreamMetadatas: { [key: string]: StreamMetadata | null; }; + streamsByUserAndGuild: { [key: string]: { [key: string]: ApplicationStream; }; }; +} + +/** + * example how a stream key could look like: `call(type of connection):1116549917987192913(channelId):305238513941667851(ownerId)` + */ +export interface ApplicationStreamingStore extends FluxStore { + getActiveStreamForApplicationStream: (stream: ApplicationStream) => Stream | null; + getActiveStreamForStreamKey: (streamKey: string) => Stream | null; + getActiveStreamForUser: (userId: string | bigint, guildId?: string | bigint | null) => Stream | null; + getAllActiveStreams: () => Stream[]; + getAllApplicationStreams: () => ApplicationStream[]; + getAllApplicationStreamsForChannel: (channelId: string | bigint) => ApplicationStream[]; + getAllActiveStreamsForChannel: (channelId: string | bigint) => Stream[]; + getAnyStreamForUser: (userId: string | bigint) => Stream | ApplicationStream | null; + getStreamForUser: (userId: string | bigint, guildId?: string | bigint | null) => Stream | null; + getCurrentUserActiveStream: () => Stream | null; + getLastActiveStream: () => Stream | null; + getState: () => StreamingStoreState; + getRTCStream: (streamKey: string) => RTCStream | null; + getStreamerActiveStreamMetadata: () => StreamMetadata; + getViewerIds: (stream: ApplicationStream) => string[]; + isSelfStreamHidden: (channelId: string | bigint | null) => boolean; +} diff --git a/src/plugins/clientTheme/index.tsx b/src/plugins/clientTheme/index.tsx index 259d2147..b36a2cb8 100644 --- a/src/plugins/clientTheme/index.tsx +++ b/src/plugins/clientTheme/index.tsx @@ -11,8 +11,8 @@ import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { classes } from "@utils/misc"; import definePlugin, { OptionType, StartAt } from "@utils/types"; -import { findByCodeLazy, findComponentByCodeLazy } from "@webpack"; -import { Button, Forms, NitroThemeStore, ThemeStore, useStateFromStores } from "@webpack/common"; +import { findByCodeLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; +import { Button, Forms, useStateFromStores } from "@webpack/common"; const ColorPicker = findComponentByCodeLazy(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)"); @@ -36,6 +36,9 @@ function setTheme(theme: string) { saveClientTheme({ theme }); } +const ThemeStore = findStoreLazy("ThemeStore"); +const NitroThemeStore = findStoreLazy("ClientThemesBackgroundStore"); + function ThemeSettings() { const theme = useStateFromStores([ThemeStore], () => ThemeStore.theme); const isLightTheme = theme === "light"; diff --git a/src/plugins/emoteCloner/index.tsx b/src/plugins/emoteCloner/index.tsx index 608a7164..6dd3eb30 100644 --- a/src/plugins/emoteCloner/index.tsx +++ b/src/plugins/emoteCloner/index.tsx @@ -23,9 +23,11 @@ import { Logger } from "@utils/Logger"; import { Margins } from "@utils/margins"; import { ModalContent, ModalHeader, ModalRoot, openModalLazy } from "@utils/modal"; import definePlugin from "@utils/types"; -import { findByCodeLazy } from "@webpack"; -import { Constants, EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionsBits, PermissionStore, React, RestAPI, StickerStore, Toasts, Tooltip, UserStore } from "@webpack/common"; +import { findByCodeLazy, findStoreLazy } from "@webpack"; +import { Constants, EmojiStore, FluxDispatcher, Forms, GuildStore, Menu, PermissionsBits, PermissionStore, React, RestAPI, Toasts, Tooltip, UserStore } from "@webpack/common"; import { Promisable } from "type-fest"; + +const StickersStore = findStoreLazy("StickersStore"); const uploadEmoji = findByCodeLazy(".GUILD_EMOJIS(", "EMOJI_UPLOAD_START"); interface Sticker { @@ -58,7 +60,7 @@ function getUrl(data: Data) { } async function fetchSticker(id: string) { - const cached = StickerStore.getStickerById(id); + const cached = StickersStore.getStickerById(id); if (cached) return cached; const { body } = await RestAPI.get({ diff --git a/src/plugins/fakeNitro/index.tsx b/src/plugins/fakeNitro/index.tsx index 874e6dfd..5f7429d0 100644 --- a/src/plugins/fakeNitro/index.tsx +++ b/src/plugins/fakeNitro/index.tsx @@ -23,13 +23,21 @@ import { ApngBlendOp, ApngDisposeOp, importApngJs } from "@utils/dependencies"; import { getCurrentGuild } from "@utils/discord"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; -import { findByCodeLazy, findByPropsLazy, proxyLazyWebpack } from "@webpack"; -import { Alerts, ChannelStore, DraftType, EmojiStore, FluxDispatcher, Forms, GuildMemberStore, IconUtils, lodash, Parser, PermissionsBits, PermissionStore, StickerStore, UploadHandler, UserSettingsActionCreators, UserSettingsProtoStore, UserStore } from "@webpack/common"; +import { findByCodeLazy, findByPropsLazy, findStoreLazy, proxyLazyWebpack } from "@webpack"; +import { Alerts, ChannelStore, DraftType, EmojiStore, FluxDispatcher, Forms, GuildMemberStore, IconUtils, lodash, Parser, PermissionsBits, PermissionStore, UploadHandler, UserSettingsActionCreators, UserStore } from "@webpack/common"; import type { Emoji } from "@webpack/types"; import type { Message } from "discord-types/general"; import { applyPalette, GIFEncoder, quantize } from "gifenc"; import type { ReactElement, ReactNode } from "react"; +const StickerStore = findStoreLazy("StickersStore") as { + getPremiumPacks(): StickerPack[]; + getAllGuildStickers(): Map; + getStickerById(id: string): Sticker | undefined; +}; + +const UserSettingsProtoStore = findStoreLazy("UserSettingsProtoStore"); + const BINARY_READ_OPTIONS = findByPropsLazy("readerFactory"); function searchProtoClassField(localName: string, protoClass: any) { diff --git a/src/plugins/ignoreActivities/index.tsx b/src/plugins/ignoreActivities/index.tsx index 7377d961..bab69d89 100644 --- a/src/plugins/ignoreActivities/index.tsx +++ b/src/plugins/ignoreActivities/index.tsx @@ -12,7 +12,8 @@ import { Flex } from "@components/Flex"; import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import definePlugin, { OptionType } from "@utils/types"; -import { Button, Forms, RunningGameStore, showToast, TextInput, Toasts, Tooltip, useEffect, useState } from "webpack/common"; +import { findStoreLazy } from "@webpack"; +import { Button, Forms, showToast, TextInput, Toasts, Tooltip, useEffect, useState } from "webpack/common"; const enum ActivitiesTypes { Game, @@ -25,6 +26,8 @@ interface IgnoredActivity { type: ActivitiesTypes; } +const RunningGameStore = findStoreLazy("RunningGameStore"); + const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; function ToggleIcon(activity: IgnoredActivity, tooltipText: string, path: string, fill: string) { diff --git a/src/plugins/implicitRelationships/index.ts b/src/plugins/implicitRelationships/index.ts index fd2d864e..7d8c9748 100644 --- a/src/plugins/implicitRelationships/index.ts +++ b/src/plugins/implicitRelationships/index.ts @@ -19,9 +19,12 @@ import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { ChannelStore, Constants, FluxDispatcher, GuildStore, RelationshipStore, SnowflakeUtils, UserAffinitiesStore, UserStore } from "@webpack/common"; +import { findStoreLazy } from "@webpack"; +import { ChannelStore, Constants, FluxDispatcher, GuildStore, RelationshipStore, SnowflakeUtils, UserStore } from "@webpack/common"; import { Settings } from "Vencord"; +const UserAffinitiesStore = findStoreLazy("UserAffinitiesStore"); + export default definePlugin({ name: "ImplicitRelationships", description: "Shows your implicit relationships in the Friends tab.", diff --git a/src/plugins/memberCount/MemberCount.tsx b/src/plugins/memberCount/MemberCount.tsx index e5eeeb02..3231d01c 100644 --- a/src/plugins/memberCount/MemberCount.tsx +++ b/src/plugins/memberCount/MemberCount.tsx @@ -5,9 +5,9 @@ */ import { getCurrentChannel } from "@utils/discord"; -import { ChannelMemberStore, GuildMemberCountStore, SelectedChannelStore, Tooltip, useEffect, useStateFromStores } from "@webpack/common"; +import { SelectedChannelStore, Tooltip, useEffect, useStateFromStores } from "@webpack/common"; -import { cl, numberFormat } from "."; +import { ChannelMemberStore, cl, GuildMemberCountStore, numberFormat } from "."; import { OnlineMemberCountStore } from "./OnlineMemberCountStore"; export function MemberCount({ isTooltip, tooltipGuildId }: { isTooltip?: true; tooltipGuildId?: string; }) { diff --git a/src/plugins/memberCount/index.tsx b/src/plugins/memberCount/index.tsx index 22a4d164..28ecb9db 100644 --- a/src/plugins/memberCount/index.tsx +++ b/src/plugins/memberCount/index.tsx @@ -23,9 +23,16 @@ import { classNameFactory } from "@api/Styles"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; +import { findStoreLazy } from "@webpack"; +import { FluxStore } from "@webpack/types"; import { MemberCount } from "./MemberCount"; +export const GuildMemberCountStore = findStoreLazy("GuildMemberCountStore") as FluxStore & { getMemberCount(guildId: string): number | null; }; +export const ChannelMemberStore = findStoreLazy("ChannelMemberStore") as FluxStore & { + getProps(guildId: string, channelId: string): { groups: { count: number; id: string; }[]; }; +}; + const settings = definePluginSettings({ toolTip: { type: OptionType.BOOLEAN, diff --git a/src/plugins/pinDms/data.ts b/src/plugins/pinDms/data.ts index 6d86104e..a4e40dde 100644 --- a/src/plugins/pinDms/data.ts +++ b/src/plugins/pinDms/data.ts @@ -6,10 +6,10 @@ import * as DataStore from "@api/DataStore"; import { Settings } from "@api/Settings"; -import { PrivateChannelSortStore, UserStore } from "@webpack/common"; +import { UserStore } from "@webpack/common"; import { DEFAULT_COLOR } from "./constants"; -import { forceUpdate, PinOrder, settings } from "./index"; +import { forceUpdate, PinOrder, PrivateChannelSortStore, settings } from "./index"; export interface Category { id: string; diff --git a/src/plugins/pinDms/index.tsx b/src/plugins/pinDms/index.tsx index 92632f11..620a615a 100644 --- a/src/plugins/pinDms/index.tsx +++ b/src/plugins/pinDms/index.tsx @@ -11,8 +11,8 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { classes } from "@utils/misc"; import definePlugin, { OptionType, StartAt } from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { ContextMenuApi, FluxDispatcher, Menu, PrivateChannelSortStore, React } from "@webpack/common"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { ContextMenuApi, FluxDispatcher, Menu, React } from "@webpack/common"; import { Channel } from "discord-types/general"; import { contextMenus } from "./components/contextMenu"; @@ -29,6 +29,8 @@ interface ChannelComponentProps { const headerClasses = findByPropsLazy("privateChannelsHeaderContainer"); +export const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore") as { getPrivateChannelIds: () => string[]; }; + export let instance: any; export const forceUpdate = () => instance?.props?._forceUpdate?.(); diff --git a/src/plugins/platformIndicators/index.tsx b/src/plugins/platformIndicators/index.tsx index 21131aaa..5e479080 100644 --- a/src/plugins/platformIndicators/index.tsx +++ b/src/plugins/platformIndicators/index.tsx @@ -25,10 +25,25 @@ import { Settings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { findByPropsLazy } from "@webpack"; -import { PresenceStore, SessionsStore, Tooltip, UserStore } from "@webpack/common"; +import { findByPropsLazy, findStoreLazy } from "@webpack"; +import { PresenceStore, Tooltip, UserStore } from "@webpack/common"; import { User } from "discord-types/general"; +export interface Session { + sessionId: string; + status: string; + active: boolean; + clientInfo: { + version: number; + os: string; + client: string; + }; +} + +const SessionsStore = findStoreLazy("SessionsStore") as { + getSessions(): Record; +}; + function Icon(path: string, opts?: { viewBox?: string; width?: number; height?: number; }) { return ({ color, tooltip, small }: { color: string; tooltip: string; small: boolean; }) => ( diff --git a/src/plugins/relationshipNotifier/functions.ts b/src/plugins/relationshipNotifier/functions.ts index 0ce68bfc..5bff474b 100644 --- a/src/plugins/relationshipNotifier/functions.ts +++ b/src/plugins/relationshipNotifier/functions.ts @@ -17,11 +17,11 @@ */ import { getUniqueUsername, openUserProfile } from "@utils/discord"; -import { GuildAvailabilityStore, UserUtils } from "@webpack/common"; +import { UserUtils } from "@webpack/common"; import settings from "./settings"; import { ChannelDelete, ChannelType, GuildDelete, RelationshipRemove, RelationshipType } from "./types"; -import { deleteGroup, deleteGuild, getGroup, getGuild, notify } from "./utils"; +import { deleteGroup, deleteGuild, getGroup, getGuild, GuildAvailabilityStore, notify } from "./utils"; let manuallyRemovedFriend: string | undefined; let manuallyRemovedGuild: string | undefined; diff --git a/src/plugins/relationshipNotifier/utils.ts b/src/plugins/relationshipNotifier/utils.ts index 33f0ea30..053cff83 100644 --- a/src/plugins/relationshipNotifier/utils.ts +++ b/src/plugins/relationshipNotifier/utils.ts @@ -19,11 +19,20 @@ import { DataStore, Notices } from "@api/index"; import { showNotification } from "@api/Notifications"; import { getUniqueUsername, openUserProfile } from "@utils/discord"; -import { ChannelStore, GuildAvailabilityStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common"; +import { findStoreLazy } from "@webpack"; +import { ChannelStore, GuildMemberStore, GuildStore, RelationshipStore, UserStore, UserUtils } from "@webpack/common"; +import { FluxStore } from "@webpack/types"; import settings from "./settings"; import { ChannelType, RelationshipType, SimpleGroupChannel, SimpleGuild } from "./types"; +export const GuildAvailabilityStore = findStoreLazy("GuildAvailabilityStore") as FluxStore & { + totalGuilds: number; + totalUnavailableGuilds: number; + unavailableGuilds: string[]; + isUnavailable(guildId: string): boolean; +}; + const guilds = new Map(); const groups = new Map(); const friends = { diff --git a/src/plugins/showConnections/index.tsx b/src/plugins/showConnections/index.tsx index 304a0909..d6909dc9 100644 --- a/src/plugins/showConnections/index.tsx +++ b/src/plugins/showConnections/index.tsx @@ -25,13 +25,14 @@ import { CopyIcon, LinkIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; import { copyWithToast } from "@utils/misc"; import definePlugin, { OptionType } from "@utils/types"; -import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy } from "@webpack"; -import { Text, ThemeStore, Tooltip, UserProfileStore } from "@webpack/common"; +import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack"; +import { Text, Tooltip, UserProfileStore } from "@webpack/common"; import { User } from "discord-types/general"; import { VerifiedIcon } from "./VerifiedIcon"; const Section = findComponentByCodeLazy(".lastSection", "children:"); +const ThemeStore = findStoreLazy("ThemeStore"); const useLegacyPlatformType: (platform: string) => string = findByCodeLazy(".TWITTER_LEGACY:"); const platforms: { get(type: string): ConnectionPlatform; } = findByPropsLazy("isSupported", "getByUrl"); diff --git a/src/plugins/typingIndicator/index.tsx b/src/plugins/typingIndicator/index.tsx index e1e29242..ef770a71 100644 --- a/src/plugins/typingIndicator/index.tsx +++ b/src/plugins/typingIndicator/index.tsx @@ -22,13 +22,15 @@ import { definePluginSettings, Settings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { findComponentByCodeLazy, findExportedComponentLazy } from "@webpack"; -import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, SelectedChannelStore, Tooltip, TypingStore, UserGuildSettingsStore, UserStore, useStateFromStores } from "@webpack/common"; +import { findComponentByCodeLazy, findExportedComponentLazy, findStoreLazy } from "@webpack"; +import { ChannelStore, GuildMemberStore, i18n, RelationshipStore, SelectedChannelStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common"; import { buildSeveralUsers } from "../typingTweaks"; const ThreeDots = findExportedComponentLazy("Dots", "AnimatedDots"); const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); +const TypingStore = findStoreLazy("TypingStore"); +const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore"); const enum IndicatorMode { Dots = 1 << 0, diff --git a/src/plugins/userVoiceShow/index.tsx b/src/plugins/userVoiceShow/index.tsx index 7d7bc2bc..7d640171 100644 --- a/src/plugins/userVoiceShow/index.tsx +++ b/src/plugins/userVoiceShow/index.tsx @@ -20,11 +20,14 @@ import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { ChannelStore, GuildStore, UserStore, VoiceStateStore } from "@webpack/common"; +import { findStoreLazy } from "@webpack"; +import { ChannelStore, GuildStore, UserStore } from "@webpack/common"; import { User } from "discord-types/general"; import { VoiceChannelSection } from "./components/VoiceChannelSection"; +const VoiceStateStore = findStoreLazy("VoiceStateStore"); + const settings = definePluginSettings({ showInUserProfileModal: { type: OptionType.BOOLEAN, diff --git a/src/webpack/common/types/stores.d.ts b/src/webpack/common/types/stores.d.ts index 03c7e3a5..037b2d81 100644 --- a/src/webpack/common/types/stores.d.ts +++ b/src/webpack/common/types/stores.d.ts @@ -17,7 +17,6 @@ */ import { DraftType } from "@webpack/common"; -import { FluxStore } from "@webpack/types"; import { Channel, Guild, Role } from "discord-types/general"; import { FluxDispatcher, FluxEvents } from "./utils"; diff --git a/src/webpack/common/types/utils.d.ts b/src/webpack/common/types/utils.d.ts index ffb8ed4b..ce1e3e26 100644 --- a/src/webpack/common/types/utils.d.ts +++ b/src/webpack/common/types/utils.d.ts @@ -316,69 +316,3 @@ export interface DisplayProfileUtils { getDisplayProfile(userId: string, guildId?: string, customStores?: any): DisplayProfile | null; useDisplayProfile(userId: string, guildId?: string, customStores?: any): DisplayProfile | null; } - -export interface ApplicationStreamPreviewStore extends FluxStore { - getIsPreviewLoading: (guildId: string | bigint | null, channelId: string | bigint, ownerId: string | bigint) => boolean; - getPreviewURL: (guildId: string | bigint | null, channelId: string | bigint, ownerId: string | bigint) => Promise; - getPreviewURLForStreamKey: (streamKey: string) => ReturnType; -} - -export interface ApplicationStream { - streamType: string; - guildId: string; - channelId: string; - ownerId: string; -} - -export interface Stream extends ApplicationStream { - state: string; -} - -export interface RTCStream { - region: string, - streamKey: string, - viewerIds: string[]; -} - -export interface StreamMetadata { - id: string | null, - pid: number | null, - sourceName: string | null; -} - -export interface StreamingStoreState { - activeStreams: [string, Stream][]; - rtcStreams: { [key: string]: RTCStream; }; - streamerActiveStreamMetadatas: { [key: string]: StreamMetadata | null; }; - streamsByUserAndGuild: { [key: string]: { [key: string]: ApplicationStream; }; }; -} - -export interface ApplicationStreamingStore extends FluxStore { - getActiveStreamForApplicationStream: (stream: ApplicationStream) => Stream | null; - getActiveStreamForStreamKey: (streamKey: string) => Stream | null; - getActiveStreamForUser: (userId: string | bigint, guildId?: string | bigint | null) => Stream | null; - getAllActiveStreams: () => Stream[]; - getAllApplicationStreams: () => ApplicationStream[]; - getAllApplicationStreamsForChannel: (channelId: string | bigint) => ApplicationStream[]; - getAllActiveStreamsForChannel: (channelId: string | bigint) => Stream[]; - getAnyStreamForUser: (userId: string | bigint) => Stream | ApplicationStream | null; - getStreamForUser: (userId: string | bigint, guildId?: string | bigint | null) => Stream | null; - getCurrentUserActiveStream: () => Stream; - getLastActiveStream: () => Stream | null; - getState: () => StreamingStoreState; - getRTCStream: (streamKey: string) => RTCStream | null; - getStreamerActiveStreamMetadata: () => StreamMetadata; - getViewerIds: (stream: ApplicationStream) => string[]; - isSelfStreamHidden: (channelId: string | bigint | null) => boolean; -} - -export interface Session { - sessionId: string; - status: string; - active: boolean; - clientInfo: { - version: number; - os: string; - client: string; - }; -} diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index c98207e9..2aba23dd 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -19,8 +19,7 @@ import { canonicalizeMatch } from "@utils/patches"; import type { Channel } from "discord-types/general"; -import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy, mapMangledModuleLazy, waitFor } from "../webpack"; -import { FluxStore } from "./types/stores"; +import { _resolveReady, filters, findByCodeLazy, findByPropsLazy, findLazy, mapMangledModuleLazy, waitFor } from "../webpack"; import type * as t from "./types/utils"; export let FluxDispatcher: t.FluxDispatcher; @@ -161,6 +160,13 @@ export const InviteActions = findByPropsLazy("resolveInvite"); export const IconUtils: t.IconUtils = findByPropsLazy("getGuildBannerURL", "getUserAvatarURL"); +const openExpressionPickerMatcher = canonicalizeMatch(/setState\({activeView:\i,activeViewType:/); +// TODO: type +export const ExpressionPickerStore: t.ExpressionPickerStore = mapMangledModuleLazy("expression-picker-last-active-view", { + closeExpressionPicker: filters.byCode("setState({activeView:null"), + openExpressionPicker: m => typeof m === "function" && openExpressionPickerMatcher.test(m.toString()), +}); + export const PopoutActions: t.PopoutActions = mapMangledModuleLazy('type:"POPOUT_WINDOW_OPEN"', { open: filters.byCode('type:"POPOUT_WINDOW_OPEN"'), close: filters.byCode('type:"POPOUT_WINDOW_CLOSE"'), @@ -172,41 +178,3 @@ export const DisplayProfileUtils: t.DisplayProfileUtils = mapMangledModuleLazy(/ getDisplayProfile: filters.byCode(".getGuildMemberProfile("), useDisplayProfile: filters.byCode(/\[\i\.\i,\i\.\i],\(\)=>/) }); - -const openExpressionPickerMatcher = canonicalizeMatch(/setState\({activeView:\i,activeViewType:/); - -// findStoreLazy Stores -export const ExpressionPickerStore: t.ExpressionPickerStore = mapMangledModuleLazy("expression-picker-last-active-view", { - closeExpressionPicker: filters.byCode("setState({activeView:null"), - openExpressionPicker: m => typeof m === "function" && openExpressionPickerMatcher.test(m.toString()), -}); -export const ApplicationStreamPreviewStore: t.ApplicationStreamPreviewStore = findStoreLazy("ApplicationStreamPreviewStore"); -export const ApplicationStreamingStore: t.ApplicationStreamingStore = findStoreLazy("ApplicationStreamingStore"); -export const VoiceStateStore = findStoreLazy("VoiceStateStore"); -export const RunningGameStore = findStoreLazy("RunningGameStore"); -export const TypingStore = findStoreLazy("TypingStore"); -export const PrivateChannelSortStore = findStoreLazy("PrivateChannelSortStore") as { getPrivateChannelIds: () => string[]; }; -export const UserGuildSettingsStore = findStoreLazy("UserGuildSettingsStore"); -export const SessionsStore = findStoreLazy("SessionsStore") as { - getSessions(): Record; -}; -export const GuildMemberCountStore = findStoreLazy("GuildMemberCountStore") as FluxStore & { getMemberCount(guildId: string): number | null; }; -export const ChannelMemberStore = findStoreLazy("ChannelMemberStore") as FluxStore & { - getProps(guildId: string, channelId: string): { groups: { count: number; id: string; }[]; }; -}; -export const ChannelRTCStore = findStoreLazy("ChannelRTCStore"); -export const SortedGuildStore = findStoreLazy("SortedGuildStore"); -export const ExpandedGuildFolderStore = findStoreLazy("ExpandedGuildFolderStore"); -export const ThemeStore = findStoreLazy("ThemeStore"); -export const NitroThemeStore = findStoreLazy("ClientThemesBackgroundStore"); -export const AuthSessionsStore = findStoreLazy("AuthSessionsStore"); -export const StickerStore = findStoreLazy("StickersStore"); -export const UserSettingsProtoStore = findStoreLazy("UserSettingsProtoStore"); -export const UserAffinitiesStore = findStoreLazy("UserAffinitiesStore"); -export const GuildAvailabilityStore = findStoreLazy("GuildAvailabilityStore") as FluxStore & { - totalGuilds: number; - totalUnavailableGuilds: number; - unavailableGuilds: string[]; - isUnavailable(guildId: string): boolean; -}; -export const MediaEngineStore = findStoreLazy("MediaEngineStore");