fix: restart clash should update something
This commit is contained in:
parent
65fb2ca2d5
commit
4b5b62c8ae
@ -49,6 +49,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
if let Err(err) = profiles.activate(clash.info.clone()) {
|
if let Err(err) = profiles.activate(clash.info.clone()) {
|
||||||
log::error!("{}", err);
|
log::error!("{}", err);
|
||||||
}
|
}
|
||||||
|
let window = app_handle.get_window("main").unwrap();
|
||||||
|
window.emit("restart_clash", "yes").unwrap();
|
||||||
}
|
}
|
||||||
Err(err) => log::error!("{}", err),
|
Err(err) => log::error!("{}", err),
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import useSWR, { SWRConfig } from "swr";
|
import useSWR, { SWRConfig, useSWRConfig } from "swr";
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { Route, Routes } from "react-router-dom";
|
import { Route, Routes } from "react-router-dom";
|
||||||
import { useRecoilState } from "recoil";
|
import { useRecoilState } from "recoil";
|
||||||
import { alpha, createTheme, List, Paper, ThemeProvider } from "@mui/material";
|
import { alpha, createTheme, List, Paper, ThemeProvider } from "@mui/material";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { appWindow } from "@tauri-apps/api/window";
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
import { atomPaletteMode, atomThemeBlur } from "../states/setting";
|
import { atomPaletteMode, atomThemeBlur } from "../states/setting";
|
||||||
import { getVergeConfig } from "../services/cmds";
|
import { getVergeConfig } from "../services/cmds";
|
||||||
|
import { getAxios } from "../services/api";
|
||||||
import { routers } from "./_routers";
|
import { routers } from "./_routers";
|
||||||
import LogoSvg from "../assets/image/logo.svg";
|
import LogoSvg from "../assets/image/logo.svg";
|
||||||
import Traffic from "../components/traffic";
|
import Traffic from "../components/traffic";
|
||||||
@ -14,6 +16,7 @@ import UpdateButton from "../components/update-button";
|
|||||||
import LayoutControl from "../components/layout-control";
|
import LayoutControl from "../components/layout-control";
|
||||||
|
|
||||||
const Layout = () => {
|
const Layout = () => {
|
||||||
|
const { mutate } = useSWRConfig();
|
||||||
const [mode, setMode] = useRecoilState(atomPaletteMode);
|
const [mode, setMode] = useRecoilState(atomPaletteMode);
|
||||||
const [blur, setBlur] = useRecoilState(atomThemeBlur);
|
const [blur, setBlur] = useRecoilState(atomThemeBlur);
|
||||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
@ -22,6 +25,15 @@ const Layout = () => {
|
|||||||
window.addEventListener("keydown", (e) => {
|
window.addEventListener("keydown", (e) => {
|
||||||
if (e.key === "Escape") appWindow.hide();
|
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(() => {
|
useEffect(() => {
|
||||||
|
@ -7,8 +7,9 @@ let server = "";
|
|||||||
let secret = "";
|
let secret = "";
|
||||||
|
|
||||||
/// initialize some infomation
|
/// initialize some infomation
|
||||||
export async function getAxios() {
|
/// enable force update axiosIns
|
||||||
if (axiosIns) return axiosIns;
|
export async function getAxios(force: boolean = false) {
|
||||||
|
if (axiosIns && !force) return axiosIns;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const info = await getClashInfo();
|
const info = await getClashInfo();
|
||||||
|
Loading…
Reference in New Issue
Block a user