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 #14230 from bsclifton/fix-partner-page-focus
Browse files Browse the repository at this point in the history
Only call createTabRequested if window is ready
  • Loading branch information
NejcZdovc committed May 24, 2018
1 parent 03e86dd commit 7b0a0e2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,12 +2161,15 @@ const onReferralRead = (state, body, activeWindowId) => {
if (body.has('offer_page_url')) {
const url = body.get('offer_page_url')
if (urlutil.isURL(url)) {
if (activeWindowId === windowState.WINDOW_ID_NONE) {
if (activeWindowId === windowState.WINDOW_ID_NONE || !state.get('windowReady')) {
// write referralPage to state if initial window is not created/visible yet
state = updateState.setUpdateProp(state, 'referralPage', url)
} else {
// initial window exists and should be ready; create tab directly
appActions.createTabRequested({
url,
windowId: activeWindowId
windowId: activeWindowId,
active: true
})
state = updateState.setUpdateProp(state, 'referralPage', null)
}
Expand Down
1 change: 1 addition & 0 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ const tabsReducer = (state, action, immutableAction) => {
state = updateState.setUpdateProp(state, 'referralPage', null)
}
}
state = state.set('windowReady', true)
break
}
case appConstants.APP_ENABLE_PEPPER_MENU: {
Expand Down
8 changes: 7 additions & 1 deletion app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ module.exports.cleanAppData = (immutableData, isShutdown) => {
console.error('cleanAppData: error cleaning up data: urls', e)
}

// delete the window ready state (gets set again on program start)
if (immutableData.has('windowReady')) {
immutableData = immutableData.delete('windowReady')
}

return immutableData
}

Expand Down Expand Up @@ -1162,7 +1167,8 @@ module.exports.defaultAppState = () => {
publishers: {}
},
promotion: {}
}
},
windowReady: false
}
}

Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ AppStore
autocompleteURL: string, // ditto re: {searchTerms}
searchURL: string // with replacement var in string: {searchTerms}
},
windowReady: boolean // set to false on start; set to true when first window is ready
}
```
Expand Down
6 changes: 4 additions & 2 deletions test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3231,15 +3231,17 @@ describe('ledger api unit tests', function () {
})

it('window is ready', function () {
ledgerApi.onReferralRead(defaultAppState, Immutable.fromJS({
const windowReadyState = defaultAppState.set('windowReady', true)
ledgerApi.onReferralRead(windowReadyState, Immutable.fromJS({
download_id: 1,
referral_code: 'code',
offer_page_url: url
}), 1)
assert(setUpdatePropSpy.withArgs(sinon.match.any, 'referralPage', null).calledOnce)
assert(createTabRequestedSpy.withArgs({
url,
windowId: 1
windowId: 1,
active: true
}).calledOnce)
})
})
Expand Down

0 comments on commit 7b0a0e2

Please sign in to comment.