9

1.Step

mainWindow = new BrowserWindow({
  width: 1200,
  height: 700,
  center: true,
  'min-height': 700,
  'min-width': 1200,
  webPreferences: {nodeIntegration:true}});
mainWindow.loadURL(HOME_URL);

2.Step (some event occur and i want to temporary hide main window and show another(createFacebookWindow() fn is already loadingURL))

mainWindow.hide();



facebookWindow = require('./modules/auth/views.js').createFacebookWindow();

FB Window settings ({
                                              width: 1200,
                                              height: 700,
                                              center: true,
                                              'min-height': 700,
                                              'min-width': 1200,
                                               webPreferences: {nodeIntegration:false}})

3.Step (another event occur i destroy fb window and show main window)

 facebookWindow.close();

 facebookWindow.on('closed', function() {
    facebookWindow = null;
    mainWindow.show();
    //I tried below options it doesn't work
    //mainWindow.setSize(1200, 700);
    //mainWindow.setMinimumSize(1200, 700);

Summary:

So actually after these steps, when I show mainWindow back it doesn't remember mainWindow settings min-height and min-width are not working.

When facebookWindow is not opened, all is fine, so something must happening during switching with windows. Maybe something is done in wrong order ?

2 Answers 2

26

You can read the BrowserWindow documentation here: https://github.com/electron/electron/blob/master/docs/api/browser-window.md

  • maxWidth instead max-width
  • minWidth instead min-width

  • maxHeight instead max-height

  • minHeight instead min-height
3

You can add minWidth: 500 when initializing the BrowserWindow, like this:

function createWindow () {
  // Create the browser window.
  const win = new BrowserWindow({
    backgroundColor: '#ffffff',
    width: 1024,
    height: 768,
    minWidth:500,
    webPreferences: {
      nodeIntegration: true
    }
  })
}

Note: The function createWindow is located in the main.js file, so you simply need to add minWidth: value inside the function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.