Skip to content

Commit

Permalink
resume monetization on focus change in serial to reduce server load
Browse files Browse the repository at this point in the history
(looking at you, Vivaldi tab-tiling)

nits
  • Loading branch information
sidvishnoi committed Sep 19, 2024
1 parent 7c57663 commit ac4c96c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/background/services/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Background {
});
const popupWasOpen = popupOpen;
popupOpen = this.sendToPopup.isPopupOpen;
if (popupWasOpen || this.sendToPopup.isPopupOpen) {
if (popupWasOpen || popupOpen) {
// This is intentionally called after windows.getAll, to add a little
// delay for popup port to open
this.logger.debug('Popup is open, ignoring focus change');
Expand All @@ -155,9 +155,9 @@ export class Background {
`[focus change] resume monetization for window=${windowId}, tabIds=${JSON.stringify(tabIds)}`,
);
for (const tabId of tabIds) {
void this.monetizationService.resumePaymentSessionsByTabId(tabId);
await this.monetizationService.resumePaymentSessionsByTabId(tabId);
}
void this.updateVisualIndicatorsForCurrentTab();
await this.updateVisualIndicatorsForCurrentTab();
} else {
this.logger.info(
`[focus change] stop monetization for window=${windowId}, tabIds=${JSON.stringify(tabIds)}`,
Expand Down
11 changes: 5 additions & 6 deletions src/background/services/windowState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ export class WindowState {
}

/**
* Browsers like Edge, Vivaldi allow having multiple tabs in same "view". We
* can use this data to resume/pause monetization for multiple tabs on window
* focus change, not just the one active tab that browser APIs return.
* For given window, get the list of tabs that are currently in view.
*
* For given window, we store the set of tabs that are currently in view. We
* only store per window, as we don't have anything like a view ID, and we
* reset the view when new tab is opened or switched.
* Browsers like Edge, Vivaldi allow having multiple tabs in same "view"
* (split-view, tab-tiling). We can use this data to resume/pause monetization
* for multiple tabs on window focus change, not just the one active tab that
* browser APIs return.
*/
async getTabsForCurrentView(
windowId: WindowId = this.getCurrentWindowId(),
Expand Down

0 comments on commit ac4c96c

Please sign in to comment.