2017-12-07 21:06:37 +01:00
|
|
|
import MainBackground from './main.background';
|
|
|
|
|
|
|
|
export default class TabsBackground {
|
2019-08-21 15:42:34 +02:00
|
|
|
constructor(private main: MainBackground) {
|
2017-12-07 21:06:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async init() {
|
2021-10-18 18:02:19 +02:00
|
|
|
if (!chrome.tabs) {
|
2017-12-07 21:06:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-18 18:02:19 +02:00
|
|
|
chrome.tabs.onActivated.addListener(async (activeInfo: chrome.tabs.TabActiveInfo) => {
|
2017-12-07 21:06:37 +01:00
|
|
|
await this.main.refreshBadgeAndMenu();
|
2020-08-24 16:17:15 +02:00
|
|
|
this.main.messagingService.send('tabActivated');
|
|
|
|
this.main.messagingService.send('tabChanged');
|
2017-12-07 21:06:37 +01:00
|
|
|
});
|
|
|
|
|
2021-10-18 18:02:19 +02:00
|
|
|
chrome.tabs.onReplaced.addListener(async (addedTabId: number, removedTabId: number) => {
|
2017-12-07 21:06:37 +01:00
|
|
|
if (this.main.onReplacedRan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.main.onReplacedRan = true;
|
2018-08-01 05:24:11 +02:00
|
|
|
await this.main.checkNotificationQueue();
|
2017-12-07 21:06:37 +01:00
|
|
|
await this.main.refreshBadgeAndMenu();
|
2020-08-24 16:17:15 +02:00
|
|
|
this.main.messagingService.send('tabReplaced');
|
|
|
|
this.main.messagingService.send('tabChanged');
|
2017-12-07 21:06:37 +01:00
|
|
|
});
|
|
|
|
|
2021-10-18 18:02:19 +02:00
|
|
|
chrome.tabs.onUpdated.addListener(async (tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => {
|
2017-12-07 21:06:37 +01:00
|
|
|
if (this.main.onUpdatedRan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.main.onUpdatedRan = true;
|
2021-10-18 18:03:46 +02:00
|
|
|
await this.main.checkNotificationQueue(tab);
|
2017-12-07 21:06:37 +01:00
|
|
|
await this.main.refreshBadgeAndMenu();
|
2020-08-24 16:17:15 +02:00
|
|
|
this.main.messagingService.send('tabUpdated');
|
|
|
|
this.main.messagingService.send('tabChanged');
|
2017-12-07 21:06:37 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|