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