mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
🔧 更新(ui/autoMate):修复路径错误
🔧 更新(ui/autoMate):修复浏览器窗口加载的问题 🔧 更新(ui/autoMate):修复加载图标的路径错误 📝 更新(ui/autoMate):更新文档声明和类型定义 🔧 更新(ui/autoMate):修复快捷键注册问题 🔧 更新(ui/autoMate):修复点击事件绑定错误 🔧 更新(ui/autoMate):修复快捷键注册问题 📝 更新(ui/autoMate):更新文档声明和类型定义
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { BrowserWindow, IpcMainEvent, ipcMain } from "electron"
|
||||
|
||||
export default (win: BrowserWindow) => {
|
||||
ipcMain.on('setIgnoreMouseEvents', (_event: IpcMainEvent, ignore: boolean, options?:{forward: boolean}) => {
|
||||
win.setIgnoreMouseEvents(ignore, options)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export function createWindow(): BrowserWindow { // Create the browser window.
|
||||
// Load the remote URL for development or the local html file for production.
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
// win.loadURL(process.env['ELECTRON_RENDERER_URL'] + "/#config/category/contentList")
|
||||
win.loadURL(process.env['ELECTRON_RENDERER_URL'] + "/#config")
|
||||
win.loadURL(process.env['ELECTRON_RENDERER_URL'] + "/#config/category/contentList")
|
||||
} else {
|
||||
win.loadURL(
|
||||
url.format({
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
|
||||
import { BrowserWindow, BrowserWindowConstructorOptions, shell } from 'electron'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import icon from '../../../resources/icon.png?asset'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import { join } from 'path'
|
||||
|
||||
import url from 'node:url'
|
||||
export interface OptionsType extends Partial<BrowserWindowConstructorOptions>{
|
||||
openDevTools?: boolean
|
||||
openDevTools?: boolean,
|
||||
hash?: string
|
||||
}
|
||||
export function createWindow(options: OptionsType): BrowserWindow { // Create the browser window.
|
||||
const win = new BrowserWindow(Object.assign({
|
||||
@@ -34,13 +35,21 @@ export function createWindow(options: OptionsType): BrowserWindow { // Create t
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
// HMR for renderer base on electron-vite cli.
|
||||
// Load the remote URL for development or the local html file for production.
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
// win.loadURL(process.env['ELECTRON_RENDERER_URL'] + "/#config/category/contentList")
|
||||
win.loadURL(process.env['ELECTRON_RENDERER_URL'] + options.hash)
|
||||
} else {
|
||||
win.loadURL(
|
||||
url.format({
|
||||
pathname: join(__dirname, '../renderer/index.html'),
|
||||
protocol: 'file',
|
||||
slashes: true,
|
||||
hash: 'config/category/contentList'
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import { ipcMain, IpcMainEvent } from "electron"
|
||||
import { getWindow, WindowNameType } from "./windows"
|
||||
import {ipcMain, IpcMainEvent } from "electron"
|
||||
import { getWindowByName, getWindowByEvent} from "./windows"
|
||||
|
||||
ipcMain.on('openWindow', (_event: IpcMainEvent, name: WindowNameType) => {
|
||||
getWindow(name).show()
|
||||
getWindowByName(name).show()
|
||||
})
|
||||
|
||||
ipcMain.on('closeWindow', (_event: IpcMainEvent, name: WindowNameType) => {
|
||||
getWindow(name).hide()
|
||||
getWindowByName(name).hide()
|
||||
})
|
||||
|
||||
|
||||
|
||||
ipcMain.on('setIgnoreMouseEvents',
|
||||
(event: IpcMainEvent, ignore: boolean, options?:{forward: boolean}) => {
|
||||
getWindowByEvent(event).setIgnoreMouseEvents(ignore, options)
|
||||
})
|
||||
@@ -1,21 +1,29 @@
|
||||
import { BrowserWindow } from "electron"
|
||||
import { BrowserWindow, IpcMainEvent, IpcMainInvokeEvent, app } from "electron"
|
||||
import { OptionsType, createWindow} from "./createWindow"
|
||||
export type WindowNameType = 'search' | 'config'
|
||||
|
||||
export const config = {
|
||||
search: {
|
||||
id: 0,
|
||||
options: {}
|
||||
options: {
|
||||
hash: ''
|
||||
}
|
||||
},
|
||||
config: {
|
||||
id: 0,
|
||||
options: {}
|
||||
options: {
|
||||
width: 1300,
|
||||
height: 600,
|
||||
frame: true,
|
||||
transparent: false,
|
||||
hash: '/#config/category/contentList'
|
||||
}
|
||||
}
|
||||
|
||||
} as Record<WindowNameType, {id: number, options: OptionsType }>
|
||||
// createWindow({})
|
||||
|
||||
|
||||
export const getWindow = (name: WindowNameType)=>{
|
||||
// 根据名称获取窗口
|
||||
export const getWindowByName = (name: WindowNameType)=>{
|
||||
// 根据id取得窗口
|
||||
let win = BrowserWindow.fromId(config[name].id)
|
||||
// 避免重复点击重复创建窗口
|
||||
@@ -24,4 +32,15 @@ export const getWindow = (name: WindowNameType)=>{
|
||||
config[name].id = win.id
|
||||
}
|
||||
return win
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 根据触发来源获取窗口
|
||||
export const getWindowByEvent = (event: IpcMainEvent | IpcMainInvokeEvent) => {
|
||||
return BrowserWindow.fromWebContents(event.sender)!
|
||||
}
|
||||
|
||||
|
||||
app.whenReady().then(() => {
|
||||
getWindowByName('search')
|
||||
})
|
||||
3
ui/autoMate/src/preload/index.d.ts
vendored
3
ui/autoMate/src/preload/index.d.ts
vendored
@@ -4,11 +4,12 @@ declare global {
|
||||
interface Window {
|
||||
electron: ElectronAPI
|
||||
api: {
|
||||
hideWindow: () => void,
|
||||
shortCut: (type: 'search', 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>
|
||||
openWindow: (name: WindowNameType) => void,
|
||||
closeWindow: (name: WindowNameType) => void,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
hideWindow: () =>{
|
||||
ipcRenderer.send("hideWindow")
|
||||
},
|
||||
shortCut: (type: 'search', shortCut: string) => {
|
||||
return ipcRenderer.invoke("shortCut", type, shortCut)
|
||||
},
|
||||
@@ -17,7 +14,13 @@ const api = {
|
||||
},
|
||||
sql: (sql: string, type: SqlActionType, params={}) => {
|
||||
return ipcRenderer.invoke("sql", sql, type, params)
|
||||
}
|
||||
},
|
||||
openWindow: (name: WindowNameType) =>{
|
||||
ipcRenderer.send("openWindow", name)
|
||||
},
|
||||
closeWindow: (name: WindowNameType) =>{
|
||||
ipcRenderer.send("closeWindow", name)
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export default function Search(): JSX.Element {
|
||||
fill="#34495e"
|
||||
strokeWidth={4}
|
||||
className="cursor-pointer"
|
||||
onClick={()=>window.api.openConfigWindow()
|
||||
onClick={()=>window.api.openWindow('config')
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
|
||||
@@ -15,8 +15,9 @@ function Home(): JSX.Element {
|
||||
// //为开发方便,临时代码
|
||||
// window.api.openConfigWindow()
|
||||
}, [])
|
||||
const shortCut = useShortCut()
|
||||
shortCut.register("search", "CommandOrControl+n")
|
||||
// 注册快捷键
|
||||
// const shortCut = useShortCut()
|
||||
// shortCut.register("search", "CommandOrControl+n")
|
||||
return (
|
||||
<CodeProvider>
|
||||
<main className="relative" ref={mainRef}>
|
||||
|
||||
5
ui/autoMate/types.d.ts
vendored
5
ui/autoMate/types.d.ts
vendored
@@ -12,4 +12,7 @@ type ContentType = {
|
||||
content: string
|
||||
category_id: string
|
||||
created_at: string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type WindowNameType = 'search' | 'config'
|
||||
Reference in New Issue
Block a user