diff --git a/packages/web/src/javascripts/Application/Device/WebOrDesktopDevice.ts b/packages/web/src/javascripts/Application/Device/WebOrDesktopDevice.ts index 47aa4f6c9..579080f66 100644 --- a/packages/web/src/javascripts/Application/Device/WebOrDesktopDevice.ts +++ b/packages/web/src/javascripts/Application/Device/WebOrDesktopDevice.ts @@ -35,8 +35,19 @@ export abstract class WebOrDesktopDevice implements WebOrDesktopDeviceInterface removeApplication(application: ApplicationInterface): void { const database = this.databaseForIdentifier(application.identifier) - database.deinit() - this.databases = this.databases.filter((db) => db !== database) + + if (database) { + database.deinit() + this.databases = this.databases.filter((db) => db !== database) + } + } + + deinit() { + for (const database of this.databases) { + database.deinit() + } + + this.databases = [] } public async getJsonParsedRawStorageValue(key: string): Promise { @@ -66,14 +77,6 @@ export abstract class WebOrDesktopDevice implements WebOrDesktopDeviceInterface return { killsApplication: false } } - deinit() { - for (const database of this.databases) { - database.deinit() - } - - this.databases = [] - } - async getRawStorageValue(key: string): Promise { const result = localStorage.getItem(key) diff --git a/packages/web/src/javascripts/Application/WebApplication.ts b/packages/web/src/javascripts/Application/WebApplication.ts index d7e187ccc..36c6bd96b 100644 --- a/packages/web/src/javascripts/Application/WebApplication.ts +++ b/packages/web/src/javascripts/Application/WebApplication.ts @@ -152,6 +152,10 @@ export class WebApplication extends SNApplication implements WebApplicationInter override deinit(mode: DeinitMode, source: DeinitSource): void { super.deinit(mode, source) + if (!this.isNativeMobileWeb()) { + this.webOrDesktopDevice().removeApplication(this) + } + try { for (const service of Object.values(this.webServices)) { if (!service) { @@ -278,6 +282,10 @@ export class WebApplication extends SNApplication implements WebApplicationInter return this.deviceInterface as MobileDeviceInterface } + webOrDesktopDevice(): WebOrDesktopDevice { + return this.deviceInterface as WebOrDesktopDevice + } + public getThemeService() { return this.webServices.themeService }