Merge pull request #21 from Pylogmon/tray-event

feat: Config Tray Click Event
This commit is contained in:
wonfen 2023-11-28 01:46:16 +08:00 committed by GitHub
commit b88486601b
7 changed files with 42 additions and 6 deletions

View File

@ -23,6 +23,9 @@ pub struct IVerge {
/// maybe be able to set the alpha /// maybe be able to set the alpha
pub theme_blur: Option<bool>, pub theme_blur: Option<bool>,
/// tray click event
pub tray_event: Option<String>,
/// enable traffic graph default is true /// enable traffic graph default is true
pub traffic_graph: Option<bool>, pub traffic_graph: Option<bool>,
@ -166,6 +169,7 @@ impl IVerge {
patch!(language); patch!(language);
patch!(theme_mode); patch!(theme_mode);
patch!(theme_blur); patch!(theme_blur);
patch!(tray_event);
patch!(traffic_graph); patch!(traffic_graph);
patch!(enable_memory_usage); patch!(enable_memory_usage);

View File

@ -146,8 +146,20 @@ impl Tray {
Ok(()) Ok(())
} }
pub fn on_left_click(app_handle: &AppHandle) {
let tray_event = { Config::verge().latest().tray_event.clone() };
let tray_event = tray_event.unwrap_or("main_window".into());
match tray_event.as_str() {
"system_proxy" => feat::toggle_system_proxy(),
"tun_mode" => feat::toggle_tun_mode(),
_ => resolve::create_window(app_handle),
}
}
pub fn on_system_tray_event(app_handle: &AppHandle, event: SystemTrayEvent) { pub fn on_system_tray_event(app_handle: &AppHandle, event: SystemTrayEvent) {
match event { match event {
#[cfg(not(target_os = "linux"))]
SystemTrayEvent::LeftClick { .. } => Tray::on_left_click(app_handle),
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
mode @ ("rule_mode" | "global_mode" | "direct_mode" | "script_mode") => { mode @ ("rule_mode" | "global_mode" | "direct_mode" | "script_mode") => {
let mode = &mode[0..mode.len() - 5]; let mode = &mode[0..mode.len() - 5];
@ -177,10 +189,6 @@ impl Tray {
} }
_ => {} _ => {}
}, },
#[cfg(target_os = "windows")]
SystemTrayEvent::LeftClick { .. } => {
resolve::create_window(app_handle);
}
_ => {} _ => {}
} }
} }

View File

@ -29,8 +29,7 @@ const SettingVerge = ({ onError }: Props) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { verge, patchVerge, mutateVerge } = useVerge(); const { verge, patchVerge, mutateVerge } = useVerge();
const { theme_mode, language } = verge ?? {}; const { theme_mode, language, tray_event } = verge ?? {};
const configRef = useRef<DialogRef>(null); const configRef = useRef<DialogRef>(null);
const hotkeyRef = useRef<DialogRef>(null); const hotkeyRef = useRef<DialogRef>(null);
const miscRef = useRef<DialogRef>(null); const miscRef = useRef<DialogRef>(null);
@ -91,6 +90,24 @@ const SettingVerge = ({ onError }: Props) => {
</GuardState> </GuardState>
</SettingItem> </SettingItem>
{OS !== "linux" && (
<SettingItem label={t("Tray Click Event")}>
<GuardState
value={tray_event ?? "main_window"}
onCatch={onError}
onFormat={(e: any) => e.target.value}
onChange={(e) => onChangeData({ tray_event: e })}
onGuard={(e) => patchVerge({ tray_event: e })}
>
<Select size="small" sx={{ width: 140, "> div": { py: "7.5px" } }}>
<MenuItem value="main_window">{t("Show Main Window")}</MenuItem>
<MenuItem value="system_proxy">{t("System Proxy")}</MenuItem>
<MenuItem value="tun_mode">{t("Tun Mode")}</MenuItem>
</Select>
</GuardState>
</SettingItem>
)}
<SettingItem label={t("Theme Setting")}> <SettingItem label={t("Theme Setting")}>
<IconButton <IconButton
color="inherit" color="inherit"

View File

@ -85,6 +85,8 @@
"Current System Proxy": "Current System Proxy", "Current System Proxy": "Current System Proxy",
"Theme Mode": "Theme Mode", "Theme Mode": "Theme Mode",
"Theme Blur": "Theme Blur", "Theme Blur": "Theme Blur",
"Tray Click Event": "Tray Click Event",
"Show Main Window": "Show Main Window",
"Theme Setting": "Theme Setting", "Theme Setting": "Theme Setting",
"Layout Setting": "Layout Setting", "Layout Setting": "Layout Setting",
"Miscellaneous": "Miscellaneous", "Miscellaneous": "Miscellaneous",

View File

@ -78,6 +78,8 @@
"Current System Proxy": "Текущий системный прокси", "Current System Proxy": "Текущий системный прокси",
"Theme Mode": "Режим темы", "Theme Mode": "Режим темы",
"Theme Blur": "Размытие темы", "Theme Blur": "Размытие темы",
"Tray Click Event": "Событие щелчка в лотке",
"Show Main Window": "Показать главное окно",
"Theme Setting": "Настройка темы", "Theme Setting": "Настройка темы",
"Hotkey Setting": "Настройка клавиатурных сокращений", "Hotkey Setting": "Настройка клавиатурных сокращений",
"Traffic Graph": "График трафика", "Traffic Graph": "График трафика",

View File

@ -85,6 +85,8 @@
"Bypass": "当前绕过:", "Bypass": "当前绕过:",
"Theme Mode": "主题模式", "Theme Mode": "主题模式",
"Theme Blur": "背景模糊", "Theme Blur": "背景模糊",
"Tray Click Event": "托盘点击事件",
"Show Main Window": "显示主窗口",
"Theme Setting": "主题设置", "Theme Setting": "主题设置",
"Layout Setting": "界面设置", "Layout Setting": "界面设置",
"Miscellaneous": "杂项设置", "Miscellaneous": "杂项设置",

View File

@ -155,6 +155,7 @@ interface IProfilesConfig {
interface IVergeConfig { interface IVergeConfig {
app_log_level?: "trace" | "debug" | "info" | "warn" | "error" | string; app_log_level?: "trace" | "debug" | "info" | "warn" | "error" | string;
language?: string; language?: string;
tray_event?: "main_window" | "system_proxy" | "tun_mode" | string;
clash_core?: string; clash_core?: string;
theme_mode?: "light" | "dark" | "system"; theme_mode?: "light" | "dark" | "system";
theme_blur?: boolean; theme_blur?: boolean;