mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 17:15:38 +08:00
feat: save proxy page state
This commit is contained in:
@@ -3,6 +3,7 @@ import i18next from "i18next";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import useSWR, { SWRConfig, useSWRConfig } from "swr";
|
||||
import { useEffect } from "react";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Route, Routes } from "react-router-dom";
|
||||
import { alpha, List, Paper, ThemeProvider } from "@mui/material";
|
||||
@@ -10,7 +11,8 @@ import { listen } from "@tauri-apps/api/event";
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
import { routers } from "./_routers";
|
||||
import { getAxios } from "../services/api";
|
||||
import { getVergeConfig } from "../services/cmds";
|
||||
import { atomCurrentProfile } from "../services/states";
|
||||
import { getVergeConfig, getProfiles } from "../services/cmds";
|
||||
import { ReactComponent as LogoSvg } from "../assets/image/logo.svg";
|
||||
import LayoutItem from "../components/layout/layout-item";
|
||||
import LayoutControl from "../components/layout/layout-control";
|
||||
@@ -33,6 +35,8 @@ const Layout = () => {
|
||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||
const { theme_blur, language } = vergeConfig || {};
|
||||
|
||||
const setCurrentProfile = useSetRecoilState(atomCurrentProfile);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") appWindow.close();
|
||||
@@ -47,6 +51,9 @@ const Layout = () => {
|
||||
|
||||
// update the verge config
|
||||
listen("verge://refresh-verge-config", () => mutate("getVergeConfig"));
|
||||
|
||||
// set current profile uid
|
||||
getProfiles().then((data) => setCurrentProfile(data.current ?? ""));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import useSWR, { useSWRConfig } from "swr";
|
||||
import { useLockFn } from "ahooks";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import { Box, Button, Grid, TextField } from "@mui/material";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
importProfile,
|
||||
} from "../services/cmds";
|
||||
import { getProxies, updateProxy } from "../services/api";
|
||||
import { atomCurrentProfile } from "../services/states";
|
||||
import Notice from "../components/base/base-notice";
|
||||
import BasePage from "../components/base/base-page";
|
||||
import ProfileNew from "../components/profile/profile-new";
|
||||
@@ -24,6 +26,8 @@ const ProfilePage = () => {
|
||||
const [disabled, setDisabled] = useState(false);
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
|
||||
const setCurrentProfile = useSetRecoilState(atomCurrentProfile);
|
||||
|
||||
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
||||
|
||||
// distinguish type
|
||||
@@ -52,6 +56,9 @@ const ProfilePage = () => {
|
||||
|
||||
const current = profiles.current;
|
||||
const profile = regularItems.find((p) => p.uid === current);
|
||||
|
||||
setCurrentProfile(current);
|
||||
|
||||
if (!profile) return;
|
||||
|
||||
setTimeout(async () => {
|
||||
@@ -121,6 +128,7 @@ const ProfilePage = () => {
|
||||
|
||||
try {
|
||||
await selectProfile(uid);
|
||||
setCurrentProfile(uid);
|
||||
mutate("getProfiles", { ...profiles, current: uid }, true);
|
||||
if (force) Notice.success("Refresh clash config", 1000);
|
||||
} catch (err: any) {
|
||||
|
||||
Reference in New Issue
Block a user