fix: improve deinit logic and flow
This commit is contained in:
@@ -39,8 +39,8 @@ export type WebEventObserver = (event: WebAppEvent) => void;
|
||||
|
||||
export class WebApplication extends SNApplication {
|
||||
private webServices!: WebServices;
|
||||
public noteControllerGroup: NoteGroupController;
|
||||
private webEventObservers: WebEventObserver[] = [];
|
||||
public noteControllerGroup: NoteGroupController;
|
||||
public iconsController: IconsController;
|
||||
|
||||
constructor(
|
||||
@@ -70,28 +70,26 @@ export class WebApplication extends SNApplication {
|
||||
this.iconsController = new IconsController();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
deinit(source: DeinitSource): void {
|
||||
for (const service of Object.values(this.webServices)) {
|
||||
if ('deinit' in service) {
|
||||
service.deinit?.(source);
|
||||
super.deinit(source);
|
||||
try {
|
||||
for (const service of Object.values(this.webServices)) {
|
||||
if ('deinit' in service) {
|
||||
service.deinit?.(source);
|
||||
}
|
||||
(service as any).application = undefined;
|
||||
}
|
||||
(service as any).application = undefined;
|
||||
}
|
||||
this.webServices = {} as WebServices;
|
||||
this.noteControllerGroup.deinit();
|
||||
this.iconsController.deinit();
|
||||
this.webEventObservers.length = 0;
|
||||
/**
|
||||
* Allow any pending renders to complete before destroying the global
|
||||
* application instance and all its services
|
||||
*/
|
||||
setTimeout(() => {
|
||||
super.deinit(source);
|
||||
this.webServices = {} as WebServices;
|
||||
this.noteControllerGroup.deinit();
|
||||
this.iconsController.deinit();
|
||||
this.webEventObservers.length = 0;
|
||||
|
||||
if (source === DeinitSource.SignOut) {
|
||||
this.bridge.onSignOut();
|
||||
}
|
||||
}, 0);
|
||||
} catch (error) {
|
||||
console.error('Error while deiniting application', error);
|
||||
}
|
||||
}
|
||||
|
||||
setWebServices(services: WebServices): void {
|
||||
|
||||
Reference in New Issue
Block a user