2021-12-20 00:01:32 +08:00
|
|
|
import useSWR, { useSWRConfig } from "swr";
|
2022-02-16 03:21:34 +08:00
|
|
|
import { IconButton, ListItemText, Switch, Typography } from "@mui/material";
|
|
|
|
import {
|
|
|
|
getVergeConfig,
|
|
|
|
openAppDir,
|
|
|
|
openLogsDir,
|
|
|
|
patchVergeConfig,
|
|
|
|
} from "../../services/cmds";
|
2022-02-19 18:14:40 +08:00
|
|
|
import { ArrowForward } from "@mui/icons-material";
|
2022-01-16 03:22:37 +08:00
|
|
|
import { SettingList, SettingItem } from "./setting";
|
|
|
|
import { CmdType } from "../../services/types";
|
|
|
|
import { version } from "../../../package.json";
|
2022-01-16 18:30:25 +08:00
|
|
|
import PaletteSwitch from "./palette-switch";
|
2022-02-19 18:14:40 +08:00
|
|
|
import GuardState from "./guard-state";
|
2021-12-20 00:01:32 +08:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
onError?: (err: Error) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingVerge = ({ onError }: Props) => {
|
|
|
|
const { mutate } = useSWRConfig();
|
|
|
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
|
|
|
|
2022-02-19 18:14:40 +08:00
|
|
|
const { theme_mode = "light", theme_blur = false, traffic_graph } =
|
2022-01-17 02:42:52 +08:00
|
|
|
vergeConfig ?? {};
|
2021-12-20 00:01:32 +08:00
|
|
|
|
|
|
|
const onSwitchFormat = (_e: any, value: boolean) => value;
|
2021-12-25 22:33:29 +08:00
|
|
|
const onChangeData = (patch: Partial<CmdType.VergeConfig>) => {
|
2021-12-20 00:01:32 +08:00
|
|
|
mutate("getVergeConfig", { ...vergeConfig, ...patch }, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-01-17 02:42:52 +08:00
|
|
|
<SettingList title="Verge Setting">
|
2021-12-20 00:01:32 +08:00
|
|
|
<SettingItem>
|
2022-01-08 02:54:37 +08:00
|
|
|
<ListItemText primary="Theme Mode" />
|
2021-12-20 00:01:32 +08:00
|
|
|
<GuardState
|
2022-02-19 18:14:40 +08:00
|
|
|
value={theme_mode === "dark"}
|
2021-12-20 00:01:32 +08:00
|
|
|
valueProps="checked"
|
|
|
|
onCatch={onError}
|
|
|
|
onFormat={onSwitchFormat}
|
|
|
|
onChange={(e) => onChangeData({ theme_mode: e ? "dark" : "light" })}
|
2022-01-11 02:24:43 +08:00
|
|
|
onGuard={(c) =>
|
|
|
|
patchVergeConfig({ theme_mode: c ? "dark" : "light" })
|
|
|
|
}
|
2021-12-20 00:01:32 +08:00
|
|
|
>
|
|
|
|
<PaletteSwitch edge="end" />
|
|
|
|
</GuardState>
|
|
|
|
</SettingItem>
|
|
|
|
|
2022-01-12 02:27:29 +08:00
|
|
|
<SettingItem>
|
|
|
|
<ListItemText primary="Theme Blur" />
|
|
|
|
<GuardState
|
2022-02-19 18:14:40 +08:00
|
|
|
value={theme_blur}
|
2022-01-12 02:27:29 +08:00
|
|
|
valueProps="checked"
|
|
|
|
onCatch={onError}
|
|
|
|
onFormat={onSwitchFormat}
|
|
|
|
onChange={(e) => onChangeData({ theme_blur: e })}
|
|
|
|
onGuard={(e) => patchVergeConfig({ theme_blur: e })}
|
|
|
|
>
|
|
|
|
<Switch edge="end" />
|
|
|
|
</GuardState>
|
|
|
|
</SettingItem>
|
|
|
|
|
2022-02-16 03:21:34 +08:00
|
|
|
<SettingItem>
|
2022-02-19 18:14:40 +08:00
|
|
|
<ListItemText primary="Traffic Graph" />
|
|
|
|
<GuardState
|
|
|
|
value={traffic_graph ?? true}
|
|
|
|
valueProps="checked"
|
|
|
|
onCatch={onError}
|
|
|
|
onFormat={onSwitchFormat}
|
|
|
|
onChange={(e) => onChangeData({ traffic_graph: e })}
|
|
|
|
onGuard={(e) => patchVergeConfig({ traffic_graph: e })}
|
2022-02-16 03:21:34 +08:00
|
|
|
>
|
2022-02-19 18:14:40 +08:00
|
|
|
<Switch edge="end" />
|
|
|
|
</GuardState>
|
|
|
|
</SettingItem>
|
|
|
|
|
|
|
|
<SettingItem>
|
|
|
|
<ListItemText primary="Open App Dir" />
|
|
|
|
<IconButton color="inherit" size="small" onClick={openAppDir}>
|
2022-02-16 03:21:34 +08:00
|
|
|
<ArrowForward />
|
|
|
|
</IconButton>
|
|
|
|
</SettingItem>
|
|
|
|
|
|
|
|
<SettingItem>
|
|
|
|
<ListItemText primary="Open Logs Dir" />
|
|
|
|
<IconButton color="inherit" size="small" onClick={openLogsDir}>
|
|
|
|
<ArrowForward />
|
|
|
|
</IconButton>
|
|
|
|
</SettingItem>
|
|
|
|
|
2021-12-28 01:35:58 +08:00
|
|
|
<SettingItem>
|
|
|
|
<ListItemText primary="Version" />
|
|
|
|
<Typography sx={{ py: "6px" }}>v{version}</Typography>
|
|
|
|
</SettingItem>
|
2022-01-16 03:22:37 +08:00
|
|
|
</SettingList>
|
2021-12-20 00:01:32 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SettingVerge;
|