mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
fix: after importing a subscription, it cannot be automatically switched to the current subscription.
This commit is contained in:
@@ -4,7 +4,7 @@ import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import { SWRConfig, mutate } from "swr";
|
||||
import { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLocation, useRoutes } from "react-router-dom";
|
||||
import { useLocation, useRoutes, useNavigate } from "react-router-dom";
|
||||
import { List, Paper, ThemeProvider, SvgIcon } from "@mui/material";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
@@ -25,7 +25,6 @@ import getSystem from "@/utils/get-system";
|
||||
import "dayjs/locale/ru";
|
||||
import "dayjs/locale/zh-cn";
|
||||
import { getPortableFlag } from "@/services/cmds";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import React from "react";
|
||||
import { TransitionGroup, CSSTransition } from "react-transition-group";
|
||||
const appWindow = getCurrentWebviewWindow();
|
||||
@@ -73,9 +72,12 @@ const Layout = () => {
|
||||
const [status, msg] = payload as [string, string];
|
||||
switch (status) {
|
||||
case "import_sub_url::ok":
|
||||
navigate("/profile", { state: { current: msg } });
|
||||
|
||||
Notice.success(t("Import Subscription Successful"));
|
||||
break;
|
||||
case "import_sub_url::error":
|
||||
navigate("/profile");
|
||||
Notice.error(msg);
|
||||
break;
|
||||
case "set_config::ok":
|
||||
|
||||
@@ -50,9 +50,11 @@ import { BaseStyledTextField } from "@/components/base/base-styled-text-field";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { readTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { readText } from "@tauri-apps/plugin-clipboard-manager";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
const ProfilePage = () => {
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
|
||||
const [url, setUrl] = useState("");
|
||||
const [disabled, setDisabled] = useState(false);
|
||||
@@ -64,6 +66,7 @@ const ProfilePage = () => {
|
||||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
})
|
||||
);
|
||||
const { current } = location.state || {};
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = listen("tauri://file-drop", async (event) => {
|
||||
@@ -138,11 +141,11 @@ const ProfilePage = () => {
|
||||
|
||||
const remoteItem = newProfiles.items?.find((e) => e.type === "remote");
|
||||
|
||||
const profilesCount = newProfiles.items?.filter(
|
||||
const itemsCount = newProfiles.items?.filter(
|
||||
(e) => e.type === "remote" || e.type === "local"
|
||||
).length as number;
|
||||
|
||||
if (remoteItem && (profilesCount == 1 || !newProfiles.current)) {
|
||||
if (remoteItem && (itemsCount == 1 || !newProfiles.current)) {
|
||||
const current = remoteItem.uid;
|
||||
await patchProfiles({ current });
|
||||
mutateLogs();
|
||||
@@ -168,27 +171,40 @@ const ProfilePage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const onSelect = useLockFn(async (current: string, force: boolean) => {
|
||||
if (!force && current === profiles.current) return;
|
||||
const activateProfile = async (profile: string) => {
|
||||
// 避免大多数情况下loading态闪烁
|
||||
|
||||
const reset = setTimeout(() => {
|
||||
setActivatings([...currentActivatings(), current]);
|
||||
setActivatings((prev) => [...prev, profile]);
|
||||
}, 100);
|
||||
|
||||
try {
|
||||
await patchProfiles({ current });
|
||||
await patchProfiles({ current: profile });
|
||||
await mutateLogs();
|
||||
closeAllConnections();
|
||||
activateSelected().then(() => {
|
||||
Notice.success(t("Profile Switched"), 1000);
|
||||
});
|
||||
await activateSelected();
|
||||
Notice.success(t("Profile Switched"), 1000);
|
||||
} catch (err: any) {
|
||||
Notice.error(err?.message || err.toString(), 4000);
|
||||
} finally {
|
||||
clearTimeout(reset);
|
||||
setActivatings([]);
|
||||
}
|
||||
};
|
||||
const onSelect = useLockFn(async (current: string, force: boolean) => {
|
||||
if (!force && current === profiles.current) return;
|
||||
await activateProfile(current);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (current && current !== profiles.current) {
|
||||
console.log("current:", current);
|
||||
await activateProfile(current);
|
||||
}
|
||||
})();
|
||||
}, current);
|
||||
|
||||
const onEnhance = useLockFn(async () => {
|
||||
setActivatings(currentActivatings());
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user