Files
clash-verge-rev/src/services/states.ts
T

73 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-02-23 02:00:45 +08:00
import { atom } from "recoil";
2022-07-17 16:02:17 +08:00
export const atomThemeMode = atom<"light" | "dark">({
key: "atomThemeMode",
default: "light",
});
2022-11-19 17:22:29 +08:00
export const atomLogData = atom<ILogItem[]>({
2022-02-23 02:00:45 +08:00
key: "atomLogData",
default: [],
});
2022-03-21 11:40:27 +08:00
2022-09-20 22:15:28 +08:00
export const atomEnableLog = atom<boolean>({
key: "atomEnableLog",
2022-09-24 19:03:14 +08:00
effects: [
({ setSelf, onSet }) => {
const key = "enable-log";
2022-09-25 01:35:21 +08:00
try {
setSelf(localStorage.getItem(key) !== "false");
} catch {}
2022-09-24 19:03:14 +08:00
onSet((newValue, _, isReset) => {
2022-09-25 01:35:21 +08:00
try {
if (isReset) {
localStorage.removeItem(key);
} else {
localStorage.setItem(key, newValue.toString());
}
} catch {}
});
},
],
});
interface IConnectionSetting {
layout: "table" | "list";
}
export const atomConnectionSetting = atom<IConnectionSetting>({
key: "atomConnectionSetting",
effects: [
({ setSelf, onSet }) => {
const key = "connections-setting";
try {
const value = localStorage.getItem(key);
2022-11-19 17:22:29 +08:00
const data = value == null ? { layout: "table" } : JSON.parse(value);
2022-09-25 01:35:21 +08:00
setSelf(data);
} catch {
2022-11-19 17:22:29 +08:00
setSelf({ layout: "table" });
2022-09-25 01:35:21 +08:00
}
onSet((newValue) => {
try {
localStorage.setItem(key, JSON.stringify(newValue));
} catch {}
2022-09-24 19:03:14 +08:00
});
},
],
2022-09-20 22:15:28 +08:00
});
2022-03-21 11:40:27 +08:00
// save the state of each profile item loading
export const atomLoadingCache = atom<Record<string, boolean>>({
key: "atomLoadingCache",
default: {},
});
2022-03-22 01:27:22 +08:00
// save update state
export const atomUpdateState = atom<boolean>({
key: "atomUpdateState",
default: false,
});