feat(0.2.1): 合并 Windows 外壳 + 离线编辑, 版本 0.2.1, 正式域名 https://iboard.honor3.com
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// 悬浮球交互 (W-SNP-04/05/12/13/14):
|
||||
// mouseenter/leave → hover 延时恢复 (Rust 侧计时 150ms)
|
||||
// 单击 (位移 ≤4px) → 立即恢复, 触屏点按等效
|
||||
// 拖动 → dock_drag_move 增量移动, 结束时按最近边停靠/换边/拖出
|
||||
const { invoke } = window.__TAURI__.core
|
||||
const ball = document.getElementById('ball')
|
||||
|
||||
let dragging = false
|
||||
let moved = 0
|
||||
let lastX = 0
|
||||
let lastY = 0
|
||||
|
||||
ball.addEventListener('mouseenter', () => invoke('dock_hover_start'))
|
||||
ball.addEventListener('mouseleave', () => invoke('dock_hover_end'))
|
||||
ball.addEventListener('contextmenu', (e) => e.preventDefault())
|
||||
|
||||
ball.addEventListener('pointerdown', (e) => {
|
||||
dragging = true
|
||||
moved = 0
|
||||
lastX = e.clientX
|
||||
lastY = e.clientY
|
||||
ball.setPointerCapture(e.pointerId)
|
||||
invoke('dock_drag_start')
|
||||
})
|
||||
|
||||
ball.addEventListener('pointermove', (e) => {
|
||||
if (!dragging) return
|
||||
const dx = e.clientX - lastX
|
||||
const dy = e.clientY - lastY
|
||||
if (dx === 0 && dy === 0) return
|
||||
lastX = e.clientX
|
||||
lastY = e.clientY
|
||||
moved += Math.abs(dx) + Math.abs(dy)
|
||||
if (moved > 4) {
|
||||
// clientX 为逻辑像素, 增量按 DPI 缩放换算成物理像素 (Rust 注入 __SCALE)
|
||||
const s = window.__SCALE || 1
|
||||
invoke('dock_drag_move', { dx: Math.round(dx * s), dy: Math.round(dy * s) })
|
||||
}
|
||||
})
|
||||
|
||||
ball.addEventListener('pointerup', (e) => {
|
||||
if (!dragging) return
|
||||
dragging = false
|
||||
try { ball.releasePointerCapture(e.pointerId) } catch { /* 已释放 */ }
|
||||
if (moved <= 4) {
|
||||
invoke('dock_click')
|
||||
} else {
|
||||
invoke('dock_drag_end')
|
||||
}
|
||||
})
|
||||
|
||||
ball.addEventListener('pointercancel', () => {
|
||||
dragging = false
|
||||
invoke('dock_drag_end')
|
||||
})
|
||||
|
||||
// Rust 在停靠/换边/主题变化时调用
|
||||
window.applyDock = (edge, theme) => {
|
||||
document.body.className = 'dock-' + edge + ' theme-' + theme
|
||||
}
|
||||
window.applyTheme = (theme) => {
|
||||
const edge = [...document.body.classList].find((c) => c.startsWith('dock-')) || 'dock-left'
|
||||
document.body.className = edge + ' theme-' + theme
|
||||
}
|
||||
window.__SCALE = 1
|
||||
Reference in New Issue
Block a user