问题描述
我做了我的第一次尝试,想使用角度渲染器过程中的电子 API。我按照
中的说明进行操作Instruction creating Angular -Electron application
所以在我的 main.js 文件中我添加了:
const {app,BrowserWindow,ipcMain} = require('electron')
我也加了
function openModal(){
const { BrowserWindow } = require('electron');
let modal = new BrowserWindow({ parent: mainWindow,modal: true,show: false })
modal.loadURL('https://www.sitepoint.com')
modal.once('ready-to-show',() => {
modal.show()
})
}
ipcMain.on('openModal',(event,arg) => {
openModal()
})
在我的 app.component.ts 文件中添加了导入 import { IpcRenderer } from 'electron';
并且我添加了以下构造函数
private ipc: IpcRenderer
constructor(){
if ((<any>window).require) {
try {
this.ipc = (<any>window).require('electron').ipcRenderer;
} catch (e) {
throw e;
}
} else {
console.warn('App not running inside Electron!');
}
}
因为我的 CLI 并不完全清楚 icp 将是 IpcRenderer 类型,所以我在这一行中添加了
private ipc: IpcRenderer | any;
带功能
openModal(){
console.log("Open a modal");
this.ipc.send("openModal");
}
它应该能够向“主”进程发送一些东西。但是如果我调用该函数,我会收到错误
类型错误:无法读取未定义的属性“发送”
我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)