电子-如何知道渲染器窗口何时准备就绪 [英] Electron - How to know when renderer window is ready
问题描述
在我的主要过程中,我创建了一个渲染器窗口:
In my main process I create a renderer window:
var mainWindow = new BrowserWindow({
height: 600,
width: 800,
x: 0,
y: 0,
frame: false,
resizable: true
});
mainWindow.openDevTools();
mainWindow.loadURL('file://' + __dirname + '/renderer/index.html');
然后我想通过某种方式与之进行交流:
Then I want to communicate with it in some way:
mainWindow.webContents.send('message', 'hello world');
但是,主窗口没有收到此消息,因为在窗口未完全完成创建我试图发送它。
However the main window doesn't receive this message because it isn't fully done being created at the time I attempt to send it.
我已经通过将后面的代码包装在setTimeout()中暂时解决了这个问题,但这绝对不是解决比赛的正确方法条件。
I have temporarily solved this by wrapping the latter code in a setTimeout() but that is most definitely not the right way to resolve a race condition.
主窗口准备就绪时是否存在回调?我尝试了文档中提到的准备展示事件,但没有成功。
Is there a callback for when the main window is ready? I tried the 'ready-to-show' event mentioned in the docs but it did not work.
推荐答案
mainWindow对我不起作用。我改用了 mainWindow.webContents。
A listener on "mainWindow" doesn't worked for me. I used instead "mainWindow.webContents".
mainWindow.webContents.once('dom-ready', () => {});
这篇关于电子-如何知道渲染器窗口何时准备就绪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!