-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Fixing #1869. Ensuring that the restored window position is valid #2459
Conversation
Thank you so much for this PR. We need to include them in Otherwise, I'll make another PR. |
I shall modify the test command =]. Once this is in, do I need to cherry pick it to master? |
Ping |
We definitely need to run UTs on push. Can you make UTs run on prepush? |
Certainly! I'll get around to it either tomorrow or later this week =] |
Actually, turns out I can edit on my phone =]. Done! |
I will test & merge ASAP |
app/config/windows.js
Outdated
function validateAndFixWindowPosition(position, size) { | ||
const displays = electron.screen.getAllDisplays(); | ||
const [x, y] = position; | ||
const positionIsValid = displays.some(({workArea}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't test with any of available displays, only with targeted screen.
Screen targeting and some verification are done here: https://github.com/zeit/hyper/blob/5d0c6355e12ec8d9a89182556fa73227374b488f/app/index.js#L113-L148
It is a little bit messy and we probably should refactor it to add your position/size validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't test with any of available displays, only with targeted screen.
I'm having trouble understanding what you mean by this?
It is a little bit messy and we probably should refactor it to add your position/size validation.
Sounds reasonable. Would you have the logic persist a fixed location? Or just assume that a correct location will be written on next close, and if not, the verification logic will take care of it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first point: I misunderstood that a windows referential is always the same. I was thinking that we specified a screen when opening a new window. I was wrong.
My second point: I would assume that a correct location will be written or fixed if needed. But never mind, let's merge this as it is.
app/config/windows.js
Outdated
const displays = electron.screen.getAllDisplays(); | ||
const [x, y] = position; | ||
const positionIsValid = displays.some(({workArea}) => { | ||
return x >= workArea.x && x <= workArea.x + workArea.width && y >= workArea.y && y <= workArea.y + workArea.height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test if size is valid too. We don't want to have a valid position and an almost invisible window. For example if x === workArea.width - 1
or y === workArea.height - 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had contemplated this, but decided to keep it simple and follow YAGNI. If we were to get into this case, the use would have had to positioned the window there themselves and if it's on the screen the standard ctrl + arrow shortcuts would work.
If we go with this method we would need to define how big a work area is permissible. We could perhaps change the logic to check the center of the window, if the center of a terminal window is in the workarea, then we're good, if not, relocate? (This would cover both the edge case you mention, and the original "my monitor is no longer plugged in" case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that considering window center is really better than top-left corner.
I know there is some shortcuts (different on each OS), but I am pretty sure that some users know nothing about them.
I will fix this by myself, because this PR had a too long wait time. Sorry again for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to consider new window center because startX/startY is already corrected by existing code.
app/config/windows.js
Outdated
const {workArea} = electron.screen.getPrimaryDisplay(); | ||
position[0] = workArea.x + (workArea.width - size[0]) / 2; | ||
position[1] = workArea.y + (workArea.height - size[1]) / 2; | ||
cfg.set('windowPosition', position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to calculate a valid position. I think that fallback to default position/size is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The defaults are private to the windows config module. If I refactor my change to be in index.js
how would I go about invalidating the set values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you to have fixed this
I finally got around to refactoring this and addressing your comments. Could you please take a look? |
Ping @chabou Sorry if I'm being pushy, just this PR is pretty old now =] |
Only for me this bug is a block? I can't use hyper. |
…ition # Conflicts: # yarn.lock
@albinekb, could we get a second reviewer on this please? |
I am really sorry for the delay. |
This reverts commit 35f5985.
Thanks a lot for your help 🙏 |
Thanks so much @chabou! |
Fixes #1869
I have also added unit tests for the change. And removed unit tests for files that no longer exist (does this imply UTs aren't run for this project?).