mirror of
				https://github.com/smartfrigde/armcord.git
				synced 2024-08-14 23:56:58 +00:00 
			
		
		
		
	fix arRPC (again) (#531)
* fix arRPC * Re-apply the rpc handler every 30 seconds Co-authored-by: millistice <148235157+millistice@users.noreply.github.com> * apply ven's suggestions --------- Co-authored-by: millistice <148235157+millistice@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									4f6d40c129
								
							
						
					
					
						commit
						da4463beb8
					
				
					 1 changed files with 50 additions and 86 deletions
				
			
		|  | @ -1,97 +1,61 @@ | ||||||
| window.addEventListener("load", async () => { | { | ||||||
|   let Dispatcher = undefined, |     const cb = () => { | ||||||
|     lookupAsset = undefined, |         let Dispatcher, | ||||||
|     lookupApp = undefined; |             lookupAsset, | ||||||
|  |             lookupApp, | ||||||
|  |             apps = {}; | ||||||
| 
 | 
 | ||||||
|   let apps = {}; |         ArmCordRPC.listen(async (msg) => { | ||||||
|   const chunkName = 'webpackChunkdiscord_app'; |             if (!Dispatcher) { | ||||||
|  |                 let wpRequire; | ||||||
|  |                 window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => (wpRequire = x)]); | ||||||
|  |                 window.webpackChunkdiscord_app.pop(); | ||||||
| 
 | 
 | ||||||
|   const wpRequire = window[chunkName].push( |                 const modules = wpRequire.c; | ||||||
|     [ [Symbol()], {}, (x) => x ] |                 lookupAsset = Object.values(modules).find(m => m.exports?.fetchAssetIds).exports.fetchAssetIds; | ||||||
|   ); |                 lookupApp = Object.values(modules).find(m => m.exports?.fetchApplicationsRPC).exports.fetchApplicationsRPC;  | ||||||
| 
 | 
 | ||||||
|   const cache = wpRequire.c; |                 for (const id in modules) { | ||||||
|   window[chunkName].pop(); |                     const mod = modules[id].exports; | ||||||
|  |                     if (!mod?.__esModule) continue; | ||||||
| 
 | 
 | ||||||
|   for (const id in cache) { |                     for (const prop in mod) { | ||||||
|     let mod = cache[id].exports; |                         if (!mod.hasOwnProperty(prop)) continue; | ||||||
|     if (typeof mod !== "object") continue; |  | ||||||
| 
 | 
 | ||||||
|     let candidates; |                         const candidate = mod[prop]; | ||||||
|     try { |  | ||||||
|       candidates = Object.values(mod); |  | ||||||
|     } catch { |  | ||||||
|       continue; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     for (const candidate of candidates) { |  | ||||||
|                         if (candidate && candidate.register && candidate.wait) { |                         if (candidate && candidate.register && candidate.wait) { | ||||||
|                             Dispatcher = candidate; |                             Dispatcher = candidate; | ||||||
|                             break; |                             break; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     if (Dispatcher) break; | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|   const factories = wpRequire.m; |             if (msg.activity?.assets?.large_image) | ||||||
|   for (const id in factories) { |  | ||||||
|     if ( |  | ||||||
|       factories[id] |  | ||||||
|         .toString() |  | ||||||
|         .includes("getAssetImage: size must === [number, number] for Twitch") |  | ||||||
|     ) { |  | ||||||
|       const mod = wpRequire(id); |  | ||||||
| 
 |  | ||||||
|       // fetchAssetIds
 |  | ||||||
|       const _lookupAsset = Object.values(mod).find( |  | ||||||
|         (e) => |  | ||||||
|           typeof e === "function" && |  | ||||||
|           e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS"), |  | ||||||
|       ); |  | ||||||
|       if (_lookupAsset) |  | ||||||
|         lookupAsset = async (appId, name) => |  | ||||||
|           (await _lookupAsset(appId, [name, undefined]))[0]; |  | ||||||
|     } |  | ||||||
|     if (lookupAsset) break; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   for (const id in factories) { |  | ||||||
|     if (factories[id].toString().includes("APPLICATION_RPC")) { |  | ||||||
|       const mod = wpRequire(id); |  | ||||||
| 
 |  | ||||||
|       // fetchApplicationsRPC
 |  | ||||||
|       const _lookupApp = Object.values(mod).find( |  | ||||||
|         (e) => typeof e === "function" && e.toString().includes(",coverImage:"), |  | ||||||
|       ); |  | ||||||
|       if (_lookupApp) |  | ||||||
|         lookupApp = async (appId) => { |  | ||||||
|           let socket = {}; |  | ||||||
|           await _lookupApp(socket, appId); |  | ||||||
|           return socket.application; |  | ||||||
|         }; |  | ||||||
|     } |  | ||||||
|     if (lookupApp) break; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   ArmCordRPC.listen(async (msg) => { |  | ||||||
|     if (msg.activity) { |  | ||||||
|       if (msg.activity?.assets?.large_image && lookupAsset) |  | ||||||
|                 msg.activity.assets.large_image = await lookupAsset( |                 msg.activity.assets.large_image = await lookupAsset( | ||||||
|                     msg.activity.application_id, |                     msg.activity.application_id, | ||||||
|           msg.activity.assets.large_image, |                     msg.activity.assets.large_image | ||||||
|                 ); |                 ); | ||||||
|       if (msg.activity?.assets?.small_image && lookupAsset) |             if (msg.activity?.assets?.small_image) | ||||||
|                 msg.activity.assets.small_image = await lookupAsset( |                 msg.activity.assets.small_image = await lookupAsset( | ||||||
|                     msg.activity.application_id, |                     msg.activity.application_id, | ||||||
|           msg.activity.assets.small_image, |                     msg.activity.assets.small_image | ||||||
|                 ); |                 ); | ||||||
| 
 | 
 | ||||||
|  |             if (msg.activity) { | ||||||
|                 const appId = msg.activity.application_id; |                 const appId = msg.activity.application_id; | ||||||
|       if (!apps[appId] && lookupApp) apps[appId] = await lookupApp(appId); |                 if (!apps[appId]) apps[appId] = await lookupApp(appId); | ||||||
| 
 | 
 | ||||||
|                 const app = apps[appId]; |                 const app = apps[appId]; | ||||||
|                 if (!msg.activity.name) msg.activity.name = app.name; |                 if (!msg.activity.name) msg.activity.name = app.name; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|     Dispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...msg }); // set RPC status
 |             Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status
 | ||||||
|         }); |         }); | ||||||
| }); |     }; | ||||||
|  | 
 | ||||||
|  |     cb(); | ||||||
|  |     setInterval(cb, 30 * 1000); | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue