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

Menu items which need a window will create / show one if needed #13749

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

petemill
Copy link
Member

@petemill petemill commented Apr 5, 2018

Fix #13689
Partially addresses some items in #8164

This bug was caused because menu items were using a hidden window for their new tabs.

We should not use electron{.remote}.BrowserWindow.getAllWindows() or .get{Active, Focused}Window directly. There are two reasons that could have bad results:

  1. We create BrowserWindows which are not normal tabbed renderer windows (e.g. some code that runs on Bookmark creation)
  2. We have a hidden window sometimes (the Buffer Window)
    Instead call app/browser/window.js: getAllRendererWindows and getActiveWindowId.
    Fix for main menu actions, which can be called when there are no windows, but when searching for BrowserWindow.

Test Plan:

  • Check all menu items open new tab in currently active window
  • Check all menu items open new tab in currently active window, when app is not focused
  • Check all menu items open new tab in new window if there is no visible window
  • Check tabs in all windows are persisted on restart when app / windows close
  • Check process quits in Windows when last visible window is closed

Submitter Checklist:

  • 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).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

  • Adequate test coverage exists to prevent regressions

  • Tests should be independent and work correctly when run individually or as a suite ref

  • New files have MPL2 license header

@petemill petemill added this to the 0.22.x Release 2 (Beta Channel) milestone Apr 5, 2018
@petemill petemill self-assigned this Apr 5, 2018
@petemill petemill requested a review from bsclifton April 5, 2018 17:21
@codecov-io
Copy link

codecov-io commented Apr 5, 2018

Codecov Report

Merging #13749 into master will decrease coverage by <.01%.
The diff coverage is 13.63%.

@@            Coverage Diff             @@
##           master   #13749      +/-   ##
==========================================
- Coverage   56.78%   56.77%   -0.01%     
==========================================
  Files         285      285              
  Lines       29038    29042       +4     
  Branches     4803     4800       -3     
==========================================
+ Hits        16488    16489       +1     
- Misses      12550    12553       +3
Flag Coverage Δ
#unittest 56.77% <13.63%> (-0.01%) ⬇️
Impacted Files Coverage Δ
app/common/commonMenu.js 54% <ø> (+1.79%) ⬆️
app/browser/reducers/tabsReducer.js 39.94% <20%> (-0.11%) ⬇️
app/browser/windows.js 33.44% <8.33%> (-0.23%) ⬇️

@bsclifton bsclifton modified the milestones: 0.22.x Release 2 (Beta Channel), 0.22.x Release 3 Apr 6, 2018
@petemill petemill force-pushed the fix/new-tab-no-visible-windows branch from 718bbd1 to fe52ce2 Compare April 6, 2018 20:58
@bsclifton
Copy link
Member

bsclifton commented Apr 6, 2018

@petemill looks like a lot of the items called out in #8164 don't work:
(screenshot of checklist from that issue after I ran through it)
screen shot 2018-04-06 at 2 10 15 pm

When doing many of those, I'm getting this error via stdout:

An uncaught exception occurred in the main process Uncaught Exception:
TypeError: Cannot read property 'id' of null
    at /Users/clifton/Documents/browser-laptop/app/common/lib/menuUtil.js:171:60
    at MenuItem.click (/Users/clifton/Documents/browser-laptop/node_modules/electron-prebuilt/dist/Brave.app/Contents/Resources/electron.asar/browser/api/menu-item.js:59:9)
    at Function.executeCommand (/Users/clifton/Documents/browser-laptop/node_modules/electron-prebuilt/dist/Brave.app/Contents/Resources/electron.asar/browser/api/menu.js:121:15)

Fix #13689

This bug was caused because menu items were using a hidden window for their new tabs.

We should _not_ use `electron{.remote}.BrowserWindow.getAllWindows()` or `.get{Active, Focused}Window` directly. There are two reasons that could have bad results:
1. We create BrowserWindows which are not normal tabbed renderer windows (e.g. some code that runs on Bookmark creation)
2. We have a hidden window sometimes (the Buffer Window)
Instead call `app/browser/window.js`: `getAllRendererWindows` and `getActiveWindowId`.
Fix for main menu actions, which can be called when there are no windows, but when searching for `BrowserWindow.`

Test Plan:
- Check all menu items open new tab in currently active window
- Check all menu items open new tab in currently active window, when app is not focused
- Check all menu items open new tab in new window if there is no visible window
- Check tabs in all windows are persisted on restart when app / windows close
- Check process quits in Windows when last visible window is closed
@petemill petemill force-pushed the fix/new-tab-no-visible-windows branch from fe52ce2 to e329340 Compare April 6, 2018 21:15
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Works great! 😄 👍

@bsclifton bsclifton merged commit 56f9e72 into master Apr 6, 2018
@bsclifton bsclifton deleted the fix/new-tab-no-visible-windows branch April 6, 2018 21:18
bsclifton added a commit that referenced this pull request Apr 6, 2018
Menu items which need a window will create / show one if needed
bsclifton added a commit that referenced this pull request Apr 6, 2018
Menu items which need a window will create / show one if needed
@bsclifton
Copy link
Member

master 56f9e72
0.23.x 0f240f7
0.22.x cb60d71

@petemill petemill modified the milestones: 0.22.x Release 3 (Beta channel), 0.22.x w/ Chromium 66 Apr 19, 2018
petemill pushed a commit that referenced this pull request Apr 19, 2018
Menu items which need a window will create / show one if needed
@petemill
Copy link
Member Author

0.22.x-c66 a415cb0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Tab doesn't work without an open window on macOS
3 participants