【发布时间】:2018-07-01 06:07:15
【问题描述】:
我正在尝试基于 Electron Boilerplate 编写我的第一个 Electron 应用程序。我正在尝试从主电子进程向我的窗口发送一条简单的消息,但似乎没有发送消息。
我实现的主要代码如下
background.js(主 Electron 进程)
// Window setup
app.on("ready", () => {
mainWindow = new BrowserWindow({
width: 1000,
height: 300,
frame: false,
resizable: false,
transparent: true,
});
mainWindow.setIgnoreMouseEvents(true);
mainWindow.hide();
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "app.html"),
protocol: "file:",
slashes: true
})
);
const ret = globalShortcut.register(getKeyboardShortCut(), () => {
mainWindow.isVisible ? mainWindow.hide() : mainWindow.show();
})
if(isDev()){
mainWindow.openDevTools();
mainWindow.setIgnoreMouseEvents(false);
console.log("======== DEV ==========");
mainWindow.show();
mainWindow.webContents.send('test','This is a test');
}
});
app.js(窗口映射到 mainWindow)
import { ipcRenderer } from "electron";
ipcRenderer.on('test', (event, text) => { console.log("Received test
message:", text)});
console.log(ipcRenderer);
知道为什么没有收到活动吗?我看到 DEV 代码正在运行的控制台日志,但在应用程序窗口一侧没有任何内容(在开发人员控制台日志中)完整代码可以在 Git Repo
找到任何帮助将不胜感激。
谢谢 奥利弗
【问题讨论】:
标签: electron