fix: async-await for toggle and cleanup discordRPC

This commit is contained in:
Fazri Gading
2026-01-26 05:05:25 +08:00
parent ba95187ee6
commit d285dc7517

13
main.js
View File

@@ -82,7 +82,7 @@ function setDiscordActivity() {
}
}
function toggleDiscordRPC(enabled) {
async function toggleDiscordRPC(enabled) {
console.log('Toggling Discord RPC:', enabled);
if (enabled && !discordRPC) {
@@ -92,11 +92,12 @@ function toggleDiscordRPC(enabled) {
try {
console.log('Disconnecting Discord RPC...');
discordRPC.clearActivity();
await new Promise(r => setTimeout(r, 100));
discordRPC.destroy();
discordRPC = null;
console.log('Discord RPC disconnected successfully');
} catch (error) {
console.error('Error disconnecting Discord RPC:', error.message);
} finally {
discordRPC = null;
}
}
@@ -367,19 +368,19 @@ app.whenReady().then(async () => {
}, 3000);
});
function cleanupDiscordRPC() {
if (discordRPC) {
async function cleanupDiscordRPC() {
if (!discordRPC) return;
try {
console.log('Cleaning up Discord RPC...');
discordRPC.clearActivity();
await new Promise(r => setTimeout(r, 100));
discordRPC.destroy();
discordRPC = null;
console.log('Discord RPC cleaned up successfully');
} catch (error) {
console.log('Error cleaning up Discord RPC:', error.message);
} finally {
discordRPC = null;
}
}
}
app.on('before-quit', () => {