I wanna have a listener ( or something ) to check if the size of the window changes, do something ( like re-rendering entire view page ).
How should I do this?
Call mainWindow. maximize() to maximize the window after you create it. Save this answer.
To make an Electron app run in full-screen mode when it's started, pass the following configuration option when creating the BrowserWindow instance: mainWindow = new BrowserWindow({fullscreen: true});
You can use the resize
event like so:
window.on('resize', function () {
var size = window.getSize();
var width = size[0];
var height = size[1];
console.log("width: " + width);
console.log("height: " + height);
});
Docs here
To clarify the above answer. You have to set the resize
event on the main window you created. Further, if you want to access the width or height inside another file, you can emit another event and pass the width or height as a parameter. Here is a simple example of what I have done.
mainWindow.on("resize", function () {
var size = mainWindow.getSize();
var width = size[0];
var height = size[1];
mainWindow.webContents.send("resized", height);
console.log(size);
console.log("width: " + width);
console.log("height: " + height);
});
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