1
0
mirror of https://github.com/XFox111/TabsAsideExtension.git synced 2026-04-22 07:58:01 +03:00

!feat: partial tab groups support on firefox

This commit is contained in:
2025-05-08 10:06:47 +03:00
parent 0ff1d63cde
commit d07c99e3a1
3 changed files with 42 additions and 27 deletions
+4 -2
View File
@@ -60,8 +60,7 @@ async function createGroup(group: GroupItem, windowId: number, discard?: boolean
)); ));
// "Pinned" group is technically not a group, so not much else to do here // "Pinned" group is technically not a group, so not much else to do here
// and Firefox doesn't even support tab groups if (group.pinned === true)
if (group.pinned === true || import.meta.env.FIREFOX)
return; return;
const groupId: number = await chrome.tabs.group({ const groupId: number = await chrome.tabs.group({
@@ -69,6 +68,9 @@ async function createGroup(group: GroupItem, windowId: number, discard?: boolean
createProperties: { windowId } createProperties: { windowId }
}); });
// Grouping support came in 138, tabGroups is expected to be in 139
// TODO: Remove this check once the API is available
if (!import.meta.env.FIREFOX)
await chrome.tabGroups.update(groupId, { await chrome.tabGroups.update(groupId, {
title: group.title, title: group.title,
color: group.color color: group.color
+23 -10
View File
@@ -83,22 +83,22 @@ async function createCollectionFromTabs(tabs: Tabs.Tab[]): Promise<[CollectionIt
} }
} }
if (import.meta.env.FIREFOX)
{
for (; tabIndex < tabs.length; tabIndex++)
collection.items.push({ type: "tab", url: tabs[tabIndex].url!, title: tabs[tabIndex].title });
return [collection, tabs];
}
// Special case, if all tabs are in the same group, create a collection with the group title // Special case, if all tabs are in the same group, create a collection with the group title
if (tabs[0].groupId && tabs[0].groupId !== chrome.tabGroups.TAB_GROUP_ID_NONE && if (tabs[0].groupId && tabs[0].groupId !== -1 &&
tabs.every(i => i.groupId === tabs[0].groupId) tabs.every(i => i.groupId === tabs[0].groupId)
) )
{
// TODO: Remove the check when Firefox 139 is out
if (!import.meta.env.FIREFOX)
{ {
const group = await browser.tabGroups!.get(tabs[0].groupId); const group = await browser.tabGroups!.get(tabs[0].groupId);
collection.title = group.title; collection.title = group.title;
collection.color = group.color; collection.color = group.color;
}
else
{
collection.color = "blue";
}
tabs.forEach(i => tabs.forEach(i =>
collection.items.push({ type: "tab", url: i.url!, title: i.title }) collection.items.push({ type: "tab", url: i.url!, title: i.title })
@@ -113,7 +113,7 @@ async function createCollectionFromTabs(tabs: Tabs.Tab[]): Promise<[CollectionIt
{ {
const tab = tabs[tabIndex]; const tab = tabs[tabIndex];
if (!tab.groupId || tab.groupId === chrome.tabGroups.TAB_GROUP_ID_NONE) if (!tab.groupId || tab.groupId === -1)
{ {
collection.items.push({ type: "tab", url: tab.url!, title: tab.title }); collection.items.push({ type: "tab", url: tab.url!, title: tab.title });
activeGroup = null; activeGroup = null;
@@ -123,6 +123,18 @@ async function createCollectionFromTabs(tabs: Tabs.Tab[]): Promise<[CollectionIt
if (!activeGroup || activeGroup !== tab.groupId) if (!activeGroup || activeGroup !== tab.groupId)
{ {
activeGroup = tab.groupId; activeGroup = tab.groupId;
// TODO: Remove the check when Firefox 139 is out
if (import.meta.env.FIREFOX)
{
collection.items.push({
type: "group",
color: "blue",
items: []
});
}
else
{
const group = await browser.tabGroups!.get(activeGroup); const group = await browser.tabGroups!.get(activeGroup);
collection.items.push({ collection.items.push({
@@ -132,6 +144,7 @@ async function createCollectionFromTabs(tabs: Tabs.Tab[]): Promise<[CollectionIt
items: [] items: []
}); });
} }
}
(collection.items[collection.items.length - 1] as GroupItem).items.push({ (collection.items[collection.items.length - 1] as GroupItem).items.push({
type: "tab", type: "tab",
+1 -1
View File
@@ -78,7 +78,7 @@ export default defineConfig({
gecko: gecko:
{ {
id: "tabsaside@xfox111.net", id: "tabsaside@xfox111.net",
strict_min_version: "109.0" strict_min_version: "138.0"
} }
}; };