rpc library images ( need api to work first)

This commit is contained in:
vapormusic 2022-02-13 00:07:16 +07:00
parent 802436e875
commit 2336b85291
4 changed files with 21 additions and 16 deletions

View file

@ -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);
})
// })
})
}
/**

View file

@ -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 ?? ''}

View file

@ -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)

View file

@ -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
},