I want to detect when a user maximizes the window in my Electron app. I know I can listen the the maximize
event but I don't know how to use it. The docs are not very clear on the usage.
My current code -
main.js
const { app, BrowserWindow } = require('electron')
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
show: false
});
mainWindow.loadFile('index.html')
mainWindow.removeMenu();
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.on('maximize',(e) =>{
document.getElementById("topBar").style.display="none";
//Does not work as we cannot access the DOM in this process
console.log("Maximized") //Does not work too
});
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
I know I need to use some logic in the renderer process but I don't know how.
If I do something like this inside a script
tag
window.addEventListener("maximize", function(){
//Do something
});
it does not work too.