mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:53:44 +08:00
feat: make SettingItem
clickable (#1138)
* feat: make `SettingItem` clickable * clean up
This commit is contained in:
parent
2725322fd5
commit
7737b8b596
@ -3,32 +3,39 @@ import {
|
|||||||
Box,
|
Box,
|
||||||
List,
|
List,
|
||||||
ListItem,
|
ListItem,
|
||||||
|
ListItemButton,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
ListSubheader,
|
ListSubheader,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { ChevronRightRounded } from "@mui/icons-material";
|
||||||
|
|
||||||
interface ItemProps {
|
interface ItemProps {
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
extra?: ReactNode;
|
extra?: ReactNode;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
secondary?: ReactNode;
|
secondary?: ReactNode;
|
||||||
|
onClick?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SettingItem: React.FC<ItemProps> = (props) => {
|
export const SettingItem: React.FC<ItemProps> = (props) => {
|
||||||
const { label, extra, children, secondary } = props;
|
const { label, extra, children, secondary, onClick } = props;
|
||||||
|
const clickable = !!onClick;
|
||||||
|
|
||||||
const primary = !extra ? (
|
const primary = (
|
||||||
<Box sx={{ display: "flex", alignItems: "center", fontSize: "14px" }}>
|
<Box sx={{ display: "flex", alignItems: "center", fontSize: "14px" }}>
|
||||||
<span>{label}</span>
|
<span>{label}</span>
|
||||||
</Box>
|
{extra ? extra : null}
|
||||||
) : (
|
|
||||||
<Box sx={{ display: "flex", alignItems: "center", fontSize: "14px" }}>
|
|
||||||
<span>{label}</span>
|
|
||||||
{extra}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return clickable ? (
|
||||||
|
<ListItem disablePadding>
|
||||||
|
<ListItemButton onClick={onClick}>
|
||||||
|
<ListItemText primary={primary} secondary={secondary} />
|
||||||
|
<ChevronRightRounded />
|
||||||
|
</ListItemButton>
|
||||||
|
</ListItem>
|
||||||
|
) : (
|
||||||
<ListItem sx={{ pt: "5px", pb: "5px" }}>
|
<ListItem sx={{ pt: "5px", pb: "5px" }}>
|
||||||
<ListItemText primary={primary} secondary={secondary} />
|
<ListItemText primary={primary} secondary={secondary} />
|
||||||
{children}
|
{children}
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { ArrowForward, Settings, Shuffle } from "@mui/icons-material";
|
import { Settings, Shuffle } from "@mui/icons-material";
|
||||||
import { DialogRef, Notice, Switch } from "@/components/base";
|
import { DialogRef, Notice, Switch } from "@/components/base";
|
||||||
import { useClash } from "@/hooks/use-clash";
|
import { useClash } from "@/hooks/use-clash";
|
||||||
import { GuardState } from "./mods/guard-state";
|
import { GuardState } from "./mods/guard-state";
|
||||||
@ -120,7 +120,10 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
color={enable_random_port ? "primary" : "inherit"}
|
color={enable_random_port ? "primary" : "inherit"}
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
Notice.success(t("Restart Application to Apply Modifications"), 1000);
|
Notice.success(
|
||||||
|
t("Restart Application to Apply Modifications"),
|
||||||
|
1000
|
||||||
|
);
|
||||||
onChangeVerge({ enable_random_port: !enable_random_port });
|
onChangeVerge({ enable_random_port: !enable_random_port });
|
||||||
patchVerge({ enable_random_port: !enable_random_port });
|
patchVerge({ enable_random_port: !enable_random_port });
|
||||||
}}
|
}}
|
||||||
@ -146,27 +149,12 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
<SettingItem label={t("External")}>
|
<SettingItem
|
||||||
<IconButton
|
onClick={() => ctrlRef.current?.open()}
|
||||||
color="inherit"
|
label={t("External")}
|
||||||
size="small"
|
/>
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => ctrlRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Web UI")}>
|
<SettingItem onClick={() => webRef.current?.open()} label={t("Web UI")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => webRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem
|
<SettingItem
|
||||||
label={t("Clash Core")}
|
label={t("Clash Core")}
|
||||||
@ -187,28 +175,10 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
{isWIN && (
|
{isWIN && (
|
||||||
<SettingItem label={t("Open UWP tool")}>
|
<SettingItem onClick={invoke_uwp_tool} label={t("Open UWP tool")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={invoke_uwp_tool}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<SettingItem label={t("Update GeoData")}>
|
<SettingItem onClick={onUpdateGeo} label={t("Update GeoData")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={onUpdateGeo}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
</SettingList>
|
</SettingList>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,14 +2,7 @@ import { useRef } from "react";
|
|||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { open } from "@tauri-apps/api/dialog";
|
import { open } from "@tauri-apps/api/dialog";
|
||||||
import {
|
import { Button, MenuItem, Select, Input, Typography } from "@mui/material";
|
||||||
Button,
|
|
||||||
IconButton,
|
|
||||||
MenuItem,
|
|
||||||
Select,
|
|
||||||
Input,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
|
||||||
import {
|
import {
|
||||||
exitApp,
|
exitApp,
|
||||||
openAppDir,
|
openAppDir,
|
||||||
@ -17,7 +10,6 @@ import {
|
|||||||
openLogsDir,
|
openLogsDir,
|
||||||
openDevTools,
|
openDevTools,
|
||||||
} from "@/services/cmds";
|
} from "@/services/cmds";
|
||||||
import { ArrowForward } from "@mui/icons-material";
|
|
||||||
import { checkUpdate } from "@tauri-apps/api/updater";
|
import { checkUpdate } from "@tauri-apps/api/updater";
|
||||||
import { useVerge } from "@/hooks/use-verge";
|
import { useVerge } from "@/hooks/use-verge";
|
||||||
import { version } from "@root/package.json";
|
import { version } from "@root/package.json";
|
||||||
@ -213,128 +205,48 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
></Input>
|
></Input>
|
||||||
</GuardState>
|
</GuardState>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem label={t("Theme Setting")}>
|
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => themeRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Layout Setting")}>
|
<SettingItem
|
||||||
<IconButton
|
onClick={() => themeRef.current?.open()}
|
||||||
color="inherit"
|
label={t("Theme Setting")}
|
||||||
size="small"
|
/>
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => layoutRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Miscellaneous")}>
|
<SettingItem
|
||||||
<IconButton
|
onClick={() => layoutRef.current?.open()}
|
||||||
color="inherit"
|
label={t("Layout Setting")}
|
||||||
size="small"
|
/>
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => miscRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Hotkey Setting")}>
|
<SettingItem
|
||||||
<IconButton
|
onClick={() => miscRef.current?.open()}
|
||||||
color="inherit"
|
label={t("Miscellaneous")}
|
||||||
size="small"
|
/>
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => hotkeyRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Runtime Config")}>
|
<SettingItem
|
||||||
<IconButton
|
onClick={() => hotkeyRef.current?.open()}
|
||||||
color="inherit"
|
label={t("Hotkey Setting")}
|
||||||
size="small"
|
/>
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={() => configRef.current?.open()}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Open App Dir")}>
|
<SettingItem
|
||||||
<IconButton
|
onClick={() => configRef.current?.open()}
|
||||||
color="inherit"
|
label={t("Runtime Config")}
|
||||||
size="small"
|
/>
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={openAppDir}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Open Core Dir")}>
|
<SettingItem onClick={openAppDir} label={t("Open App Dir")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={openCoreDir}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Open Logs Dir")}>
|
<SettingItem onClick={openCoreDir} label={t("Open Core Dir")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={openLogsDir}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Check for Updates")}>
|
<SettingItem onClick={openLogsDir} label={t("Open Logs Dir")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={onCheckUpdate}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Open Dev Tools")}>
|
<SettingItem onClick={onCheckUpdate} label={t("Check for Updates")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
|
||||||
size="small"
|
|
||||||
sx={{ my: "2px" }}
|
|
||||||
onClick={openDevTools}
|
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Exit")}>
|
<SettingItem onClick={openDevTools} label={t("Open Dev Tools")} />
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
<SettingItem
|
||||||
size="small"
|
onClick={() => {
|
||||||
sx={{ my: "2px" }}
|
exitApp();
|
||||||
onClick={() => {
|
}}
|
||||||
exitApp();
|
label={t("Exit")}
|
||||||
}}
|
/>
|
||||||
>
|
|
||||||
<ArrowForward />
|
|
||||||
</IconButton>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem label={t("Verge Version")}>
|
<SettingItem label={t("Verge Version")}>
|
||||||
<Typography sx={{ py: "7px", pr: 1 }}>v{version}</Typography>
|
<Typography sx={{ py: "7px", pr: 1 }}>v{version}</Typography>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user