mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
🐛 修复(ui/autoMate/src/main/db/tables.ts):插入配置时添加了id字段和默认值
🔧 修复(ui/autoMate/src/main/shortCut.ts):更新快捷键注册逻辑和查询配置的方式 🔧 修复(ui/autoMate/src/main/windows.ts):修复配置窗口在启动时的调用方式 🔧 修复(ui/autoMate/src/preload/index.d.ts):更新shortCut函数的参数 🔧 修复(ui/autoMate/src/preload/index.ts):更新shortCut函数的调用 🔧 修复(ui/autoMate/src/renderer/src/hooks/useShortCut.ts):更新快捷键注册逻辑 🔧 修复(ui/autoMate/src/renderer/src/layouts/Home/index.tsx):更新快捷键注册逻辑 🔧 修复(ui/autoMate/src/renderer/src/pages/Setting/index.tsx):更新快捷键定义逻辑和处理方式
This commit is contained in:
@@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS config (
|
||||
function initData() {
|
||||
const initData = findOne('select * from config')
|
||||
if (initData) return
|
||||
db.exec(`insert into config (content) values('')`)
|
||||
db.exec(`insert into config (id, content) values(1,'{"shortCut":"Alt+Space","databaseDirectory":""}')`)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
import { BrowserWindow, IpcMainInvokeEvent } from "electron"
|
||||
import { IpcMainInvokeEvent } from "electron"
|
||||
import { ipcMain } from "electron"
|
||||
import { getWindowByName } from "./windows"
|
||||
import { findOne } from "./db/query"
|
||||
const { app, globalShortcut } = require('electron')
|
||||
|
||||
const config = {
|
||||
search: ""
|
||||
}
|
||||
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, type) => {
|
||||
|
||||
|
||||
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, type: 'search', shortCut: string) => {
|
||||
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键,也用户注册过快捷键想修改成其他快捷键
|
||||
if (config.search) globalShortcut.unregister(config.search)
|
||||
config.search = shortCut
|
||||
switch(type){
|
||||
case 'search':
|
||||
return registerSearchShortCut(getWindowByName('search'), shortCut)
|
||||
}
|
||||
return registerSearchShortCut( )
|
||||
|
||||
})
|
||||
|
||||
|
||||
function registerSearchShortCut(win: BrowserWindow, shortCut: string){
|
||||
function registerSearchShortCut(){
|
||||
const ret = findOne(`select * from config where id=1`) as {content: string}
|
||||
const shortCut = JSON.parse(ret.content).shortCut as string
|
||||
if (globalShortcut.isRegistered(shortCut)){
|
||||
globalShortcut.unregister(shortCut)
|
||||
}
|
||||
const win = getWindowByName('search')
|
||||
const res = globalShortcut.register(shortCut, () => {
|
||||
win.isVisible() ? win.hide() : win.show()
|
||||
})
|
||||
|
||||
@@ -43,6 +43,6 @@ export const getWindowByEvent = (event: IpcMainEvent | IpcMainInvokeEvent) => {
|
||||
|
||||
|
||||
app.whenReady().then(() => {
|
||||
// getWindowByName('search')
|
||||
getWindowByName('search')
|
||||
getWindowByName('config')
|
||||
})
|
||||
2
ui/autoMate/src/preload/index.d.ts
vendored
2
ui/autoMate/src/preload/index.d.ts
vendored
@@ -4,7 +4,7 @@ declare global {
|
||||
interface Window {
|
||||
electron: ElectronAPI
|
||||
api: {
|
||||
shortCut: (type: 'search', shortCut: string) => Promise<boolean>,
|
||||
shortCut: () => Promise<boolean>,
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward: boolean }) => void,
|
||||
openConfigWindow: () => void,
|
||||
sql: <T>(sql: string, type: SqlActionType, params?: Record<string, any>) => Promise<T>
|
||||
|
||||
@@ -3,8 +3,8 @@ import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
shortCut: (type: 'search', shortCut: string) => {
|
||||
return ipcRenderer.invoke("shortCut", type, shortCut)
|
||||
shortCut: () => {
|
||||
return ipcRenderer.invoke("shortCut")
|
||||
},
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward: boolean }) => {
|
||||
ipcRenderer.send("setIgnoreMouseEvents", ignore, options)
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useStore } from "@renderer/store/useStore"
|
||||
|
||||
export default() => {
|
||||
const setError = useStore(state => state.setError)
|
||||
const register = async (type: 'search', shortCut: string)=>{
|
||||
const ret = await window.api.shortCut(type, shortCut)
|
||||
const register = async ()=>{
|
||||
const ret = await window.api.shortCut()
|
||||
ret || setError("注册失败")
|
||||
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ function Home(): JSX.Element {
|
||||
// window.api.openConfigWindow()
|
||||
}, [])
|
||||
// 注册快捷键
|
||||
// const shortCut = useShortCut()
|
||||
// shortCut.register("search", "CommandOrControl+n")
|
||||
const shortCut = useShortCut()
|
||||
shortCut.register()
|
||||
return (
|
||||
<CodeProvider>
|
||||
<main className="relative" ref={mainRef}>
|
||||
|
||||
@@ -1,29 +1,41 @@
|
||||
import { Form, useLoaderData, useSubmit } from 'react-router-dom'
|
||||
import styles from './styles.module.scss'
|
||||
import { useState } from 'react'
|
||||
|
||||
export const Setting = () => {
|
||||
const config = useLoaderData() as ConfigDataType
|
||||
const submit = useSubmit()
|
||||
const [keys, setKeys] = useState<string[]>([])
|
||||
return (
|
||||
<Form method="POST">
|
||||
<main className={styles.settingPage}>
|
||||
<h1>Setting</h1>
|
||||
<section>
|
||||
<h5>快捷键定义</h5>
|
||||
<input
|
||||
type="text"
|
||||
name="shortcut"
|
||||
defaultValue={config.shortCut}
|
||||
onKeyUp={(e)=>{
|
||||
submit(e.currentTarget.form, {method: 'POST'})
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
<section>
|
||||
<h5>数据库</h5>
|
||||
<input type="text" name="databaseDirectory" defaultValue={config.databaseDirectory}/>
|
||||
</section>
|
||||
</main>
|
||||
<main className={styles.settingPage}>
|
||||
<h1>Setting</h1>
|
||||
<section>
|
||||
<h5>快捷键定义</h5>
|
||||
<input
|
||||
type="text"
|
||||
name="shortcut"
|
||||
defaultValue={config.shortCut}
|
||||
readOnly
|
||||
onKeyDown={(e) => {
|
||||
if (e.metaKey || e.ctrlKey || e.altKey) {
|
||||
keys.push(e.code.replace(/Left|Right|Key|Digit/, ''))
|
||||
setKeys(keys)
|
||||
e.currentTarget.value = keys.join('+')
|
||||
}
|
||||
|
||||
}}
|
||||
onKeyUp={(e) => {
|
||||
submit(e.currentTarget.form, {method: 'POST'})
|
||||
setKeys([])
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
<section>
|
||||
<h5>数据库</h5>
|
||||
<input type="text" name="databaseDirectory" defaultValue={config.databaseDirectory} />
|
||||
</section>
|
||||
</main>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user