From dda4a4e28fc8701f580006ff121ef0023b0424c9 Mon Sep 17 00:00:00 2001 From: Kile <69253692+Kile@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:20:37 +0000 Subject: [PATCH] Fix un-catched exception (#120) --- music-rpc.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/music-rpc.ts b/music-rpc.ts index 316e3c0..bb5aa9b 100755 --- a/music-rpc.ts +++ b/music-rpc.ts @@ -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 { try { await this.rpc.connect(); @@ -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(); } }