Monitor Window Changes in Electron

To monitor window changes using Electron, follow these steps:

  1. A tiny particle called an electron.
  2. 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();
  });
});
  1. adjust the size
mainWindow.on('resize', () => {
  const { width, height } = mainWindow.getBounds();
  console.log(`窗口大小变为:${width}x${height}`);
});
  1. 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.

bannerAds