fix: 修复窗口控制功能 - 拖拽、最小化、最大化、关闭

🔧 问题修复:
- 修复窗口拖拽功能不可用问题
- 修复窗口最小化/最大化/关闭按钮不工作问题
- 优化 Tauri 窗口配置

🛠️ 技术改进:
- 更新 TitleBar 组件,使用正确的 Tauri v2 API
- 添加错误处理和状态管理
- 设置正确的拖拽区域 (data-tauri-drag-region)
- 优化窗口配置 (decorations: false, titleBarStyle: Overlay)

 功能特性:
- 自定义标题栏设计
- 响应式窗口控制按钮
- 窗口状态实时同步
- 现代化 UI 设计

📋 测试说明:
- 在有 GUI 环境中测试拖拽功能
- 验证所有窗口控制按钮正常工作
- 确认窗口大小限制生效
This commit is contained in:
root 2025-07-10 10:20:41 +08:00
parent de2dafe661
commit 4ffb8a278e
4 changed files with 49 additions and 12 deletions

View File

@ -16,16 +16,17 @@
},
"dependencies": {
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.0",
"@tauri-apps/plugin-fs": "^2.0.0",
"@tauri-apps/plugin-dialog": "^2.0.0",
"@tauri-apps/plugin-fs": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.0",
"@tauri-apps/plugin-window": "2.0.0-alpha.1",
"clsx": "^2.0.0",
"lucide-react": "^0.263.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"zustand": "^4.4.0",
"lucide-react": "^0.263.1",
"clsx": "^2.0.0",
"tailwind-merge": "^1.14.0"
"tailwind-merge": "^1.14.0",
"zustand": "^4.4.0"
},
"devDependencies": {
"@tauri-apps/cli": "^2.0.0",

View File

@ -20,6 +20,9 @@ importers:
'@tauri-apps/plugin-shell':
specifier: ^2.0.0
version: 2.3.0
'@tauri-apps/plugin-window':
specifier: 2.0.0-alpha.1
version: 2.0.0-alpha.1
clsx:
specifier: ^2.0.0
version: 2.1.1
@ -387,6 +390,10 @@ packages:
'@rolldown/pluginutils@1.0.0-beta.19':
resolution: {integrity: sha512-3FL3mnMbPu0muGOCaKAhhFEYmqv9eTfPSJRJmANrCwtgK8VuxpsZDGK+m0LYAGoyO8+0j5uRe4PeyPDK1yA/hA==}
'@tauri-apps/api@2.0.0-alpha.6':
resolution: {integrity: sha512-ZMOc3eu9amwvkC6M69h3hWt4/EsFaAXmtkiw4xd2LN59/lTb4ZQiVfq2QKlRcu1rj3n/Tcr7U30ZopvHwXBGIg==}
engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'}
'@tauri-apps/api@2.6.0':
resolution: {integrity: sha512-hRNcdercfgpzgFrMXWwNDBN0B7vNzOzRepy6ZAmhxi5mDLVPNrTpo9MGg2tN/F7JRugj4d2aF7E1rtPXAHaetg==}
@ -470,6 +477,9 @@ packages:
'@tauri-apps/plugin-shell@2.3.0':
resolution: {integrity: sha512-6GIRxO2z64uxPX4CCTuhQzefvCC0ew7HjdBhMALiGw74vFBDY95VWueAHOHgNOMV4UOUAFupyidN9YulTe5xlA==}
'@tauri-apps/plugin-window@2.0.0-alpha.1':
resolution: {integrity: sha512-dFOAgal/3Txz3SQ+LNQq0AK1EPC+acdaFlwPVB/6KXUZYmaFleIlzgxDVoJCQ+/xOhxvYrdQaFLefh0I/Kldbg==}
'@types/babel__core@7.20.5':
resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==}
@ -2113,6 +2123,8 @@ snapshots:
'@rolldown/pluginutils@1.0.0-beta.19': {}
'@tauri-apps/api@2.0.0-alpha.6': {}
'@tauri-apps/api@2.6.0': {}
'@tauri-apps/cli-darwin-arm64@2.6.2':
@ -2174,6 +2186,10 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.6.0
'@tauri-apps/plugin-window@2.0.0-alpha.1':
dependencies:
'@tauri-apps/api': 2.0.0-alpha.6
'@types/babel__core@7.20.5':
dependencies:
'@babel/parser': 7.28.0

View File

@ -20,6 +20,7 @@
"resizable": true,
"fullscreen": false,
"decorations": false,
"titleBarStyle": "Overlay",
"transparent": false,
"center": true
}

View File

@ -7,20 +7,39 @@ const TitleBar: React.FC = () => {
useEffect(() => {
const checkMaximized = async () => {
const window = getCurrentWindow()
const maximized = await window.isMaximized()
setIsMaximized(maximized)
try {
const window = getCurrentWindow()
const maximized = await window.isMaximized()
setIsMaximized(maximized)
} catch (error) {
console.error('Failed to check window state:', error)
}
}
checkMaximized()
// Listen for window resize events
const unlisten = getCurrentWindow().listen('tauri://resize', () => {
checkMaximized()
const setupListener = async () => {
try {
const unlisten = await getCurrentWindow().listen('tauri://resize', () => {
checkMaximized()
})
return unlisten
} catch (error) {
console.error('Failed to setup window listener:', error)
return () => {}
}
}
let unlistenFn: (() => void) | null = null
setupListener().then(fn => {
unlistenFn = fn
})
return () => {
unlisten.then(fn => fn())
if (unlistenFn) {
unlistenFn()
}
}
}, [])