fix(Last.fm): fetch app assets
This commit is contained in:
parent
9e9572eb5d
commit
74f6b7a228
3 changed files with 13 additions and 11 deletions
|
|
@ -17,7 +17,7 @@ export const currentSettings = { ...plugin.storage } as LFMSettings;
|
|||
|
||||
// Discord modules that we need
|
||||
export const UserStore = findByStoreName("UserStore");
|
||||
export const SET_ACTIVITY = findByProps("SET_ACTIVITY").SET_ACTIVITY;
|
||||
export const { SET_ACTIVITY } = findByProps("SET_ACTIVITY");
|
||||
|
||||
export const verboseLog = (...message: any) => currentSettings.verboseLogging && console.log(...message);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ import { showToast } from "@vendetta/ui/toasts";
|
|||
import { UserStore, currentSettings, global, verboseLog } from ".";
|
||||
import Constants from "./constants";
|
||||
|
||||
const AssetManager = findByProps("getAssetIds");
|
||||
const AssetManager = findByProps("getAssetIds") as {
|
||||
getAssetIds: (appId: string, ids: string[]) => string[];
|
||||
fetchAssetIds: (appId: string, ids: string[]) => Promise<string[]>;
|
||||
[key: PropertyKey]: any;
|
||||
};
|
||||
const PresenceStore = findByStoreName("PresenceStore");
|
||||
|
||||
enum ActivityType {
|
||||
|
|
@ -82,15 +86,13 @@ function sendRequest(activity: Activity) {
|
|||
}
|
||||
|
||||
/** Fetches a Discord application's asset */
|
||||
async function fetchAsset<T extends string | string[]>(asset: T, appId: string = Constants.APPLICATION_ID): Promise<T> {
|
||||
if (!asset) return null;
|
||||
async function fetchAsset(asset: string[], appId: string = Constants.APPLICATION_ID): Promise<string[]> {
|
||||
if (!asset) return [];
|
||||
|
||||
if (typeof asset === "string") {
|
||||
const assetId = await AssetManager.getAssetIds(appId, [asset]);
|
||||
return assetId[0] as T;
|
||||
}
|
||||
const assetIds = AssetManager.getAssetIds(appId, asset);
|
||||
if (assetIds.length > 0) return assetIds;
|
||||
|
||||
return await AssetManager.getAssetIds(appId, asset);
|
||||
return await AssetManager.fetchAssetIds(appId, asset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,7 +163,7 @@ async function update() {
|
|||
|
||||
if (lastTrack.album) {
|
||||
activity.assets = {
|
||||
large_image: await fetchAsset(lastTrack.albumArt),
|
||||
large_image: (await fetchAsset([lastTrack.albumArt]))[0],
|
||||
large_text: `on ${lastTrack.album}`
|
||||
};
|
||||
}
|
||||
|
|
|
|||
2
plugins/defs.d.ts
vendored
2
plugins/defs.d.ts
vendored
|
|
@ -6,7 +6,7 @@ type Activity = {
|
|||
details?: string;
|
||||
state?: string;
|
||||
timestamps?: {
|
||||
_enabled: boolean;
|
||||
_enabled?: boolean;
|
||||
start: number | string;
|
||||
end?: number | string;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue