fix: restart clash should update something

This commit is contained in:
GyDi 2022-01-21 00:29:33 +08:00
parent 65fb2ca2d5
commit 4b5b62c8ae
No known key found for this signature in database
GPG Key ID: 1C95E0D3467B3084
3 changed files with 18 additions and 3 deletions

View File

@ -49,6 +49,8 @@ fn main() -> std::io::Result<()> {
if let Err(err) = profiles.activate(clash.info.clone()) {
log::error!("{}", err);
}
let window = app_handle.get_window("main").unwrap();
window.emit("restart_clash", "yes").unwrap();
}
Err(err) => log::error!("{}", err),
}

View File

@ -1,11 +1,13 @@
import useSWR, { SWRConfig } from "swr";
import useSWR, { SWRConfig, useSWRConfig } from "swr";
import { useEffect, useMemo } from "react";
import { Route, Routes } from "react-router-dom";
import { useRecoilState } from "recoil";
import { alpha, createTheme, List, Paper, ThemeProvider } from "@mui/material";
import { listen } from "@tauri-apps/api/event";
import { appWindow } from "@tauri-apps/api/window";
import { atomPaletteMode, atomThemeBlur } from "../states/setting";
import { getVergeConfig } from "../services/cmds";
import { getAxios } from "../services/api";
import { routers } from "./_routers";
import LogoSvg from "../assets/image/logo.svg";
import Traffic from "../components/traffic";
@ -14,6 +16,7 @@ import UpdateButton from "../components/update-button";
import LayoutControl from "../components/layout-control";
const Layout = () => {
const { mutate } = useSWRConfig();
const [mode, setMode] = useRecoilState(atomPaletteMode);
const [blur, setBlur] = useRecoilState(atomThemeBlur);
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
@ -22,6 +25,15 @@ const Layout = () => {
window.addEventListener("keydown", (e) => {
if (e.key === "Escape") appWindow.hide();
});
listen("restart_clash", async () => {
// the clash info may be updated
await getAxios(true);
// make sure that the clash is ok
setTimeout(() => mutate("getProxies"), 1000);
setTimeout(() => mutate("getProxies"), 2000);
mutate("getClashConfig");
});
}, []);
useEffect(() => {

View File

@ -7,8 +7,9 @@ let server = "";
let secret = "";
/// initialize some infomation
export async function getAxios() {
if (axiosIns) return axiosIns;
/// enable force update axiosIns
export async function getAxios(force: boolean = false) {
if (axiosIns && !force) return axiosIns;
try {
const info = await getClashInfo();