mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 06:04:22 +08:00
Fix desktop touch screen window dragging issue
Key features implemented: - Add window_start_dragging command to src-tauri/src/commands/window.rs for initiating window drag operations - Implement touch-based window dragging functionality in src/main.tsx with proper touch event handling and drag region detection - Add startDraggingWindow API method to src/preload/types.ts to expose the window dragging capability - Update .gitignore with comprehensive ignore patterns for various development environments and file types The changes introduce proper support for dragging application windows on desktop devices with touch screens, addressing the core issue while maintaining compatibility with existing mouse-based interactions. The touch event handling includes safeguards to prevent interference with normal UI element interactions.
This commit is contained in:
+32
-48
@@ -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
|
||||
```
|
||||
@@ -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<RwLock<AppState>>>,
|
||||
) -> 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(())
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -218,6 +218,7 @@ const api = {
|
||||
windowMaximize: (): Promise<boolean> => invoke("window_maximize"),
|
||||
windowClose: (): Promise<void> => invoke("window_close"),
|
||||
windowIsMaximized: (): Promise<boolean> => invoke("window_is_maximized"),
|
||||
startDraggingWindow: (): Promise<void> => invoke("window_start_dragging"),
|
||||
toggleDevTools: (): Promise<void> => invoke("toggle_devtools"),
|
||||
windowResize: (width: number, height: number): Promise<void> =>
|
||||
invoke("window_resize", { width, height }),
|
||||
|
||||
Reference in New Issue
Block a user