From fbc5038306eeeb809a77639237d50aa25c71211f Mon Sep 17 00:00:00 2001 From: rini Date: Wed, 25 Oct 2023 13:20:32 -0300 Subject: [PATCH] fix: RPC plugins (#1873) --- src/plugins/arRPC.web/index.tsx | 17 +++++------------ src/plugins/customRPC/index.tsx | 14 +++----------- src/plugins/lastfm/index.tsx | 12 +++--------- src/webpack/common/utils.ts | 4 ++++ 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/plugins/arRPC.web/index.tsx b/src/plugins/arRPC.web/index.tsx index 1db0c457..423dce9b 100644 --- a/src/plugins/arRPC.web/index.tsx +++ b/src/plugins/arRPC.web/index.tsx @@ -20,26 +20,19 @@ import { popNotice, showNotice } from "@api/Notices"; import { Link } from "@components/Link"; import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; -import { filters, findByCodeLazy, mapMangledModuleLazy } from "@webpack"; -import { FluxDispatcher, Forms, Toasts } from "@webpack/common"; +import { findByPropsLazy } from "@webpack"; +import { ApplicationAssetUtils, FluxDispatcher, Forms, Toasts } from "@webpack/common"; -const assetManager = mapMangledModuleLazy( - "getAssetImage: size must === [number, number] for Twitch", - { - getAsset: filters.byCode("apply("), - } -); - -const lookupRpcApp = findByCodeLazy(".APPLICATION_RPC("); +const RpcUtils = findByPropsLazy("fetchApplicationsRPC", "getRemoteIconURL"); async function lookupAsset(applicationId: string, key: string): Promise { - return (await assetManager.getAsset(applicationId, [key, undefined]))[0]; + return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0]; } const apps: any = {}; async function lookupApp(applicationId: string): Promise { const socket: any = {}; - await lookupRpcApp(socket, applicationId); + await RpcUtils.fetchApplicationsRPC(socket, applicationId); return socket.application; } diff --git a/src/plugins/customRPC/index.tsx b/src/plugins/customRPC/index.tsx index 2ec7f53f..25ad7b3e 100644 --- a/src/plugins/customRPC/index.tsx +++ b/src/plugins/customRPC/index.tsx @@ -22,23 +22,15 @@ import { Devs } from "@utils/constants"; import { isTruthy } from "@utils/guards"; import { useAwaiter } from "@utils/react"; import definePlugin, { OptionType } from "@utils/types"; -import { filters, findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "@webpack"; -import { FluxDispatcher, Forms, GuildStore, React, SelectedChannelStore, SelectedGuildStore, UserStore } from "@webpack/common"; +import { findByCodeLazy, findByPropsLazy } from "@webpack"; +import { ApplicationAssetUtils, FluxDispatcher, Forms, GuildStore, React, SelectedChannelStore, SelectedGuildStore, UserStore } from "@webpack/common"; const ActivityComponent = findByCodeLazy("onOpenGameProfile"); const ActivityClassName = findByPropsLazy("activity", "buttonColor"); const Colors = findByPropsLazy("profileColors"); -const assetManager = mapMangledModuleLazy( - "getAssetImage: size must === [number, number] for Twitch", - { - getAsset: filters.byCode("APPLICATION_ASSETS_FETCH_SUCCESS"), - } -); - async function getApplicationAsset(key: string): Promise { - if (/https?:\/\/(cdn|media)\.discordapp\.(com|net)\/attachments\//.test(key)) return "mp:" + key.replace(/https?:\/\/(cdn|media)\.discordapp\.(com|net)\//, ""); - return (await assetManager.getAsset(settings.store.appID, [key, undefined]))[0]; + return (await ApplicationAssetUtils.fetchAssetIds(settings.store.appID!, [key]))[0]; } interface ActivityAssets { diff --git a/src/plugins/lastfm/index.tsx b/src/plugins/lastfm/index.tsx index 7a42f8f7..179b8260 100644 --- a/src/plugins/lastfm/index.tsx +++ b/src/plugins/lastfm/index.tsx @@ -21,8 +21,8 @@ import { Link } from "@components/Link"; import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; -import { filters, findByPropsLazy, mapMangledModuleLazy } from "@webpack"; -import { FluxDispatcher, Forms } from "@webpack/common"; +import { findByPropsLazy } from "@webpack"; +import { ApplicationAssetUtils, FluxDispatcher, Forms } from "@webpack/common"; interface ActivityAssets { large_image?: string; @@ -86,15 +86,9 @@ const placeholderId = "2a96cbd8b46e442fc41c2b86b821562f"; const logger = new Logger("LastFMRichPresence"); const presenceStore = findByPropsLazy("getLocalPresence"); -const assetManager = mapMangledModuleLazy( - "getAssetImage: size must === [number, number] for Twitch", - { - getAsset: filters.byCode("apply("), - } -); async function getApplicationAsset(key: string): Promise { - return (await assetManager.getAsset(applicationId, [key, undefined]))[0]; + return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0]; } function setActivity(activity: Activity | null) { diff --git a/src/webpack/common/utils.ts b/src/webpack/common/utils.ts index ec0de86d..a1dcadc6 100644 --- a/src/webpack/common/utils.ts +++ b/src/webpack/common/utils.ts @@ -93,6 +93,10 @@ export function showToast(message: string, type = ToastType.MESSAGE) { export const UserUtils = findByPropsLazy("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise; }; +export const ApplicationAssetUtils = findByPropsLazy("fetchAssetIds", "getAssetImage") as { + fetchAssetIds: (applicationId: string, e: string[]) => Promise; +}; + export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', { copy: filters.byCode(".copy("), SUPPORTS_COPY: x => typeof x === "boolean",