fix storage bug
This commit is contained in:
@@ -3,7 +3,6 @@ import { browser, isExt, isGm, isWeb } from "../libs/browser";
|
|||||||
import {
|
import {
|
||||||
STOKEY_SETTING,
|
STOKEY_SETTING,
|
||||||
STOKEY_RULES,
|
STOKEY_RULES,
|
||||||
STOKEY_MSAUTH,
|
|
||||||
STOKEY_SYNC,
|
STOKEY_SYNC,
|
||||||
DEFAULT_SETTING,
|
DEFAULT_SETTING,
|
||||||
DEFAULT_RULES,
|
DEFAULT_RULES,
|
||||||
@@ -15,12 +14,13 @@ import storage from "../libs/storage";
|
|||||||
* 默认配置
|
* 默认配置
|
||||||
*/
|
*/
|
||||||
export const defaultStorage = {
|
export const defaultStorage = {
|
||||||
[STOKEY_MSAUTH]: null,
|
|
||||||
[STOKEY_SETTING]: DEFAULT_SETTING,
|
[STOKEY_SETTING]: DEFAULT_SETTING,
|
||||||
[STOKEY_RULES]: DEFAULT_RULES,
|
[STOKEY_RULES]: DEFAULT_RULES,
|
||||||
[STOKEY_SYNC]: DEFAULT_SYNC,
|
[STOKEY_SYNC]: DEFAULT_SYNC,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const activeKeys = Object.keys(defaultStorage);
|
||||||
|
|
||||||
const StoragesContext = createContext(null);
|
const StoragesContext = createContext(null);
|
||||||
|
|
||||||
export function StoragesProvider({ children }) {
|
export function StoragesProvider({ children }) {
|
||||||
@@ -38,7 +38,10 @@ export function StoragesProvider({ children }) {
|
|||||||
}
|
}
|
||||||
const newStorages = {};
|
const newStorages = {};
|
||||||
Object.entries(changes)
|
Object.entries(changes)
|
||||||
.filter(([_, { oldValue, newValue }]) => oldValue !== newValue)
|
.filter(
|
||||||
|
([key, { oldValue, newValue }]) =>
|
||||||
|
activeKeys.includes(key) && oldValue !== newValue
|
||||||
|
)
|
||||||
.forEach(([key, { newValue }]) => {
|
.forEach(([key, { newValue }]) => {
|
||||||
newStorages[key] = JSON.parse(newValue);
|
newStorages[key] = JSON.parse(newValue);
|
||||||
});
|
});
|
||||||
@@ -51,8 +54,7 @@ export function StoragesProvider({ children }) {
|
|||||||
// 首次从storage同步配置到内存
|
// 首次从storage同步配置到内存
|
||||||
(async () => {
|
(async () => {
|
||||||
const curStorages = {};
|
const curStorages = {};
|
||||||
const keys = Object.keys(defaultStorage);
|
for (const key of activeKeys) {
|
||||||
for (const key of keys) {
|
|
||||||
const val = await storage.get(key);
|
const val = await storage.get(key);
|
||||||
if (val) {
|
if (val) {
|
||||||
curStorages[key] = JSON.parse(val);
|
curStorages[key] = JSON.parse(val);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
EVENT_KISS,
|
EVENT_KISS,
|
||||||
MSG_TRANS_CURRULE,
|
MSG_TRANS_CURRULE,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
import { StoragesProvider } from "../hooks/Storage";
|
|
||||||
import { queryEls } from ".";
|
import { queryEls } from ".";
|
||||||
import Content from "../views/Content";
|
import Content from "../views/Content";
|
||||||
import { fetchUpdate, fetchClear } from "./fetch";
|
import { fetchUpdate, fetchClear } from "./fetch";
|
||||||
@@ -144,10 +143,6 @@ export class Translator {
|
|||||||
"-webkit-line-clamp: unset; max-height: none; height: auto;";
|
"-webkit-line-clamp: unset; max-height: none; height: auto;";
|
||||||
|
|
||||||
const root = createRoot(span);
|
const root = createRoot(span);
|
||||||
root.render(
|
root.render(<Content q={q} translator={this} />);
|
||||||
<StoragesProvider>
|
|
||||||
<Content q={q} translator={this} />
|
|
||||||
</StoragesProvider>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user