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.
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.
getElementById("close-btn"). addEventListener("click", function (e) { var window = remote. getCurrentWindow(); window. close(); });
For electron's BrowserWindow you can use isDestroyed() method as well, which potentially makes the use of 'closed' unnecessary but invalidating objects is a general technique while destroy queries are always up to the API.
Kiosk mode is a common way to lock down a Windows device when that device is used for a specific task or used in a public setting. So in electron kiosk mode, we'd have the ability to lock down our application to a point that users are restricted to the actions that we want them to perform.
A listener on "mainWindow" doesn't worked for me. I used instead "mainWindow.webContents".
mainWindow.webContents.once('dom-ready', () => {});
Have a look at the did-finish-load
event mentioned in the Electron browser-window documentation.
mainWindow.once('did-finish-load', () => { // Send Message })
There seems to be a dom-ready
event too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With