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

@@ -92,7 +92,7 @@ export class LockManager {
async documentVisibilityChanged(visible) {
if(visible) {
const locked = await this.application.isPasscodeLocked();
const locked = await this.application.isLocked();
if(
!locked &&
this.lockAfterDate &&

View File

@@ -1,25 +1,31 @@
import { isDesktopApplication, dictToArray } from '@/utils';
import { SFPredicate, ContentTypes, CreateMaxPayloadFromAnyObject } from 'snjs';
import {
ApplicationEvents,
SFPredicate,
ContentTypes,
CreateMaxPayloadFromAnyObject
} from 'snjs';
const STREAM_ITEMS_PERMISSION = 'stream-items';
/** A class for handling installation of system extensions */
export class NativeExtManager {
/* @ngInject */
constructor(application, appState) {
constructor(application) {
this.application = application;
this.extManagerId = 'org.standardnotes.extensions-manager';
this.batchManagerId = 'org.standardnotes.batch-manager';
application.onUnlock(() => {
this.unsub = application.addSingleEventObserver(ApplicationEvents.Unlocked, () => {
this.reload();
this.streamChanges();
});
}
isSystemExtension(extension) {
return this.nativeExtIds.includes(extension.uuid);
}
streamChanges() {
this.application.streamItems({
contentType: ContentTypes.Component,
@@ -28,7 +34,7 @@ export class NativeExtManager {
}
});
}
reload() {
this.nativeExtIds = [];
// this.resolveExtensionsManager();
@@ -53,12 +59,12 @@ export class NativeExtManager {
{
name: STREAM_ITEMS_PERMISSION,
content_types: [
ContentTypes.Component,
ContentTypes.Theme,
ContentTypes.Component,
ContentTypes.Theme,
ContentTypes.ServerExtension,
ContentTypes.ActionsExtension,
ContentTypes.Mfa,
ContentTypes.Editor,
ContentTypes.ActionsExtension,
ContentTypes.Mfa,
ContentTypes.Editor,
ContentTypes.ExtensionRepo
]
}

View File

@@ -1,4 +1,4 @@
import { SFPredicate, ContentTypes, CreateMaxPayloadFromAnyObject } from 'snjs';
import { ApplicationEvents, SFPredicate, ContentTypes, CreateMaxPayloadFromAnyObject } from 'snjs';
export const PrefKeys = {
TagsPanelWidth: 'tagsPanelWidth',
@@ -24,8 +24,8 @@ export class PreferencesManager {
application
) {
this.application = application;
this.appState = appState;
application.onUnlock(() => {
this.appState = appState;
this.unsub = application.addSingleEventObserver(ApplicationEvents.Unlocked, () => {
this.streamPreferences();
this.loadSingleton();
});

View File

@@ -1,5 +1,5 @@
import _ from 'lodash';
import { ContentTypes, StorageValueModes, EncryptionIntents, PureService } from 'snjs';
import { ApplicationEvents, ContentTypes, StorageValueModes, EncryptionIntents, PureService } from 'snjs';
import { AppStateEvents } from '@/state';
const CACHED_THEMES_KEY = 'cachedThemes';
@@ -16,12 +16,17 @@ export class ThemeManager extends PureService {
this.appState = appState;
this.desktopManager = desktopManager;
this.activeThemes = [];
this.registerObservers();
application.onStart(() => {
if (!desktopManager.isDesktop) {
this.activateCachedThemes();
if (this.application.isStarted()) {
this.onAppStart();
}
this.unsub = application.addEventObserver((event) => {
if (event === ApplicationEvents.Started) {
this.onAppStart();
} else if(event === ApplicationEvents.SignedOut) {
this.deactivateAllThemes();
}
});
this.unsubState = appState.addObserver((eventName, data) => {
if (eventName === AppStateEvents.DesktopExtsReady) {
this.activateCachedThemes();
@@ -29,6 +34,13 @@ export class ThemeManager extends PureService {
});
}
onAppStart() {
this.registerObservers();
if (!this.desktopManager.isDesktop) {
this.activateCachedThemes();
}
}
/** @override */
async deinit() {
super.deinit();
@@ -72,8 +84,8 @@ export class ThemeManager extends PureService {
}
deactivateAllThemes() {
var activeThemes = this.application.componentManager.getActiveThemes();
for (var theme of activeThemes) {
const activeThemes = this.application.componentManager.getActiveThemes();
for (const theme of activeThemes) {
if (theme) {
this.application.componentManager.deactivateComponent(theme);
}
@@ -142,7 +154,7 @@ export class ThemeManager extends PureService {
);
if (cachedThemes) {
const themes = [];
for(const cachedTheme of cachedThemes) {
for (const cachedTheme of cachedThemes) {
const theme = await this.application.createItem({
contentType: ContentTypes.Theme,
content: cachedTheme.content