[PE mobile] keep current theme type for next launch

This commit is contained in:
Maxim Kadushkin 2021-11-18 22:40:59 +03:00
parent d1bd1c67fa
commit f0b21727cb
2 changed files with 5 additions and 20 deletions

View file

@ -2,6 +2,7 @@ import React, { Component } from "react";
import { ApplicationSettings } from "../../view/settings/ApplicationSettings";
import { LocalStorage } from '../../../../../common/mobile/utils/LocalStorage';
import {observer, inject} from "mobx-react";
import { Themes } from '../../../../../common/mobile/lib/controller/Themes.js';
class ApplicationSettingsController extends Component {
constructor(props) {
@ -26,29 +27,12 @@ class ApplicationSettingsController extends Component {
LocalStorage.setItem("pe-mobile-macros-mode", value);
}
switchDarkTheme(value) {
const theme = value ? {id:'theme-dark', type:'dark'} : {id:'theme-light', type:'light'};
LocalStorage.setItem("ui-theme", JSON.stringify(theme));
const $body = $$('body');
$body.attr('class') && $body.attr('class', $body.attr('class').replace(/\s?theme-type-(?:dark|light)/, ''));
$body.addClass(`theme-type-${theme.type}`);
}
isThemeDark() {
const obj = LocalStorage.getItem("ui-theme");
return !!obj ? JSON.parse(obj).type === 'dark' : false;
}
render() {
return (
<ApplicationSettings
setUnitMeasurement={this.setUnitMeasurement}
switchSpellCheck={this.switchSpellCheck}
setMacrosSettings={this.setMacrosSettings}
isThemeDark={this.isThemeDark}
switchDarkTheme={this.switchDarkTheme}
setMacrosSettings={this.setMacrosSettings}
/>
)
}

View file

@ -2,6 +2,7 @@ import React, {Fragment, useState} from "react";
import { observer, inject } from "mobx-react";
import { Page, Navbar, List, ListItem, BlockTitle, Toggle } from "framework7-react";
import { useTranslation } from "react-i18next";
import { Themes } from '../../../../../common/mobile/lib/controller/Themes.js';
const PageApplicationSettings = props => {
const { t } = useTranslation();
@ -9,7 +10,7 @@ const PageApplicationSettings = props => {
const store = props.storeApplicationSettings;
const unitMeasurement = store.unitMeasurement;
const isSpellChecking = store.isSpellChecking;
const [isThemeDark, setIsThemeDark] = useState(props.isThemeDark);
const [isThemeDark, setIsThemeDark] = useState(Themes.isCurrentDark);
const changeMeasureSettings = value => {
store.changeUnitMeasurement(value);
@ -47,7 +48,7 @@ const PageApplicationSettings = props => {
</ListItem>
<ListItem title={'Dark theme'}>
<Toggle checked={isThemeDark}
onToggleChange={toggle => {props.switchDarkTheme(!toggle), setIsThemeDark(!toggle)}}>
onToggleChange={toggle => {Themes.switchDarkTheme(!toggle), setIsThemeDark(!toggle)}}>
</Toggle>
</ListItem>
</List>