fix: RPC plugins (#1873)
This commit is contained in:
parent
ddc39fe84d
commit
fbc5038306
|
@ -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<string> {
|
||||
return (await assetManager.getAsset(applicationId, [key, undefined]))[0];
|
||||
return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0];
|
||||
}
|
||||
|
||||
const apps: any = {};
|
||||
async function lookupApp(applicationId: string): Promise<string> {
|
||||
const socket: any = {};
|
||||
await lookupRpcApp(socket, applicationId);
|
||||
await RpcUtils.fetchApplicationsRPC(socket, applicationId);
|
||||
return socket.application;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<string> {
|
||||
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 {
|
||||
|
|
|
@ -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<string> {
|
||||
return (await assetManager.getAsset(applicationId, [key, undefined]))[0];
|
||||
return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0];
|
||||
}
|
||||
|
||||
function setActivity(activity: Activity | null) {
|
||||
|
|
|
@ -93,6 +93,10 @@ export function showToast(message: string, type = ToastType.MESSAGE) {
|
|||
|
||||
export const UserUtils = findByPropsLazy("getUser", "fetchCurrentUser") as { getUser: (id: string) => Promise<User>; };
|
||||
|
||||
export const ApplicationAssetUtils = findByPropsLazy("fetchAssetIds", "getAssetImage") as {
|
||||
fetchAssetIds: (applicationId: string, e: string[]) => Promise<string[]>;
|
||||
};
|
||||
|
||||
export const Clipboard = mapMangledModuleLazy('document.queryCommandEnabled("copy")||document.queryCommandSupported("copy")', {
|
||||
copy: filters.byCode(".copy("),
|
||||
SUPPORTS_COPY: x => typeof x === "boolean",
|
||||
|
|
Loading…
Reference in a new issue