fix: improve deinit logic and flow
This commit is contained in:
@@ -93,7 +93,6 @@ export class AppState {
|
||||
|
||||
private readonly tagChangedDisposer: IReactionDisposer;
|
||||
|
||||
/* @ngInject */
|
||||
constructor(application: WebApplication, private bridge: Bridge) {
|
||||
this.application = application;
|
||||
this.notes = new NotesState(
|
||||
@@ -171,18 +170,39 @@ export class AppState {
|
||||
storage.remove(StorageKey.ShowBetaWarning);
|
||||
this.noAccountWarning.reset();
|
||||
}
|
||||
(this.application as unknown) = undefined;
|
||||
this.actionsMenu.reset();
|
||||
this.unsubApp?.();
|
||||
this.unsubApp = undefined;
|
||||
this.observers.length = 0;
|
||||
|
||||
this.appEventObserverRemovers.forEach((remover) => remover());
|
||||
this.features.deinit();
|
||||
this.appEventObserverRemovers.length = 0;
|
||||
|
||||
this.features.deinit();
|
||||
(this.features as unknown) = undefined;
|
||||
|
||||
this.webAppEventDisposer?.();
|
||||
this.webAppEventDisposer = undefined;
|
||||
|
||||
(this.quickSettingsMenu as unknown) = undefined;
|
||||
(this.accountMenu as unknown) = undefined;
|
||||
(this.actionsMenu as unknown) = undefined;
|
||||
(this.preferences as unknown) = undefined;
|
||||
(this.purchaseFlow as unknown) = undefined;
|
||||
(this.noteTags as unknown) = undefined;
|
||||
(this.sync as unknown) = undefined;
|
||||
(this.searchOptions as unknown) = undefined;
|
||||
(this.notes as unknown) = undefined;
|
||||
(this.features as unknown) = undefined;
|
||||
(this.tags as unknown) = undefined;
|
||||
(this.notesView as unknown) = undefined;
|
||||
|
||||
document.removeEventListener('visibilitychange', this.onVisibilityChange);
|
||||
this.onVisibilityChange = undefined;
|
||||
|
||||
this.tagChangedDisposer();
|
||||
(this.tagChangedDisposer as unknown) = undefined;
|
||||
}
|
||||
|
||||
openSessionsModal(): void {
|
||||
|
||||
@@ -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