Skip to content
Snippets Groups Projects
Unverified Commit 4b5b62c8 authored by GyDi's avatar GyDi
Browse files

fix: restart clash should update something

parent 65fb2ca2
No related branches found
No related tags found
No related merge requests found
......@@ -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),
}
......
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(() => {
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment