diff options
author | Vendicated <vendicated@riseup.net> | 2023-10-13 03:49:58 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2023-10-13 03:49:58 +0200 |
commit | 61cd7b4d99d4a4b90adb73530610d578a7b46334 (patch) | |
tree | df3c3b8b0cde66c5aee46d48ef2b5af330f81814 /src | |
parent | 926af0d1cd1ee44c6a4fe2c695fd59ff4431407e (diff) | |
download | Vencord-61cd7b4d99d4a4b90adb73530610d578a7b46334.tar.gz Vencord-61cd7b4d99d4a4b90adb73530610d578a7b46334.tar.bz2 Vencord-61cd7b4d99d4a4b90adb73530610d578a7b46334.zip |
arrpc: refactor for use in vesktop
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/arRPC.web/index.tsx | 37 |
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) { |