Monitor Window Changes in Electron
To monitor window changes using Electron, follow these steps:
- A tiny particle called an electron.
- Window for web browsing
const { app, BrowserWindow } = require('electron');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// 其他窗口创建逻辑...
}
app.whenReady().then(() => {
createWindow();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
- adjust the size
mainWindow.on('resize', () => {
const { width, height } = mainWindow.getBounds();
console.log(`窗口大小变为:${width}x${height}`);
});
- adjust the size
Please note that the code above is just a simple example, and you can make modifications and extensions according to your specific needs.