mawie81 / electron-window-state

A library to store and restore window sizes and positions for your Electron app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maximize window problem

Sigmanor opened this issue · comments

Hi! Im use your cool library, and together with this, I use this code:

    mainWindow = new BrowserWindow({
        show: false,
    });

    mainWindow.webContents.on('dom-ready', function() {
        mainWindow.show();
    });

in order to the contents of the window displayed only when fully loaded. When window is no maximized this working fine, but when app start maximized, this code does not work. Without your library all working as it should. Is there any solution?

Hm, what do you mean by "this code does not work"? Will the window not show up at all? Or not maximized?
What platform are you on and what electron version do you use?

I´m doing pretty much the same in here and haven´t head of any issues yet.

@mawie81
win10 x64
electron v0.36.7

Window show up maximized, but on dom-ready doesn't work. First, I see a white screen and then the application is fully load.

Here is video demonstration: https://vid.me/jrBw

I just learned that calling maximize() on the BrowserWindow also shows the window on Windows. On Mac it does not. This is even a reported bug in chromium https://code.google.com/p/chromium/issues/detail?id=452737

What I could try is to wait until the dom-readyevent to restore the maximized state but I´m not sure if this is a good solution. I´ll have to think about that.

In the meantime you could just opt-out of the restoration of the maximized state like this:

let mainWindowState = windowStateKeeper({
  defaultWidth: 1000,
  defaultHeight: 800,
  maximize: false
});

And then restore it yourself if needed:

window.webContents.on('dom-ready', () => {
  if (mainWindowState.isMaximized()) {
   window.maximize();
  }
});

Thank you for the answer.

And about your solution, i got strange error:
TypeError: mainWindowState.isMaximized is not a function

For now i decide save maximize value using configstore

Sorry my bad. isMaximized is a getter so its without the parenthesis:

mainWindowState.isMaximized

Closing because this seems be resolved.

Just for reference for anyone else having problems, do not name the return of the remote.getCurrentWindow() as window. For example this will work:

const remote = require('electron').remote;

$("div#title-bar-max").on("click", function()
{
  if(remote.getCurrentWindow().isMaximized())
  {
    remote.getCurrentWindow().unmaximize();
  }
  else
  {
    remote.getCurrentWindow().maximize();
  }
});

However, this will not:

const remote = require('electron').remote;

$("div#title-bar-max").on("click", function()
{
  window = remote.getCurrentWindow();

  if(window.isMaximized())
  {
    window.unmaximize();
  }
  else
  {
    window.maximize();
  }
});

This is mainly due to window being a reversed variable for the browser window.