[enhancement]: use discord activity type listening

This commit is contained in:
Kendall Garner 2024-08-23 08:27:40 -07:00
parent 271be93a96
commit 284db988c9
No known key found for this signature in database
GPG key ID: 18D2767419676C87
3 changed files with 197 additions and 21 deletions

View file

@ -25,23 +25,27 @@ export const useDiscordRpc = () => {
return;
}
const song = currentSong?.id ? currentSong : null;
const currentTime = usePlayerStore.getState().current.time;
const now = Date.now();
const start = currentTime ? Math.round(now - currentTime * 1000) : null;
const end =
currentSong?.duration && start ? Math.round(start + currentSong.duration) : null;
const end = song?.duration && start ? Math.round(start + song.duration) : null;
const artists = currentSong?.artists.map((artist) => artist.name).join(', ');
const artists = song?.artists.map((artist) => artist.name).join(', ');
const activity: SetActivity = {
details: currentSong?.name.padEnd(2, ' ') || 'Idle',
details: song?.name.padEnd(2, ' ') || 'Idle',
instance: false,
largeImageKey: undefined,
largeImageText: currentSong?.album || 'Unknown album',
largeImageText: song?.album || 'Unknown album',
smallImageKey: undefined,
smallImageText: currentStatus,
state: (artists && `By ${artists}`) || 'Unknown artist',
// 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: 2,
};
if (currentStatus === PlayerStatus.PLAYING) {
@ -56,11 +60,11 @@ export const useDiscordRpc = () => {
}
if (
currentSong?.serverType === ServerType.JELLYFIN &&
song?.serverType === ServerType.JELLYFIN &&
discordSettings.showServerImage &&
currentSong?.imageUrl
song?.imageUrl
) {
activity.largeImageKey = currentSong?.imageUrl;
activity.largeImageKey = song?.imageUrl;
}
// Fall back to default icon if not set