fix: clean up on unmount

This commit is contained in:
Botzy 2026-06-02 15:49:15 +03:00
parent 76acf1a0f2
commit 61ffe117b4
2 changed files with 13 additions and 7 deletions

View file

@ -106,6 +106,7 @@ const App = () => {
return () => {
services.chromecast.stop();
services.chromecast.off('stateChanged', onChromecastStateChange);
services.discord.destroy();
};
}, []);

View file

@ -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', {});