mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
✨ 添加(main/code):为窗口忽略鼠标事件功能添加新文件和逻辑
🚀 部署(main/code):在窗口就绪后注册窗口忽略鼠标事件逻辑 🔧 更新(main/code):在快捷键注册逻辑中删除旧的快捷键后再注册新快捷键 🔧 更新(preload/index.d.ts):更新preload类型定义以支持设置忽略鼠标事件功能 🔧 更新(preload/index):更新preload以支持设置忽略鼠标事件功能 📝 更新(components/Search):更新搜索组件添加鼠标事件监听以控制鼠标事件忽略行为
This commit is contained in:
8
ui/autoMate/src/main/code/ignoreMouseEvents.ts
Normal file
8
ui/autoMate/src/main/code/ignoreMouseEvents.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { BrowserWindow, IpcMainEvent, ipcMain } from "electron"
|
||||
|
||||
export default (win: BrowserWindow) => {
|
||||
ipcMain.on('setIgnoreMouseEvents', (_event: IpcMainEvent, ignore: boolean, options?:{forward: boolean}) => {
|
||||
win.setIgnoreMouseEvents(ignore, options)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ import { app } from 'electron'
|
||||
import { createWindow } from './window'
|
||||
import * as ipc from './ipc'
|
||||
import { registerShortCut } from './shortCut'
|
||||
import ignoreMouseEvents from './ignoreMouseEvents'
|
||||
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const window = createWindow()
|
||||
ipc.registerIpc(window)
|
||||
registerShortCut(window)
|
||||
ignoreMouseEvents(window)
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ export const registerShortCut = (win: BrowserWindow) => {
|
||||
|
||||
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, type: 'search', shortCut: string) => {
|
||||
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键,也用户注册过快捷键想修改成其他快捷键
|
||||
// if (config.search) globalShortcut.unregister(config.search)
|
||||
if (config.search) globalShortcut.unregister(config.search)
|
||||
config.search = shortCut
|
||||
switch(type){
|
||||
case 'search':
|
||||
|
||||
3
ui/autoMate/src/preload/index.d.ts
vendored
3
ui/autoMate/src/preload/index.d.ts
vendored
@@ -5,7 +5,8 @@ declare global {
|
||||
electron: ElectronAPI
|
||||
api: {
|
||||
hideWindow: () => void,
|
||||
shortCut: (type: 'search', shortCut: string) => Promise<boolean>
|
||||
shortCut: (type: 'search', shortCut: string) => Promise<boolean>,
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward: boolean }) => void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ const api = {
|
||||
},
|
||||
shortCut: (type: 'search', shortCut: string) => {
|
||||
return ipcRenderer.invoke("shortCut", type, shortCut)
|
||||
},
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward: boolean }) => {
|
||||
ipcRenderer.send("setIgnoreMouseEvents", ignore, options)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,21 @@ import { useStore } from "@renderer/store/useStore"
|
||||
import useSearch from "@renderer/hooks/useSearch"
|
||||
import { SettingOne } from "@icon-park/react"
|
||||
import { Input } from "antd"
|
||||
import { useEffect, useRef } from "react"
|
||||
export default function Search(): JSX.Element {
|
||||
const search = useStore((state)=>state.search)
|
||||
const {handleSearch} = useSearch()
|
||||
const mainRef = useRef<HTMLDivElement | null>(null)
|
||||
useEffect(()=>{
|
||||
mainRef.current?.addEventListener('mouseover', (_e: MouseEvent)=>{
|
||||
window.api.setIgnoreMouseEvents(false)
|
||||
})
|
||||
mainRef.current?.addEventListener('mouseout', (_e: MouseEvent)=>{
|
||||
window.api.setIgnoreMouseEvents(true, {forward: true})
|
||||
})
|
||||
},[])
|
||||
return (
|
||||
<div className="bg-slate-50 p-3 rounded-lg drag" >
|
||||
<main className="bg-slate-50 p-3 rounded-lg drag" ref={mainRef}>
|
||||
<section className="bg-slate-200 p-3 rounded-lg flex items-center gap-1 nodrag">
|
||||
<SettingOne
|
||||
theme="outline"
|
||||
@@ -31,6 +41,6 @@ export default function Search(): JSX.Element {
|
||||
autoFocus/> */}
|
||||
</section>
|
||||
<section className="text-center text-slate-600 text-xs mt-2">autoMate</section>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user