mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-14 04:20:07 +02:00
Feature: Add song and artist links to discord RPC (#1160)
* Add song and artist links to discord RPC * use first artist name for artist link, full artist name for song link * use first album artist for song link * add discord rpc links setting * simplify discord link settings * fix setting description * add musicbrainz links * fix callback missing dependency * use encodeURIComponent for lastfm links Co-authored-by: Kendall Garner <17521368+kgarner7@users.noreply.github.com> * split musicbrainz ids * combine link settings --------- Co-authored-by: Kendall Garner <17521368+kgarner7@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
import { controller } from '/@/renderer/api/controller';
|
||||
import {
|
||||
DiscordDisplayType,
|
||||
DiscordLinkType,
|
||||
getServerById,
|
||||
useAppStore,
|
||||
useDiscordSettings,
|
||||
@@ -77,6 +78,34 @@ export const useDiscordRpc = () => {
|
||||
type: discordSettings.showAsListening ? 2 : 0,
|
||||
};
|
||||
|
||||
if (
|
||||
(discordSettings.linkType == DiscordLinkType.LAST_FM ||
|
||||
discordSettings.linkType == DiscordLinkType.MBZ_LAST_FM) &&
|
||||
song?.artistName
|
||||
) {
|
||||
activity.stateUrl =
|
||||
'https://www.last.fm/music/' + encodeURIComponent(song.artists[0].name);
|
||||
activity.detailsUrl =
|
||||
'https://www.last.fm/music/' +
|
||||
encodeURIComponent(song.albumArtists[0].name) +
|
||||
'/' +
|
||||
encodeURIComponent(song.album || '_') +
|
||||
'/' +
|
||||
encodeURIComponent(song.name);
|
||||
}
|
||||
|
||||
if (
|
||||
discordSettings.linkType == DiscordLinkType.MBZ ||
|
||||
discordSettings.linkType == DiscordLinkType.MBZ_LAST_FM
|
||||
) {
|
||||
if (song?.mbzTrackId) {
|
||||
activity.detailsUrl = 'https://musicbrainz.org/track/' + song.mbzTrackId;
|
||||
} else if (song?.mbzRecordingId) {
|
||||
activity.detailsUrl =
|
||||
'https://musicbrainz.org/recording/' + song.mbzRecordingId;
|
||||
}
|
||||
}
|
||||
|
||||
if ((current[2] as PlayerStatus) === PlayerStatus.PLAYING) {
|
||||
if (start && end) {
|
||||
activity.startTimestamp = start;
|
||||
@@ -145,6 +174,7 @@ export const useDiscordRpc = () => {
|
||||
generalSettings.lastfmApiKey,
|
||||
discordSettings.clientId,
|
||||
discordSettings.displayType,
|
||||
discordSettings.linkType,
|
||||
lastUniqueId,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '/@/renderer/features/settings/components/settings-section';
|
||||
import {
|
||||
DiscordDisplayType,
|
||||
DiscordLinkType,
|
||||
useDiscordSettings,
|
||||
useGeneralSettings,
|
||||
useSettingsStoreActions,
|
||||
@@ -162,6 +163,54 @@ export const DiscordSettings = () => {
|
||||
}),
|
||||
isHidden: !isElectron(),
|
||||
title: t('setting.discordDisplayType', {
|
||||
discord: 'Discord',
|
||||
musicbrainz: 'musicbrainz',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
},
|
||||
{
|
||||
control: (
|
||||
<Select
|
||||
aria-label={t('setting.discordLinkType')}
|
||||
clearable={false}
|
||||
data={[
|
||||
{
|
||||
label: t('setting.discordLinkType_none', {
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
value: DiscordLinkType.NONE,
|
||||
},
|
||||
{ label: 'last.fm', value: DiscordLinkType.LAST_FM },
|
||||
{ label: 'musicbrainz', value: DiscordLinkType.MBZ },
|
||||
{
|
||||
label: t('setting.discordLinkType_mbz_lastfm', {
|
||||
lastfm: 'last.fm',
|
||||
musicbrainz: 'musicbrainz',
|
||||
}),
|
||||
value: DiscordLinkType.MBZ_LAST_FM,
|
||||
},
|
||||
]}
|
||||
defaultValue={settings.linkType}
|
||||
onChange={(e) => {
|
||||
if (!e) return;
|
||||
setSettings({
|
||||
discord: {
|
||||
...settings,
|
||||
linkType: e as DiscordLinkType,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
),
|
||||
description: t('setting.discordLinkType', {
|
||||
context: 'description',
|
||||
discord: 'Discord',
|
||||
lastfm: 'last.fm',
|
||||
musicbrainz: 'musicbrainz',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
isHidden: !isElectron(),
|
||||
title: t('setting.discordLinkType', {
|
||||
discord: 'Discord',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
|
||||
@@ -164,6 +164,13 @@ export enum DiscordDisplayType {
|
||||
SONG_NAME = 'song',
|
||||
}
|
||||
|
||||
export enum DiscordLinkType {
|
||||
LAST_FM = 'last_fm',
|
||||
MBZ = 'musicbrainz',
|
||||
MBZ_LAST_FM = 'musicbrainz_last_fm',
|
||||
NONE = 'none',
|
||||
}
|
||||
|
||||
export enum GenreTarget {
|
||||
ALBUM = 'album',
|
||||
TRACK = 'track',
|
||||
@@ -207,6 +214,7 @@ export interface SettingsState {
|
||||
clientId: string;
|
||||
displayType: DiscordDisplayType;
|
||||
enabled: boolean;
|
||||
linkType: DiscordLinkType;
|
||||
showAsListening: boolean;
|
||||
showPaused: boolean;
|
||||
showServerImage: boolean;
|
||||
@@ -364,6 +372,7 @@ const initialState: SettingsState = {
|
||||
clientId: '1165957668758900787',
|
||||
displayType: DiscordDisplayType.FEISHIN,
|
||||
enabled: false,
|
||||
linkType: DiscordLinkType.NONE,
|
||||
showAsListening: false,
|
||||
showPaused: true,
|
||||
showServerImage: false,
|
||||
|
||||
Reference in New Issue
Block a user