diff --git a/.gitignore b/.gitignore index f07c258..0d33260 100644 --- a/.gitignore +++ b/.gitignore @@ -1,59 +1,43 @@ +``` # Dependencies -node_modules -.pnp -.pnp.js +node_modules/ +target/ -# Build outputs -dist -dist-ssr -out -*.local - -# Tauri -src-tauri/target -src-tauri/Cargo.lock -src-tauri/gen -.cargo-local/ - -# Database -data.sql -*.sqlite -*.sqlite3 -*.db -*.db-shm -*.db-wal +# IDE +.vscode/ +.idea/ # Logs -logs *.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* -# Editor directories and files -.DS_Store -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? - -# Environment files +# Environment .env .env.local -.env.*.local +*.env.* -# Testing -coverage - -# Cache +# Python +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +env/ +venv/ +.venv/ +pip-log.txt +pip-delete-this-directory.txt +.tox/ +.coverage +.coverage.* .cache -.temp -.tmp -.eslintcache -# OS files +nosetests.xml +coverage.xml +*.cover +*.log +.git/modules/ +*.sublime-workspace +.pytest_cache/ +.hypothesis/ +.DS_Store Thumbs.db +``` \ No newline at end of file diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 125d175..770fa93 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -152,3 +152,20 @@ pub async fn window_set_resizable( } Ok(()) } + +#[tauri::command] +pub async fn window_start_dragging( + app: AppHandle, + _state: tauri::State<'_, Arc>>, +) -> Result<(), String> { + #[cfg(not(desktop))] + { + let _ = app; + } + + #[cfg(desktop)] + if let Some(window) = app.get_webview_window("main") { + window.start_dragging().map_err(|e| e.to_string())?; + } + Ok(()) +} diff --git a/src/main.tsx b/src/main.tsx index 2239dc2..3160273 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -143,6 +143,83 @@ const disableTouchZoom = () => { } disableTouchZoom() +// 桌面端触屏窗口拖动支持 +const enableTouchWindowDrag = () => { + const api = (window as any).api + if (!api) return + + let touchStartX = 0 + let touchStartY = 0 + let isDragging = false + let dragElement: Element | null = null + + document.addEventListener( + "touchstart", + (event) => { + const target = event.target as Element + if (!target) return + + // 检查是否在可拖动区域内 + const dragRegion = target.closest('[data-tauri-drag-region]') + if (!dragRegion) return + + // 检查是否点击了不可拖动的元素(如按钮) + const noDragElement = target.closest('button, input, select, a, [role="button"]') + if (noDragElement) return + + const touch = event.touches[0] + if (!touch) return + + touchStartX = touch.clientX + touchStartY = touch.clientY + isDragging = true + dragElement = dragRegion + }, + { passive: true } + ) + + document.addEventListener( + "touchmove", + (event) => { + if (!isDragging || !dragElement) return + + const touch = event.touches[0] + if (!touch) return + + const deltaX = touch.clientX - touchStartX + const deltaY = touch.clientY - touchStartY + + // 只有当移动距离超过阈值时才认为是拖动窗口 + if (Math.abs(deltaX) > 3 || Math.abs(deltaY) > 3) { + event.preventDefault() + api.startDraggingWindow?.() + isDragging = false + dragElement = null + } + }, + { passive: false } + ) + + document.addEventListener( + "touchend", + () => { + isDragging = false + dragElement = null + }, + { passive: true } + ) + + document.addEventListener( + "touchcancel", + () => { + isDragging = false + dragElement = null + }, + { passive: true } + ) +} +enableTouchWindowDrag() + const platform = navigator.userAgent.toLowerCase() const isIos = /iphone|ipad|ipod/.test(platform) const isAndroid = platform.includes("android") diff --git a/src/preload/types.ts b/src/preload/types.ts index 29520f8..0e8dde9 100644 --- a/src/preload/types.ts +++ b/src/preload/types.ts @@ -218,6 +218,7 @@ const api = { windowMaximize: (): Promise => invoke("window_maximize"), windowClose: (): Promise => invoke("window_close"), windowIsMaximized: (): Promise => invoke("window_is_maximized"), + startDraggingWindow: (): Promise => invoke("window_start_dragging"), toggleDevTools: (): Promise => invoke("toggle_devtools"), windowResize: (width: number, height: number): Promise => invoke("window_resize", { width, height }),