@@ -19,6 +19,7 @@ interface FormattedPresence {
1919}
2020export interface FormattedActivity {
2121 name : string ;
22+ applicationId : string | null ;
2223 createdTimestamp : number | null ;
2324 details : string | null ;
2425 state : string | null ;
@@ -89,7 +90,7 @@ export const useDiscordActivityTracker = () => {
8990 handleActivity ( data ) ;
9091 } ;
9192 const handleActivity = debounce ( ( data : FormattedPresence ) => {
92- const activity = data . activities
93+ const activities = data . activities
9394 . filter ( ( a ) => a . type !== ActivityType . CUSTOM )
9495 . sort ( ( a , b ) => {
9596 const isASpotify = ! ! a . assets ?. largeImage ?. startsWith ( "spotify:" ) ;
@@ -105,36 +106,40 @@ export const useDiscordActivityTracker = () => {
105106
106107 // If neither or both are Spotify, maintain the original order (or add another sorting criteria)
107108 return 0 ;
108- } ) [ 0 ] ;
109- if ( ! activity ) {
110- localRPC . updateRPC ( NERIMITY_APP_ID ) ;
111- return ;
112- }
113- let url = undefined ;
109+ } ) ;
114110
115- const isSpotify = ! ! activity . assets ?. largeImage ?. startsWith ( "spotify:" ) ;
111+ let url : string | undefined = undefined ;
116112
117- if ( isSpotify && activity . syncId ) {
118- url = `https://open.spotify.com/track/${ activity . syncId } ` ;
119- }
113+ const mapped = activities . map ( ( activity ) => {
114+ const isSpotify = ! ! activity . assets ?. largeImage ?. startsWith ( "spotify:" ) ;
120115
121- console . log ( `Activity Update: ${ activity ?. name || null } ` ) ;
122- localRPC . updateRPC ( NERIMITY_APP_ID , {
123- startedAt : activity . timestamps ?. start || undefined ,
124- endsAt : activity . timestamps ?. end || undefined ,
125- imgSrc :
126- activity . assets ?. largeImageUrl ||
127- activity . assets ?. smallImageUrl ||
128- undefined ,
129- title : activity . details || undefined ,
130- subtitle : activity . state || undefined ,
131- link : url || activity . url || undefined ,
132- ...ActivityTypeToNameAndAction ( activity )
116+ if ( isSpotify && activity . syncId ) {
117+ url = `https://open.spotify.com/track/${ activity . syncId } ` ;
118+ }
119+
120+ console . log ( `Activity Update: ${ activity ?. name || null } ` ) ;
121+ return {
122+ id : activity . syncId || activity . applicationId || NERIMITY_APP_ID ,
123+ data : {
124+ startedAt : activity . timestamps ?. start || undefined ,
125+ endsAt : activity . timestamps ?. end || undefined ,
126+ imgSrc :
127+ activity . assets ?. largeImageUrl ||
128+ activity . assets ?. smallImageUrl ||
129+ undefined ,
130+ title : activity . details || undefined ,
131+ subtitle : activity . state || undefined ,
132+ link : url || activity . url || undefined ,
133+ ...ActivityTypeToNameAndAction ( activity )
134+ }
135+ } ;
133136 } ) ;
137+
138+ localRPC . updateDiscordRPCs ( mapped ) ;
134139 } , 500 ) ;
135140
136141 ws . onclose = ( ) => {
137- localRPC . updateRPC ( NERIMITY_APP_ID ) ;
142+ localRPC . updateDiscordRPCs ( [ ] ) ;
138143 clearInterval ( pingIntervalId ) ;
139144 clearTimeout ( restartDelayTimeoutId ) ;
140145 restartDelayTimeoutId = setTimeout ( ( ) => {
0 commit comments