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

Commit

Permalink
make api calls with setImmediate if possible
Browse files Browse the repository at this point in the history
auditors @bbondy @bsclifton
[DEV CHANNEL]
  • Loading branch information
bridiver authored and bsclifton committed May 3, 2017
1 parent d78e72a commit a79882e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 49 deletions.
4 changes: 2 additions & 2 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const tabsReducer = (state, action, immutableAction) => {
break
}
case appConstants.APP_CREATE_TAB_REQUESTED:
state = tabs.createTab(state, action)
tabs.createTab(action)
break
case appConstants.APP_MAYBE_CREATE_TAB_REQUESTED:
state = tabs.maybeCreateTab(state, action)
Expand Down Expand Up @@ -63,7 +63,7 @@ const tabsReducer = (state, action, immutableAction) => {
state = tabs.setAudioMuted(state, action)
break
case windowConstants.WINDOW_SET_ACTIVE_FRAME:
state = tabs.setActive(state, action)
tabs.setActive(action.getIn(['frameProps', 'tabId']))
break
case appConstants.APP_TAB_TOGGLE_DEV_TOOLS:
state = tabs.toggleDevTools(state, action)
Expand Down
62 changes: 28 additions & 34 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,13 @@ const api = {
return state
},

setActive: (state, action) => {
action = makeImmutable(action)
let frameProps = action.get('frameProps')
let tabId = frameProps.get('tabId')
let tab = getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
tab.setActive(true)
let tabValue = getTabValue(tabId)
return tabState.updateTab(state, { tabValue })
}
return state
setActive: (tabId) => {
setImmediate(() => {
let tab = getWebContents(tabId)
if (tab && !tab.isDestroyed()) {
tab.setActive(true)
}
})
},

loadURL: (state, action) => {
Expand Down Expand Up @@ -365,23 +361,25 @@ const api = {
},

create: (createProperties, cb = null) => {
createProperties = makeImmutable(createProperties).toJS()
const switchToNewTabsImmediately = getSetting(settings.SWITCH_TO_NEW_TABS) === true
if (switchToNewTabsImmediately) {
createProperties.active = true
}
if (!createProperties.url) {
createProperties.url = newFrameUrl()
}
createProperties.url = normalizeUrl(createProperties.url)
if (needsPartitionAssigned(createProperties)) {
createProperties.partition = getPartition(createProperties)
if (isSessionPartition(createProperties.partition)) {
createProperties.parent_partition = ''
setImmediate(() => {
createProperties = makeImmutable(createProperties).toJS()
const switchToNewTabsImmediately = getSetting(settings.SWITCH_TO_NEW_TABS) === true
if (switchToNewTabsImmediately) {
createProperties.active = true
}
}
extensions.createTab(createProperties, (tab) => {
cb && cb(tab)
if (!createProperties.url) {
createProperties.url = newFrameUrl()
}
createProperties.url = normalizeUrl(createProperties.url)
if (needsPartitionAssigned(createProperties)) {
createProperties.partition = getPartition(createProperties)
if (isSessionPartition(createProperties.partition)) {
createProperties.parent_partition = ''
}
}
extensions.createTab(createProperties, (tab) => {
cb && cb(tab)
})
})
},

Expand All @@ -401,10 +399,9 @@ const api = {
win.loadURL('about:blank')
},

createTab: (state, action) => {
createTab: (action) => {
action = makeImmutable(action)
api.create(action.get('createProperties'))
return state
},

moveTo: (state, tabId, frameOpts, browserOpts, windowId) => {
Expand Down Expand Up @@ -459,12 +456,9 @@ const api = {
}
const tabData = tabState.getMatchingTab(state, createProperties, windowId, url)
if (tabData) {
const tab = getWebContents(tabData.get('id'))
if (tab && !tab.isDestroyed()) {
tab.setActive(true)
}
api.setActive(tabData.get('id'))
} else {
api.createTab(state, action)
api.createTab(action)
}
return state
}
Expand Down
86 changes: 73 additions & 13 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,30 +245,90 @@ const api = {
},

pinnedTabsChanged: () => {
for (let windowId in currentWindows) {
if (currentWindows[windowId].__ready) {
updatePinnedTabs(currentWindows[windowId])
setImmediate(() => {
for (let windowId in currentWindows) {
if (currentWindows[windowId].__ready) {
updatePinnedTabs(currentWindows[windowId])
}
}
}
})
},

minimize: (windowId) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.minimize()
}
})
},

maximize: (windowId) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.maximize()
}
})
},

unmaximize: (windowId) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.unmaximize()
}
})
},

setTitle: (windowId, title) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.setTitle(title)
}
})
},

setFullScreen: (windowId, fullScreen) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.setFullScreen(fullScreen)
}
})
},

openDevTools: (windowId, fullScreen) => {
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.webContents.openDevTools()
}
})
},

windowReady: (windowId) => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.__alreadyPinnedSites = new Immutable.Set()
updatePinnedTabs(win)
win.__ready = true
}
setImmediate(() => {
const win = currentWindows[windowId]
if (win && !win.isDestroyed()) {
win.__alreadyPinnedSites = new Immutable.Set()
updatePinnedTabs(win)
win.__ready = true
}
})
},

closeWindow: (state, action) => {
action = makeImmutable(action)
let windowId = action.get('windowId')
let win = api.getWindow(windowId)
try {
if (!win.isDestroyed()) {
win.close()
}
setImmediate(() => {
if (!win.isDestroyed()) {
win.close()
}
})
} catch (e) {
// ignore
}
Expand Down

0 comments on commit a79882e

Please sign in to comment.