mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 04:57:18 +08:00
✨ 更新(ui): 添加IPC通信和快捷键注册功能
✨ 更新(ui): 创建窗口函数现在返回BrowserWindow对象
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { app } from 'electron'
|
||||
import { createWindow } from './window'
|
||||
import * as ipc from './ipc'
|
||||
import { registerShortCut } from './shortcut'
|
||||
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
const window = createWindow()
|
||||
ipc.registerIpc(window)
|
||||
registerShortCut(window)
|
||||
})
|
||||
|
||||
|
||||
|
||||
19
ui/autoMate/src/main/code/shortCut.ts
Normal file
19
ui/autoMate/src/main/code/shortCut.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { BrowserWindow } from "electron"
|
||||
|
||||
const { app, globalShortcut } = require('electron')
|
||||
export const registerShortCut = (win: BrowserWindow) => {
|
||||
app.whenReady().then(() => {
|
||||
// Register a 'CommandOrControl+X' shortcut listener.
|
||||
const ret = globalShortcut.register('CommandOrControl+X', () => {
|
||||
win.show()
|
||||
})
|
||||
|
||||
if (!ret) {
|
||||
console.log('registration failed')
|
||||
}
|
||||
})
|
||||
|
||||
app.on('will-quit', () => {
|
||||
// Unregister all shortcuts.
|
||||
globalShortcut.unregisterAll()
|
||||
})}
|
||||
@@ -2,10 +2,9 @@
|
||||
import { BrowserWindow, shell } from 'electron'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import icon from '../../../resources/icon.png?asset'
|
||||
import * as ipc from '../ipc'
|
||||
import { join } from 'path'
|
||||
|
||||
export function createWindow(): void { // Create the browser window.
|
||||
export function createWindow(): BrowserWindow { // Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 600,
|
||||
height: 350,
|
||||
@@ -20,7 +19,6 @@ export function createWindow(): void { // Create the browser window.
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
ipc.registerIpc(mainWindow)
|
||||
|
||||
mainWindow.webContents.openDevTools()
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
@@ -39,5 +37,7 @@ export function createWindow(): void { // Create the browser window.
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
|
||||
return mainWindow
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { app, BrowserWindow, ipcMain } from 'electron'
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
||||
import { createWindow } from './code/window'
|
||||
|
||||
import "./code"
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user