电子 BrowserWindow 最小高度和宽度在 hide() show() 方法后不起作用

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(发生某些事件,我想暂时隐藏主 window 并显示另一个(createFacebookWindow() fn 已经在加载 URL))

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(另一个事件发生,我销毁 fb window 并显示 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);

总结:

所以实际上在这些步骤之后,当我返回 mainWindow 时它不记得 mainWindow 设置 min-height 和 min-width 不起作用。

当 facebookWindow 未打开时,一切都很好,所以在使用 windows 切换期间一定发生了一些事情。也许某些事情的顺序有误?

您可以在此处阅读 BrowserWindow 文档:https://github.com/electron/electron/blob/master/docs/api/browser-window.md

  • maxWidth 而不是 max-width
  • minWidth 改为 min-width

  • maxHeight 改为 max-height

  • minHeight 而不是 min-height
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
    }
  })

注意:函数 (createWindow) 位于 main.js 文件中,因此您只需在函数内部添加 minWidth:value。