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

Ensuring File > Share context menu items are disabled when no windows are open #13933

Merged
merged 2 commits into from
May 1, 2018

Conversation

ryanml
Copy link
Contributor

@ryanml ryanml commented Apr 25, 2018

Fixes #13928

This PR also includes some refactoring for the menu code concerning setting the checked status of a menu item. The functions are now generalized to setting a given attribute, so that enabled can be toggled as well.

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

Test Plan:

  1. Launch Brave from the terminal.
  2. Close any open windows, but ensure Brave is still running.
  3. Select File > Share
  4. Ensure that all of the submenu options are disabled
  5. Ensure that no error is being shown in the terminal
  6. Open a new window
  7. Select File > Share
  8. Ensure that the submenu options are enabled again

Reviewer Checklist:

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

Tests

  • 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

@codecov-io
Copy link

codecov-io commented Apr 25, 2018

Codecov Report

Merging #13933 into master will decrease coverage by <.01%.
The diff coverage is 60.71%.

@@            Coverage Diff             @@
##           master   #13933      +/-   ##
==========================================
- Coverage   56.46%   56.45%   -0.01%     
==========================================
  Files         284      284              
  Lines       29340    29362      +22     
  Branches     4872     4877       +5     
==========================================
+ Hits        16566    16577      +11     
- Misses      12774    12785      +11
Flag Coverage Δ
#unittest 56.45% <60.71%> (-0.01%) ⬇️
Impacted Files Coverage Δ
app/common/commonMenu.js 53.24% <100%> (+0.3%) ⬆️
app/common/lib/menuUtil.js 71.07% <100%> (+0.28%) ⬆️
app/browser/menu.js 51.69% <47.61%> (-0.47%) ⬇️

@bsclifton bsclifton self-requested a review May 1, 2018 05:27
@bsclifton bsclifton added this to the 0.22.x Release 3 (Beta channel) milestone May 1, 2018
case appConstants.APP_WINDOW_CREATED:
{
const windowCount = BrowserWindow.getAllWindows().filter((w) => w.isFocused()).length
if (action.actionType === 'app-window-closed' && windowCount === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

could you use the constant name here instead?
if (action.actionType === appConstants.APP_WINDOW_CLOSED && windowCount === 0) {

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.

comments left- otherwise, works and looks great! 😄 👍

const windowCount = BrowserWindow.getAllWindows().filter((w) => w.isFocused()).length
if (action.actionType === 'app-window-closed' && windowCount === 0) {
updateShareMenuItems(state, false)
} else if (action.actionType === 'app-window-created' && windowCount === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above comment

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Changes requested to make sure we are using window API that considers tabbed browser windows instead of any muon/electron window

case appConstants.APP_WINDOW_CLOSED:
case appConstants.APP_WINDOW_CREATED:
{
const windowCount = BrowserWindow.getAllWindows().filter((w) => w.isFocused()).length
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use the muon BrowserWindow API raw. Instead please use the app/browser/windows.js API, specifically getAllRendererWindows or getActiveWindow. The former should be enough as it makes sure the hidden window isn't included.

Copy link
Member

Choose a reason for hiding this comment

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

Good call- I was wondering that myself 😄

@ryanml ryanml force-pushed the file-share-menu-fix branch 2 times, most recently from eacab52 to 99cba57 Compare May 1, 2018 19:10
@ryanml
Copy link
Contributor Author

ryanml commented May 1, 2018

Changes pushed

cc: @bsclifton @petemill

bsclifton
bsclifton previously approved these changes May 1, 2018
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! Updated changes look good too

petemill
petemill previously approved these changes May 1, 2018
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Works nicely 👍 . Just left a comment about the neccessity of excludeShareSites rather that just removing the digg entry as I don't think it's being used anywhere else. Worth another search in order to reduce the complexity. 🔍

@@ -19,6 +19,11 @@ const templateUrls = {
reddit: 'https://reddit.com/submit?url={url}&title={title}'
}

// Sites that are not currently in the File > Share context menu
const excludedShareSites = [
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this rather than just remove the digg item from templateUrls. From a quick search I could not find any other usage of the templateUrls export from share.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petemill good thought, I did a search and it looks fine to remove. I've pushed an update removing the excludedShareSites addition. I left removing Digg from templateUrls a separate commit for ease of search should we want to add it back at any point.

@ryanml ryanml dismissed stale reviews from petemill and bsclifton via 191cdb0 May 1, 2018 22:08
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the additional fixes and cleanup 🥇

@bsclifton bsclifton merged commit ca83ee3 into brave:master May 1, 2018
bsclifton added a commit that referenced this pull request May 1, 2018
Ensuring File > Share context menu items are disabled when no windows are open
bsclifton added a commit that referenced this pull request May 1, 2018
Ensuring File > Share context menu items are disabled when no windows are open
@bsclifton
Copy link
Member

master ca83ee3
0.23.x 1954b5c
0.22.x-release3 4403af2

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

Successfully merging this pull request may close these issues.

4 participants