ApplicationService integration

This commit is contained in:
Mo Bitar
2020-03-20 19:03:02 -05:00
parent 0ec0fd4872
commit 0ef1ce8ef1
9 changed files with 897 additions and 447 deletions

View File

@@ -3,34 +3,23 @@ import {
ApplicationEvents,
StorageValueModes,
EncryptionIntents,
PureService,
ApplicationService,
} from 'snjs';
import { AppStateEvents } from '@/state';
const CACHED_THEMES_KEY = 'cachedThemes';
export class ThemeManager extends PureService {
export class ThemeManager extends ApplicationService {
/* @ngInject */
constructor(
application,
appState,
desktopManager,
) {
super();
this.application = application;
super(application);
this.appState = appState;
this.desktopManager = desktopManager;
this.activeThemes = [];
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();
@@ -38,18 +27,20 @@ export class ThemeManager extends PureService {
});
}
/** @override */
onAppStart() {
super.onAppStart();
this.registerObservers();
if (!this.desktopManager.isDesktop) {
this.activateCachedThemes();
}
}
/** @override */
async deinit() {
super.deinit();
this.unsubState();
this.activeThemes = [];
onAppEvent(eventName) {
super.onAppEvent(eventName);
if (eventName === ApplicationEvents.SignedOut) {
this.deactivateAllThemes();
}
}
async activateCachedThemes() {