Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Default window position now recorded and used for new windows #5102

Merged
merged 1 commit into from
Oct 26, 2016
Merged

Default window position now recorded and used for new windows #5102

merged 1 commit into from
Oct 26, 2016

Conversation

bsclifton
Copy link
Member

@bsclifton bsclifton commented Oct 24, 2016

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Default window position now recorded and used for new windows

  • renamed setDefaultWindowSize => defaultWindowParamsChanged
  • created new state (code will backfill value by trying to read the new value and if null, then try the old value)
  • defaultWindowParamsChanged now saves x/y and uses when creating window
  • consolidated duplicate BrowserWindow event handlers from appStore.js in main.js
  • window resize handler now has a sliding 1 second timer to avoid spamming events (causing extreme slowness)

Fixes #3754
Fixes #3247
Fixes #586

Auditors: @bridiver, @bbondy
cc: @BrendanEich (I know this one has got you a few times- should be g2g after this!)

Test Plan:

for #3754

  1. Launch Brave and go to Preferences
  2. Set "Brave starts with" to "My homepage" and specify duckduckgo.com
  3. Move window somewhere specific and resize it too
  4. Close the browser
  5. Launch browser and notice window size and position is correct (even though no window state was saved)

for #3247
6. Launch Brave on macOS
8. Only have one window open (close others; verify via the Window menu)
9. Move window somewhere specific and resize it to a weird (but memorable) size
10. Close the only window
11. Pick "New Window" from the file menu
12. Notice window goes to position of last window and assumes size of last window

for #586
13. Go to slashdot.org
14. Resize the window horizontally as fast as you possibly can!
15. Notice that while it could be better, it's MUCH faster than it is now
16. Move the window somewhere specific

Upgrade test plan:

  1. Launch Brave (version 0.12.6) and go to Preferences
  2. Set "Brave starts with" to "My homepage" and specify duckduckgo.com
  3. Resize the window to a very specific size
  4. Close the browser
  5. Install Brave version 0.12.7
  6. Launch Brave and notice that the window has the same dimensions as before (remember, position was not saved prior to this fix).

const size = event.sender.getSize()
// NOTE: the default window size is whatever the last window resize was
appActions.defaultWindowParamsChanged(size)
windowActions.saveSize(size)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this second action? Can defaultWindowParamsChanged also save them?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not it's ok, just wanted to check

Copy link
Member Author

@bsclifton bsclifton Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the updated design that we'll move to (where app state has control over window state), it would be a no brainer as one action.

With our system now, does the WindowStore also receive AppStore events? (if so, would it be possible for us to add the window id in there and then fetch the session object, based on that?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure if the window store receives app events, but if you need the window or session those are available in the browser process. DM me for details

windowActions.onFocusChanged(false)
})

// NOTE: setTimeout is used to avoid spamming events
let moveTimeout = null
currentWindow.on('move', function (event) {
if (moveTimeout) {
clearTimeout(moveTimeout)
}
moveTimeout = setTimeout(function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this still call the method just as many times, but delayed by 1 second? Can we use debounce here instead?

resizeTimeout = setTimeout(function () {
const size = event.sender.getSize()
// NOTE: the default window size is whatever the last window resize was
appActions.defaultWindowParamsChanged(size)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful with these inside events. This is ok because it's wrapped in a setTimeout (see below for possible change to debounce which would also be ok). Otherwise they should be wrapped in setImmediate. No change needed for that, just a reminder.

*/
setDefaultWindowSize: function (size) {
defaultWindowParamsChanged: function (size, position) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ on declarative event naming

windowActions.onFocusChanged(false)
})

// NOTE: setTimeout is used to avoid spamming events
let moveTimeout = null
currentWindow.on('move', function (event) {
if (moveTimeout) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: my comment below, I didn't see this at first, but I still think debounce would be better. Can move and resize call a common method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would work well with debounce because you can can do method = method.debounce(...) or similar

- renamed setDefaultWindowSize => defaultWindowParamsChanged
- created new state (code will backfill value by trying to read the new value and if null, then try the old value)
- defaultWindowParamsChanged now saves x/y and uses when creating window
- consolidated duplicate BrowserWindow event handlers from `appStore.js` in `main.js`
- window resize handler now has a sliding 1 second timer to avoid spamming events (causing extreme slowness)

(NOTE: this is a squashed rebase and includes the debounce implementation, per feedback by @bridiver)

Fixes #3754
Fixes #3247
Fixes #586

Auditors: @bridiver, @bbondy
cc: @BrendanEich (I know this one has got you a few times- should be g2g after this!)

Test Plan:

for #3754
1. Launch Brave and go to Preferences
2. Set "Brave starts with" to "My homepage" and specify duckduckgo.com
3. Move window somewhere specific and resize it too
4. Close the browser
5. Launch browser and notice window size and position is correct (even though no window state was saved)

for #3247
6. Launch Brave on macOS
8. Only have one window open (close others; verify via the Window menu)
9. Move window somewhere specific and resize it to a weird (but memorable) size
10. Close the only window
11. Pick "New Window" from the file menu
12. Notice window goes to position of last window and assumes size of last window

for #586
13. Go to slashdot.org
14. Resize the window horizontally as fast as you possibly can!
15. Notice that while it could be better, it's MUCH faster than it is now
16. Move the window somewhere specific

Upgrade test plan:
1. Launch Brave (version 0.12.6) and go to Preferences
2. Set "Brave starts with" to "My homepage" and specify duckduckgo.com
3. Resize the window to a very specific size
4. Close the browser
5. Install Brave version 0.12.7
6. Lauch Brave and notice that the window has the same dimensions as before (remember, position was not saved prior to this fix).
@bsclifton
Copy link
Member Author

implemented debounce feedback and rebased; issue to track the cleanup for the window methods can be found here #5127 😄

@bbondy
Copy link
Member

bbondy commented Oct 26, 2016

thanks, merging!

@srirambv
Copy link
Collaborator

Test Plan: for #3754

  1. Launch Brave and go to Preferences
  2. Set "Brave starts with" to "My homepage" and specify duckduckgo.com
  3. Move window somewhere specific and resize it too
  4. Close the browser
  5. Launch browser and notice window size and position is correct (even though no window state was saved)

Only remembers the size but not the window position.

@luixxiul
Copy link
Contributor

@srirambv because this was not merged in 0.12.7 Preview1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.