feat: record selected proxy

This commit is contained in:
GyDi
2021-12-28 01:47:43 +08:00
parent 61b9670b45
commit 14bda4f3a5
4 changed files with 69 additions and 11 deletions

View File

@@ -22,6 +22,8 @@ import {
} from "@mui/icons-material";
import { updateProxy } from "../services/api";
import { ApiType } from "../services/types";
import { getProfiles, setProfiles } from "../services/cmds";
import noop from "../utils/noop";
interface ItemProps {
proxy: ApiType.ProxyItem;
@@ -86,6 +88,24 @@ const ProxyGroup = ({ group }: Props) => {
try {
setNow(name);
await updateProxy(group.name, name);
const profiles = await getProfiles().catch(console.error);
if (!profiles) return;
const profile = profiles.items![profiles.current!]!;
if (!profile) return;
if (!profile.selected) profile.selected = [];
const index = profile.selected.findIndex(
(item) => item.name === group.name
);
if (index < 0) {
profile.selected.push({ name: group.name, now: name });
} else {
profile.selected[index] = { name: group.name, now: name };
}
setProfiles(profiles.current!, profile).catch(console.error);
} catch {
setNow(oldValue);
// Todo