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

Fix platformUtil usage in app/browser/menu.js #9990

Merged
merged 1 commit into from
Jul 14, 2017
Merged

Fix platformUtil usage in app/browser/menu.js #9990

merged 1 commit into from
Jul 14, 2017

Conversation

bsclifton
Copy link
Member

@bsclifton bsclifton commented Jul 14, 2017

...and standardize usage of platformUtil

When #9678 was merged, unfortunately menu.js was not updated to call the function.
Instead of updating to call the function, I updated all usage to resolve the value at the top of each file (preventing multiple unneeded calls)

Auditors: @NejcZdovc

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.

Reviewer Checklist:

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

@bsclifton bsclifton requested a review from NejcZdovc July 14, 2017 06:02
const {isDarwin, isLinux} = require('../common/lib/platformUtil')
const platformUtil = require('../common/lib/platformUtil')
const isDarwin = platformUtil.isDarwin()
const isLinux = platformUtil.isLinux()
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the most important part of the PR. Without this PR, isDarwin and isLinux are always truthy (because they are set to the function itself, not the return value of the function)

@@ -530,7 +533,7 @@ class Main extends React.Component {
// used in renderer
props.isFullScreen = activeFrame.get('isFullScreen', false)
props.isMaximized = isMaximized() || isFullScreen()
props.captionButtonsVisible = isWindows()
props.captionButtonsVisible = isWindows
props.showContextMenu = !!currentWindow.get('contextMenuDetail')
Copy link
Member Author

Choose a reason for hiding this comment

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

This being cached at the top could potentially save some time (avoiding an extra function call and check for navigator)

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

PR looks good ++ Thank you for this fix.

Just a note about imports. Personally I don't like const isWindows = require('../../../common/lib/platformUtil').isWindows(), because you lock yourself for the further use of platformUtil. If we need to cache this values I like what you did in menu.js with const platformUtil = require('../common/lib/platformUtil') and then assigning values to the appropriate OS.

…f platformUtil

When #9678 was merged, unfortunately menu.js was not updated to call the function.
Instead of updating to call the function, I updated all usage to resolve the value at the top of each file (preventing multiple unneeded calls)

Auditors: @NejcZdovc
}

module.exports.isWindows = () => {
return process.platform === 'win32' ||
navigator.platform === 'Win32'
(navigator && navigator.platform === 'Win32')
}
Copy link
Member Author

@bsclifton bsclifton Jul 14, 2017

Choose a reason for hiding this comment

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

These checks are put in place because if the first one fails (ex: calling isWindows on mac) from the browser process, it checks navigator (which was undefined)... throwing an error when calling navigator.platform

@NejcZdovc NejcZdovc merged commit 2e92a01 into brave:master Jul 14, 2017
@bsclifton bsclifton deleted the fix-platform-utils branch July 14, 2017 06:45
bsclifton added a commit that referenced this pull request Jul 14, 2017
I followed up on travis tests and noticed they were failing :(

Auditors: @NejcZdovc
bbondy pushed a commit that referenced this pull request Jul 17, 2017
I followed up on travis tests and noticed they were failing :(

Auditors: @NejcZdovc
bbondy pushed a commit that referenced this pull request Jul 17, 2017
I followed up on travis tests and noticed they were failing :(

Auditors: @NejcZdovc
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.

2 participants