Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,15 @@
"hide-duration-left": "Hide duration left",
"hide-github-button": "Hide GitHub link Button",
"play-on-youtube-music": "Play on YouTube Music",
"set-inactivity-timeout": "Set inactivity timeout"
"set-inactivity-timeout": "Set inactivity timeout",
"set-status-display-type": {
"label": "Status text",
"submenu": {
"youtube-music": "Listening to YouTube Music",
"artist": "Listening to {artist}",
"title": "Listening to {song title}"
}
}
},
"name": "Discord Rich Presence",
"prompt": {
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/discord/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ export enum TimerKey {
UpdateTimeout = 'updateTimeout', // Timer for throttled activity updates
DiscordConnectRetry = 'discordConnectRetry', // Timer for Discord connection retries
}

/**
* An enum for Discord's activity.status_display_type field, governing which field of the activity should be used after
* "Listening to..." in the user's Discord status.
*/
export const DiscordStatusDisplayType = {
YOUTUBE_MUSIC: 0,
ARTIST: 1,
TITLE: 2,
} as const;
3 changes: 2 additions & 1 deletion src/plugins/discord/discord-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export class DiscordService {

const activityInfo: SetActivity = {
type: ActivityType.Listening,
statusDisplayType: config.statusDisplayType,
details: truncateString(songInfo.title, 128), // Song title
detailsUrl: songInfo.url,
detailsUrl: songInfo.url ?? undefined,
state: truncateString(songInfo.artist, 128), // Artist name
stateUrl: songInfo.artistUrl,
largeImageKey: songInfo.imageSrc ?? undefined,
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/discord/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createPlugin } from '@/utils';
import { backend } from './main';
import { onMenu } from './menu';
import { t } from '@/i18n';
import { DiscordStatusDisplayType } from './constants';

export type DiscordPluginConfig = {
enabled: boolean;
Expand Down Expand Up @@ -33,6 +34,10 @@ export type DiscordPluginConfig = {
* Hide the "duration left" in the rich presence
*/
hideDurationLeft: boolean;
/**
* Controls which field is displayed in the Discord status text
*/
statusDisplayType: (typeof DiscordStatusDisplayType)[keyof typeof DiscordStatusDisplayType];
};

export default createPlugin({
Expand All @@ -47,6 +52,7 @@ export default createPlugin({
playOnYouTubeMusic: true,
hideGitHubButton: false,
hideDurationLeft: false,
statusDisplayType: DiscordStatusDisplayType.ARTIST,
} as DiscordPluginConfig,
menu: onMenu,
backend,
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/discord/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import type { MenuContext } from '@/types/contexts';
import type { DiscordPluginConfig } from './index';

import type { MenuTemplate } from '@/menu';
import { DiscordStatusDisplayType } from './constants';

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

const DiscordStatusDisplayTypeLabels = {
[DiscordStatusDisplayType.YOUTUBE_MUSIC]: "plugins.discord.menu.set-status-display-type.submenu.youtube-music",
[DiscordStatusDisplayType.ARTIST]: "plugins.discord.menu.set-status-display-type.submenu.artist",
[DiscordStatusDisplayType.TITLE]: "plugins.discord.menu.set-status-display-type.submenu.title",
}

export const onMenu = async ({
window,
getConfig,
Expand Down Expand Up @@ -92,6 +99,19 @@ export const onMenu = async ({
label: t('plugins.discord.menu.set-inactivity-timeout'),
click: () => setInactivityTimeout(window, config),
},
{
label: t('plugins.discord.menu.set-status-display-type.label'),
submenu: Object.values(DiscordStatusDisplayType).map((statusDisplayType) => ({
label: t(DiscordStatusDisplayTypeLabels[statusDisplayType]),
type: 'radio',
checked: config.statusDisplayType == statusDisplayType,
click() {
setConfig({
statusDisplayType
});
},
})),
},
];
};

Expand Down
Loading