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())
|
||||
}
|
||||
|
||||
#[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]
|
||||
fn is_autostart() -> Result<bool, String> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
@@ -243,7 +260,8 @@ pub fn run() {
|
||||
set_logging_level,
|
||||
set_tun_fd,
|
||||
is_autostart,
|
||||
easytier_version
|
||||
easytier_version,
|
||||
set_dock_visibility
|
||||
])
|
||||
.on_window_event(|_win, event| match event {
|
||||
#[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 { useTray } from '~/composables/tray'
|
||||
import { getAutoLaunchStatusAsync as getAutoLaunchStatus, loadAutoLaunchStatusAsync } from '~/modules/auto_launch'
|
||||
import { getDockVisibilityStatus, loadDockVisibilityAsync } from '~/modules/dock_visibility'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
const visible = ref(false)
|
||||
@@ -177,6 +178,14 @@ const setting_menu_items = ref([
|
||||
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'),
|
||||
icon: 'pi pi-file',
|
||||
|
||||
Reference in New Issue
Block a user