Improve event handling + restarts

This commit is contained in:
Mo Bitar
2020-02-12 14:21:58 -06:00
parent 0fcfd98e5d
commit a364a9ec03
19 changed files with 1202 additions and 814 deletions

View File

@@ -1,6 +1,6 @@
import { isDesktopApplication } from '@/utils';
import pull from 'lodash/pull';
import { ProtectedActions } from 'snjs';
import { ProtectedActions, ApplicationEvents } from 'snjs';
export const AppStateEvents = {
TagChanged: 1,
@@ -33,7 +33,23 @@ export class AppState {
this.application = application;
this.godService = godService;
this.observers = [];
this.locked = true;
this.registerVisibilityObservers();
this.addAppEventObserver();
}
addAppEventObserver() {
this.unsubApp = this.application.addEventObserver(async (eventName) => {
if (eventName === ApplicationEvents.Started) {
this.locked = true;
} else if (eventName === ApplicationEvents.Unlocked) {
this.locked = false;
}
});
}
isLocked() {
return this.locked;
}
registerVisibilityObservers() {
@@ -87,9 +103,9 @@ export class AppState {
this.selectedTag = tag;
this.notifyEvent(
AppStateEvents.TagChanged,
{
{
tag: tag,
previousTag: previousTag
previousTag: previousTag
}
);
}