Cache active themes
This commit is contained in:
@@ -1,9 +1,27 @@
|
|||||||
class ThemeManager {
|
class ThemeManager {
|
||||||
|
|
||||||
constructor(componentManager, desktopManager) {
|
constructor(componentManager, desktopManager, storageManager) {
|
||||||
this.componentManager = componentManager;
|
this.componentManager = componentManager;
|
||||||
|
this.storageManager = storageManager;
|
||||||
|
this.desktopManager = desktopManager;
|
||||||
|
this.activeThemes = [];
|
||||||
|
|
||||||
desktopManager.registerUpdateObserver((component) => {
|
ThemeManager.CachedThemesKey = "cachedThemes";
|
||||||
|
|
||||||
|
this.registerObservers();
|
||||||
|
this.activateCachedThemes();
|
||||||
|
}
|
||||||
|
|
||||||
|
activateCachedThemes() {
|
||||||
|
let cachedThemes = this.getCachedThemes();
|
||||||
|
let writeToCache = false;
|
||||||
|
for(var theme of cachedThemes) {
|
||||||
|
this.activateTheme(theme, writeToCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerObservers() {
|
||||||
|
this.desktopManager.registerUpdateObserver((component) => {
|
||||||
// Reload theme if active
|
// Reload theme if active
|
||||||
if(component.active && component.isTheme()) {
|
if(component.active && component.isTheme()) {
|
||||||
this.deactivateTheme(component);
|
this.deactivateTheme(component);
|
||||||
@@ -13,7 +31,7 @@ class ThemeManager {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
componentManager.registerHandler({identifier: "themeManager", areas: ["themes"], activationHandler: (component) => {
|
this.componentManager.registerHandler({identifier: "themeManager", areas: ["themes"], activationHandler: (component) => {
|
||||||
if(component.active) {
|
if(component.active) {
|
||||||
this.activateTheme(component);
|
this.activateTheme(component);
|
||||||
} else {
|
} else {
|
||||||
@@ -33,9 +51,19 @@ class ThemeManager {
|
|||||||
this.componentManager.deactivateComponent(theme);
|
this.componentManager.deactivateComponent(theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.decacheThemes();
|
||||||
}
|
}
|
||||||
|
|
||||||
activateTheme(theme) {
|
activateTheme(theme, writeToCache = true) {
|
||||||
|
if(_.find(this.activeThemes, {uuid: theme.uuid})) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Activating theme", theme.uuid);
|
||||||
|
|
||||||
|
this.activeThemes.push(theme);
|
||||||
|
|
||||||
var url = this.componentManager.urlForComponent(theme);
|
var url = this.componentManager.urlForComponent(theme);
|
||||||
var link = document.createElement("link");
|
var link = document.createElement("link");
|
||||||
link.href = url;
|
link.href = url;
|
||||||
@@ -44,6 +72,10 @@ class ThemeManager {
|
|||||||
link.media = "screen,print";
|
link.media = "screen,print";
|
||||||
link.id = theme.uuid;
|
link.id = theme.uuid;
|
||||||
document.getElementsByTagName("head")[0].appendChild(link);
|
document.getElementsByTagName("head")[0].appendChild(link);
|
||||||
|
|
||||||
|
if(writeToCache) {
|
||||||
|
this.cacheThemes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivateTheme(theme) {
|
deactivateTheme(theme) {
|
||||||
@@ -52,6 +84,37 @@ class ThemeManager {
|
|||||||
element.disabled = true;
|
element.disabled = true;
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_.remove(this.activeThemes, {uuid: theme.uuid});
|
||||||
|
|
||||||
|
this.cacheThemes();
|
||||||
|
}
|
||||||
|
|
||||||
|
async cacheThemes() {
|
||||||
|
let mapped = await Promise.all(this.activeThemes.map(async (theme) => {
|
||||||
|
let transformer = new SFItemParams(theme);
|
||||||
|
let params = await transformer.paramsForLocalStorage();
|
||||||
|
return params;
|
||||||
|
}));
|
||||||
|
let data = JSON.stringify(mapped);
|
||||||
|
console.log("Caching themes", data);
|
||||||
|
return this.storageManager.setItem(ThemeManager.CachedThemesKey, data, StorageManager.Fixed);
|
||||||
|
}
|
||||||
|
|
||||||
|
async decacheThemes() {
|
||||||
|
return this.storageManager.removeItem(ThemeManager.CachedThemesKey, StorageManager.Fixed);
|
||||||
|
}
|
||||||
|
|
||||||
|
getCachedThemes() {
|
||||||
|
let cachedThemes = this.storageManager.getItemSync(ThemeManager.CachedThemesKey, StorageManager.Fixed);
|
||||||
|
if(cachedThemes) {
|
||||||
|
let parsed = JSON.parse(cachedThemes);
|
||||||
|
return parsed.map((theme) => {
|
||||||
|
return new SNTheme(theme);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,24 +12,17 @@
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|
||||||
z-index: $z-index-lock-screen;
|
z-index: $z-index-lock-screen;
|
||||||
background-color: var(--sn-stylekit-contrast-background-color);
|
background-color: var(--sn-stylekit-background-color);
|
||||||
color: var(--sn-stylekit-foreground-color);
|
color: var(--sn-stylekit-foreground-color);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
.background {
|
|
||||||
position: absolute;
|
|
||||||
z-index: -1;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sk-panel {
|
.sk-panel {
|
||||||
width: 315px;
|
width: 315px;
|
||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
border-radius: 0;
|
// border-radius: 0;
|
||||||
|
|
||||||
.sk-panel-header {
|
.sk-panel-header {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
%div{"ng-if" => "formData.showRecovery"}
|
%div{"ng-if" => "formData.showRecovery"}
|
||||||
.sk-p
|
.sk-p
|
||||||
If you forgot your local passcode, your only option is to clear all your local data from this device
|
If you forgot your local passcode, your only option is to clear your local data from this device
|
||||||
and sign back in to your account.
|
and sign back in to your account.
|
||||||
%a.sk-a.danger{"ng-click" => "beginDeleteData()"} Delete Local Data
|
.sk-panel-row
|
||||||
|
%a.sk-a.danger.center-text{"ng-click" => "beginDeleteData()"} Delete Local Data
|
||||||
|
|||||||
Reference in New Issue
Block a user