1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// Event-page entry point. Wires browser events to the grouping engine.
import {
evaluateTab,
handleGroupChange,
handleGroupRemoved,
handleTabRemoved,
reorganizeAll,
} from "./src/grouper.js";
// React to navigations (incl. SPA url changes) and pin state, and detect manual
// group moves. No event filter: `properties` filtering for groupId isn't
// portable across versions, so we branch cheaply on changeInfo instead.
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if ("groupId" in changeInfo) {
handleGroupChange(tabId);
}
if ("url" in changeInfo || "pinned" in changeInfo) {
evaluateTab(tab);
}
});
// Firefox auto-removes empty groups; keep our instance map in sync.
if (browser.tabGroups?.onRemoved) {
browser.tabGroups.onRemoved.addListener((group) => handleGroupRemoved(group));
}
browser.tabs.onRemoved.addListener((tabId) => handleTabRemoved(tabId));
// Toolbar button: open the options page. Without a `default_popup`, the click
// fires onClicked instead of opening a popup.
browser.action.onClicked.addListener(() => browser.runtime.openOptionsPage());
// Options-page commands.
browser.runtime.onMessage.addListener((message) => {
if (message?.type === "reorganize") {
return reorganizeAll().then(() => ({ ok: true }));
}
return undefined;
});
|