refactor: done

This commit is contained in:
GyDi
2022-11-18 18:18:41 +08:00
parent ce2d4498e1
commit bedd3abf8a
24 changed files with 343 additions and 341 deletions

View File

@@ -7,7 +7,7 @@ import {
getProfiles,
deleteProfile,
enhanceProfiles,
changeProfileChain,
patchProfilesConfig,
getRuntimeLogs,
} from "@/services/cmds";
import ProfileMore from "./profile-more";
@@ -43,7 +43,7 @@ const EnhancedMode = (props: Props) => {
if (chain.includes(uid)) return;
const newChain = [...chain, uid];
await changeProfileChain(newChain);
await patchProfilesConfig({ chain: newChain });
mutateProfiles((conf = {}) => ({ ...conf, chain: newChain }), true);
mutateLogs();
});
@@ -52,7 +52,7 @@ const EnhancedMode = (props: Props) => {
if (!chain.includes(uid)) return;
const newChain = chain.filter((i) => i !== uid);
await changeProfileChain(newChain);
await patchProfilesConfig({ chain: newChain });
mutateProfiles((conf = {}) => ({ ...conf, chain: newChain }), true);
mutateLogs();
});
@@ -72,7 +72,7 @@ const EnhancedMode = (props: Props) => {
if (!chain.includes(uid)) return;
const newChain = [uid].concat(chain.filter((i) => i !== uid));
await changeProfileChain(newChain);
await patchProfilesConfig({ chain: newChain });
mutateProfiles((conf = {}) => ({ ...conf, chain: newChain }), true);
mutateLogs();
});
@@ -81,7 +81,7 @@ const EnhancedMode = (props: Props) => {
if (!chain.includes(uid)) return;
const newChain = chain.filter((i) => i !== uid).concat([uid]);
await changeProfileChain(newChain);
await patchProfilesConfig({ chain: newChain });
mutateProfiles((conf = {}) => ({ ...conf, chain: newChain }), true);
mutateLogs();
});

View File

@@ -15,9 +15,9 @@ import {
} from "@mui/material";
import { InfoRounded } from "@mui/icons-material";
import {
changeProfileValid,
getProfiles,
getRuntimeExists,
patchProfilesConfig,
} from "@/services/cmds";
import { ModalHandler } from "@/hooks/use-modal-handler";
import {
@@ -91,7 +91,7 @@ const ClashFieldViewer = ({ handler }: Props) => {
if (curSet.size === oldSet.size && curSet.size === joinSet.size) return;
try {
await changeProfileValid([...curSet]);
await patchProfilesConfig({ valid: [...curSet] });
mutateProfile();
// Notice.success("Refresh clash config", 1000);
} catch (err: any) {

View File

@@ -7,7 +7,7 @@ import { useTranslation } from "react-i18next";
import {
getProfiles,
patchProfile,
selectProfile,
patchProfilesConfig,
importProfile,
} from "@/services/cmds";
import { getProxies, updateProxy } from "@/services/api";
@@ -113,7 +113,7 @@ const ProfilePage = () => {
if (!newProfiles.current && remoteItem) {
const current = remoteItem.uid;
selectProfile(current);
patchProfilesConfig({ current });
mutate("getProfiles", { ...newProfiles, current }, true);
mutate("getRuntimeLogs");
}
@@ -125,13 +125,13 @@ const ProfilePage = () => {
}
};
const onSelect = useLockFn(async (uid: string, force: boolean) => {
if (!force && uid === profiles.current) return;
const onSelect = useLockFn(async (current: string, force: boolean) => {
if (!force && current === profiles.current) return;
try {
await selectProfile(uid);
setCurrentProfile(uid);
mutate("getProfiles", { ...profiles, current: uid }, true);
await patchProfilesConfig({ current });
setCurrentProfile(current);
mutate("getProfiles", { ...profiles, current: current }, true);
mutate("getRuntimeLogs");
// if (force) Notice.success("Refresh clash config", 1000);
} catch (err: any) {

View File

@@ -32,6 +32,10 @@ export async function enhanceProfiles() {
return invoke<void>("enhance_profiles");
}
export async function patchProfilesConfig(profiles: CmdType.ProfilesConfig) {
return invoke<void>("patch_profiles_config");
}
export async function createProfile(
item: Partial<CmdType.ProfileItem>,
fileData?: string | null
@@ -76,18 +80,6 @@ export async function patchProfile(
return invoke<void>("patch_profile", { index, profile });
}
export async function selectProfile(index: string) {
return invoke<void>("select_profile", { index });
}
export async function changeProfileChain(chain?: string[]) {
return invoke<void>("change_profile_chain", { chain });
}
export async function changeProfileValid(valid?: string[]) {
return invoke<void>("change_profile_valid", { valid });
}
export async function getClashInfo() {
return invoke<CmdType.ClashInfo | null>("get_clash_info");
}
@@ -136,10 +128,6 @@ export async function restartSidecar() {
return invoke<void>("restart_sidecar");
}
// export async function killSidecar() {
// return invoke<any>("kill_sidecar");
// }
export async function openAppDir() {
return invoke<void>("open_app_dir").catch((err) =>
Notice.error(err?.message || err.toString(), 1500)