Skip to content

Commit

Permalink
Abstract logic into method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kile committed Dec 20, 2024
1 parent eea2087 commit d4d8301
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 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,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();
}
}

Expand Down

0 comments on commit d4d8301

Please sign in to comment.