1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-14 10:26:19 +01:00
bitwarden-browser/src/background/tabs.background.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.5 KiB
TypeScript
Raw Normal View History

import MainBackground from "./main.background";
import NotificationBackground from "./notification.background";
export default class TabsBackground {
constructor(
private main: MainBackground,
private notificationBackground: NotificationBackground
) {}
async init() {
if (!chrome.tabs) {
return;
}
chrome.tabs.onActivated.addListener(async (activeInfo: chrome.tabs.TabActiveInfo) => {
await this.main.refreshBadgeAndMenu();
this.main.messagingService.send("tabActivated");
this.main.messagingService.send("tabChanged");
});
chrome.tabs.onReplaced.addListener(async (addedTabId: number, removedTabId: number) => {
if (this.main.onReplacedRan) {
return;
}
this.main.onReplacedRan = true;
await this.notificationBackground.checkNotificationQueue();
await this.main.refreshBadgeAndMenu();
this.main.messagingService.send("tabReplaced");
this.main.messagingService.send("tabChanged");
});
chrome.tabs.onUpdated.addListener(
async (tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => {
if (this.main.onUpdatedRan) {
return;
}
this.main.onUpdatedRan = true;
await this.notificationBackground.checkNotificationQueue(tab);
await this.main.refreshBadgeAndMenu();
this.main.messagingService.send("tabUpdated");
this.main.messagingService.send("tabChanged");
}
);
}
}