Skip to content

Commit

Permalink
Merge branch 'main' into faster-polyfill-injection
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Sep 17, 2024
2 parents c1724eb + d8a4e01 commit dde155a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/background/services/tabEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ export class TabEvents {
await this.setIconAndTooltip(path, title, tabId);
};

// TODO: memoize this call
private setIconAndTooltip = async (
path: (typeof ICONS)[keyof typeof ICONS],
title: string,
tabId?: TabId,
tabId: TabId,
) => {
await this.browser.action.setIcon({ path, tabId });
if (this.tabState.getIcon(tabId) !== path) {
this.tabState.setIcon(tabId, path);
await this.browser.action.setIcon({ path, tabId });
}
await this.browser.action.setTitle({ title, tabId });
};

Expand Down
11 changes: 11 additions & 0 deletions src/background/services/tabState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class TabState {

private state = new Map<TabId, Map<string, State>>();
private sessions = new Map<TabId, Map<SessionId, PaymentSession>>();
private currentIcon = new Map<TabId, Record<number, string>>();

constructor({ logger }: Cradle) {
Object.assign(this, {
Expand Down Expand Up @@ -118,6 +119,14 @@ export class TabState {
return [...this.sessions.values()].flatMap((s) => [...s.values()]);
}

getIcon(tabId: TabId) {
return this.currentIcon.get(tabId);
}

setIcon(tabId: TabId, icon: Record<number, string>) {
this.currentIcon.set(tabId, icon);
}

getAllTabs(): TabId[] {
return [...this.sessions.keys()];
}
Expand All @@ -128,6 +137,8 @@ export class TabState {
}

clearSessionsByTabId(tabId: TabId) {
this.currentIcon.delete(tabId);

const sessions = this.getSessions(tabId);
if (!sessions.size) return;

Expand Down

0 comments on commit dde155a

Please sign in to comment.