mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 20:57:26 +08:00
feat(gui): add macOS dock icon visibility control (#1328)
This commit is contained in:
@@ -30,6 +30,23 @@ fn easytier_version() -> Result<String, String> {
|
|||||||
Ok(easytier::VERSION.to_string())
|
Ok(easytier::VERSION.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn set_dock_visibility(app: tauri::AppHandle, visible: bool) -> Result<(), String> {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
use tauri::ActivationPolicy;
|
||||||
|
app.set_activation_policy(if visible {
|
||||||
|
ActivationPolicy::Regular
|
||||||
|
} else {
|
||||||
|
ActivationPolicy::Accessory
|
||||||
|
})
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
let _ = (app, visible);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn is_autostart() -> Result<bool, String> {
|
fn is_autostart() -> Result<bool, String> {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
@@ -243,7 +260,8 @@ pub fn run() {
|
|||||||
set_logging_level,
|
set_logging_level,
|
||||||
set_tun_fd,
|
set_tun_fd,
|
||||||
is_autostart,
|
is_autostart,
|
||||||
easytier_version
|
easytier_version,
|
||||||
|
set_dock_visibility
|
||||||
])
|
])
|
||||||
.on_window_event(|_win, event| match event {
|
.on_window_event(|_win, event| match event {
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
|
|||||||
18
easytier-gui/src/modules/dock_visibility.ts
Normal file
18
easytier-gui/src/modules/dock_visibility.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
|
export async function loadDockVisibilityAsync(visible: boolean): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await invoke('set_dock_visibility', { visible })
|
||||||
|
localStorage.setItem('dock_visibility', JSON.stringify(visible))
|
||||||
|
return visible
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error('Failed to set dock visibility:', e)
|
||||||
|
return getDockVisibilityStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDockVisibilityStatus(): boolean {
|
||||||
|
const stored = localStorage.getItem('dock_visibility')
|
||||||
|
return stored !== null ? JSON.parse(stored) : true
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import { NetworkTypes, Config, Status, Utils, I18nUtils, ConfigEditDialog } from
|
|||||||
import { isAutostart, setLoggingLevel } from '~/composables/network'
|
import { isAutostart, setLoggingLevel } from '~/composables/network'
|
||||||
import { useTray } from '~/composables/tray'
|
import { useTray } from '~/composables/tray'
|
||||||
import { getAutoLaunchStatusAsync as getAutoLaunchStatus, loadAutoLaunchStatusAsync } from '~/modules/auto_launch'
|
import { getAutoLaunchStatusAsync as getAutoLaunchStatus, loadAutoLaunchStatusAsync } from '~/modules/auto_launch'
|
||||||
|
import { getDockVisibilityStatus, loadDockVisibilityAsync } from '~/modules/dock_visibility'
|
||||||
|
|
||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
@@ -177,6 +178,14 @@ const setting_menu_items = ref([
|
|||||||
await loadAutoLaunchStatusAsync(!getAutoLaunchStatus())
|
await loadAutoLaunchStatusAsync(!getAutoLaunchStatus())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: () => getDockVisibilityStatus() ? t('hide_dock_icon') : t('show_dock_icon'),
|
||||||
|
icon: 'pi pi-eye-slash',
|
||||||
|
command: async () => {
|
||||||
|
await loadDockVisibilityAsync(!getDockVisibilityStatus())
|
||||||
|
},
|
||||||
|
visible: () => type() === 'macos',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: () => t('logging'),
|
label: () => t('logging'),
|
||||||
icon: 'pi pi-file',
|
icon: 'pi pi-file',
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ logging_open_dir: 打开日志目录
|
|||||||
logging_copy_dir: 复制日志路径
|
logging_copy_dir: 复制日志路径
|
||||||
disable_auto_launch: 关闭开机自启
|
disable_auto_launch: 关闭开机自启
|
||||||
enable_auto_launch: 开启开机自启
|
enable_auto_launch: 开启开机自启
|
||||||
|
hide_dock_icon: 隐藏 Dock 图标
|
||||||
|
show_dock_icon: 显示 Dock 图标
|
||||||
exit: 退出
|
exit: 退出
|
||||||
chips_placeholder: 例如: {0}, 输入后在下拉框中选择生效
|
chips_placeholder: 例如: {0}, 输入后在下拉框中选择生效
|
||||||
hostname_placeholder: '留空默认为主机名: {0}'
|
hostname_placeholder: '留空默认为主机名: {0}'
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ logging_open_dir: Open Log Directory
|
|||||||
logging_copy_dir: Copy Log Path
|
logging_copy_dir: Copy Log Path
|
||||||
disable_auto_launch: Disable Launch on Reboot
|
disable_auto_launch: Disable Launch on Reboot
|
||||||
enable_auto_launch: Enable Launch on Reboot
|
enable_auto_launch: Enable Launch on Reboot
|
||||||
|
hide_dock_icon: Hide Dock Icon
|
||||||
|
show_dock_icon: Show Dock Icon
|
||||||
exit: Exit
|
exit: Exit
|
||||||
use_latency_first: Latency First Mode
|
use_latency_first: Latency First Mode
|
||||||
chips_placeholder: 'e.g: {0}, select from the dropdown after input'
|
chips_placeholder: 'e.g: {0}, select from the dropdown after input'
|
||||||
|
|||||||
Reference in New Issue
Block a user