Skip to content

Commit

Permalink
Fix un-catched exception (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kile authored Dec 20, 2024
1 parent feb4a8f commit dda4a4e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions music-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ class AppleMusicDiscordRPC {
}
}

tryCloseRPC(): void {
if (this.rpc.ipc) {
console.log("Attempting to close connection to Discord RPC");
try {
this.rpc.close();
} finally {
console.log("Connection to Discord RPC closed");
this.rpc.ipc = undefined;
}
}
}

async setActivityLoop(): Promise<void> {
try {
await this.rpc.connect();
Expand All @@ -43,11 +55,7 @@ class AppleMusicDiscordRPC {
}
} finally {
// Ensure the connection is properly closed
if (this.rpc.ipc) {
console.log("Closing connection to Discord RPC");
this.rpc.close();
this.rpc.ipc = undefined;
}
this.tryCloseRPC();
}
}

Expand Down

0 comments on commit dda4a4e

Please sign in to comment.