Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@jellybrick/mpris-service": "2.1.5",
"@jimp/plugin-color": "1.6.0",
"@skyra/jaro-winkler": "1.1.1",
"@xhayper/discord-rpc": "1.2.2",
"@xhayper/discord-rpc": "1.3.0",
"async-mutex": "0.5.0",
"bgutils-js": "3.2.0",
"butterchurn": "3.0.0-beta.5",
Expand Down
33 changes: 14 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,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;
2 changes: 2 additions & 0 deletions src/plugins/discord/discord-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export class DiscordService {

const activityInfo: SetActivity = {
type: ActivityType.Listening,
statusDisplayType: config.statusDisplayType,
details: truncateString(songInfo.title, 128), // Song title
detailsUrl: songInfo.url ?? undefined,
state: truncateString(songInfo.artist, 128), // Artist name
largeImageKey: songInfo.imageSrc ?? undefined,
largeImageText: songInfo.album
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;
/**
* Hide the "duration left" in the rich presence
*/
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