mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
🐛 修复(shortCut.ts):修复快捷键注册前后的值不一致bug
📝 更新(components/Error.tsx):更新Error组件以清除错误消息的效果 ♻️ 重构(hooks/useShortCut.ts):更新注册快捷键逻辑以使用新的useStore逻辑
This commit is contained in:
@@ -8,8 +8,9 @@ const config = {
|
||||
export const registerShortCut = (win: BrowserWindow) => {
|
||||
|
||||
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, type: 'search', shortCut: string) => {
|
||||
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键
|
||||
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键,也用户注册过快捷键想修改成其他快捷键
|
||||
if (config.search) globalShortcut.unregister(config.search)
|
||||
config.search = shortCut
|
||||
switch(type){
|
||||
case 'search':
|
||||
return registerSearchShortCut(shortCut, win)
|
||||
@@ -18,9 +19,10 @@ export const registerShortCut = (win: BrowserWindow) => {
|
||||
}
|
||||
|
||||
function registerSearchShortCut(shortCut: string, win: BrowserWindow){
|
||||
return globalShortcut.register(shortCut, () => {
|
||||
const res = globalShortcut.register(shortCut, () => {
|
||||
win.isVisible() ? win.hide() : win.show()
|
||||
})
|
||||
return res
|
||||
}
|
||||
app.on('will-quit', () => {
|
||||
// Unregister all shortcuts.
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
import { useEffect } from "react"
|
||||
|
||||
function Error(){
|
||||
const {error} = useStore()
|
||||
const error = useStore(state => state.error)
|
||||
const setError = useStore(state => state.setError)
|
||||
useEffect(() => {
|
||||
const id = setTimeout(() => setError(""), 2000)
|
||||
return () => clearTimeout(id)
|
||||
}, [error])
|
||||
if (!error) return <></>
|
||||
return <><div className="bg-red-600 text-white">{error}</div></>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
|
||||
export default() => {
|
||||
const {setError} = useStore()
|
||||
const setError = useStore(state => state.setError)
|
||||
const register = async (type: 'search', shortCut: string)=>{
|
||||
const ret = await window.api.shortCut(type, shortCut)
|
||||
ret || setError("注册失败")
|
||||
|
||||
Reference in New Issue
Block a user