mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
📝 ui(autoMate/src/main/db/query.ts): 添加config方法以获取配置信息
📝 ui(autoMate/src/main/shortCut.ts): 修改registerSearchShortCut函数签名 📝 ui(autoMate/src/preload/index.d.ts): 更新shortCut函数签名 📝 ui(autoMate/src/preload/index.ts): 更新shortCut函数调用 📝 ui(autoMate/src/renderer/src/hooks/useShortCut.ts): 修改shortCut函数调用 📝 ui(autoMate/src/renderer/src/pages/Setting/SettingAction.ts): 根据快捷键注册状态更新数据库配置 📝 ui(autoMate/types.d.ts): 添加'config'到SqlActionType
This commit is contained in:
@@ -20,4 +20,9 @@ export const update = (sql: string, params: Record<string, any>) => {
|
||||
|
||||
export const del = (sql: string, params={}) => {
|
||||
return db.prepare(sql).run(params).changes;
|
||||
}
|
||||
|
||||
export const config = () => {
|
||||
const ret = findOne(`select * from config where id=1`) as {content: string}
|
||||
return JSON.parse(ret.content)
|
||||
}
|
||||
@@ -4,19 +4,19 @@ import { getWindowByName } from "./windows"
|
||||
import { findOne } from "./db/query"
|
||||
const { app, globalShortcut } = require('electron')
|
||||
|
||||
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, type) => {
|
||||
ipcMain.handle("shortCut", (_event: IpcMainInvokeEvent, shortCut: string) => {
|
||||
|
||||
// react 严格模式会执行两次,可能会导致快捷键重复注册,这里在注册前会删除旧快捷键,也用户注册过快捷键想修改成其他快捷键
|
||||
return registerSearchShortCut( )
|
||||
return registerSearchShortCut(shortCut)
|
||||
|
||||
})
|
||||
|
||||
|
||||
function registerSearchShortCut(){
|
||||
const ret = findOne(`select * from config where id=1`) as {content: string}
|
||||
const shortCut = JSON.parse(ret.content).shortCut as string
|
||||
function registerSearchShortCut(shortCut: string){
|
||||
// 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)
|
||||
return false
|
||||
}
|
||||
const win = getWindowByName('search')
|
||||
const res = globalShortcut.register(shortCut, () => {
|
||||
|
||||
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: () => Promise<boolean>,
|
||||
shortCut: (shortCut: string) => 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: () => {
|
||||
return ipcRenderer.invoke("shortCut")
|
||||
shortCut: (shortCut: string) => {
|
||||
return ipcRenderer.invoke("shortCut", shortCut)
|
||||
},
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward: boolean }) => {
|
||||
ipcRenderer.send("setIgnoreMouseEvents", ignore, options)
|
||||
|
||||
@@ -13,8 +13,8 @@ function App(): JSX.Element {
|
||||
useEffect(()=>{
|
||||
setIgnoreMouseEvents(mainRef as MutableRefObject<HTMLDivElement>)
|
||||
}, [])
|
||||
const shortCut = useShortCut()
|
||||
shortCut.register("search", "CommandOrControl+n")
|
||||
// const shortCut = useShortCut("CommandOrControl+n")
|
||||
// shortCut.register()
|
||||
return (
|
||||
<CodeProvider>
|
||||
<main className="relative" ref={mainRef}>
|
||||
|
||||
@@ -3,8 +3,9 @@ import { useStore } from "@renderer/store/useStore"
|
||||
export default() => {
|
||||
const setError = useStore(state => state.setError)
|
||||
const register = async ()=>{
|
||||
const ret = await window.api.shortCut()
|
||||
ret || setError("注册失败")
|
||||
const ret = (await window.api.sql('', 'config')) as Record<string, any>
|
||||
const isBind = await window.api.shortCut(ret.shortCut)
|
||||
isBind || setError("注册失败")
|
||||
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -15,7 +15,7 @@ function Home(): JSX.Element {
|
||||
// //为开发方便,临时代码
|
||||
// window.api.openConfigWindow()
|
||||
}, [])
|
||||
// 注册快捷键
|
||||
// // 注册快捷键
|
||||
const shortCut = useShortCut()
|
||||
shortCut.register()
|
||||
return (
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
export default async ({request})=>{
|
||||
const formData = await request.formData()
|
||||
const data = Object.fromEntries(formData)
|
||||
window.api.sql(`update config set content=@content where id = 1`,
|
||||
'update',
|
||||
{
|
||||
content: JSON.stringify(data)
|
||||
}
|
||||
)
|
||||
|
||||
const isRegistered = await window.api.shortCut(data.shortCut)
|
||||
if (isRegistered){
|
||||
return window.api.sql(`update config set content=@content where id = 1`,
|
||||
'update',
|
||||
{
|
||||
content: JSON.stringify(data)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
2
ui/autoMate/types.d.ts
vendored
2
ui/autoMate/types.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
type SqlActionType = 'findAll' | 'findOne' | 'create' | 'update' | 'del'
|
||||
type SqlActionType = 'findAll' | 'findOne' | 'create' | 'update' | 'del'|'config'
|
||||
|
||||
type CategoryType = {
|
||||
id: number
|
||||
|
||||
Reference in New Issue
Block a user