aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/arRPC.web/index.tsx37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/plugins/arRPC.web/index.tsx b/src/plugins/arRPC.web/index.tsx
index f0d4841..1db0c45 100644
--- a/src/plugins/arRPC.web/index.tsx
+++ b/src/plugins/arRPC.web/index.tsx
@@ -58,6 +58,26 @@ export default definePlugin({
</>
),
+ async handleEvent(e: MessageEvent<any>) {
+ const data = JSON.parse(e.data);
+
+ const { activity } = data;
+ const assets = activity?.assets;
+
+ if (assets?.large_image) assets.large_image = await lookupAsset(activity.application_id, assets.large_image);
+ if (assets?.small_image) assets.small_image = await lookupAsset(activity.application_id, assets.small_image);
+
+ if (activity) {
+ const appId = activity.application_id;
+ apps[appId] ||= await lookupApp(appId);
+
+ const app = apps[appId];
+ activity.name ||= app.name;
+ }
+
+ FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...data });
+ },
+
async start() {
// ArmCord comes with its own arRPC implementation, so this plugin just confuses users
if ("armcord" in window) return;
@@ -65,22 +85,7 @@ export default definePlugin({
if (ws) ws.close();
ws = new WebSocket("ws://127.0.0.1:1337"); // try to open WebSocket
- ws.onmessage = async e => { // on message, set status to data
- const data = JSON.parse(e.data);
-
- if (data.activity?.assets?.large_image) data.activity.assets.large_image = await lookupAsset(data.activity.application_id, data.activity.assets.large_image);
- if (data.activity?.assets?.small_image) data.activity.assets.small_image = await lookupAsset(data.activity.application_id, data.activity.assets.small_image);
-
- if (data.activity) {
- const appId = data.activity.application_id;
- apps[appId] ||= await lookupApp(appId);
-
- const app = apps[appId];
- data.activity.name ||= app.name;
- }
-
- FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...data });
- };
+ ws.onmessage = this.handleEvent;
const connectionSuccessful = await new Promise(res => setTimeout(() => res(ws.readyState === WebSocket.OPEN), 1000)); // check if open after 1s
if (!connectionSuccessful) {