[PS-2072] Browser Badge fixes (#4363)
* Force update of badge icon and text on all windows Affects MV2 and MV3 No longer pass in tab and windowId to setLoggedOut and setLocked When the vault is locked or the user logs out, all open windows/tabs need to be updated Iterating over all active tabs like in 2022.10.1 was missing:488734577f/apps/browser/src/background/main.background.ts (L859-L867)
Create clearBadgeText function to take care of it. * Only try to retrieve tab in unlocked state * Remove lock icon when unlocking on all windows * Only use windowId to retrieve tab when defined In MV2 the `windowId` isn't passed into updateBage and fails to retrieve the correct tab to update. This resorted in the badge not showing a match count in another window. Fixes #4260 Ensure in MV3 that all listener pass on the windowId if present. * Fix Firefox private mode Only pass on the windowId if defined and within Firefox In private mode the main.background bootstrap-method passes in the windowId Do not refreshBadge when in private mode Previously488734577f/apps/browser/src/background/main.background.ts (L575-L586)
setIcon would skip in private mode. Calling refreshBadge without this would update the badge on all windows (normal and private ones)
This commit is contained in:
parent
d41b3b13ea
commit
ec19fc7225
|
@ -608,7 +608,9 @@ export default class MainBackground {
|
|||
return new Promise<void>((resolve) => {
|
||||
setTimeout(async () => {
|
||||
await this.environmentService.setUrlsFromStorage();
|
||||
if (!this.isPrivateMode) {
|
||||
await this.refreshBadge();
|
||||
}
|
||||
this.fullSync(true);
|
||||
setTimeout(() => this.notificationsService.init(), 2500);
|
||||
resolve();
|
||||
|
|
|
@ -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<void> {
|
||||
await this.setBadgeIcon("_gray", opts?.windowId);
|
||||
await this.setBadgeText("", opts?.tab?.id);
|
||||
async setLoggedOut(): Promise<void> {
|
||||
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 }))
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue