diff --git a/app/services/app/app.ts b/app/services/app/app.ts index b9fb29a19d23..766734b9bc7c 100644 --- a/app/services/app/app.ts +++ b/app/services/app/app.ts @@ -48,6 +48,7 @@ import { StreamAvatarService } from 'services/stream-avatar/stream-avatar-servic import { NavigationService } from 'services/navigation'; import { StreamingService } from 'services/streaming'; import { VirtualWebcamService } from 'services/virtual-webcam'; +import { WebsocketService } from 'services/websocket'; interface IAppState { loading: boolean; @@ -104,6 +105,7 @@ export class AppService extends StatefulService { @Inject() private navigationService: NavigationService; @Inject() private streamingService: StreamingService; @Inject() private virtualWebcamService: VirtualWebcamService; + @Inject() private websocketService: WebsocketService; static initialState: IAppState = { loading: true, @@ -213,6 +215,8 @@ export class AppService extends StatefulService { this.streamAvatarService.stopAvatarProcess(); this.crashReporterService.beginShutdown(); this.shutdownStarted.next(); + this.recentEventsService.shutdown(); + this.websocketService.disconnect(); this.keyListenerService.shutdown(); this.platformAppsService.unloadAllApps(); await this.usageStatisticsService.flushEvents(); @@ -232,6 +236,7 @@ export class AppService extends StatefulService { obs.NodeObs.RemoveVolmeterCallback(); obs.NodeObs.OBS_service_removeCallback(); obs.IPC.disconnect(); + this.realmService.close(); this.crashReporterService.endShutdown(); electron.ipcRenderer.send('shutdownComplete'); }, 300); diff --git a/app/services/realm.ts b/app/services/realm.ts index def72002403b..11abdada8830 100644 --- a/app/services/realm.ts +++ b/app/services/realm.ts @@ -374,6 +374,11 @@ export class RealmService extends Service { this.ephemeralDb = await Realm.open(this.ephemeralConfig as any); } + close() { + this.persistentDb?.close(); + this.ephemeralDb?.close(); + } + executeMigrations(oldRealm: Realm, newRealm: Realm) { Object.values(RealmService.registeredClasses).forEach(klass => { klass.onMigration(oldRealm, newRealm); diff --git a/app/services/recent-events.ts b/app/services/recent-events.ts index 99da4dd08e76..bab3d70b2835 100644 --- a/app/services/recent-events.ts +++ b/app/services/recent-events.ts @@ -472,6 +472,10 @@ export class RecentEventsService extends StatefulService { this.unsubscribeFromSocketConnection(); } + shutdown() { + this.unsubscribeFromSocketConnection(); + } + fetchRecentEvents() { const typeString = this.getEventTypesString(); // eslint-disable-next-line diff --git a/app/services/websocket.ts b/app/services/websocket.ts index 98c20453e80c..0d1387b40515 100644 --- a/app/services/websocket.ts +++ b/app/services/websocket.ts @@ -244,6 +244,13 @@ export class WebsocketService extends Service { }); } + disconnect() { + if (this.socket) { + this.socket.disconnect(); + this.socket = undefined; + } + } + private log(message: string, ...args: any[]) { console.debug(`WS: ${message}`, ...args);