From 2336b85291305200326fcaa69f751d50ce24336d Mon Sep 17 00:00:00 2001 From: vapormusic Date: Sun, 13 Feb 2022 00:07:16 +0700 Subject: [PATCH] rpc library images ( need api to work first) --- src/main/plugins/discordrpc.ts | 29 +++++++++++-------- src/preload/cider-preload.js | 4 +-- src/renderer/index.js | 2 +- .../views/components/mediaitem-list-item.ejs | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/plugins/discordrpc.ts b/src/main/plugins/discordrpc.ts index 1a444b7f..49bb35df 100644 --- a/src/main/plugins/discordrpc.ts +++ b/src/main/plugins/discordrpc.ts @@ -202,22 +202,27 @@ export default class DiscordRichPresence { * Runs on app ready */ onReady(_win: any): void { + let self = this this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350'); console.debug(`[Plugin][${this.name}] Ready.`); - // ipcMain.on('updateRPCImage', (_event, imageurl) => { - // fetch('https://api.cider.sh/v1/images' ,{ + ipcMain.on('updateRPCImage', (_event, imageurl) => { + fetch('https://api.cider.sh/v1/images' ,{ - // method: 'POST', - // body: JSON.stringify({url : imageurl}), - // headers: { - // 'Content-Type': 'application/json', - // 'User-Agent': 'Cider Development Environment' - // }, - // }) - // .then(res => res.text()) - // .then(json => console.log(json)) + method: 'POST', + body: JSON.stringify({url : imageurl}), + headers: { + 'Content-Type': 'application/json', + 'User-Agent': _win.webContents.getUserAgent() + }, + }) + .then(res => res.json()) + .then(function(json){ + self._activity['largeImageKey'] = json.url + console.log(json.url) + self._client.setActivity(self._activity); + }) - // }) + }) } /** diff --git a/src/preload/cider-preload.js b/src/preload/cider-preload.js index 42990ce2..f6317878 100644 --- a/src/preload/cider-preload.js +++ b/src/preload/cider-preload.js @@ -47,9 +47,9 @@ const MusicKitInterop = { return; } const id = nowPlayingItem?._songId ?? (nowPlayingItem?.songId ?? nowPlayingItem?.id) - if (id != null) { + if (id != null && id != -1) { try{ - const query = await mk.api.v3.music(`/v1${((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`); + const query = await mk.api.v3.music(`/v1${(((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != null) && ((nowPlayingItem?._songId ?? nowPlayingItem?.songId) != -1)) ? `/catalog/${mk.storefrontId}/` : `/me/library/`}songs/${id}?l=${app.mklang}`); if (query?.data?.data[0]){ let attrs = query?.data?.data[0]?.attributes; if (attrs?.name) { nowPlayingItem.attributes.name = attrs?.name ?? ''} diff --git a/src/renderer/index.js b/src/renderer/index.js index e6c2814e..004b1bf4 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -746,7 +746,7 @@ const app = new Vue({ previewURL = app.mk.nowPlayingItem.previewURL } catch (e) { } - if (!previewURL) { + if (previewURL == null && ((app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)) != -1)) { app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)}`).then((response) => { previewURL = response.data.data[0].attributes.previews[0].url if (previewURL) diff --git a/src/renderer/views/components/mediaitem-list-item.ejs b/src/renderer/views/components/mediaitem-list-item.ejs index c2df9efd..fc671c53 100644 --- a/src/renderer/views/components/mediaitem-list-item.ejs +++ b/src/renderer/views/components/mediaitem-list-item.ejs @@ -124,7 +124,7 @@ return } this.$root.inLibrary([this.item]).then(res => { - this.addedToLibrary = res[0].attributes.inLibrary + this.addedToLibrary = res[0]?.attributes?.inLibrary ?? false }) return this.addedToLibrary },