Bypasses connect function, new client not needed.

This commit is contained in:
Core 2022-06-03 14:15:43 +01:00
parent 544568c215
commit 69cc7ee6b2
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6

View file

@ -70,13 +70,21 @@ export default class DiscordRPC {
}) })
} }
}) })
ipcMain.handle("reloadRPC", (e) => { ipcMain.on("reloadRPC", () => {
console.log(`[DiscordRPC][reload] Reloading DiscordRPC.`); console.log(`[DiscordRPC][reload] Reloading DiscordRPC.`);
if (this._client) {
this._client.destroy() this._client.destroy()
this._client = null
this._client.endlessLogin({clientId: this._utils.getStoreValue("general.discordrpc.client") === "Cider" ? '911790844204437504' : '886578863147192350'})
.then(() => {
this.ready = true
this._utils.getWindow().webContents.send("rpcReloaded", this._client.user)
if (this._activityCache && this._activityCache.details && this._activityCache.state) {
console.info(`[DiscordRPC][reload] Restoring activity cache.`);
this._client.setActivity(this._activityCache)
} }
this.connect(true) })
.catch((e: any) => console.error(`[DiscordRPC][reload] ${e}`));
// this.connect(true)
}) })
} }
@ -116,11 +124,10 @@ export default class DiscordRPC {
* Connect to Discord RPC * Connect to Discord RPC
* @private * @private
*/ */
private connect(reload = false) { private connect() {
if (!this._utils.getStoreValue("general.discordrpc.enabled")) { if (!this._utils.getStoreValue("general.discordrpc.enabled")) {
return; return;
} }
const clientId = this._utils.getStoreValue("general.discordrpc.client") === "Cider" ? '911790844204437504' : '886578863147192350';
// Create the client // Create the client
this._client = new AutoClient({transport: "ipc"}); this._client = new AutoClient({transport: "ipc"});
@ -133,14 +140,10 @@ export default class DiscordRPC {
console.info(`[DiscordRPC][connect] Restoring activity cache.`); console.info(`[DiscordRPC][connect] Restoring activity cache.`);
this._client.setActivity(this._activityCache) this._client.setActivity(this._activityCache)
} }
if (reload) {
this._utils.getWindow().webContents.send("rpcReloaded", this._client.user)
}
}) })
// Login to Discord // Login to Discord
this._client.endlessLogin({clientId: clientId}) this._client.endlessLogin({clientId: this._utils.getStoreValue("general.discordrpc.client") === "Cider" ? '911790844204437504' : '886578863147192350'})
.then(() => { .then(() => {
this.ready = true this.ready = true
}) })