From 739161849a22f3f3f19c65d35c1d1db54dd809fb Mon Sep 17 00:00:00 2001 From: MystiPanda Date: Sun, 10 Mar 2024 19:54:47 +0800 Subject: [PATCH] feat: Add option to control menu icon --- src-tauri/src/config/verge.rs | 5 +++++ src/components/layout/layout-item.tsx | 17 +++++++++----- src/components/setting/mods/layout-viewer.tsx | 19 +++++++++++++++- src/locales/zh.json | 3 +++ src/pages/_routers.tsx | 22 +++++++++++++------ src/services/types.d.ts | 1 + 6 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 64e3f206..579fde82 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -42,6 +42,9 @@ pub struct IVerge { /// common tray icon pub common_tray_icon: Option, + /// menu icon + pub menu_icon: Option, + /// sysproxy tray icon pub sysproxy_tray_icon: Option, @@ -176,6 +179,7 @@ impl IVerge { traffic_graph: Some(true), enable_memory_usage: Some(true), enable_group_icon: Some(true), + menu_icon: Some("monochrome".into()), common_tray_icon: Some(false), sysproxy_tray_icon: Some(false), tun_tray_icon: Some(false), @@ -221,6 +225,7 @@ impl IVerge { patch!(traffic_graph); patch!(enable_memory_usage); patch!(enable_group_icon); + patch!(menu_icon); patch!(common_tray_icon); patch!(sysproxy_tray_icon); patch!(tun_tray_icon); diff --git a/src/components/layout/layout-item.tsx b/src/components/layout/layout-item.tsx index 1852ad23..37be8229 100644 --- a/src/components/layout/layout-item.tsx +++ b/src/components/layout/layout-item.tsx @@ -6,15 +6,16 @@ import { ListItemIcon, } from "@mui/material"; import { useMatch, useResolvedPath, useNavigate } from "react-router-dom"; - +import { useVerge } from "@/hooks/use-verge"; interface Props { to: string; children: string; - icon: React.ReactNode; + icon: React.ReactNode[]; } export const LayoutItem = (props: Props) => { const { to, children, icon } = props; - + const { verge } = useVerge(); + const { menu_icon } = verge ?? {}; const resolved = useResolvedPath(to); const match = useMatch({ path: resolved.pathname, end: true }); const navigate = useNavigate(); @@ -27,7 +28,7 @@ export const LayoutItem = (props: Props) => { { borderRadius: 2, marginLeft: 1.25, - paddingLeft: 1.5, + paddingLeft: 1, paddingRight: 1, marginRight: 1.25, "& .MuiListItemText-primary": { @@ -51,9 +52,13 @@ export const LayoutItem = (props: Props) => { ]} onClick={() => navigate(to)} > - {icon} + {menu_icon === "monochrome" && {icon[0]}} + {menu_icon === "colorful" && {icon[1]}} diff --git a/src/components/setting/mods/layout-viewer.tsx b/src/components/setting/mods/layout-viewer.tsx index 4bccf7ee..4c0fdd78 100644 --- a/src/components/setting/mods/layout-viewer.tsx +++ b/src/components/setting/mods/layout-viewer.tsx @@ -1,6 +1,6 @@ import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { useTranslation } from "react-i18next"; -import { List, Button } from "@mui/material"; +import { List, Button, Select, MenuItem } from "@mui/material"; import { useVerge } from "@/hooks/use-verge"; import { BaseDialog, DialogRef, Notice, Switch } from "@/components/base"; import { SettingItem } from "./setting-comp"; @@ -19,6 +19,7 @@ export const LayoutViewer = forwardRef((props, ref) => { const [sysproxyIcon, setSysproxyIcon] = useState(""); const [tunIcon, setTunIcon] = useState(""); + // const { menu_icon } = verge ?? {}; useEffect(() => { initIconPath(); }, []); @@ -97,6 +98,22 @@ export const LayoutViewer = forwardRef((props, ref) => { + + e.target.value} + onChange={(e) => onChangeData({ menu_icon: e })} + onGuard={(e) => patchVerge({ menu_icon: e })} + > + + + + , + icon: [, ], ele: ProxiesPage, }, { label: "Label-Profiles", link: "/profile", - icon: , + icon: [, ], ele: ProfilesPage, }, { label: "Label-Connections", link: "/connections", - icon: , + icon: [, ], ele: ConnectionsPage, }, { label: "Label-Rules", link: "/rules", - icon: , + icon: [, ], ele: RulesPage, }, { label: "Label-Logs", link: "/logs", - icon: , + icon: [, ], ele: LogsPage, }, { label: "Label-Test", link: "/test", - icon: , + icon: [, ], ele: TestPage, }, { label: "Label-Settings", link: "/settings", - icon: , + icon: [, ], ele: SettingsPage, }, ]; diff --git a/src/services/types.d.ts b/src/services/types.d.ts index 89112b47..a81751b7 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -202,6 +202,7 @@ interface IVergeConfig { traffic_graph?: boolean; enable_memory_usage?: boolean; enable_group_icon?: boolean; + menu_icon?: "monochrome" | "colorful" | "disable"; common_tray_icon?: boolean; sysproxy_tray_icon?: boolean; tun_tray_icon?: boolean;