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

Commit

Permalink
Merge pull request #9990 from bsclifton/fix-platform-utils
Browse files Browse the repository at this point in the history
Fix platformUtil usage in app/browser/menu.js
  • Loading branch information
NejcZdovc authored Jul 14, 2017
2 parents d3f96bb + 969b1e8 commit 2e92a01
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 32 deletions.
4 changes: 3 additions & 1 deletion app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const menuUtil = require('../common/lib/menuUtil')
const {getSetting} = require('../../js/settings')
const locale = require('../locale')
const {isLocationBookmarked} = require('../../js/state/siteUtil')
const {isDarwin, isLinux} = require('../common/lib/platformUtil')
const platformUtil = require('../common/lib/platformUtil')
const isDarwin = platformUtil.isDarwin()
const isLinux = platformUtil.isLinux()

let appMenu = null
let closedFrames = new Immutable.OrderedMap()
Expand Down
4 changes: 2 additions & 2 deletions app/common/lib/platformUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ module.exports.getPathFromFileURI = (fileURI) => {

module.exports.isDarwin = () => {
return process.platform === 'darwin' ||
navigator.platform === 'MacIntel'
(navigator && navigator.platform === 'MacIntel')
}

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

module.exports.isLinux = () => {
Expand Down
4 changes: 2 additions & 2 deletions app/common/state/menuBarState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const {isWindows} = require('../lib/platformUtil')
const isWindows = require('../lib/platformUtil').isWindows()
const {getSetting} = require('../../../js/settings')
const settings = require('../../../js/constants/settings')

const api = {
isMenuBarVisible: (windowState) => {
return isWindows() && (!getSetting(settings.AUTO_HIDE_MENU) || windowState.getIn(['ui', 'menubar', 'isVisible']))
return isWindows && (!getSetting(settings.AUTO_HIDE_MENU) || windowState.getIn(['ui', 'menubar', 'isVisible']))
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const contextMenus = require('../../../../js/contextMenus')
const cx = require('../../../../js/lib/classSet')
const dnd = require('../../../../js/dnd')
const dndData = require('../../../../js/dndData')
const {isWindows} = require('../../../common/lib/platformUtil')
const isWindows = require('../../../common/lib/platformUtil').isWindows()
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const bookmarkUtil = require('../../../common/lib/bookmarkUtil')

Expand Down Expand Up @@ -145,7 +145,7 @@ class BookmarksToolbar extends React.Component {
props.showOnlyFavicon = bookmarkUtil.showOnlyFavicon()
props.showFavicon = bookmarkUtil.showFavicon()
props.shouldAllowWindowDrag = windowState.shouldAllowWindowDrag(state, currentWindow, activeFrame, isFocused()) &&
!isWindows()
!isWindows
props.visibleBookmarks = bookmarks.visibleBookmarks
props.hiddenBookmarks = bookmarks.hiddenBookmarks

Expand Down
13 changes: 8 additions & 5 deletions app/renderer/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ const cx = require('../../../../js/lib/classSet')
const eventUtil = require('../../../../js/lib/eventUtil')
const {isSourceAboutUrl} = require('../../../../js/lib/appUrlUtil')
const {getCurrentWindowId, isMaximized, isFocused, isFullScreen} = require('../../currentWindow')
const {isDarwin, isWindows, isLinux} = require('../../../common/lib/platformUtil')
const platformUtil = require('../../../common/lib/platformUtil')
const isDarwin = platformUtil.isDarwin()
const isWindows = platformUtil.isWindows()
const isLinux = platformUtil.isLinux()

class Main extends React.Component {
constructor (props) {
Expand All @@ -85,7 +88,7 @@ class Main extends React.Component {
this.exitFullScreen()
break
case keyCodes.F12:
if (!isDarwin()) {
if (!isDarwin) {
ipc.emit(messages.SHORTCUT_ACTIVE_FRAME_TOGGLE_DEV_TOOLS)
}
break
Expand Down Expand Up @@ -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')
props.showPopupWindow = !!currentWindow.get('popupWindowDetail')
props.showSiteInfo = currentWindow.getIn(['ui', 'siteInfo', 'isVisible']) &&
Expand All @@ -539,7 +542,7 @@ class Main extends React.Component {
!!currentWindow.get('braveryPanelDetail')
props.showClearData = !!currentWindow.getIn(['ui', 'isClearBrowsingDataPanelVisible'])
props.showImportData = !!currentWindow.get('importBrowserDataDetail')
props.showWidevine = currentWindow.getIn(['widevinePanelDetail', 'shown']) && !isLinux()
props.showWidevine = currentWindow.getIn(['widevinePanelDetail', 'shown']) && !isLinux
props.showAutoFillAddress = !!currentWindow.get('autofillAddressDetail')
props.showAutoFillCC = !!currentWindow.get('autofillCreditCardDetail')
props.showLogin = !!loginRequiredDetails
Expand Down Expand Up @@ -568,7 +571,7 @@ class Main extends React.Component {

// used in other functions
props.menubarSelectedIndex = currentWindow.getIn(['ui', 'menubar', 'selectedIndex'])
props.showCustomTitleBar = isWindows()
props.showCustomTitleBar = isWindows
props.menubarVisible = menuBarState.isMenuBarVisible(currentWindow)
props.mouseInFrame = currentWindow.getIn(['ui', 'mouseInFrame'])
props.braveShieldEnabled = shieldState.braveShieldsEnabled(activeFrame)
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/main/siteInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const tabState = require('../../../common/state/tabState')
const cx = require('../../../../js/lib/classSet')
const {isPotentialPhishingUrl} = require('../../../../js/lib/urlutil')
const siteUtil = require('../../../../js/state/siteUtil')
const platformUtil = require('../../../common/lib/platformUtil')
const isLinux = require('../../../common/lib/platformUtil').isLinux()
const frameStateUtil = require('../../../../js/state/frameStateUtil')

// Styles
Expand Down Expand Up @@ -135,7 +135,7 @@ class SiteInfo extends React.Component {

get viewCertificateButton () {
// TODO(Anthony): Hide it until muon support linux
if (!platformUtil.isLinux()) {
if (!isLinux) {
return <div className={css(styles.flexJustifyEnd, styles.viewCertificateButton__wrapper)}>
<Button
l10nId='viewCertificate'
Expand Down
6 changes: 3 additions & 3 deletions app/renderer/components/navigation/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const windowState = require('../../../common/state/windowState')

// Util
const {getCurrentWindowId, isMaximized, isFullScreen, isFocused} = require('../../currentWindow')
const {isWindows} = require('../../../common/lib/platformUtil')
const isWindows = require('../../../common/lib/platformUtil').isWindows()
const {braveShieldsEnabled} = require('../../../common/state/shieldState')
const eventUtil = require('../../../../js/lib/eventUtil')
const {isNavigatableAboutPage, getBaseUrl} = require('./../../../../js/lib/appUrlUtil')
Expand Down Expand Up @@ -180,7 +180,7 @@ class Navigator extends React.Component {
props.shieldEnabled = braveShieldsEnabled(activeFrame)
props.menuBarVisible = menuBarState.isMenuBarVisible(currentWindow)
props.isMaximized = isMaximized() || isFullScreen()
props.isCaptionButton = isWindows() && !props.menuBarVisible
props.isCaptionButton = isWindows && !props.menuBarVisible
props.activeTabShowingMessageBox = activeTabShowingMessageBox
props.extensionBrowserActions = extensionBrowserActions
props.showBrowserActions = !activeTabShowingMessageBox &&
Expand Down Expand Up @@ -319,7 +319,7 @@ class Navigator extends React.Component {
this.props.isCounterEnabled
? <div className={css(
styles.lionBadge,
(this.props.menuBarVisible || !isWindows()) && styles.lionBadgeRight,
(this.props.menuBarVisible || !isWindows) && styles.lionBadgeRight,
// delay badge show-up.
// this is also set for extension badge
// in a way that both can appear at the same time.
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/navigation/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const {eventElHasAncestorWithClasses, isForSecondaryAction} = require('../../../
const {getBaseUrl, isUrl} = require('../../../../js/lib/appUrlUtil')
const {getCurrentWindowId} = require('../../currentWindow')
const {normalizeLocation, getNormalizedSuggestion} = require('../../../common/lib/suggestion')
const {isDarwin} = require('../../../common/lib/platformUtil')
const isDarwin = require('../../../common/lib/platformUtil').isDarwin()
const publisherUtil = require('../../../common/lib/publisherUtil')

// Icons
Expand Down Expand Up @@ -123,7 +123,7 @@ class UrlBar extends React.Component {
(this.props.urlbarLocationSuffix && this.props.autocompleteEnabled))) {
// Hack to make alt enter open a new tab for url bar suggestions when hitting enter on them.
if (e.altKey) {
if (isDarwin()) {
if (isDarwin) {
e.metaKey = true
} else {
e.ctrlKey = true
Expand Down
6 changes: 4 additions & 2 deletions app/renderer/components/preferences/advancedTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const {scaleSize} = require('../../../common/constants/toolbarUserInterfaceScale
// Utils
const {changeSetting} = require('../../lib/settingsUtil')
const platformUtil = require('../../../common/lib/platformUtil')
const isDarwin = platformUtil.isDarwin()
const isLinux = platformUtil.isLinux()

class AdvancedTab extends ImmutableComponent {
previewReleases () {
return platformUtil.isLinux()
return isLinux
? null
: <SettingCheckbox
dataL10nId='updateToPreviewReleases'
Expand All @@ -36,7 +38,7 @@ class AdvancedTab extends ImmutableComponent {
}

get swipeNavigationDistanceSetting () {
if (platformUtil.isDarwin()) {
if (isDarwin) {
return <div>
<DefaultSectionTitle data-l10n-id='swipeNavigationDistance' />
<SettingsList listClassName={css(styles.swipeNavigation)}>
Expand Down
9 changes: 6 additions & 3 deletions app/renderer/components/preferences/pluginsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const aboutActions = require('../../../../js/about/aboutActions')
const getSetting = require('../../../../js/settings').getSetting
const settings = require('../../../../js/constants/settings')
const appConfig = require('../../../../js/constants/appConfig')
const {isWindows, isDarwin, isLinux} = require('../../../common/lib/platformUtil')
const platformUtil = require('../../../common/lib/platformUtil')
const isDarwin = platformUtil.isDarwin()
const isLinux = platformUtil.isLinux()
const isWindows = platformUtil.isLinux()

const WidevineInfo = require('../main/widevineInfo')
const flash = appConfig.resourceNames.FLASH
Expand Down Expand Up @@ -55,7 +58,7 @@ class PluginsTab extends ImmutableComponent {
<SettingCheckbox checked={this.flashInstalled ? this.props.braveryDefaults.get('flash') : false} dataL10nId='enableFlash' onChange={this.onToggleFlash} disabled={!this.flashInstalled} />
<div className='subtext flashText'>
{
isDarwin() || isWindows()
isDarwin || isWindows
? <div>
{this.infoCircle(appConfig.flash.installUrl)}
<span data-l10n-id='enableFlashSubtext' />&nbsp;
Expand All @@ -81,7 +84,7 @@ class PluginsTab extends ImmutableComponent {
</div>
</SettingsList>
{
!isLinux()
!isLinux
? <div>
<DefaultSectionTitle data-l10n-id='widevineSection' />
<SettingsList>
Expand Down
8 changes: 5 additions & 3 deletions app/renderer/components/tabs/content/tabTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const ReduxComponent = require('../../reduxComponent')
const tabContentState = require('../../../../common/state/tabContentState')

// Utils
const {isWindows, isDarwin} = require('../../../../common/lib/platformUtil')
const platformUtil = require('../../../../common/lib/platformUtil')
const isWindows = platformUtil.isWindows()
const isDarwin = platformUtil.isDarwin()

// Styles
const globalStyles = require('../../styles/global')
Expand All @@ -25,7 +27,7 @@ class TabTitle extends React.Component {

const props = {}
// used in renderer
props.enforceFontVisibility = isDarwin() && tabIconColor === 'white'
props.enforceFontVisibility = isDarwin && tabIconColor === 'white'
props.tabIconColor = tabIconColor
props.displayTitle = tabContentState.getDisplayTitle(currentWindow, frameKey)

Expand All @@ -49,7 +51,7 @@ class TabTitle extends React.Component {
titleStyles.gradientText,
this.props.enforceFontVisibility && styles.enforceFontVisibility,
// Windows specific style
isWindows() && styles.tabTitleForWindows
isWindows && styles.tabTitleForWindows
)}>
{this.props.displayTitle}
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const dnd = require('../../../../js/dnd')
const throttle = require('../../../../js/lib/throttle')
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const {getTabBreakpoint, tabUpdateFrameRate} = require('../../lib/tabUtil')
const {isWindows} = require('../../../common/lib/platformUtil')
const isWindows = require('../../../common/lib/platformUtil').isWindows()
const {getCurrentWindowId} = require('../../currentWindow')
const UrlUtil = require('../../../../js/lib/urlutil')
const {hasBreakpoint} = require('../../lib/tabUtil')
Expand Down Expand Up @@ -295,7 +295,7 @@ class Tab extends React.Component {
className={css(
styles.tab,
// Windows specific style
isWindows() && styles.tabForWindows,
isWindows && styles.tabForWindows,
this.props.isPinnedTab && styles.isPinned,
this.props.isActive && styles.active,
this.props.isPlayIndicatorBreakpoint && this.props.canPlayAudio && styles.narrowViewPlayIndicator,
Expand Down
6 changes: 3 additions & 3 deletions js/lib/eventUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const {isDarwin} = require('../../app/common/lib/platformUtil')
const isDarwin = require('../../app/common/lib/platformUtil').isDarwin()

module.exports.isForSecondaryAction = (e) =>
(e.ctrlKey && !isDarwin()) ||
(e.metaKey && isDarwin()) ||
(e.ctrlKey && !isDarwin) ||
(e.metaKey && isDarwin) ||
e.button === 1

module.exports.eventElHasAncestorWithClasses = (e, classesToCheck) => {
Expand Down

0 comments on commit 2e92a01

Please sign in to comment.