Improved discordrpc
This commit is contained in:
parent
aa11c208d8
commit
09db8af283
2 changed files with 11 additions and 11 deletions
|
@ -101,9 +101,7 @@ export default class DiscordRichPresence {
|
||||||
this._client.clearActivity().catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
|
this._client.clearActivity().catch((e: any) => console.error(`[DiscordRichPresence][clearActivity] ${e}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const listenURL = `https://cider.sh/p?s&id=${attributes.playParams.id}` // cider://play/s/[id] (for song)
|
|
||||||
const amURL = `https://music.apple.com/${attributes.storefrontId}/song/${attributes.playParams.catalogId || attributes.playParams.id}`;
|
|
||||||
console.log("DiscordRPC URL: ", amURL);
|
|
||||||
this._activity = {
|
this._activity = {
|
||||||
details: attributes.name,
|
details: attributes.name,
|
||||||
state: `${attributes.artistName ? `by ${attributes.artistName}` : ''}`,
|
state: `${attributes.artistName ? `by ${attributes.artistName}` : ''}`,
|
||||||
|
@ -114,8 +112,8 @@ export default class DiscordRichPresence {
|
||||||
instance: false, // Whether the activity is in a game session
|
instance: false, // Whether the activity is in a game session
|
||||||
|
|
||||||
buttons: [
|
buttons: [
|
||||||
{label: "Listen on Cider", url: listenURL},
|
{label: "Listen on Cider", url: attributes.url.cider},
|
||||||
{label: "View on Apple Music", url: amURL},
|
{label: "View on Apple Music", url: attributes.url.appleMusic},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ const MusicKitInterop = {
|
||||||
init: function () {
|
init: function () {
|
||||||
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackStateDidChange, () => {
|
MusicKit.getInstance().addEventListener(MusicKit.Events.playbackStateDidChange, () => {
|
||||||
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), true, false)) {
|
if (MusicKitInterop.filterTrack(MusicKitInterop.getAttributes(), true, false)) {
|
||||||
console.log("ayy");
|
|
||||||
global.ipcRenderer.send('playbackStateDidChange', MusicKitInterop.getAttributes())
|
global.ipcRenderer.send('playbackStateDidChange', MusicKitInterop.getAttributes())
|
||||||
ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes());
|
ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes());
|
||||||
// if (typeof _plugins != "undefined") {
|
// if (typeof _plugins != "undefined") {
|
||||||
|
@ -39,11 +38,12 @@ const MusicKitInterop = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getAttributes: function () {
|
getAttributes: function () {
|
||||||
const nowPlayingItem = MusicKit.getInstance().nowPlayingItem;
|
const mk = MusicKit.getInstance()
|
||||||
const isPlayingExport = MusicKit.getInstance().isPlaying;
|
const nowPlayingItem = mk.nowPlayingItem;
|
||||||
const remainingTimeExport = MusicKit.getInstance().currentPlaybackTimeRemaining;
|
const isPlayingExport = mk.isPlaying;
|
||||||
|
const remainingTimeExport = mk.currentPlaybackTimeRemaining;
|
||||||
const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {});
|
const attributes = (nowPlayingItem != null ? nowPlayingItem.attributes : {});
|
||||||
const storefrontId = MusicKit.getInstance().storefrontId;
|
|
||||||
attributes.storefrontId = storefrontId;
|
attributes.storefrontId = storefrontId;
|
||||||
attributes.status = isPlayingExport ?? false;
|
attributes.status = isPlayingExport ?? false;
|
||||||
attributes.name = attributes?.name ?? 'No Title Found';
|
attributes.name = attributes?.name ?? 'No Title Found';
|
||||||
|
@ -51,6 +51,8 @@ const MusicKitInterop = {
|
||||||
attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`,"png");
|
attributes.artwork.url = (attributes?.artwork?.url ?? '').replace(`{f}`,"png");
|
||||||
attributes.playParams = attributes?.playParams ?? { id: 'no-id-found' };
|
attributes.playParams = attributes?.playParams ?? { id: 'no-id-found' };
|
||||||
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
attributes.playParams.id = attributes?.playParams?.id ?? 'no-id-found';
|
||||||
|
attributes.playParams.songid = nowPlayingItem.songId ?? 'no-id-found'
|
||||||
|
attribtues.url = { cider: "https://cider.sh/p?id=" + attributes.playParams.id, appleMusic: "https://music.apple.com/song/" + nowPlayingItem.songId }
|
||||||
if (attributes.playParams.id === 'no-id-found') { attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found'; }
|
if (attributes.playParams.id === 'no-id-found') { attributes.playParams.id = nowPlayingItem?.id ?? 'no-id-found'; }
|
||||||
attributes.albumName = attributes?.albumName ?? '';
|
attributes.albumName = attributes?.albumName ?? '';
|
||||||
attributes.artistName = attributes?.artistName ?? '';
|
attributes.artistName = attributes?.artistName ?? '';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue