feat: show system proxy info

This commit is contained in:
GyDi 2022-01-12 02:54:50 +08:00
parent df5953dd7b
commit 7fc9631434
3 changed files with 67 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import useSWR, { useSWRConfig } from "swr"; import useSWR, { useSWRConfig } from "swr";
import { import {
Box,
List, List,
ListItemText, ListItemText,
ListSubheader, ListSubheader,
@ -12,6 +13,7 @@ import { version } from "../../package.json";
import GuardState from "./guard-state"; import GuardState from "./guard-state";
import SettingItem from "./setting-item"; import SettingItem from "./setting-item";
import PaletteSwitch from "./palette-switch"; import PaletteSwitch from "./palette-switch";
import SysproxyTooltip from "./sysproxy-tooltip";
interface Props { interface Props {
onError?: (err: Error) => void; onError?: (err: Error) => void;
@ -84,7 +86,14 @@ const SettingVerge = ({ onError }: Props) => {
</SettingItem> </SettingItem>
<SettingItem> <SettingItem>
<ListItemText primary="System Proxy" /> <ListItemText
primary={
<Box sx={{ display: "flex", alignItems: "center" }}>
System Proxy
<SysproxyTooltip />
</Box>
}
/>
<GuardState <GuardState
value={proxy} value={proxy}
valueProps="checked" valueProps="checked"

View File

@ -0,0 +1,53 @@
import { useEffect, useState } from "react";
import { InfoRounded } from "@mui/icons-material";
import { ClickAwayListener, Tooltip } from "@mui/material";
import { getSystemProxy } from "../services/cmds";
const SysproxyTooltip = () => {
const [open, setOpen] = useState(false);
const [info, setInfo] = useState<any>({});
const onShow = async () => {
const data = await getSystemProxy();
console.log(data);
setInfo(data ?? {});
setOpen(true);
};
useEffect(() => {
if (!open) return;
const timer = setTimeout(() => setOpen(false), 2000);
return () => clearTimeout(timer);
}, [open]);
// todo: add error info
const showTitle = (
<div>
<div>Enable: {(!!info.enable).toString()}</div>
<div>Server: {info.server}</div>
<div>Bypass: {info.bypass}</div>
</div>
);
return (
<ClickAwayListener onClickAway={() => setOpen(false)}>
<Tooltip
PopperProps={{
disablePortal: true,
}}
onClose={() => setOpen(false)}
open={open}
disableFocusListener
disableHoverListener
disableTouchListener
placement="top"
title={showTitle}
arrow
>
<InfoRounded fontSize="small" onClick={onShow} />
</Tooltip>
</ClickAwayListener>
);
};
export default SysproxyTooltip;

View File

@ -63,3 +63,7 @@ export async function getVergeConfig() {
export async function patchVergeConfig(payload: CmdType.VergeConfig) { export async function patchVergeConfig(payload: CmdType.VergeConfig) {
return invoke<void>("patch_verge_config", { payload }); return invoke<void>("patch_verge_config", { payload });
} }
export async function getSystemProxy() {
return invoke<any>("get_sys_proxy");
}