bitwarden-estensione-browser/src/background/tabs.background.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

import MainBackground from './main.background';
2018-01-13 20:56:38 +01:00
import { PlatformUtilsService } from 'jslib/abstractions';
export default class TabsBackground {
private tabs: any;
2018-01-13 20:56:38 +01:00
private isSafari: boolean;
2018-01-13 20:56:38 +01:00
constructor(private main: MainBackground, private platformUtilsService: PlatformUtilsService) {
this.isSafari = this.platformUtilsService.isSafari();
this.tabs = this.isSafari ? safari.application : chrome.tabs;
}
async init() {
if (!this.tabs) {
return;
}
2018-01-13 20:56:38 +01:00
if (this.isSafari) {
this.tabs.addEventListener('activate', async (ev: any) => {
await this.main.refreshBadgeAndMenu();
}, true);
2018-01-13 21:09:05 +01:00
2018-01-13 20:56:38 +01:00
this.tabs.addEventListener('navigate', async (ev: any) => {
await this.main.checkLoginsToAdd();
await this.main.refreshBadgeAndMenu();
}, true);
return;
}
this.tabs.onActivated.addListener(async (activeInfo: any) => {
await this.main.refreshBadgeAndMenu();
});
this.tabs.onReplaced.addListener(async (addedTabId: any, removedTabId: any) => {
if (this.main.onReplacedRan) {
return;
}
this.main.onReplacedRan = true;
await this.main.checkLoginsToAdd();
await this.main.refreshBadgeAndMenu();
});
this.tabs.onUpdated.addListener(async (tabId: any, changeInfo: any, tab: any) => {
if (this.main.onUpdatedRan) {
return;
}
this.main.onUpdatedRan = true;
await this.main.checkLoginsToAdd();
await this.main.refreshBadgeAndMenu();
});
}
}