Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dongchengjie committed May 15, 2024
2 parents 7e3a759 + ecb2fbf commit 3581300
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/config/verge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct IVerge {
pub common_tray_icon: Option<bool>,

/// tray icon
#[cfg(target_os = "macos")]
pub tray_icon: Option<String>,

/// menu icon
Expand Down Expand Up @@ -203,8 +204,6 @@ impl IVerge {
enable_group_icon: Some(true),
#[cfg(target_os = "macos")]
tray_icon: Some("monochrome".into()),
#[cfg(not(target_os = "macos"))]
tray_icon: Some("colorful".into()),
menu_icon: Some("monochrome".into()),
common_tray_icon: Some(false),
sysproxy_tray_icon: Some(false),
Expand Down Expand Up @@ -262,6 +261,7 @@ impl IVerge {
patch!(traffic_graph);
patch!(enable_memory_usage);
patch!(enable_group_icon);
#[cfg(target_os = "macos")]
patch!(tray_icon);
patch!(menu_icon);
patch!(common_tray_icon);
Expand Down
21 changes: 9 additions & 12 deletions src-tauri/src/core/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ impl Tray {
let tun_mode = verge.enable_tun_mode.as_ref().unwrap_or(&false);
#[cfg(target_os = "macos")]
let tray_icon = verge.tray_icon.clone().unwrap_or("monochrome".to_string());
#[cfg(not(target_os = "macos"))]
let tray_icon = verge.tray_icon.clone().unwrap_or("colorful".to_string());
let common_tray_icon = verge.common_tray_icon.as_ref().unwrap_or(&false);
let sysproxy_tray_icon = verge.sysproxy_tray_icon.as_ref().unwrap_or(&false);
let tun_tray_icon = verge.tun_tray_icon.as_ref().unwrap_or(&false);
Expand All @@ -185,20 +183,19 @@ impl Tray {
let _ = tray.set_icon_as_template(true);
}
"colorful" => {
#[cfg(target_os = "macos")]
let _ = tray.set_icon_as_template(false);
}
_ => {}
}
let mut indication_icon = if *system_proxy {
#[cfg(target_os = "macos")]
let mut icon = match tray_icon.as_str() {
"monochrome" => include_bytes!("../../icons/tray-icon-sys-mono.ico").to_vec(),
"colorful" => include_bytes!("../../icons/tray-icon-sys.ico").to_vec(),
#[cfg(target_os = "macos")]
_ => include_bytes!("../../icons/tray-icon-sys-mono.ico").to_vec(),
#[cfg(not(target_os = "macos"))]
_ => include_bytes!("../../icons/tray-icon-sys.ico").to_vec(),
};
#[cfg(not(target_os = "macos"))]
let mut icon = include_bytes!("../../icons/tray-icon-sys.ico").to_vec();

if *sysproxy_tray_icon {
let icon_dir_path = dirs::app_home_dir()?.join("icons");
Expand All @@ -212,14 +209,14 @@ impl Tray {
}
icon
} else {
#[cfg(target_os = "macos")]
let mut icon = match tray_icon.as_str() {
"monochrome" => include_bytes!("../../icons/tray-icon-mono.ico").to_vec(),
"colorful" => include_bytes!("../../icons/tray-icon.ico").to_vec(),
#[cfg(target_os = "macos")]
_ => include_bytes!("../../icons/tray-icon-mono.ico").to_vec(),
#[cfg(not(target_os = "macos"))]
_ => include_bytes!("../../icons/tray-icon.ico").to_vec(),
};
#[cfg(not(target_os = "macos"))]
let mut icon = include_bytes!("../../icons/tray-icon.ico").to_vec();
if *common_tray_icon {
let icon_dir_path = dirs::app_home_dir()?.join("icons");
let png_path = icon_dir_path.join("common.png");
Expand All @@ -234,14 +231,14 @@ impl Tray {
};

if *tun_mode {
#[cfg(target_os = "macos")]
let mut icon = match tray_icon.as_str() {
"monochrome" => include_bytes!("../../icons/tray-icon-tun-mono.ico").to_vec(),
"colorful" => include_bytes!("../../icons/tray-icon-tun.ico").to_vec(),
#[cfg(target_os = "macos")]
_ => include_bytes!("../../icons/tray-icon-tun-mono.ico").to_vec(),
#[cfg(not(target_os = "macos"))]
_ => include_bytes!("../../icons/tray-icon-tun.ico").to_vec(),
};
#[cfg(not(target_os = "macos"))]
let mut icon = include_bytes!("../../icons/tray-icon-tun.ico").to_vec();
if *tun_tray_icon {
let icon_dir_path = dirs::app_home_dir()?.join("icons");
let png_path = icon_dir_path.join("tun.png");
Expand Down
6 changes: 5 additions & 1 deletion src-tauri/src/feat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
let proxy_bypass = patch.system_proxy_bypass;
let language = patch.language;
let port = patch.verge_mixed_port;
#[cfg(target_os = "macos")]
let tray_icon = patch.tray_icon;
let common_tray_icon = patch.common_tray_icon;
let sysproxy_tray_icon = patch.sysproxy_tray_icon;
Expand Down Expand Up @@ -235,13 +236,16 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
handle::Handle::update_systray()?;
} else if system_proxy.is_some()
|| tun_mode.is_some()
|| tray_icon.is_some()
|| common_tray_icon.is_some()
|| sysproxy_tray_icon.is_some()
|| tun_tray_icon.is_some()
{
handle::Handle::update_systray_part()?;
}
#[cfg(target_os = "macos")]
if tray_icon.is_some() {
handle::Handle::update_systray_part()?;
}

<Result<()>>::Ok(())
} {
Expand Down
39 changes: 21 additions & 18 deletions src/components/setting/mods/layout-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { join } from "@tauri-apps/api/path";
import { exists } from "@tauri-apps/api/fs";
import getSystem from "@/utils/get-system";

const OS = getSystem();

export const LayoutViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation();
const { verge, patchVerge, mutateVerge } = useVerge();
Expand Down Expand Up @@ -129,24 +131,25 @@ export const LayoutViewer = forwardRef<DialogRef>((props, ref) => {
</Select>
</GuardState>
</SettingItem>

<SettingItem label={t("Tray Icon")}>
<GuardState
value={
verge?.tray_icon ??
(getSystem() === "macos" ? "monochrome" : "colorful")
}
onCatch={onError}
onFormat={(e: any) => e.target.value}
onChange={(e) => onChangeData({ tray_icon: e })}
onGuard={(e) => patchVerge({ tray_icon: e })}
>
<Select size="small" sx={{ width: 140, "> div": { py: "7.5px" } }}>
<MenuItem value="monochrome">{t("Monochrome")}</MenuItem>
<MenuItem value="colorful">{t("Colorful")}</MenuItem>
</Select>
</GuardState>
</SettingItem>
{OS === "macos" && (
<SettingItem label={t("Tray Icon")}>
<GuardState
value={verge?.tray_icon ?? "monochrome"}
onCatch={onError}
onFormat={(e: any) => e.target.value}
onChange={(e) => onChangeData({ tray_icon: e })}
onGuard={(e) => patchVerge({ tray_icon: e })}
>
<Select
size="small"
sx={{ width: 140, "> div": { py: "7.5px" } }}
>
<MenuItem value="monochrome">{t("Monochrome")}</MenuItem>
<MenuItem value="colorful">{t("Colorful")}</MenuItem>
</Select>
</GuardState>
</SettingItem>
)}

<SettingItem label={t("Common Tray Icon")}>
<GuardState
Expand Down

0 comments on commit 3581300

Please sign in to comment.