Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider a state without bounds still valid if fullscreen of maximized #10

Merged

Conversation

mateusmedeiros
Copy link
Contributor

@mateusmedeiros mateusmedeiros commented Aug 22, 2016

The state will have it's coordinates and size info updated only if the
app is not in fullscreen mode or maximized at the time of the update.

This makes sense because coordinates and size are not relevant when in
fullscreen or maximized. The problem is that only the defaultWidth and
defaultHeight definitions will be read if the state in the file is not
considered valid, and to be considered valid, a state must have bounds
(x, y, width and height must be defined).

When leaving the application for the first time (no preexistent
window-store.json), if the application was in fullscreen mode or
maximized when exiting, the newly created window-store.json will not
have coordinates and size info (since the update function that is called
right before the save operation will ignore the coordinates and size, as
said before).

Because of that, when the application is opened for the second time, the
state is considered invalid and the saved isMaximized or
isFullScreen options are completely ignored.

This fixes that by considering the state valid if isFullScreen or
isMaximized are true, even if it has no bounds. It also adds some basic
tests to this functionality.

I noticed this problem when I was trying to follow Nyaovim's documentation on it's browser-config.json file and remember_window_state wasn't working as expected. I dug a little on Nyaovim's source and eventually found that when the remember_window_statewas set to true, it basically turned on electron-window-state. So I started digging here as well initially so that I could open an issue with some useful info instead of a simple "this ain't working".

The damn bug ended up being so erratic that it wasn't until I actually found the problem on the code that I understood how to reproduce it and what was really happening. By that time, I figured it was easier to fork the repo and make a pull request. 😄

The state will have it's coordinates and size info updated only if the
app is not in fullscreen mode or maximized at the time of the update.

This makes sense because coordinates and size are not relevant when in
fullscreen or maximized. The problem is that only the defaultWidth and
defaultHeight definitions will be read if the state in the file is not
considered valid, and to be considered valid, a state must have bounds
(x, y, width and height must be defined).

When leaving the application for the first time (no preexistent
window-store.json), if the application was in fullscreen mode or
maximized when exiting, the newly created window-store.json will not
have coordinates and size info (since the update function that is called
right before the save operation will ignore the coordinates and size, as
said before).

Because of that, when the application is opened for the second time, the
state will be considered invalid and the saved isMaximized or
isFullScreen options will be completely ignored.

This fixes that by considering the state valid if isFullScreen or
isMaximized are true, even if it has no bounds. It also adds some basic
tests to this functionality.
@mawie81 mawie81 merged commit 57ac4b8 into mawie81:master Aug 23, 2016
@mawie81
Copy link
Owner

mawie81 commented Aug 23, 2016

Thanks a lot 😄

@mateusmedeiros mateusmedeiros deleted the state-valid-if-fullscreen-or-maximized branch August 25, 2016 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants