From c1bcfc67858a385b360dade83b4fb574f24ca196 Mon Sep 17 00:00:00 2001 From: GyDi Date: Fri, 17 Dec 2021 02:17:04 +0800 Subject: [PATCH] feat: system proxy command demo --- src/pages/setting.tsx | 22 +++++++++++++++++++++- src/services/command.ts | 4 ++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pages/setting.tsx b/src/pages/setting.tsx index 002dea4..0770a2d 100644 --- a/src/pages/setting.tsx +++ b/src/pages/setting.tsx @@ -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 ( @@ -48,7 +64,11 @@ const SettingPage = () => { - + onSysproxy(c)} + /> diff --git a/src/services/command.ts b/src/services/command.ts index 57bd471..7489a45 100644 --- a/src/services/command.ts +++ b/src/services/command.ts @@ -48,3 +48,7 @@ export async function setProfiles(current: number, profile: ProfileItem) { export async function putProfiles(current: number) { return invoke("put_profiles", { current }); } + +export async function setSysProxy(enable: boolean) { + return invoke("set_sys_proxy", { enable }); +}