-
Notifications
You must be signed in to change notification settings - Fork 975
Default window position now recorded and used for new windows #5102
Conversation
const size = event.sender.getSize() | ||
// NOTE: the default window size is whatever the last window resize was | ||
appActions.defaultWindowParamsChanged(size) | ||
windowActions.saveSize(size) |
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.
do we need this second action? Can defaultWindowParamsChanged
also save them?
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.
if not it's ok, just wanted to check
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 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?)
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'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 () { |
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.
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) |
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.
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) { |
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.
++ 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) { |
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.
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?
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.
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).
implemented debounce feedback and rebased; issue to track the cleanup for the window methods can be found here #5127 😄 |
thanks, merging! |
Only remembers the size but not the window position. |
@srirambv because this was not merged in 0.12.7 Preview1 |
git rebase -i
to squash commits (if needed).Default window position now recorded and used for new windows
appStore.js
inmain.js
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
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: