From 76770de7d8d7fda044aeb8ab343c224af68421c7 Mon Sep 17 00:00:00 2001 From: mae taylor Date: Fri, 1 Aug 2025 16:43:34 +0100 Subject: [PATCH] feat: discord presence display type --- src/i18n/locales/en.json | 4 ++ .../features/discord-rpc/use-discord-rpc.ts | 13 +++++- .../components/window/discord-settings.tsx | 46 +++++++++++++++++++ src/renderer/store/settings.store.ts | 8 ++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index f0709093..fe21c13e 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -529,6 +529,10 @@ "discordServeImage_description": "share cover art for {{discord}} rich presence from server itself, only available for jellyfin and navidrome", "discordUpdateInterval": "{{discord}} rich presence update interval", "discordUpdateInterval_description": "the time in seconds between each update (minimum 15 seconds)", + "discordDisplayType": "{{discord}} presence display type", + "discordDisplayType_description": "changes what you are listening to in your status", + "discordDisplayType_songname": "song name", + "discordDisplayType_artistname": "artist name(s)", "doubleClickBehavior": "queue all searched tracks when double clicking", "doubleClickBehavior_description": "if true, all matching tracks in a track search will be queued. otherwise, only the clicked one will be queued", "enableRemote": "enable remote control server", diff --git a/src/renderer/features/discord-rpc/use-discord-rpc.ts b/src/renderer/features/discord-rpc/use-discord-rpc.ts index a0586159..9f30bb03 100644 --- a/src/renderer/features/discord-rpc/use-discord-rpc.ts +++ b/src/renderer/features/discord-rpc/use-discord-rpc.ts @@ -1,9 +1,10 @@ -import { SetActivity } from '@xhayper/discord-rpc'; +import { SetActivity, StatusDisplayType } from '@xhayper/discord-rpc'; import isElectron from 'is-electron'; import { useCallback, useEffect, useState } from 'react'; import { controller } from '/@/renderer/api/controller'; import { + DiscordDisplayType, getServerById, useDiscordSetttings, useGeneralSettings, @@ -54,6 +55,12 @@ export const useDiscordRpc = () => { const artists = song?.artists.map((artist) => artist.name).join(', '); + const statusDisplayMap = { + [DiscordDisplayType.ARTIST_NAME]: StatusDisplayType.STATE, + [DiscordDisplayType.FEISHIN]: StatusDisplayType.NAME, + [DiscordDisplayType.SONG_NAME]: StatusDisplayType.DETAILS, + }; + const activity: SetActivity = { details: song?.name.padEnd(2, ' ') || 'Idle', instance: false, @@ -61,7 +68,8 @@ export const useDiscordRpc = () => { largeImageText: song?.album || 'Unknown album', smallImageKey: undefined, smallImageText: current[2] as string, - state: (artists && `By ${artists}`) || 'Unknown artist', + state: artists || 'Unknown artist', + statusDisplayType: statusDisplayMap[discordSettings.displayType], // I would love to use the actual type as opposed to hardcoding to 2, // but manually installing the discord-types package appears to break things type: discordSettings.showAsListening ? 2 : 0, @@ -134,6 +142,7 @@ export const useDiscordRpc = () => { discordSettings.showPaused, generalSettings.lastfmApiKey, discordSettings.clientId, + discordSettings.displayType, lastUniqueId, ], ); diff --git a/src/renderer/features/settings/components/window/discord-settings.tsx b/src/renderer/features/settings/components/window/discord-settings.tsx index af8ce176..1cad180c 100644 --- a/src/renderer/features/settings/components/window/discord-settings.tsx +++ b/src/renderer/features/settings/components/window/discord-settings.tsx @@ -6,10 +6,12 @@ import { SettingsSection, } from '/@/renderer/features/settings/components/settings-section'; import { + DiscordDisplayType, useDiscordSetttings, useGeneralSettings, useSettingsStoreActions, } from '/@/renderer/store'; +import { Select } from '/@/shared/components/select/select'; import { Switch } from '/@/shared/components/switch/switch'; import { TextInput } from '/@/shared/components/text-input/text-input'; @@ -120,6 +122,50 @@ export const DiscordSettings = () => { postProcess: 'sentenceCase', }), }, + { + control: ( +