Skip to content

Commit c924739

Browse files
committed
Add configuration for Discord status text
1 parent 18a5e09 commit c924739

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

src/i18n/resources/en.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@
349349
"prompt": {
350350
"hostname": {
351351
"title": "Proxy Hostname",
352-
"label": "Enter hostname for local proxy server (requires restart):"
352+
"label": "Enter hostname for local proxy server (requires restart):"
353353
},
354354
"port": {
355355
"title": "Proxy Port",
356-
"label": "Enter port for local proxy server (requires restart):"
356+
"label": "Enter port for local proxy server (requires restart):"
357357
}
358358
}
359359
},
@@ -437,7 +437,15 @@
437437
"hide-duration-left": "Hide duration left",
438438
"hide-github-button": "Hide GitHub link Button",
439439
"play-on-youtube-music": "Play on YouTube Music",
440-
"set-inactivity-timeout": "Set inactivity timeout"
440+
"set-inactivity-timeout": "Set inactivity timeout",
441+
"set-status-display-type": {
442+
"label": "Status text",
443+
"submenu": {
444+
"youtube-music": "Listening to YouTube Music",
445+
"artist": "Listening to {artist}",
446+
"title": "Listening to {song title}"
447+
}
448+
}
441449
},
442450
"name": "Discord Rich Presence",
443451
"prompt": {

src/plugins/discord/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ export enum TimerKey {
2323
UpdateTimeout = 'updateTimeout', // Timer for throttled activity updates
2424
DiscordConnectRetry = 'discordConnectRetry', // Timer for Discord connection retries
2525
}
26+
27+
/**
28+
* An enum for Discord's activity.status_display_type field, governing which field of the activity should be used after
29+
* "Listening to..." in the user's Discord status.
30+
*/
31+
export const DiscordStatusDisplayType = {
32+
YOUTUBE_MUSIC : 0,
33+
ARTIST: 1,
34+
TITLE: 2,
35+
} as const;

src/plugins/discord/discord-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export class DiscordService {
9898

9999
const activityInfo: SetActivity = {
100100
type: ActivityType.Listening,
101+
statusDisplayType: config.statusDisplayType,
101102
details: truncateString(songInfo.title, 128), // Song title
103+
detailsUrl: songInfo.url ?? undefined,
102104
state: truncateString(songInfo.artist, 128), // Artist name
103105
largeImageKey: songInfo.imageSrc ?? undefined,
104106
largeImageText: songInfo.album

src/plugins/discord/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createPlugin } from '@/utils';
22
import { backend } from './main';
33
import { onMenu } from './menu';
44
import { t } from '@/i18n';
5+
import { DiscordStatusDisplayType } from './constants';
56

67
export type DiscordPluginConfig = {
78
enabled: boolean;
@@ -33,6 +34,10 @@ export type DiscordPluginConfig = {
3334
* Hide the "duration left" in the rich presence
3435
*/
3536
hideDurationLeft: boolean;
37+
/**
38+
* Hide the "duration left" in the rich presence
39+
*/
40+
statusDisplayType: (typeof DiscordStatusDisplayType)[keyof typeof DiscordStatusDisplayType];
3641
};
3742

3843
export default createPlugin({
@@ -47,6 +52,7 @@ export default createPlugin({
4752
playOnYouTubeMusic: true,
4853
hideGitHubButton: false,
4954
hideDurationLeft: false,
55+
statusDisplayType: DiscordStatusDisplayType.ARTIST,
5056
} as DiscordPluginConfig,
5157
menu: onMenu,
5258
backend,

src/plugins/discord/menu.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ import { setMenuOptions } from '@/config/plugins';
99
import { t } from '@/i18n';
1010

1111
import type { MenuContext } from '@/types/contexts';
12-
import type { DiscordPluginConfig } from './index';
12+
import { type DiscordPluginConfig } from './index';
1313

1414
import type { MenuTemplate } from '@/menu';
15+
import { DiscordStatusDisplayType } from './constants';
1516

1617
const registerRefreshOnce = singleton((refreshMenu: () => void) => {
1718
discordService?.registerRefreshCallback(refreshMenu);
1819
});
1920

21+
const DiscordStatusDisplayTypeLabels = {
22+
[DiscordStatusDisplayType.YOUTUBE_MUSIC]: "plugins.discord.menu.set-status-display-type.submenu.youtube-music",
23+
[DiscordStatusDisplayType.ARTIST]: "plugins.discord.menu.set-status-display-type.submenu.artist",
24+
[DiscordStatusDisplayType.TITLE]: "plugins.discord.menu.set-status-display-type.submenu.title",
25+
}
26+
2027
export const onMenu = async ({
2128
window,
2229
getConfig,
@@ -92,6 +99,19 @@ export const onMenu = async ({
9299
label: t('plugins.discord.menu.set-inactivity-timeout'),
93100
click: () => setInactivityTimeout(window, config),
94101
},
102+
{
103+
label: t('plugins.discord.menu.set-status-display-type.label'),
104+
submenu: Object.values(DiscordStatusDisplayType).map((statusDisplayType) => ({
105+
label: t(DiscordStatusDisplayTypeLabels[statusDisplayType]),
106+
type: 'radio',
107+
checked: config.statusDisplayType == statusDisplayType,
108+
click() {
109+
setConfig({
110+
statusDisplayType
111+
});
112+
},
113+
})),
114+
},
95115
];
96116
};
97117

0 commit comments

Comments
 (0)