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')),
2022-03-08 17:52:40 +08:00
populate: () => {
2021-03-10 18:44:48 +08:00
const themes = Settings.app('themes');
2022-03-08 17:52:40 +08:00
ThemeStore.themes(isArray(themes) ? themes : []);
ThemeStore.theme(SettingsGet('Theme'));
if (!ThemeStore.isMobile()) {
ThemeStore.userBackgroundName(SettingsGet('UserBackgroundName'));
ThemeStore.userBackgroundHash(SettingsGet('UserBackgroundHash'));
}
2022-03-08 17:52:40 +08:00
leftPanelDisabled(ThemeStore.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');
}
});