mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-14 05:37:23 +08:00
feat(gui): macOS UX Improvements (#1631)
This commit is contained in:
@@ -392,19 +392,25 @@ async fn is_client_running() -> Result<bool, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
fn toggle_window_visibility<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
|
fn toggle_window_visibility(app: &tauri::AppHandle) {
|
||||||
if let Some(window) = app.get_webview_window("main") {
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
if window.is_visible().unwrap_or_default() {
|
let visible = if window.is_visible().unwrap_or_default() {
|
||||||
if window.is_minimized().unwrap_or_default() {
|
if window.is_minimized().unwrap_or_default() {
|
||||||
let _ = window.unminimize();
|
let _ = window.unminimize();
|
||||||
let _ = window.set_focus();
|
false
|
||||||
} else {
|
} else {
|
||||||
let _ = window.hide();
|
true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let _ = window.show();
|
let _ = window.show();
|
||||||
|
false
|
||||||
|
};
|
||||||
|
if visible {
|
||||||
|
let _ = window.hide();
|
||||||
|
} else {
|
||||||
let _ = window.set_focus();
|
let _ = window.set_focus();
|
||||||
}
|
}
|
||||||
|
let _ = set_dock_visibility(app.clone(), !visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -892,7 +898,7 @@ pub fn run_gui() -> std::process::ExitCode {
|
|||||||
.icon(tauri::image::Image::from_bytes(include_bytes!(
|
.icon(tauri::image::Image::from_bytes(include_bytes!(
|
||||||
"../icons/icon.png"
|
"../icons/icon.png"
|
||||||
))?)
|
))?)
|
||||||
.icon_as_template(false)
|
.icon_as_template(true)
|
||||||
.build(app)?;
|
.build(app)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -924,6 +930,7 @@ pub fn run_gui() -> std::process::ExitCode {
|
|||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
let _ = _win.hide();
|
let _ = _win.hide();
|
||||||
|
let _ = set_dock_visibility(_win.app_handle().clone(), false);
|
||||||
api.prevent_close();
|
api.prevent_close();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -931,20 +938,8 @@ pub fn run_gui() -> std::process::ExitCode {
|
|||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
app.run(|_app, _event| {});
|
app.run(|_app, _event| {});
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
use tauri::RunEvent;
|
|
||||||
app.run(|app, event| match event {
|
|
||||||
RunEvent::Reopen { .. } => {
|
|
||||||
toggle_window_visibility(app);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
std::process::ExitCode::SUCCESS
|
std::process::ExitCode::SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ import type { MenuItem } from 'primevue/menuitem'
|
|||||||
import { useTray } from '~/composables/tray'
|
import { useTray } from '~/composables/tray'
|
||||||
import { GUIRemoteClient } from '~/modules/api'
|
import { GUIRemoteClient } from '~/modules/api'
|
||||||
|
|
||||||
import { getDockVisibilityStatus, loadDockVisibilityAsync } from '~/modules/dock_visibility'
|
|
||||||
import { useToast, useConfirm } from 'primevue'
|
import { useToast, useConfirm } from 'primevue'
|
||||||
import { loadMode, saveMode, type Mode } from '~/composables/mode'
|
import { loadMode, saveMode, type Mode } from '~/composables/mode'
|
||||||
import ModeSwitcher from '~/components/ModeSwitcher.vue'
|
import ModeSwitcher from '~/components/ModeSwitcher.vue'
|
||||||
@@ -263,14 +262,6 @@ const setting_menu_items: Ref<MenuItem[]> = ref([
|
|||||||
command: openModeDialog,
|
command: openModeDialog,
|
||||||
visible: () => type() !== 'android',
|
visible: () => type() !== 'android',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: () => getDockVisibilityStatus() ? t('hide_dock_icon') : t('show_dock_icon'),
|
|
||||||
icon: 'pi pi-eye-slash',
|
|
||||||
command: async () => {
|
|
||||||
await loadDockVisibilityAsync(!getDockVisibilityStatus())
|
|
||||||
},
|
|
||||||
visible: () => type() === 'macos',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: 'logging_menu',
|
key: 'logging_menu',
|
||||||
label: () => t('logging'),
|
label: () => t('logging'),
|
||||||
|
|||||||
Reference in New Issue
Block a user