22Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
33const Logger_js_1 = require ( "../packages/logger/Logger.js" ) ;
44const store_js_1 = require ( "./store.js" ) ;
5+ const config_js_1 = require ( "../config.js" ) ;
56const DiscordRPC = require ( "discord-rpc" ) ;
67const discordRichPresenceLogger = new Logger_js_1 . Logger ( "DiscordRichPresence" ) ;
78
9+ class convertableLink {
10+ constructor ( link ) {
11+ this . link = link ;
12+ }
13+
14+ toString ( ) {
15+ return this . link ;
16+ }
17+
18+ toWeb ( ) {
19+ if ( ! this . link ) return ;
20+ return "https://music.yandex.ru/" + this . link + "?utm_source=discord&utm_medium=rich_presence_click" ;
21+ }
22+
23+ toApp ( ) {
24+ if ( ! this . link ) return ;
25+ return "yandexmusic://" + this . link ;
26+ }
27+ }
28+
829const settings = ( ) => store_js_1 . getModFeatures ( ) ?. discordRPC ;
930
1031const clientId = settings ( ) ?. applicationIDForRPC ?? "1124055337234858005" ;
1132const GITHUB_LINK = "https://github.com/TheKing-OfTime/YandexMusicModClient" ;
1233const SET_ACTIVITY_TIMEOUT_MS = 1500 ;
34+ const STATUS_DISPLAY_TYPES = {
35+ 0 : 0 , // Name
36+ 1 : 1 , // State
37+ 2 : 2 , // Details
38+ }
1339
1440let rpc = undefined ;
1541let isReady = false ;
@@ -298,12 +324,10 @@ function buildActivityObject(playingState) {
298324 "400x400" ,
299325 ) ;
300326
301- const shareTrackPath = `album/${ playingState . track . albums ?. [ 0 ] ?. id } /track/${ playingState . track . id } ` ;
302- const deepShareTrackUrl = "yandexmusic://" + shareTrackPath ;
303- const webShareTrackUrl =
304- "https://music.yandex.ru/" +
305- shareTrackPath +
306- "?utm_source=discord&utm_medium=rich_presence_click" ;
327+ const shareTrackPath = new convertableLink ( ( playingState . track . albums ?. [ 0 ] ?. id && playingState . track . id ) ? `album/${ playingState . track . albums ?. [ 0 ] ?. id } /track/${ playingState . track . id } ` : undefined ) ;
328+ const shareAlbumPath = new convertableLink ( playingState . track . albums ?. [ 0 ] ?. id ? `album/${ playingState . track . albums ?. [ 0 ] ?. id } ` : undefined ) ;
329+ const shareArtistPath = new convertableLink ( playingState . track . artists ?. [ 0 ] ?. id ? `artist/${ playingState . track . artists ?. [ 0 ] ?. id } ` : undefined ) ;
330+
307331
308332 let startTimestamp = Math . round (
309333 Date . now ( ) - ( playingState . progress ?? 0 ) * 1000 ,
@@ -329,9 +353,14 @@ function buildActivityObject(playingState) {
329353
330354 let activityObject = {
331355 type : 2 ,
356+ statusDisplayType : STATUS_DISPLAY_TYPES [ settings ( ) ?. statusDisplayType ] ?? 0 ,
332357 details : string2Discord ( title ) ,
358+ detailsUrl : shareTrackPath . toWeb ( ) ,
333359 state : string2Discord ( artist ) ,
360+ stateUrl : shareArtistPath . toWeb ( ) ,
334361 largeImageKey : albumArt ,
362+ largeImageText : `YandexMusicModClient ${ config_js_1 . config . modification . version } ` ,
363+ largeImageUrl : GITHUB_LINK ,
335364 startTimestamp,
336365 endTimestamp,
337366 instance : false ,
@@ -342,30 +371,31 @@ function buildActivityObject(playingState) {
342371 activityObject . smallImageText = stateText ;
343372 }
344373
345- if ( settings ( ) ?. showAlbum ?? true ) {
374+ if ( ( settings ( ) ?. showAlbum ?? true ) && album ) {
346375 activityObject . largeImageText = string2Discord ( album ) ;
376+ activityObject . largeImageUrl = shareAlbumPath . toWeb ( ) ;
347377 }
348378
349379 if (
350- ( deepShareTrackUrl || webShareTrackUrl ) &&
380+ ( shareTrackPath . toApp ( ) || shareTrackPath . toWeb ( ) ) &&
351381 ( settings ( ) ?. showButtons ?? true )
352382 ) {
353383 if ( ! ( settings ( ) ?. overrideDeepLinksExperiment ?? false ) ) {
354384 activityObject . buttons = [
355385 {
356386 label : "Listen in Yandex Music App" ,
357- url : deepShareTrackUrl ,
387+ url : shareTrackPath . toApp ( ) ,
358388 } ,
359389 {
360390 label : "Listen in Yandex Music Web" ,
361- url : webShareTrackUrl ,
391+ url : shareTrackPath . toWeb ( ) ,
362392 } ,
363393 ] ;
364394 } else if ( settings ( ) ?. showGitHubButton ?? true ) {
365395 activityObject . buttons = [
366396 {
367397 label : "Listen on Yandex Music" ,
368- url : webShareTrackUrl ,
398+ url : shareTrackPath . toWeb ( ) ,
369399 } ,
370400 {
371401 label : "Install from GitHub" ,
@@ -376,7 +406,7 @@ function buildActivityObject(playingState) {
376406 activityObject . buttons = [
377407 {
378408 label : "Listen on Yandex Music" ,
379- url : webShareTrackUrl ,
409+ url : shareTrackPath . toWeb ( ) ,
380410 } ,
381411 ] ;
382412 }
0 commit comments