How to re-size electron main window dynamically?


#1

i want a Button in main.html (the very first page opens when app is started) when clicked , change the size of the Main window (which is itself opened already) .
The button is in the same window .but i can’t find a way to do that . i used this code .

In Main.html

<button id="btn">Resize</button>
<script>
    const electron = require('electron');
    let {ipcRenderer} = electron;
    let btn = document.getElementById('btn');
    btn.addEventListener('click', function (e) {
        e.preventDefault();
        ipcRenderer.send('resize', 600, 800);
    });
</script>

In main.js

let {ipcRenderer} = electron;
ipcRenderer.on('resize', function (e, x, y) {
    win.setSize(x, y);
});

but it throw the following error and doesn’t work ! Please help me i spent whole day trying this :frowning:


#2

OOPS The code i am using is working fine . i just made a mistake and used ipcRenderer instead of using ipcMain in my main.js ! hope it will help someone one day !

so in Main.js correct code should be

let {ipcRenderer} = electron;
ipcRenderer.on('resize', function (e, x, y) {
win.setSize(x, y);
});