2017-12-07 21:06:37 +01:00
|
|
|
import MainBackground from './main.background';
|
|
|
|
|
2018-01-13 20:56:38 +01:00
|
|
|
import { PlatformUtilsService } from 'jslib/abstractions';
|
|
|
|
|
2017-12-07 21:06:37 +01:00
|
|
|
export default class TabsBackground {
|
|
|
|
private tabs: any;
|
2018-01-13 20:56:38 +01:00
|
|
|
private isSafari: boolean;
|
2017-12-07 21:06:37 +01:00
|
|
|
|
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;
|
2017-12-07 21:06:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:06:37 +01:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|