📝 更新(shortCut.ts, App.tsx, index.tsx):删除无用的导入和函数调用

♻️ 重构(Home/index.tsx):更新快捷键注册的调用方式
This commit is contained in:
ruotongyu
2024-06-22 23:34:09 +08:00
parent a2e09e5b98
commit 2bd63a8023
3 changed files with 3 additions and 6 deletions

View File

@@ -1,12 +1,10 @@
import { IpcMainInvokeEvent } from "electron"
import { ipcMain } from "electron"
import { getWindowByName } from "./windows"
import { findOne } from "./db/query"
const { app, globalShortcut } = require('electron')
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, shortCut: string) => {
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键,也用户注册过快捷键想修改成其他快捷键
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键
return registerSearchShortCut(shortCut)
})

View File

@@ -1,7 +1,6 @@
import Result from "./components/Result"
import Search from "./components/Search"
import { CodeProvider } from "./context/CodeContext"
import useShortCut from "./hooks/useShortCut"
import Error from "./components/Error"
import { MutableRefObject, useEffect, useRef } from "react"
import useIgnoreMouseEvents from "./hooks/useIgnoreMouseEvents"

View File

@@ -16,8 +16,8 @@ function Home(): JSX.Element {
// window.api.openConfigWindow()
}, [])
// // 注册快捷键
const shortCut = useShortCut()
shortCut.register()
const {register} = useShortCut()
register()
return (
<CodeProvider>
<main className="relative" ref={mainRef}>