feat: system proxy command demo

This commit is contained in:
GyDi 2021-12-17 02:17:04 +08:00
parent 3a9734e97d
commit c1bcfc6785
2 changed files with 25 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import { useState } from "react";
import { useRecoilState } from "recoil";
import {
Box,
@ -14,6 +15,7 @@ import {
} from "@mui/material";
import { atomPaletteMode } from "../states/setting";
import PaletteSwitch from "../components/palette-switch";
import { setSysProxy } from "../services/command";
const MiniListItem = styled(ListItem)(({ theme }) => ({
paddingTop: 5,
@ -22,6 +24,20 @@ const MiniListItem = styled(ListItem)(({ theme }) => ({
const SettingPage = () => {
const [mode, setMode] = useRecoilState(atomPaletteMode);
const [proxy, setProxy] = useState(false);
const onSysproxy = (enable: boolean) => {
const value = proxy;
setProxy(enable);
setSysProxy(enable)
.then(() => {
console.log("success");
})
.catch((err) => {
setProxy(value); // recover
console.log(err);
});
};
return (
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
@ -48,7 +64,11 @@ const SettingPage = () => {
<MiniListItem>
<ListItemText primary="设置系统代理" />
<Switch edge="end" />
<Switch
edge="end"
checked={proxy}
onChange={(_e, c) => onSysproxy(c)}
/>
</MiniListItem>
<MiniListItem>

View File

@ -48,3 +48,7 @@ export async function setProfiles(current: number, profile: ProfileItem) {
export async function putProfiles(current: number) {
return invoke<void>("put_profiles", { current });
}
export async function setSysProxy(enable: boolean) {
return invoke<void>("set_sys_proxy", { enable });
}