diff --git a/src/main/plugins/discordrpc.ts b/src/main/plugins/discordrpc.ts index f30c68c8..31e8d81f 100644 --- a/src/main/plugins/discordrpc.ts +++ b/src/main/plugins/discordrpc.ts @@ -1,4 +1,6 @@ import * as RPC from 'discord-rpc' +import {ipcMain} from "electron"; +import fetch from 'electron-fetch' export default class DiscordRichPresence { @@ -6,6 +8,7 @@ export default class DiscordRichPresence { * Private variables for interaction in plugins */ private static _store: any; + private _app : any; private static _connection: boolean = false; /** @@ -29,6 +32,7 @@ export default class DiscordRichPresence { smallImageText: '', instance: false }; + private _activityCache: RPC.Presence = { details: '', state: '', @@ -101,7 +105,7 @@ export default class DiscordRichPresence { } // Check large image - if (activity.largeImageKey === null || activity.largeImageKey === ""){ + if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) { activity.largeImageKey = "cider"; } @@ -169,7 +173,6 @@ export default class DiscordRichPresence { this._client.setActivity(this._activity) .catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`)); } - } else if (this._activity && this._activityCache !== this._activity && this._activity.details) { if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) { this._activity.smallImageKey = 'play'; @@ -190,9 +193,10 @@ export default class DiscordRichPresence { /** * Runs on plugin load (Currently run on application start) */ - constructor(_app: any, store: any) { + constructor(app: any, store: any) { DiscordRichPresence._store = store console.debug(`[Plugin][${this.name}] Loading Complete.`); + this._app = app; } /** @@ -201,6 +205,20 @@ export default class DiscordRichPresence { onReady(_win: any): void { 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' ,{ + + // 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)) + + // }) } /** diff --git a/src/renderer/index.js b/src/renderer/index.js index 2c91af90..72c9248e 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -3109,6 +3109,7 @@ const app = new Vue({ data = data.data.data[0]; if (data != null && data !== "" && data.attributes != null && data.attributes.artwork != null) { this.currentArtUrl = (data["attributes"]["artwork"]["url"] ?? '').replace('{w}', 50).replace('{h}', 50); + ipcRenderer.send('updateRPCImage', this.currentArtUrl ?? ''); try { document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`); } catch (e) {