Skip to content

Commit 03f1e01

Browse files
feat: Add new Rich Presence fields support discord/discord-api-docs#7674
1 parent 29d7f6c commit 03f1e01

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

src/main/lib/discordRichPresence.js

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,40 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
const Logger_js_1 = require("../packages/logger/Logger.js");
44
const store_js_1 = require("./store.js");
5+
const config_js_1 = require("../config.js");
56
const DiscordRPC = require("discord-rpc");
67
const 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+
829
const settings = () => store_js_1.getModFeatures()?.discordRPC;
930

1031
const clientId = settings()?.applicationIDForRPC ?? "1124055337234858005";
1132
const GITHUB_LINK = "https://github.com/TheKing-OfTime/YandexMusicModClient";
1233
const SET_ACTIVITY_TIMEOUT_MS = 1500;
34+
const STATUS_DISPLAY_TYPES = {
35+
0: 0, // Name
36+
1: 1, // State
37+
2: 2, // Details
38+
}
1339

1440
let rpc = undefined;
1541
let 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
}

src/main/lib/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const init = () => {
6868
enable: true,
6969
fromYnison: false,
7070
applicationIDForRPC: "1124055337234858005",
71+
statusDisplayType: 0,
7172
showButtons: true,
7273
showSmallIcon: false,
7374
showAlbum: true,

src/node_modules/discord-rpc/src/client.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)