Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
fix rpc assets
Browse files Browse the repository at this point in the history
  • Loading branch information
smartfrigde committed Jul 14, 2024
1 parent 5fbce8b commit 03b4065
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions plugins/armcordRPC/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03b4065

Please sign in to comment.