This commit is contained in:
vapormusic 2022-02-12 08:19:58 +07:00
parent 064b287553
commit 1e2978199e
2 changed files with 22 additions and 3 deletions

View file

@ -1,4 +1,6 @@
import * as RPC from 'discord-rpc' import * as RPC from 'discord-rpc'
import {ipcMain} from "electron";
import fetch from 'electron-fetch'
export default class DiscordRichPresence { export default class DiscordRichPresence {
@ -6,6 +8,7 @@ export default class DiscordRichPresence {
* Private variables for interaction in plugins * Private variables for interaction in plugins
*/ */
private static _store: any; private static _store: any;
private _app : any;
private static _connection: boolean = false; private static _connection: boolean = false;
/** /**
@ -29,6 +32,7 @@ export default class DiscordRichPresence {
smallImageText: '', smallImageText: '',
instance: false instance: false
}; };
private _activityCache: RPC.Presence = { private _activityCache: RPC.Presence = {
details: '', details: '',
state: '', state: '',
@ -101,7 +105,7 @@ export default class DiscordRichPresence {
} }
// Check large image // Check large image
if (activity.largeImageKey === null || activity.largeImageKey === ""){ if (activity.largeImageKey == null || activity.largeImageKey === "" || activity.largeImageKey.length > 256) {
activity.largeImageKey = "cider"; activity.largeImageKey = "cider";
} }
@ -169,7 +173,6 @@ export default class DiscordRichPresence {
this._client.setActivity(this._activity) this._client.setActivity(this._activity)
.catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`)); .catch((e: any) => console.error(`[DiscordRichPresence][setActivity] ${e}`));
} }
} else if (this._activity && this._activityCache !== this._activity && this._activity.details) { } else if (this._activity && this._activityCache !== this._activity && this._activity.details) {
if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) { if (!DiscordRichPresence._store.general.discord_rpc_clear_on_pause) {
this._activity.smallImageKey = 'play'; this._activity.smallImageKey = 'play';
@ -190,9 +193,10 @@ export default class DiscordRichPresence {
/** /**
* Runs on plugin load (Currently run on application start) * Runs on plugin load (Currently run on application start)
*/ */
constructor(_app: any, store: any) { constructor(app: any, store: any) {
DiscordRichPresence._store = store DiscordRichPresence._store = store
console.debug(`[Plugin][${this.name}] Loading Complete.`); console.debug(`[Plugin][${this.name}] Loading Complete.`);
this._app = app;
} }
/** /**
@ -201,6 +205,20 @@ export default class DiscordRichPresence {
onReady(_win: any): void { onReady(_win: any): void {
this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350'); this.connect((DiscordRichPresence._store.general.discord_rpc == 1) ? '911790844204437504' : '886578863147192350');
console.debug(`[Plugin][${this.name}] Ready.`); 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))
// })
} }
/** /**

View file

@ -3109,6 +3109,7 @@ const app = new Vue({
data = data.data.data[0]; data = data.data.data[0];
if (data != null && data !== "" && data.attributes != null && data.attributes.artwork != null) { if (data != null && data !== "" && data.attributes != null && data.attributes.artwork != null) {
this.currentArtUrl = (data["attributes"]["artwork"]["url"] ?? '').replace('{w}', 50).replace('{h}', 50); this.currentArtUrl = (data["attributes"]["artwork"]["url"] ?? '').replace('{w}', 50).replace('{h}', 50);
ipcRenderer.send('updateRPCImage', this.currentArtUrl ?? '');
try { try {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`); document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`);
} catch (e) { } catch (e) {