Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(background): update icon change logic; using TabState for sessions #420

Merged
merged 11 commits into from
Jul 29, 2024

Conversation

sidvishnoi
Copy link
Member

@sidvishnoi sidvishnoi commented Jul 12, 2024

Context

Closes #381

This PR got a bit bigger, with related/unrelated changes. Can split if wanted.

  • Moves sessions to TabState service, adding some utils
  • Use tab state to sync icons and tooltip text; some refactoring around that
    • Also remove reliance on SET_IS_SITE_MONETIZED message event (moved into SendToPopup)
  • SendToPopup: save last message that wasn't sent to popup as it was closed; send it as soon as popup opens.

@github-actions github-actions bot added the area: background Improvements or additions to extension background script label Jul 12, 2024
@raducristianpopa
Copy link
Member

raducristianpopa commented Jul 12, 2024

Extension builds preview

Name Link
Latest commit d2079d8
Latest job logs Run #10140461115
BadgeDownload
BadgeDownload


getSessions(tab: Tabs.Tab) {
if (!this.sessions.has(tab)) {
this.sessions.set(tab, new Map())
Copy link
Member Author

@sidvishnoi sidvishnoi Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're setting in a "get" as it helps to keep code clean. Initializing empty Map shouldn't be expensive (in terms of memory or CPU).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly about what I was thinking right now. It looks like whenever we will change the focus from one tab to another we will perform the set (one for resume and one for pause). The reason I believe we should avoid this, is that people (me included), have a lot of tabs open and we will rely on the service worker to be suspended to actually free up the memory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the key is Tab, memory freeing isn't an issue though.
Empty Map doesn't take much memory.

@sidvishnoi
Copy link
Member Author

There's some issue in this approach. It keeps showing "this site is not monetized". Will investigate.

@sidvishnoi sidvishnoi marked this pull request as draft July 12, 2024 14:43
@sidvishnoi
Copy link
Member Author

sidvishnoi commented Jul 12, 2024

There's some issue in this approach. It keeps showing "this site is not monetized". Will investigate.

@raducristianpopa 🤦🏽

const t1 = await this.getTabById(tabId)
const t2 = await this.getTabById(tabId)
console.log(t1 === t2) // false

Meaning overpaying isn't really fixed as of now.

@sidvishnoi
Copy link
Member Author

Blocked by #286

Copy link
Member

@raducristianpopa raducristianpopa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we remove the IS_TAB_MONETIZED message from content script to background at this point?

src/background/services/tabEvents.ts Outdated Show resolved Hide resolved
@sidvishnoi sidvishnoi changed the title refactor(background): move sessions to TabState fix(background): update icon update logic; using TabState for sessions Jul 29, 2024
@sidvishnoi sidvishnoi changed the title fix(background): update icon update logic; using TabState for sessions fix(background): update icon change logic; using TabState for sessions Jul 29, 2024
@sidvishnoi sidvishnoi merged commit c906a55 into main Jul 29, 2024
8 checks passed
@sidvishnoi sidvishnoi deleted the sessions-to-TabState branch July 29, 2024 08:07
@sidvishnoi
Copy link
Member Author

Can't we remove the IS_TAB_MONETIZED message from content script to background at this point?

Not yet, as we need to handle on-page link changes too. Will do as follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: background Improvements or additions to extension background script area: popup Improvements or additions to extension popup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move all tab information into tabState service
2 participants