Removed using and added check on local storage

This commit is contained in:
SergeyEzhin
2023-10-26 15:27:15 +02:00
parent afe060f19e
commit 70af3ef918
5 changed files with 32 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react';
import { f7, ListItem, List, Icon } from 'framework7-react';
import { useTranslation } from 'react-i18next';
import { LocalStorage } from '../../utils/LocalStorage.mjs';
const ThemeColors = ({ themeColors, onColorClick, curColor, isTypeColors, isTypeCustomColors }) => {
return (
@ -110,7 +111,7 @@ const ThemeColorPalette = props => {
let customColors = props.customColors;
if (customColors.length < 1) {
customColors = localStorage.getItem('mobile-custom-colors');
customColors = LocalStorage.getItem('mobile-custom-colors');
customColors = customColors ? customColors.toLowerCase().split(',') : [];
}
@ -177,11 +178,11 @@ const CustomColorPicker = props => {
});
const addNewColor = (color) => {
let colors = localStorage.getItem('mobile-custom-colors');
let colors = LocalStorage.getItem('mobile-custom-colors');
colors = colors ? colors.split(',') : [];
const newColor = color.slice(1);
if (colors.push(newColor) > countDynamicColors) colors.shift(); // 10 - dynamiccolors
localStorage.setItem('mobile-custom-colors', colors.join().toLowerCase());
LocalStorage.setItem('mobile-custom-colors', colors.join().toLowerCase());
props.onAddNewColor && props.onAddNewColor(colors, newColor);
};

View File

@ -8,18 +8,35 @@ const load_stylesheet = reflink => {
document.getElementsByTagName("head")[0].appendChild(link);
};
if ( !!window.Android && window.Android.editorConfig ) {
if(!!window.Android && window.Android.editorConfig) {
window.native = {editorConfig: window.Android.editorConfig()}
}
if ( localStorage && localStorage.getItem('mobile-mode-direction') === 'rtl' ) {
load_stylesheet('./css/framework7-rtl.css')
document.body.classList.add('rtl');
function isLocalStorageAvailable() {
try {
const testKey = 'test';
localStorage.setItem(testKey, '1');
localStorage.removeItem(testKey);
return true;
} catch (e) {
return false;
}
}
if(isLocalStorageAvailable()) {
if(localStorage.getItem('mobile-mode-direction') === 'rtl') {
load_stylesheet('./css/framework7-rtl.css');
document.body.classList.add('rtl');
} else {
load_stylesheet('./css/framework7.css')
}
} else {
load_stylesheet('./css/framework7.css')
}
let obj = !localStorage ? {id: 'theme-light', type: 'light'} : JSON.parse(localStorage.getItem("mobile-ui-theme"));
let obj = !isLocalStorageAvailable() ? {id: 'theme-light', type: 'light'} : JSON.parse(localStorage.getItem("mobile-ui-theme"));
if ( !obj ) {
if ( window.native && window.native.theme ) {
if ( window.native.theme.type == 'dark' ) obj = {id: 'theme-dark', type: 'dark'};
@ -30,7 +47,9 @@ if ( !obj ) {
obj = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ?
{id: 'theme-dark', type: 'dark'} : {id: 'theme-light', type: 'light'};
localStorage && localStorage.setItem("mobile-ui-theme", JSON.stringify(obj));
if(isLocalStorageAvailable()) {
localStorage.setItem("mobile-ui-theme", JSON.stringify(obj));
}
}
document.body.classList.add(`theme-type-${obj.type}`, `${window.asceditor}-editor`);

View File

@ -102,7 +102,7 @@ class MainController extends Component {
}
this.props.storeApplicationSettings.changeMacrosSettings(value);
value = localStorage.getItem("de-mobile-allow-macros-request");
value = LocalStorage.getItem("de-mobile-allow-macros-request");
this.props.storeApplicationSettings.changeMacrosRequest((value !== null) ? parseInt(value) : 0);
this.props.storeAppOptions.wopi = this.editorConfig.wopi;

View File

@ -94,7 +94,7 @@ class MainController extends Component {
}
this.props.storeApplicationSettings.changeMacrosSettings(value);
value = localStorage.getItem("pe-mobile-allow-macros-request");
value = LocalStorage.getItem("pe-mobile-allow-macros-request");
this.props.storeApplicationSettings.changeMacrosRequest((value !== null) ? parseInt(value) : 0);
};

View File

@ -138,7 +138,7 @@ class MainController extends Component {
}
this.props.storeApplicationSettings.changeMacrosSettings(value);
value = localStorage.getItem("sse-mobile-allow-macros-request");
value = LocalStorage.getItem("sse-mobile-allow-macros-request");
this.props.storeApplicationSettings.changeMacrosRequest((value !== null) ? parseInt(value) : 0);
};