diff --git a/plugins/armcordRPC/index.js b/plugins/armcordRPC/index.js index b445fc4..c6d0743 100644 --- a/plugins/armcordRPC/index.js +++ b/plugins/armcordRPC/index.js @@ -2,24 +2,50 @@ const { util: { log }, flux: { dispatcher: FluxDispatcher, - stores: { ApplicationStore, DetectableGameSupplementalStore }, + stores: { ApplicationStore }, }, + http } = shelter; let apps = {}; +let assetCache = {} + +export const fetchAssetId = async (applicationId, assetName) => { + // TO-DO Use APPLICATION_ASSETS_UPDATE and APPLICATION_ASSETS_FETCH + if (!assetCache[applicationId]) { + try { + const response = await http.get(`/oauth2/applications/${applicationId}/assets`) + + if (response.status !== 200) { + console.error('Error fetching resources') + return null + } + + assetCache[applicationId] = response.body + } catch (error) { + console.error('Request failed', error) + return null + } + } + + // Find the resource ID by its name in the cached resources + const resource = assetCache[applicationId].find((item) => item.name === assetName) + return resource ? resource.id : null +} export function onLoad() { ArmCordRPC.listen(async (msg) => { + console.log(msg) log("ArmCord RPC: detected some game") - // if (msg.activity?.assets?.large_image) - // msg.activity.assets.large_image = await DetectableGameSupplementalStore.getCoverImageUrl( - // msg.activity.application_id, - // msg.activity.assets.large_image - // ); - // if (msg.activity?.assets?.small_image) - // msg.activity.assets.small_image = await DetectableGameSupplementalStore.getCoverImageUrl( - // msg.activity.application_id, - // msg.activity.assets.small_image - // ); + if (msg.activity?.assets?.large_image) + msg.activity.assets.large_image = await fetchAssetId( + msg.activity.application_id, + msg.activity.assets.large_image + ); + if (msg.activity?.assets?.small_image) + msg.activity.assets.small_image = await fetchAssetId( + msg.activity.application_id, + msg.activity.assets.small_image + ); if (msg.activity) { // TODO - Support games from DB too lool