diff --git a/music-rpc.ts b/music-rpc.ts index db446d9..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,15 +55,7 @@ class AppleMusicDiscordRPC { } } finally { // Ensure the connection is properly closed - 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; - } - } + this.tryCloseRPC(); } }