diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 05bb21ba3d9..d906d2d42fb 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -608,7 +608,9 @@ export default class MainBackground { return new Promise((resolve) => { setTimeout(async () => { await this.environmentService.setUrlsFromStorage(); - await this.refreshBadge(); + if (!this.isPrivateMode) { + await this.refreshBadge(); + } this.fullSync(true); setTimeout(() => this.notificationsService.init(), 2500); resolve(); diff --git a/apps/browser/src/listeners/update-badge.ts b/apps/browser/src/listeners/update-badge.ts index 8762a15ab2a..c7a3d32e59a 100644 --- a/apps/browser/src/listeners/update-badge.ts +++ b/apps/browser/src/listeners/update-badge.ts @@ -44,15 +44,19 @@ export class UpdateBadge { ]; static async tabsOnActivatedListener(activeInfo: chrome.tabs.TabActiveInfo) { - await new UpdateBadge(self).run({ tabId: activeInfo.tabId }); + await new UpdateBadge(self).run({ tabId: activeInfo.tabId, windowId: activeInfo.windowId }); } static async tabsOnReplacedListener(addedTabId: number, removedTabId: number) { await new UpdateBadge(self).run({ tabId: addedTabId }); } - static async tabsOnUpdatedListener(tabId: number) { - await new UpdateBadge(self).run({ tabId }); + static async tabsOnUpdatedListener( + tabId: number, + changeInfo: chrome.tabs.TabChangeInfo, + tab: chrome.tabs.Tab + ) { + await new UpdateBadge(self).run({ tabId, windowId: tab.windowId }); } static async messageListener( @@ -81,41 +85,50 @@ export class UpdateBadge { const authStatus = await this.authService.getAuthStatus(); - const tab = await this.getTab(opts?.tabId, opts?.windowId); - const windowId = tab?.windowId; - await this.setBadgeBackgroundColor(); switch (authStatus) { case AuthenticationStatus.LoggedOut: { - await this.setLoggedOut({ tab, windowId }); + await this.setLoggedOut(); break; } case AuthenticationStatus.Locked: { - await this.setLocked({ tab, windowId }); + await this.setLocked(); break; } case AuthenticationStatus.Unlocked: { - await this.setUnlocked({ tab, windowId }); + const tab = await this.getTab(opts?.tabId, opts?.windowId); + await this.setUnlocked({ tab, windowId: tab?.windowId }); break; } } } - async setLoggedOut(opts: BadgeOptions): Promise { - await this.setBadgeIcon("_gray", opts?.windowId); - await this.setBadgeText("", opts?.tab?.id); + async setLoggedOut(): Promise { + await this.setBadgeIcon("_gray"); + await this.clearBadgeText(); } - async setLocked(opts: BadgeOptions) { - await this.setBadgeIcon("_locked", opts?.windowId); - await this.setBadgeText("", opts?.tab?.id); + async setLocked() { + await this.setBadgeIcon("_locked"); + await this.clearBadgeText(); + } + + private async clearBadgeText() { + const tabs = await BrowserApi.getActiveTabs(); + if (tabs != null) { + tabs.forEach(async (tab) => { + if (tab.id != null) { + await this.setBadgeText("", tab.id); + } + }); + } } async setUnlocked(opts: BadgeOptions) { await this.initServices(); - await this.setBadgeIcon("", opts?.windowId); + await this.setBadgeIcon(""); const disableBadgeCounter = await this.stateService.getDisableBadgeCounter(); if (disableBadgeCounter) { @@ -151,7 +164,7 @@ export class UpdateBadge { 38: "/images/icon38" + iconSuffix + ".png", }, }; - if (BrowserPlatformUtilsService.isFirefox()) { + if (windowId && BrowserPlatformUtilsService.isFirefox()) { options.windowId = windowId; } @@ -202,7 +215,9 @@ export class UpdateBadge { private async getTab(tabId?: number, windowId?: number) { return ( (await BrowserApi.getTab(tabId)) ?? - (await BrowserApi.tabsQueryFirst({ active: true, windowId })) ?? + (windowId + ? await BrowserApi.tabsQueryFirst({ active: true, windowId }) + : await BrowserApi.tabsQueryFirst({ active: true, currentWindow: true })) ?? (await BrowserApi.tabsQueryFirst({ active: true, lastFocusedWindow: true })) ?? (await BrowserApi.tabsQueryFirst({ active: true })) );