Skip to content

Commit

Permalink
Fixes panel update refresh rate
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jan 29, 2019
1 parent 600a294 commit 05d6293
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export const onTabId = (tabId: number | undefined) => action(types.ON_TAB_ID, {
tabId
})

export const onTabRetrieved = (tab: chrome.tabs.Tab, publisherBlob: string | undefined) => action(types.ON_TAB_RETRIEVED, {
export const onTabRetrieved = (tab: chrome.tabs.Tab, publisherBlob: string, onlyDiff: boolean) => action(types.ON_TAB_RETRIEVED, {
tab,
publisherBlob
publisherBlob,
onlyDiff
})

export const onPublisherData = (windowId: number, publisher: RewardsExtension.Publisher) => action(types.ON_PUBLISHER_DATA, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
export const getTabData = (tabId: number) =>
chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => {
const rewardsPanelActions = require('../actions/rewardsPanelActions').default
rewardsPanelActions.onTabRetrieved(tab)
rewardsPanelActions.onTabRetrieved(tab, '', false)
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

import rewardsPanelActions from '../actions/rewardsPanelActions'

chrome.tabs.onCreated.addListener((tab: chrome.tabs.Tab) => {
rewardsPanelActions.onTabRetrieved(tab, '')
})

chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => {
rewardsPanelActions.onTabRetrieved(tab, '')
rewardsPanelActions.onTabRetrieved(tab, '', true)
})

chrome.tabs.onActivated.addListener((activeInfo: chrome.tabs.TabActiveInfo) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export const rewardsPanelReducer = (state: RewardsExtension.State | undefined, a
const id = getWindowId(tab.windowId)
const publishers: Record<string, RewardsExtension.Publisher> = state.publishers
const publisher = publishers[id]
chrome.braveRewards.getPublisherData(tab.windowId, tab.url, tab.favIconUrl || '', payload.publisherBlob || '')

if ((payload.onlyDiff && publisher && publisher.tabUrl !== tab.url) || !payload.onlyDiff) {
chrome.braveRewards.getPublisherData(tab.windowId, tab.url, tab.favIconUrl || '', payload.publisherBlob || '')
}

if (!publisher || (publisher && publisher.tabUrl !== tab.url)) {
if (publisher) {
delete publishers[id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class RewardsPanel extends React.Component<Props, State> {
publisherBlob = result[0]
clearInterval(interval)
const rewardsPanelActions = require('../background/actions/rewardsPanelActions').default
rewardsPanelActions.onTabRetrieved(tab, publisherBlob)
rewardsPanelActions.onTabRetrieved(tab, publisherBlob, false)
} else {
chrome.storage.local.get(['rewards_panel_open'], function (result) {
if (result['rewards_panel_open'] === 'false') {
Expand All @@ -87,7 +87,7 @@ export class RewardsPanel extends React.Component<Props, State> {
clearInterval(interval)

const rewardsPanelActions = require('../background/actions/rewardsPanelActions').default
rewardsPanelActions.onTabRetrieved(tab, publisherBlob)
rewardsPanelActions.onTabRetrieved(tab, publisherBlob, false)
}
}
})
Expand All @@ -104,7 +104,7 @@ export class RewardsPanel extends React.Component<Props, State> {
}
})
} else {
this.props.actions.onTabRetrieved(tab, publisherBlob)
this.props.actions.onTabRetrieved(tab, publisherBlob, false)
}
}
let tab = tabs[0]
Expand All @@ -113,10 +113,10 @@ export class RewardsPanel extends React.Component<Props, State> {
if (url && url.host.endsWith('.twitch.tv')) {
pollData(tab, tab.id, url)
} else {
this.props.actions.onTabRetrieved(tab)
this.props.actions.onTabRetrieved(tab, '', false)
}
} else {
this.props.actions.onTabRetrieved(tabs[0])
this.props.actions.onTabRetrieved(tab, '', false)
}
})
}
Expand Down

0 comments on commit 05d6293

Please sign in to comment.