From cad0265e3ce95d5b6264b2cf557cea8d9f24a23a Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Mon, 17 Nov 2025 02:24:52 +0000 Subject: [PATCH] fix(rpc): truncate certain fields (#1263) * fix(rpc): truncate certain fields * off by one... * use elipses character --- .../features/discord-rpc/use-discord-rpc.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/renderer/features/discord-rpc/use-discord-rpc.ts b/src/renderer/features/discord-rpc/use-discord-rpc.ts index b9c599bc..21b3905f 100644 --- a/src/renderer/features/discord-rpc/use-discord-rpc.ts +++ b/src/renderer/features/discord-rpc/use-discord-rpc.ts @@ -18,6 +18,11 @@ import { PlayerStatus } from '/@/shared/types/types'; const discordRpc = isElectron() ? window.api.discordRpc : null; type ActivityState = [QueueSong | undefined, number, PlayerStatus]; +const MAX_FIELD_LENGTH = 127; + +const truncate = (field: string) => + field.length <= MAX_FIELD_LENGTH ? field : field.substring(0, MAX_FIELD_LENGTH - 1) + '…'; + export const useDiscordRpc = () => { const discordSettings = useDiscordSettings(); const generalSettings = useGeneralSettings(); @@ -66,13 +71,15 @@ export const useDiscordRpc = () => { }; const activity: SetActivity = { - details: (song?.name && song.name.padEnd(2, ' ')) || 'Idle', + details: truncate((song?.name && song.name.padEnd(2, ' ')) || 'Idle'), instance: false, largeImageKey: undefined, - largeImageText: (song?.album && song.album.padEnd(2, ' ')) || 'Unknown album', + largeImageText: truncate( + (song?.album && song.album.padEnd(2, ' ')) || 'Unknown album', + ), smallImageKey: undefined, smallImageText: sentenceCase(current[2]), - state: (artists && artists.padEnd(2, ' ')) || 'Unknown artist', + state: truncate((artists && artists.padEnd(2, ' ')) || '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