mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 03:32:36 +08:00
feat: support get merged rule-set name
Some checks are pending
Alpha Build / alpha (macos-latest, aarch64-apple-darwin) (push) Waiting to run
Alpha Build / alpha (macos-latest, x86_64-apple-darwin) (push) Waiting to run
Alpha Build / alpha (windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha (windows-latest, i686-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha (windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, aarch64-unknown-linux-gnu) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, armv7-unknown-linux-gnueabihf) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, i686-unknown-linux-gnu) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Waiting to run
Alpha Build / alpha-for-fixed-webview2 (arm64, windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha-for-fixed-webview2 (x64, windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha-for-fixed-webview2 (x86, windows-latest, i686-pc-windows-msvc) (push) Waiting to run
Alpha Build / Update tag (push) Blocked by required conditions
Some checks are pending
Alpha Build / alpha (macos-latest, aarch64-apple-darwin) (push) Waiting to run
Alpha Build / alpha (macos-latest, x86_64-apple-darwin) (push) Waiting to run
Alpha Build / alpha (windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha (windows-latest, i686-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha (windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, aarch64-unknown-linux-gnu) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, armv7-unknown-linux-gnueabihf) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, i686-unknown-linux-gnu) (push) Waiting to run
Alpha Build / alpha-for-linux (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Waiting to run
Alpha Build / alpha-for-fixed-webview2 (arm64, windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha-for-fixed-webview2 (x64, windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Alpha Build / alpha-for-fixed-webview2 (x86, windows-latest, i686-pc-windows-msvc) (push) Waiting to run
Alpha Build / Update tag (push) Blocked by required conditions
This commit is contained in:
parent
19e9e9d032
commit
e8440e06a1
|
@ -483,6 +483,8 @@ export const ProfileItem = (props: Props) => {
|
|||
onClose={() => setFileOpen(false)}
|
||||
/>
|
||||
<RulesEditorViewer
|
||||
groupsUid={option?.groups ?? ""}
|
||||
mergeUid={option?.merge ?? ""}
|
||||
profileUid={uid}
|
||||
property={option?.rules ?? ""}
|
||||
open={rulesOpen}
|
||||
|
|
|
@ -40,6 +40,8 @@ import MonacoEditor from "react-monaco-editor";
|
|||
import { useThemeMode } from "@/services/states";
|
||||
|
||||
interface Props {
|
||||
groupsUid: string;
|
||||
mergeUid: string;
|
||||
profileUid: string;
|
||||
title?: string | ReactNode;
|
||||
property: string;
|
||||
|
@ -230,7 +232,16 @@ const rules: {
|
|||
const builtinProxyPolicies = ["DIRECT", "REJECT", "REJECT-DROP", "PASS"];
|
||||
|
||||
export const RulesEditorViewer = (props: Props) => {
|
||||
const { title, profileUid, property, open, onClose, onSave } = props;
|
||||
const {
|
||||
title,
|
||||
groupsUid,
|
||||
mergeUid,
|
||||
profileUid,
|
||||
property,
|
||||
open,
|
||||
onClose,
|
||||
onSave,
|
||||
} = props;
|
||||
const { t } = useTranslation();
|
||||
const themeMode = useThemeMode();
|
||||
|
||||
|
@ -291,11 +302,11 @@ export const RulesEditorViewer = (props: Props) => {
|
|||
};
|
||||
const fetchContent = async () => {
|
||||
let data = await readProfileFile(property);
|
||||
let obj = yaml.load(data) as { prepend: []; append: []; delete: [] };
|
||||
let obj = yaml.load(data) as { prepend: []; append: []; delete: [] } | null;
|
||||
|
||||
setPrependSeq(obj.prepend || []);
|
||||
setAppendSeq(obj.append || []);
|
||||
setDeleteSeq(obj.delete || []);
|
||||
setPrependSeq(obj?.prepend || []);
|
||||
setAppendSeq(obj?.append || []);
|
||||
setDeleteSeq(obj?.delete || []);
|
||||
|
||||
setPrevData(data);
|
||||
setCurrData(data);
|
||||
|
@ -305,10 +316,14 @@ export const RulesEditorViewer = (props: Props) => {
|
|||
if (currData === "") return;
|
||||
if (visible !== true) return;
|
||||
|
||||
let obj = yaml.load(currData) as { prepend: []; append: []; delete: [] };
|
||||
setPrependSeq(obj.prepend || []);
|
||||
setAppendSeq(obj.append || []);
|
||||
setDeleteSeq(obj.delete || []);
|
||||
let obj = yaml.load(currData) as {
|
||||
prepend: [];
|
||||
append: [];
|
||||
delete: [];
|
||||
} | null;
|
||||
setPrependSeq(obj?.prepend || []);
|
||||
setAppendSeq(obj?.append || []);
|
||||
setDeleteSeq(obj?.delete || []);
|
||||
}, [visible]);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -320,26 +335,45 @@ export const RulesEditorViewer = (props: Props) => {
|
|||
|
||||
const fetchProfile = async () => {
|
||||
let data = await readProfileFile(profileUid);
|
||||
let groupsObj = yaml.load(data) as { "proxy-groups": [] };
|
||||
let rulesObj = yaml.load(data) as { rules: [] };
|
||||
let ruleSetObj = yaml.load(data) as { "rule-providers": [] };
|
||||
let subRuleObj = yaml.load(data) as { "sub-rules": [] };
|
||||
let groupsData = await readProfileFile(groupsUid);
|
||||
let mergeData = await readProfileFile(mergeUid);
|
||||
let globalMergeData = await readProfileFile("Merge");
|
||||
|
||||
let rulesObj = yaml.load(data) as { rules: [] } | null;
|
||||
|
||||
let originGroupsObj = yaml.load(data) as { "proxy-groups": [] } | null;
|
||||
let originGroups = originGroupsObj?.["proxy-groups"] || [];
|
||||
let moreGroupsObj = yaml.load(groupsData) as { "proxy-groups": [] } | null;
|
||||
let moreGroups = moreGroupsObj?.["proxy-groups"] || [];
|
||||
let groups = originGroups.concat(moreGroups);
|
||||
|
||||
let originRuleSetObj = yaml.load(data) as { "rule-providers": {} } | null;
|
||||
let originRuleSet = originRuleSetObj?.["rule-providers"] || {};
|
||||
let moreRuleSetObj = yaml.load(mergeData) as {
|
||||
"rule-providers": {};
|
||||
} | null;
|
||||
let moreRuleSet = moreRuleSetObj?.["rule-providers"] || {};
|
||||
let globalRuleSetObj = yaml.load(globalMergeData) as {
|
||||
"rule-providers": {};
|
||||
} | null;
|
||||
let globalRuleSet = globalRuleSetObj?.["rule-providers"] || {};
|
||||
let ruleSet = Object.assign({}, originRuleSet, moreRuleSet, globalRuleSet);
|
||||
|
||||
let originSubRuleObj = yaml.load(data) as { "sub-rules": {} } | null;
|
||||
let originSubRule = originSubRuleObj?.["sub-rules"] || {};
|
||||
let moreSubRuleObj = yaml.load(mergeData) as { "sub-rules": {} } | null;
|
||||
let moreSubRule = moreSubRuleObj?.["sub-rules"] || {};
|
||||
let globalSubRuleObj = yaml.load(globalMergeData) as {
|
||||
"sub-rules": {};
|
||||
} | null;
|
||||
let globalSubRule = globalSubRuleObj?.["sub-rules"] || {};
|
||||
let subRule = Object.assign({}, originSubRule, moreSubRule, globalSubRule);
|
||||
setProxyPolicyList(
|
||||
builtinProxyPolicies.concat(
|
||||
groupsObj["proxy-groups"]
|
||||
? groupsObj["proxy-groups"].map((item: any) => item.name)
|
||||
: []
|
||||
)
|
||||
);
|
||||
setRuleList(rulesObj.rules || []);
|
||||
setRuleSetList(
|
||||
ruleSetObj["rule-providers"]
|
||||
? Object.keys(ruleSetObj["rule-providers"])
|
||||
: []
|
||||
);
|
||||
setSubRuleList(
|
||||
subRuleObj["sub-rules"] ? Object.keys(subRuleObj["sub-rules"]) : []
|
||||
builtinProxyPolicies.concat(groups.map((group: any) => group.name))
|
||||
);
|
||||
setRuleSetList(Object.keys(ruleSet));
|
||||
setSubRuleList(Object.keys(subRule));
|
||||
setRuleList(rulesObj?.rules || []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user