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 #8381 from NejcZdovc/hotfix/#8380-window-actions
Browse files Browse the repository at this point in the history
Removes store logic from windowActions
  • Loading branch information
bsclifton authored Apr 19, 2017
2 parents 08edb5a + d7c8ab4 commit 90d9290
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 67 deletions.
5 changes: 5 additions & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ const tabsReducer = (state, action) => {
case windowConstants.WINDOW_SET_AUDIO_MUTED:
state = tabs.setAudioMuted(state, action)
break
case windowConstants.WINDOW_SET_ALL_AUDIO_MUTED:
action.get('frameList').forEach((frameProp) => {
state = tabs.setAudioMuted(state, frameProp)
})
break
case windowConstants.WINDOW_SET_ACTIVE_FRAME:
state = tabs.setActive(state, action)
break
Expand Down
3 changes: 1 addition & 2 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ const api = {

setAudioMuted: (state, action) => {
action = makeImmutable(action)
const frameProps = action.get('frameProps')
const muted = action.get('muted')
const tabId = frameProps.get('tabId')
const tabId = action.get('tabId')
const tab = api.getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
tab.setAudioMuted(muted)
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class Tab extends ImmutableComponent {

onMuteFrame (muted, event) {
event.stopPropagation()
windowActions.setAudioMuted(this.frame, muted)
const frame = this.frame
windowActions.setAudioMuted(frame.get('key'), frame.get('tabId'), muted)
}

get loading () {
Expand Down
25 changes: 7 additions & 18 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,38 +505,27 @@ If set, also indicates that the popup window is shown.



### setAudioMuted(frameProps, muted)
### setAudioMuted(frameKey, tabId, muted)

Dispatches a message to indicate that the frame should be muted

**Parameters**

**frameProps**: `Object`, Properties of the frame in question

**muted**: `boolean`, true if the frame is muted


**frameKey**: `number`, Key of the frame in question

### muteAllAudio(framePropsList, muted)
**tabId**: `number`, Id of the tab in question

Dispatches a mute/unmute call to all frames in a provided list (used by TabList).

**Parameters**

**framePropsList**: `Object`, List of frame properties to consider

**muted**: `boolean`, true if the frames should be muted
**muted**: `boolean`, true if the frame is muted



### muteAllAudioExcept(frameToSkip)
### muteAllAudio(frameList)

Dispatches a mute call to all frames except the one provided.
The provided frame will have its audio unmuted.
Dispatches a mute/unmute call to all frames in a provided list.

**Parameters**

**frameToSkip**: `Object`, Properties of the frame to keep audio
**frameList**: `Object`, List of frames to consider (frameKey and tabId)



Expand Down
43 changes: 11 additions & 32 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

const AppDispatcher = require('../dispatcher/appDispatcher')
const windowConstants = require('../constants/windowConstants')
const windowStore = require('../stores/windowStore')

function dispatch (action) {
AppDispatcher.dispatch(action)
Expand Down Expand Up @@ -604,48 +603,28 @@ const windowActions = {
/**
* Dispatches a message to indicate that the frame should be muted
*
* @param {Object} frameProps - Properties of the frame in question
* @param {number} frameKey - Key of the frame in question
* @param {number} tabId - Id of the tab in question
* @param {boolean} muted - true if the frame is muted
*/
setAudioMuted: function (frameProps, muted) {
setAudioMuted: function (frameKey, tabId, muted) {
dispatch({
actionType: windowConstants.WINDOW_SET_AUDIO_MUTED,
frameProps,
frameKey,
tabId,
muted
})
},

/**
* Dispatches a mute/unmute call to all frames in a provided list (used by TabList).
* Dispatches a mute/unmute call to all frames in a provided list.
*
* @param {Object} framePropsList - List of frame properties to consider
* @param {boolean} muted - true if the frames should be muted
* @param {Object} frameList - List of frames to consider (frameKey and tabId)
*/
muteAllAudio: function (framePropsList, mute) {
framePropsList.forEach((frameProps) => {
if (mute && frameProps.get('audioPlaybackActive') && !frameProps.get('audioMuted')) {
this.setAudioMuted(frameProps, true)
} else if (!mute && frameProps.get('audioMuted')) {
this.setAudioMuted(frameProps, false)
}
})
},

/**
* Dispatches a mute call to all frames except the one provided.
* The provided frame will have its audio unmuted.
*
* @param {Object} frameToSkip - Properties of the frame to keep audio
*/
muteAllAudioExcept: function (frameToSkip) {
let framePropsList = windowStore.getState().get('frames')

framePropsList.forEach((frameProps) => {
if (frameProps.get('key') !== frameToSkip.get('key') && frameProps.get('audioPlaybackActive') && !frameProps.get('audioMuted')) {
this.setAudioMuted(frameProps, true)
} else {
this.setAudioMuted(frameProps, false)
}
muteAllAudio: function (frameList) {
dispatch({
actionType: windowConstants.WINDOW_SET_ALL_AUDIO_MUTED,
frameList
})
},

Expand Down
3 changes: 2 additions & 1 deletion js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const windowConstants = {
WINDOW_SHOULD_MAXIMIZE: _,
WINDOW_SHOULD_UNMAXIMIZE: _,
WINDOW_SHOULD_EXIT_FULL_SCREEN: _,
WINDOW_SHOULD_OPEN_DEV_TOOLS: _
WINDOW_SHOULD_OPEN_DEV_TOOLS: _,
WINDOW_SET_ALL_AUDIO_MUTED: _
}

module.exports = mapValuesByKeys(windowConstants)
45 changes: 34 additions & 11 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ const getDownloadsBarHeight = () => {
function tabPageTemplateInit (framePropsList) {
return [{
label: locale.translation('unmuteTabs'),
click: (item) => {
windowActions.muteAllAudio(framePropsList, false)
click: () => {
windowActions.muteAllAudio(generateMuteFrameList(framePropsList, false))
}
}, {
label: locale.translation('muteTabs'),
click: (item) => {
windowActions.muteAllAudio(framePropsList, true)
click: () => {
windowActions.muteAllAudio(generateMuteFrameList(framePropsList, true))
}
}, {
label: locale.translation('closeTabPage'),
Expand All @@ -103,6 +103,16 @@ function tabPageTemplateInit (framePropsList) {
}]
}

function generateMuteFrameList (framePropsList, muted) {
return framePropsList.map((frameProp) => {
return {
frameKey: frameProp.get('key'),
tabId: frameProp.get('tabId'),
muted: muted && frameProp.get('audioPlaybackActive') && !frameProp.get('audioMuted')
}
})
}

function urlBarTemplateInit (searchDetail, activeFrame, e) {
const items = getEditableItems(window.getSelection().toString())
const clipboardText = clipboard.readText()
Expand Down Expand Up @@ -516,8 +526,11 @@ function flashTemplateInit (frameProps) {

function tabTemplateInit (frameProps) {
const frameKey = frameProps.get('key')
const tabId = frameProps.get('tabId')
const template = [CommonMenu.newTabMenuItem(frameProps.get('tabId'))]
const location = frameProps.get('location')
const store = windowStore.getState()

if (location !== 'about:newtab') {
template.push(
CommonMenu.separatorMenuItem,
Expand All @@ -531,7 +544,7 @@ function tabTemplateInit (frameProps) {
}, {
label: locale.translation('clone'),
click: (item) => {
appActions.tabCloned(frameProps.get('tabId'))
appActions.tabCloned(tabId)
}
})
}
Expand All @@ -543,7 +556,7 @@ function tabTemplateInit (frameProps) {
click: (item) => {
const browserOpts = { positionByMouseCursor: true }
const frameOpts = frameOptsFromFrame(frameProps).toJS()
appActions.tabMoved(frameProps.get('tabId'), frameOpts, browserOpts, -1)
appActions.tabMoved(tabId, frameOpts, browserOpts, -1)
}
})
}
Expand All @@ -555,7 +568,7 @@ function tabTemplateInit (frameProps) {
label: locale.translation(isPinned ? 'unpinTab' : 'pinTab'),
click: (item) => {
// Handle converting the current tab window into a pinned site
appActions.tabPinned(frameProps.get('tabId'), !isPinned)
appActions.tabPinned(tabId, !isPinned)
}
})
}
Expand All @@ -569,11 +582,21 @@ function tabTemplateInit (frameProps) {
// }
// })

const frames = windowStore.getState().get('frames')
const frameToSkip = frameProps.get('key')
const frameList = frames.map((frame) => {
return {
frameKey: frame.get('key'),
tabId: frame.get('tabId'),
muted: frame.get('key') !== frameToSkip && frame.get('audioPlaybackActive')
}
})

template.push(CommonMenu.separatorMenuItem,
{
label: locale.translation('muteOtherTabs'),
click: (item) => {
windowActions.muteAllAudioExcept(frameProps)
click: () => {
windowActions.muteAllAudio(frameList)
}
})

Expand All @@ -583,7 +606,7 @@ function tabTemplateInit (frameProps) {
template.push({
label: locale.translation(isMuted ? 'unmuteTab' : 'muteTab'),
click: (item) => {
windowActions.setAudioMuted(frameProps, !isMuted)
windowActions.setAudioMuted(frameKey, tabId, !isMuted)
}
})
}
Expand Down Expand Up @@ -627,7 +650,7 @@ function tabTemplateInit (frameProps) {

template.push(Object.assign({},
CommonMenu.reopenLastClosedTabItem(),
{ enabled: windowStore.getState().get('closedFrames').size > 0 }
{ enabled: store.get('closedFrames').size > 0 }
))

return menuUtil.sanitizeTemplateItems(template)
Expand Down
14 changes: 12 additions & 2 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,18 @@ const doAction = (action) => {
}
break
case windowConstants.WINDOW_SET_AUDIO_MUTED:
windowState = windowState.setIn(['frames', frameStateUtil.getFramePropsIndex(frameStateUtil.getFrames(windowState), action.frameProps), 'audioMuted'], action.muted)
windowState = windowState.setIn(['tabs', frameStateUtil.getFramePropsIndex(frameStateUtil.getFrames(windowState), action.frameProps), 'audioMuted'], action.muted)
{
const index = frameStateUtil.getFrameIndex(windowState, action.frameKey)
windowState = windowState.setIn(['frames', index, 'audioMuted'], action.muted)
windowState = windowState.setIn(['tabs', index, 'audioMuted'], action.muted)
}
break
case windowConstants.WINDOW_SET_ALL_AUDIO_MUTED:
action.frameList.forEach((frameProp) => {
let index = frameStateUtil.getFrameIndex(windowState, frameProp.frameKey)
windowState = windowState.setIn(['frames', index, 'audioMuted'], frameProp.muted)
windowState = windowState.setIn(['tabs', index, 'audioMuted'], frameProp.muted)
})
break
case windowConstants.WINDOW_SET_AUDIO_PLAYBACK_ACTIVE:
windowState = windowState.setIn(['frames', frameStateUtil.getFramePropsIndex(frameStateUtil.getFrames(windowState), action.frameProps), 'audioPlaybackActive'], action.audioPlaybackActive)
Expand Down

0 comments on commit 90d9290

Please sign in to comment.