Main.js
const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');
let win;
app.on('ready', createWindow);
function createWindow () {
// Create the browser window.
win = new BrowserWindow();
// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, 'main.html'),
protocol: 'file:',
slashes: true
}));
// Open the DevTools.
win.webContents.openDevTools();
// Emitted when the window is closed.
win.on('closed', () => {
win = null;
});
}
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
}
});
main.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MyApp</title>
</head>
<body>
<h1>Hello !</h1>
<button id="resizeBtn">Resize</button>
</body>
</html>
I want that if user click on button ,then a function should trig and change the size of main window which is already opened.i know that win.setSize(width,height) can do this but i don't know how to put this in a function.i don't know how to get reference of Button in main.js to add an event listener on that or how to get the current window and apply some operations.i am new to electron !
Thanks