From 61ffe117b475ada51657eb6d830c821f92dddfe3 Mon Sep 17 00:00:00 2001 From: Botzy Date: Tue, 2 Jun 2026 15:49:15 +0300 Subject: [PATCH] fix: clean up on unmount --- src/App/App.js | 1 + src/services/Discord/Discord.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/App/App.js b/src/App/App.js index 95eefa8b8..68d811c30 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -106,6 +106,7 @@ const App = () => { return () => { services.chromecast.stop(); services.chromecast.off('stateChanged', onChromecastStateChange); + services.discord.destroy(); }; }, []); diff --git a/src/services/Discord/Discord.ts b/src/services/Discord/Discord.ts index e790651a7..1d30b3a93 100644 --- a/src/services/Discord/Discord.ts +++ b/src/services/Discord/Discord.ts @@ -9,6 +9,7 @@ type DiscordStatusData = { class Discord { private events: EventEmitter; private shell: any; + private onDiscordStatus: ((data: DiscordStatusData) => void) | null = null; constructor() { this.events = new EventEmitter(); @@ -19,18 +20,22 @@ class Discord { this.shell = shellService; if (this.shell) { - this.shell.on('stateChanged', () => { + this.onDiscordStatus = (data: DiscordStatusData) => { this.events.emit('availabilityChanged', this.available); - }); - } - - if (this.shell) { - this.shell.on('discord-status', (data: DiscordStatusData) => { this.events.emit('statusChanged', data.connected); - }); + }; + this.shell.on('discord-status', this.onDiscordStatus); } } + destroy(): void { + if (this.shell && this.onDiscordStatus) { + this.shell.off('discord-status', this.onDiscordStatus); + this.onDiscordStatus = null; + } + this.shell = null; + } + connect(): void { if (this.shell && this.shell.active) { this.shell.send('discord-connect', {});