Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

electron BrowserWindow min height and width not working after hide() show() methods

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 ?

like image 456
IOR88 Avatar asked May 19 '16 17:05

IOR88


2 Answers

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
like image 125
spm Avatar answered Oct 27 '22 12:10

spm


you can add minWidth:500 inside the BrowserWindow while initializing window. like

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 in main.js file so you just add minWidth:value, inside the function.

like image 1
Yumick Gharti Avatar answered Oct 27 '22 13:10

Yumick Gharti