| 1 | import { BrowserWindow } from 'electron'; |
| 2 | import { SendChannelEnum } from '../../commont/UtilsEnum'; |
| 3 | |
| 4 | /** |
| 5 | * 关于主进程 win 的所有操作 |
| 6 | * 这个类会在主进程初始化调用 init 方法注入 win属性 |
| 7 | */ |
| 8 | class WindowOperate { |
| 9 | win?: BrowserWindow; |
| 10 | |
| 11 | init(win: BrowserWindow) { |
| 12 | this.win = win; |
| 13 | } |
| 14 | // window.ipcRenderer.on('main-process-message', (_event, ...args) => { |
| 15 | // console.log('[Receive Main-process message]:', ...args); |
| 16 | // }); |
| 17 | |
| 18 | // 向渲染进程发送消息 |
| 19 | sendRenderMsg(channel: SendChannelEnum, ...args: any[]) { |
| 20 | this.win?.webContents.send(channel, ...args); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | const windowOperate = new WindowOperate(); |
| 25 | export default windowOperate; |
| 26 |