From ce5db22a80ba41b5b8e2c5bff58016bb73d8fc14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gama?= Date: Mon, 26 Feb 2024 01:28:49 -0300 Subject: [PATCH] fix: fix issue where one letter albums would crash the discordrpc plugin --- plugins/DiscordRPC/src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/DiscordRPC/src/index.js b/plugins/DiscordRPC/src/index.js index 755756a..126e13e 100644 --- a/plugins/DiscordRPC/src/index.js +++ b/plugins/DiscordRPC/src/index.js @@ -18,6 +18,7 @@ client.then(() => { const { item: currentlyPlaying, type: mediaType } = currentMediaItem; const mediaURL = getMediaURLFromID(mediaType === "track" ? currentlyPlaying.album.cover : currentlyPlaying.imageId); + const largeImageTextContent = mediaType === "track" ? currentlyPlaying.album.title : currentlyPlaying.title; const date = new Date(); const now = (date.getTime() / 1000) | 0; @@ -42,7 +43,8 @@ client.then(() => { "by " + currentlyPlaying.artists.map((a) => a.name).join(", ") ), largeImageKey: mediaURL, - largeImageText: formatLongString(mediaType === 'track' ? currentlyPlaying.album.title : currentlyPlaying.title), + // Discord requires largeImageText to be at least 2 characters long. So we add a invisible space to the end of the string if it's only 1 character long. + largeImageText: largeImageTextContent.length >= 2 ? formatLongString(largeImageTextContent) : (largeImageTextContent + "‎"), }); }) );