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

Multi-screen support

etiktin opened this issue · comments

There are 2 problems with the current implementation when working with more than 1 screen:

  • If you closed your app on some external screen and than you try to open it when that screen is not available (e.g. working directly on your laptop), the app will be invisible since it's still using the positioning for the external screen. Some users might not even know how to get the app back to their available screen (on Windows you can click on the app icon in the taskbar and move it using the Win key with the left or right arrows).
  • If you opened the app on screen 1, then move it to screen 2 and maximize it. If you close it maximized on screen 2, the next time you run it, it will open as maximized on screen 1. This happens since we don't save the x and y of the second screen.

We can solve the first issue by saving the matching display bounds using screen.getDisplayMatching(rect) and then on app load we can call it again with the app bounds and see if we get the same display bounds. If they are different it means the screen is not available or the screens layout changed, so we need to use the defaults.

The second issue is more complicated. Maybe save the position on move while not maximized?

Thank you for your feedback 😀

I just had quick look on it and noticed the following:

About the first issue: I could not reproduce the issue on my multi monitor Mac. If I have a second monitor and close the app there I get some correct looking coordinates. When the app is relaunched with only the internal laptop display available it is put automatically on this display. So I assume electron would fix such issues on its own. I did not have the chance to test this on a multi display Windows environment though and will probably only have a chance to on the weekend.
Are you referring to a Windows environment?

About the second issue: At the moment the x and y coordinates are not saved if the window is maximized. I tried to change this and simply always save them. This seemed to work on the Mac but as soon as window.maximize() is called the window just jumps back to the main display.
I will investigate what happens on windows on the weekend in this case as well.

Yep. I'm using Windows. If it doesn't happen on OS X then I guess either the OS or Electron are fixing the placement. On Windows there are plenty of apps that don't take care of this and the experience for multi-screen users is pretty bad as a result.

I'm currently working on fixing these issues. I'll send a PR later today or tomorrow for your consideration.

I was able to reproduce on a mac this with another app that doesn't use electron-window-state, so I believe this is something to do with electron itself. I'll make an issue there.