Functioning UI

This commit is contained in:
Mo Bitar
2020-02-08 18:57:02 -06:00
parent f6ef4a39e2
commit 8822580e7a
23 changed files with 2088 additions and 1729 deletions

View File

@@ -1,5 +1,5 @@
import _ from 'lodash';
import { SNTheme, StorageValueModes, EncryptionIntents } from 'snjs';
import { ContentTypes, StorageValueModes, EncryptionIntents } from 'snjs';
import { AppStateEvents } from '@/state';
const CACHED_THEMES_KEY = 'cachedThemes';
@@ -16,9 +16,16 @@ export class ThemeManager {
this.desktopManager = desktopManager;
this.activeThemes = [];
this.registerObservers();
if (!desktopManager.isDesktop) {
this.activateCachedThemes();
}
application.onReady(() => {
if (!desktopManager.isDesktop) {
this.activateCachedThemes();
}
});
appState.addObserver((eventName, data) => {
if (eventName === AppStateEvents.DesktopExtsReady) {
this.activateCachedThemes();
}
});
}
async activateCachedThemes() {
@@ -30,11 +37,6 @@ export class ThemeManager {
}
registerObservers() {
this.appState.addObserver((eventName, data) => {
if (eventName === AppStateEvents.DesktopExtsReady) {
this.activateCachedThemes();
}
});
this.desktopManager.registerUpdateObserver((component) => {
// Reload theme if active
if (component.active && component.isTheme()) {
@@ -112,10 +114,9 @@ export class ThemeManager {
});
return processedPayload;
}));
const data = JSON.stringify(mapped);
return this.application.setValue(
CACHED_THEMES_KEY,
data,
mapped,
StorageValueModes.Nonwrapped
);
}
@@ -133,10 +134,15 @@ export class ThemeManager {
StorageValueModes.Nonwrapped
);
if (cachedThemes) {
const parsed = JSON.parse(cachedThemes);
return parsed.map((theme) => {
return new SNTheme(theme);
});
const themes = [];
for(const cachedTheme of cachedThemes) {
const theme = await this.application.createItem({
contentType: ContentTypes.Theme,
content: cachedTheme.content
});
themes.push(theme);
}
return themes;
} else {
return [];
}