2017-12-07 21:06:37 +01:00
|
|
|
import MainBackground from "./main.background";
|
2021-10-15 15:09:13 +02:00
|
|
|
import NotificationBackground from "./notification.background";
|
2017-12-07 21:06:37 +01:00
|
|
|
|
|
|
|
export default class TabsBackground {
|
2021-10-15 15:09:13 +02:00
|
|
|
constructor(
|
|
|
|
private main: MainBackground,
|
|
|
|
private notificationBackground: NotificationBackground
|
|
|
|
) {}
|
2017-12-07 21:06:37 +01:00
|
|
|
|
2022-04-11 12:00:07 +02:00
|
|
|
private focusedWindowId: number;
|
|
|
|
|
2017-12-07 21:06:37 +01:00
|
|
|
async init() {
|
2022-04-11 12:00:07 +02:00
|
|
|
if (!chrome.tabs || !chrome.windows) {
|
2017-12-07 21:06:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-11 12:00:07 +02:00
|
|
|
chrome.windows.onFocusChanged.addListener(async (windowId: number) => {
|
|
|
|
if (windowId === null || windowId < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.focusedWindowId = windowId;
|
|
|
|
this.main.messagingService.send("windowChanged");
|
|
|
|
});
|
|
|
|
|
2021-10-18 18:02:19 +02:00
|
|
|
chrome.tabs.onActivated.addListener(async (activeInfo: chrome.tabs.TabActiveInfo) => {
|
2022-10-19 15:55:57 +02:00
|
|
|
await this.main.refreshBadge();
|
|
|
|
await this.main.refreshMenu();
|
2020-08-24 16:17:15 +02:00
|
|
|
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;
|
2022-04-11 12:00:07 +02:00
|
|
|
|
2021-10-15 15:09:13 +02:00
|
|
|
await this.notificationBackground.checkNotificationQueue();
|
2022-10-19 15:55:57 +02:00
|
|
|
await this.main.refreshBadge();
|
|
|
|
await this.main.refreshMenu();
|
2020-08-24 16:17:15 +02:00
|
|
|
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) => {
|
2022-04-11 12:00:07 +02:00
|
|
|
if (this.focusedWindowId > 0 && tab.windowId != this.focusedWindowId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tab.active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:06:37 +01:00
|
|
|
if (this.main.onUpdatedRan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.main.onUpdatedRan = true;
|
2022-04-11 12:00:07 +02:00
|
|
|
|
2021-10-19 18:55:47 +02:00
|
|
|
await this.notificationBackground.checkNotificationQueue(tab);
|
2022-10-19 15:55:57 +02:00
|
|
|
await this.main.refreshBadge();
|
|
|
|
await this.main.refreshMenu();
|
2020-08-24 16:17:15 +02:00
|
|
|
this.main.messagingService.send("tabChanged");
|
2017-12-07 21:06:37 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|