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

Fixing #1869. Ensuring that the restored window position is valid #2459

Merged
merged 13 commits into from
Mar 2, 2018
Merged

Fixing #1869. Ensuring that the restored window position is valid #2459

merged 13 commits into from
Mar 2, 2018

Conversation

Xapphire13
Copy link
Contributor

@Xapphire13 Xapphire13 commented Nov 15, 2017

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?).

@chabou
Copy link
Collaborator

chabou commented Nov 15, 2017

Thank you so much for this PR.
Indeed UTs are not systematically run for this project. And this is bad.
I have broken these UTs without being warned about this.

We need to include them in yarn test. Not only linting.
Do you mind to fix this test command in your PR?

Otherwise, I'll make another PR.

@Xapphire13
Copy link
Contributor Author

I shall modify the test command =]. Once this is in, do I need to cherry pick it to master?

@Xapphire13
Copy link
Contributor Author

Ping

@chabou
Copy link
Collaborator

chabou commented Nov 20, 2017

We definitely need to run UTs on push.
It will not prevent commiting early and often. (commit !== push). And if you need to push with broken UTs, you still can do : yarn push --no-verify (but this is bad 😜 ), but CI tests will fail.

Can you make UTs run on prepush?
Thanks !

@Xapphire13
Copy link
Contributor Author

Certainly! I'll get around to it either tomorrow or later this week =]

@Xapphire13
Copy link
Contributor Author

Actually, turns out I can edit on my phone =]. Done!

@chabou
Copy link
Collaborator

chabou commented Nov 20, 2017

I will test & merge ASAP

@chabou chabou self-assigned this Nov 20, 2017
@chabou chabou self-requested a review November 20, 2017 08:57
function validateAndFixWindowPosition(position, size) {
const displays = electron.screen.getAllDisplays();
const [x, y] = position;
const positionIsValid = displays.some(({workArea}) => {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

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)

Copy link
Collaborator

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

Copy link
Collaborator

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.

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);
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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

@Xapphire13
Copy link
Contributor Author

@chabou

I finally got around to refactoring this and addressing your comments. Could you please take a look?

@Xapphire13
Copy link
Contributor Author

Xapphire13 commented Feb 13, 2018

Ping @chabou

Sorry if I'm being pushy, just this PR is pretty old now =]

@cnt000
Copy link

cnt000 commented Feb 19, 2018

Only for me this bug is a block? I can't use hyper.
There are issues or we will have possibilities to accept this? Gently @chabou :-D

@Xapphire13
Copy link
Contributor Author

@albinekb, could we get a second reviewer on this please?

@chabou
Copy link
Collaborator

chabou commented Feb 28, 2018

I am really sorry for the delay.
I will review/merge it before next week.

@chabou chabou merged commit 24b8361 into vercel:canary Mar 2, 2018
@chabou
Copy link
Collaborator

chabou commented Mar 2, 2018

Thanks a lot for your help 🙏

@Xapphire13
Copy link
Contributor Author

Thanks so much @chabou!

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.

None yet

3 participants