fix: adjust fields order

This commit is contained in:
GyDi 2023-01-14 14:57:55 +08:00
parent 780ab20aeb
commit 7909cf4067
No known key found for this signature in database
GPG Key ID: B28E790B95193457
3 changed files with 13 additions and 22 deletions

View File

@ -1,34 +1,34 @@
use serde_yaml::{Mapping, Value}; use serde_yaml::{Mapping, Value};
pub const HANDLE_FIELDS: [&str; 9] = [ pub const HANDLE_FIELDS: [&str; 9] = [
"mode",
"port", "port",
"socks-port", "socks-port",
"mixed-port", "mixed-port",
"mode",
"ipv6",
"log-level",
"allow-lan", "allow-lan",
"external-controller", "log-level",
"ipv6",
"secret", "secret",
"external-controller",
]; ];
pub const DEFAULT_FIELDS: [&str; 5] = [ pub const DEFAULT_FIELDS: [&str; 5] = [
"proxies", "proxies",
"proxy-groups", "proxy-groups",
"rules",
"proxy-providers", "proxy-providers",
"rules",
"rule-providers", "rule-providers",
]; ];
pub const OTHERS_FIELDS: [&str; 25] = [ pub const OTHERS_FIELDS: [&str; 25] = [
"tun",
"dns", "dns",
"tun",
"ebpf", "ebpf",
"hosts", "hosts",
"script", "script",
"profile", "profile",
"payload", "payload",
"tunnels", // clash dev "tunnels",
"auto-redir", "auto-redir",
"experimental", "experimental",
"interface-name", "interface-name",

View File

@ -13,17 +13,8 @@ import { BaseDialog, DialogRef } from "@/components/base";
import { useProfiles } from "@/hooks/use-profiles"; import { useProfiles } from "@/hooks/use-profiles";
import { Notice } from "@/components/base"; import { Notice } from "@/components/base";
const fieldSorter = (a: string, b: string) => { const otherFields = [...OTHERS_FIELDS];
if (a.includes("-") === a.includes("-")) { const handleFields = [...HANDLE_FIELDS, ...DEFAULT_FIELDS];
if (a.length === b.length) return a.localeCompare(b);
return a.length - b.length;
} else if (a.includes("-")) return 1;
else if (b.includes("-")) return -1;
return 0;
};
const otherFields = [...OTHERS_FIELDS].sort(fieldSorter);
const handleFields = [...HANDLE_FIELDS, ...DEFAULT_FIELDS].sort(fieldSorter);
export const ClashFieldViewer = forwardRef<DialogRef>((props, ref) => { export const ClashFieldViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -1,9 +1,9 @@
export const HANDLE_FIELDS = [ export const HANDLE_FIELDS = [
"mode",
"port", "port",
"socks-port", "socks-port",
"mixed-port", "mixed-port",
"allow-lan", "allow-lan",
"mode",
"log-level", "log-level",
"ipv6", "ipv6",
"secret", "secret",
@ -11,22 +11,22 @@ export const HANDLE_FIELDS = [
]; ];
export const DEFAULT_FIELDS = [ export const DEFAULT_FIELDS = [
"rules",
"proxies", "proxies",
"proxy-groups", "proxy-groups",
"proxy-providers", "proxy-providers",
"rules",
"rule-providers", "rule-providers",
] as const; ] as const;
export const OTHERS_FIELDS = [ export const OTHERS_FIELDS = [
"tun",
"dns", "dns",
"tun",
"ebpf", "ebpf",
"hosts", "hosts",
"script", "script",
"profile", "profile",
"payload", "payload",
"tunnels", // clash dev "tunnels",
"auto-redir", "auto-redir",
"experimental", "experimental",
"interface-name", "interface-name",