snappymail/dev/Stores/Theme.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

import ko from 'ko';
2021-07-20 22:49:03 +08:00
import { doc, $htmlCL, leftPanelDisabled, Settings, SettingsGet } from 'Common/Globals';
import { isArray } from 'Common/Utils';
2021-07-20 22:49:03 +08:00
import { serverRequestRaw } from 'Common/Links';
export const ThemeStore = {
themes: ko.observableArray(),
userBackgroundName: ko.observable(''),
userBackgroundHash: ko.observable(''),
isMobile: ko.observable($htmlCL.contains('rl-mobile')),
populate: function(){
2021-03-10 18:44:48 +08:00
const themes = Settings.app('themes');
this.themes(isArray(themes) ? themes : []);
2021-03-10 18:44:48 +08:00
this.theme(SettingsGet('Theme'));
if (!this.isMobile()) {
2021-03-10 18:44:48 +08:00
this.userBackgroundName(SettingsGet('UserBackgroundName'));
this.userBackgroundHash(SettingsGet('UserBackgroundHash'));
}
leftPanelDisabled(this.isMobile());
}
};
ThemeStore.theme = ko.observable('').extend({ limitedList: ThemeStore.themes });
ThemeStore.isMobile.subscribe(value => $htmlCL.toggle('rl-mobile', value));
2021-07-20 22:49:03 +08:00
ThemeStore.userBackgroundHash.subscribe(value => {
if (value) {
$htmlCL.add('UserBackground');
doc.body.style.backgroundImage = "url("+serverRequestRaw('UserBackground', value)+")";
} else {
$htmlCL.remove('UserBackground');
doc.body.removeAttribute('style');
}
});