mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 04:57:18 +08:00
✨ ui(autoMate): 添加对鼠标事件的控制,优化快捷键功能,添加新hook(useIgnoreMouseEvents)
This commit is contained in:
@@ -3,21 +3,15 @@ import Search from "./components/Search"
|
||||
import { CodeProvider } from "./context/CodeContext"
|
||||
import useShortCut from "./hooks/useShortCut"
|
||||
import Error from "./components/Error"
|
||||
import { useEffect, useRef } from "react"
|
||||
import { MutableRefObject, RefObject, useEffect, useRef } from "react"
|
||||
import useIgnoreMouseEvents from "./hooks/useIgnoreMouseEvents"
|
||||
|
||||
|
||||
function App(): JSX.Element {
|
||||
const mainRef = useRef<HTMLDivElement>(null)
|
||||
const {setIgnoreMouseEvents} = useIgnoreMouseEvents()
|
||||
useEffect(()=>{
|
||||
mainRef.current?.addEventListener('mouseover', ()=>{
|
||||
window.api.setIgnoreMouseEvents(false)
|
||||
})
|
||||
|
||||
document.body.addEventListener('mouseover', (e: MouseEvent)=>{
|
||||
if (e.target === document.body) {
|
||||
window.api.setIgnoreMouseEvents(true, {forward: true})
|
||||
}
|
||||
})
|
||||
setIgnoreMouseEvents(mainRef as MutableRefObject<HTMLDivElement>)
|
||||
}, [])
|
||||
const shortCut = useShortCut()
|
||||
shortCut.register("search", "CommandOrControl+n")
|
||||
@@ -33,3 +27,7 @@ function App(): JSX.Element {
|
||||
}
|
||||
|
||||
export default App
|
||||
function setIgnoreMouseEvents(mainRef: RefObject<HTMLDivElement>) {
|
||||
throw new Error("Function not implemented.")
|
||||
}
|
||||
|
||||
|
||||
17
ui/autoMate/src/renderer/src/hooks/useIgnoreMouseEvents.ts
Normal file
17
ui/autoMate/src/renderer/src/hooks/useIgnoreMouseEvents.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { MutableRefObject } from "react"
|
||||
|
||||
export default() => {
|
||||
const setIgnoreMouseEvents = <T extends HTMLElement>(el: MutableRefObject<T>) => {
|
||||
el.current?.addEventListener('mouseover', ()=>{
|
||||
window.api.setIgnoreMouseEvents(false)
|
||||
})
|
||||
|
||||
document.body.addEventListener('mouseover', (e: MouseEvent)=>{
|
||||
if (e.target === document.body) {
|
||||
window.api.setIgnoreMouseEvents(true, {forward: true})
|
||||
}
|
||||
})
|
||||
}
|
||||
return {setIgnoreMouseEvents}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user