2021-12-19 19:01:32 +03:00
|
|
|
import { useEffect, useMemo } from "react";
|
|
|
|
import useSWR, { SWRConfig } from "swr";
|
2021-12-08 18:36:34 +03:00
|
|
|
import { Route, Routes } from "react-router-dom";
|
2021-12-19 19:01:32 +03:00
|
|
|
import { useRecoilState } from "recoil";
|
2021-12-11 15:35:02 +03:00
|
|
|
import { createTheme, List, Paper, ThemeProvider } from "@mui/material";
|
2021-12-09 18:28:57 +03:00
|
|
|
import { atomPaletteMode } from "../states/setting";
|
2021-12-19 19:01:32 +03:00
|
|
|
import { getVergeConfig } from "../services/command";
|
2021-12-11 15:35:02 +03:00
|
|
|
import LogoSvg from "../assets/image/logo.svg";
|
2021-12-08 18:36:34 +03:00
|
|
|
import LogPage from "../pages/log";
|
|
|
|
import HomePage from "../pages/home";
|
2021-12-11 20:09:51 +03:00
|
|
|
import RulesPage from "../pages/rules";
|
2021-12-08 18:36:34 +03:00
|
|
|
import ProxyPage from "../pages/proxy";
|
|
|
|
import SettingPage from "../pages/setting";
|
|
|
|
import ConnectionsPage from "../pages/connections";
|
|
|
|
import ListItemLink from "../components/list-item-link";
|
|
|
|
import Traffic from "../components/traffic";
|
|
|
|
|
2021-12-19 19:01:32 +03:00
|
|
|
const routers = [
|
|
|
|
{
|
|
|
|
label: "代理",
|
|
|
|
link: "/proxy",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "规则",
|
|
|
|
link: "/rules",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "连接",
|
|
|
|
link: "/connections",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "日志",
|
|
|
|
link: "/log",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "设置",
|
|
|
|
link: "/setting",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-12-08 18:36:34 +03:00
|
|
|
const Layout = () => {
|
2021-12-19 19:01:32 +03:00
|
|
|
const [mode, setMode] = useRecoilState(atomPaletteMode);
|
|
|
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
2021-12-09 18:28:57 +03:00
|
|
|
|
2021-12-19 19:01:32 +03:00
|
|
|
useEffect(() => {
|
|
|
|
setMode(vergeConfig?.theme_mode ?? "light");
|
|
|
|
}, [vergeConfig?.theme_mode]);
|
2021-12-08 18:36:34 +03:00
|
|
|
|
2021-12-09 18:28:57 +03:00
|
|
|
const theme = useMemo(() => {
|
2021-12-19 19:01:32 +03:00
|
|
|
if (mode === "light") {
|
2021-12-11 15:35:02 +03:00
|
|
|
document.documentElement.style.background = "#f5f5f5";
|
|
|
|
document.documentElement.style.setProperty(
|
|
|
|
"--selection-color",
|
|
|
|
"#f5f5f5"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
document.documentElement.style.background = "#000";
|
|
|
|
document.documentElement.style.setProperty(
|
|
|
|
"--selection-color",
|
|
|
|
"#d5d5d5"
|
|
|
|
);
|
|
|
|
}
|
2021-12-09 18:28:57 +03:00
|
|
|
|
|
|
|
return createTheme({
|
2021-12-16 19:44:51 +03:00
|
|
|
breakpoints: {
|
|
|
|
values: {
|
|
|
|
xs: 0,
|
|
|
|
sm: 650,
|
|
|
|
md: 900,
|
|
|
|
lg: 1200,
|
|
|
|
xl: 1536,
|
|
|
|
},
|
|
|
|
},
|
2021-12-09 18:28:57 +03:00
|
|
|
palette: {
|
2021-12-19 19:01:32 +03:00
|
|
|
mode,
|
2021-12-09 18:28:57 +03:00
|
|
|
primary: {
|
|
|
|
main: "#5b5c9d",
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
primary: "#637381",
|
|
|
|
secondary: "#909399",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-12-19 19:01:32 +03:00
|
|
|
}, [mode]);
|
2021-12-09 18:28:57 +03:00
|
|
|
|
2021-12-08 18:36:34 +03:00
|
|
|
return (
|
2021-12-16 19:44:51 +03:00
|
|
|
<SWRConfig value={{}}>
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<Paper square elevation={0} className="layout">
|
|
|
|
<div className="layout__sidebar">
|
|
|
|
<div className="layout__logo">
|
|
|
|
<img src={LogoSvg} width="100%" alt="" />
|
|
|
|
</div>
|
2021-12-08 18:36:34 +03:00
|
|
|
|
2021-12-16 19:44:51 +03:00
|
|
|
<List sx={{ userSelect: "none" }}>
|
|
|
|
{routers.map((router) => (
|
|
|
|
<ListItemLink key={router.label} to={router.link}>
|
|
|
|
{router.label}
|
|
|
|
</ListItemLink>
|
|
|
|
))}
|
|
|
|
</List>
|
2021-12-08 18:36:34 +03:00
|
|
|
|
2021-12-16 19:44:51 +03:00
|
|
|
<div className="layout__traffic">
|
|
|
|
<Traffic />
|
|
|
|
</div>
|
2021-12-09 18:28:57 +03:00
|
|
|
</div>
|
2021-12-08 18:36:34 +03:00
|
|
|
|
2021-12-16 19:44:51 +03:00
|
|
|
<div className="layout__content">
|
|
|
|
<Routes>
|
|
|
|
<Route path="/" element={<HomePage />} />
|
|
|
|
<Route path="/proxy" element={<ProxyPage />} />
|
|
|
|
<Route path="/rules" element={<RulesPage />} />
|
|
|
|
<Route path="/log" element={<LogPage />} />
|
|
|
|
<Route path="/connections" element={<ConnectionsPage />} />
|
|
|
|
<Route path="/setting" element={<SettingPage />} />
|
|
|
|
</Routes>
|
|
|
|
</div>
|
|
|
|
</Paper>
|
|
|
|
</ThemeProvider>
|
|
|
|
</SWRConfig>
|
2021-12-08 18:36:34 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Layout;
|