Reload function changed to give response

This commit is contained in:
Core 2022-06-03 13:40:20 +01:00
parent 912f2e8f30
commit 3092880ba6
No known key found for this signature in database
GPG key ID: FE9BF1B547F8F3C6

View file

@ -70,7 +70,14 @@ export default class DiscordRPC {
})
}
})
ipcMain.on("reloadRPC", () => this.reload())
ipcMain.handle("reloadRPC", (e) => {
console.log(`[DiscordRPC][reload] Reloading DiscordRPC.`);
if (this._client) {
this._client.destroy()
this._client = null
}
this.connect(true)
})
}
/**
@ -109,7 +116,7 @@ export default class DiscordRPC {
* Connect to Discord RPC
* @private
*/
private connect() {
private connect(reload = false) {
if (!this._utils.getStoreValue("general.discordrpc.enabled")) {
return;
}
@ -126,6 +133,10 @@ export default class DiscordRPC {
console.info(`[DiscordRPC][connect] Restoring activity cache.`);
this._client.setActivity(this._activityCache)
}
if (reload) {
this._utils.getWindow().webContents.send("rpcReloaded", this._client.user)
}
})
// Login to Discord
@ -258,14 +269,4 @@ export default class DiscordRPC {
}
return activity
}
/**
* Reloads DiscordRPC
*/
private reload() {
if (this._client) {
this._client.destroy()
}
this.connect()
}
}