Skip to content

Commit defdfda

Browse files
committed
Apply updated group title and color dynamically
1 parent dc24a42 commit defdfda

4 files changed

Lines changed: 84 additions & 60 deletions

File tree

webextensions/background/api-tabs-listener.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ async function onGroupCreated(group) {
13091309
SidebarConnection.sendMessage({
13101310
type: Constants.kCOMMAND_NOTIFY_TAB_GROUP_CREATED,
13111311
windowId: group.windowId,
1312-
group,
1312+
group: { ...group, $TST: null },
13131313
});
13141314
}
13151315

webextensions/common/Tab.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,12 @@ export default class Tab {
20702070
}
20712071

20722072
apply(exported) { // not optimized and unsafe yet!
2073+
if (this.type == 'group') {
2074+
this.raw.title = exported.title;
2075+
this.raw.color = exported.color;
2076+
return;
2077+
}
2078+
20732079
if (!this.tab)
20742080
return;
20752081

webextensions/sidebar/components/TabElement.js

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -744,75 +744,77 @@ windowId = ${raw.windowId}
744744
return;
745745

746746
const raw = this.$TST.raw;
747-
const tab = this.$TST.tab;
748747
const classList = this.classList;
749748

750749
this.label = raw.title;
751750

752-
const openerOfGroupTab = tab && this.$TST.isGroupTab && Tab.getOpenerFromGroupTab(tab);
753-
this.favIconUrl = openerOfGroupTab && openerOfGroupTab.favIconUrl || tab?.favIconUrl;
754-
755-
for (const state of classList) {
756-
if (IGNORE_CLASSES.has(state) ||
757-
NATIVE_PROPERTIES.has(state))
758-
continue;
759-
if (!this.$TST.states.has(state))
760-
classList.remove(state);
761-
}
762-
for (const state of this.$TST.states) {
763-
if (IGNORE_CLASSES.has(state))
764-
continue;
765-
if (!classList.contains(state))
766-
classList.add(state);
767-
}
751+
const tab = this.$TST.tab;
752+
if (tab) {
753+
const openerOfGroupTab = tab && this.$TST.isGroupTab && Tab.getOpenerFromGroupTab(tab);
754+
this.favIconUrl = openerOfGroupTab && openerOfGroupTab.favIconUrl || tab?.favIconUrl;
755+
756+
for (const state of classList) {
757+
if (IGNORE_CLASSES.has(state) ||
758+
NATIVE_PROPERTIES.has(state))
759+
continue;
760+
if (!this.$TST.states.has(state))
761+
classList.remove(state);
762+
}
763+
for (const state of this.$TST.states) {
764+
if (IGNORE_CLASSES.has(state))
765+
continue;
766+
if (!classList.contains(state))
767+
classList.add(state);
768+
}
768769

769-
for (const state of NATIVE_PROPERTIES) {
770-
if (raw[state] == classList.contains(state))
771-
continue;
772-
classList.toggle(state, raw[state]);
773-
}
770+
for (const state of NATIVE_PROPERTIES) {
771+
if (raw[state] == classList.contains(state))
772+
continue;
773+
classList.toggle(state, raw[state]);
774+
}
774775

775-
if (this.$TST.childIds.length > 0)
776-
this.setAttribute(Constants.kCHILDREN, `|${this.$TST.childIds.join('|')}|`);
777-
else
778-
this.removeAttribute(Constants.kCHILDREN);
776+
if (this.$TST.childIds.length > 0)
777+
this.setAttribute(Constants.kCHILDREN, `|${this.$TST.childIds.join('|')}|`);
778+
else
779+
this.removeAttribute(Constants.kCHILDREN);
779780

780-
if (this.$TST.parentId)
781-
this.setAttribute(Constants.kPARENT, this.$TST.parentId);
782-
else
783-
this.removeAttribute(Constants.kPARENT);
781+
if (this.$TST.parentId)
782+
this.setAttribute(Constants.kPARENT, this.$TST.parentId);
783+
else
784+
this.removeAttribute(Constants.kPARENT);
784785

785-
const alreadyGrouped = this.$TST.getAttribute(Constants.kPERSISTENT_ALREADY_GROUPED_FOR_PINNED_OPENER) || '';
786-
if (this.getAttribute(Constants.kPERSISTENT_ALREADY_GROUPED_FOR_PINNED_OPENER) != alreadyGrouped)
787-
this.setAttribute(Constants.kPERSISTENT_ALREADY_GROUPED_FOR_PINNED_OPENER, alreadyGrouped);
786+
const alreadyGrouped = this.$TST.getAttribute(Constants.kPERSISTENT_ALREADY_GROUPED_FOR_PINNED_OPENER) || '';
787+
if (this.getAttribute(Constants.kPERSISTENT_ALREADY_GROUPED_FOR_PINNED_OPENER) != alreadyGrouped)
788+
this.setAttribute(Constants.kPERSISTENT_ALREADY_GROUPED_FOR_PINNED_OPENER, alreadyGrouped);
788789

789-
const opener = this.$TST.getAttribute(Constants.kPERSISTENT_ORIGINAL_OPENER_TAB_ID) || '';
790-
if (this.getAttribute(Constants.kPERSISTENT_ORIGINAL_OPENER_TAB_ID) != opener)
791-
this.setAttribute(Constants.kPERSISTENT_ORIGINAL_OPENER_TAB_ID, opener);
790+
const opener = this.$TST.getAttribute(Constants.kPERSISTENT_ORIGINAL_OPENER_TAB_ID) || '';
791+
if (this.getAttribute(Constants.kPERSISTENT_ORIGINAL_OPENER_TAB_ID) != opener)
792+
this.setAttribute(Constants.kPERSISTENT_ORIGINAL_OPENER_TAB_ID, opener);
792793

793-
const uri = this.$TST.getAttribute(Constants.kCURRENT_URI) || tab?.url;
794-
if (this.getAttribute(Constants.kCURRENT_URI) != uri)
795-
this.setAttribute(Constants.kCURRENT_URI, uri);
794+
const uri = this.$TST.getAttribute(Constants.kCURRENT_URI) || tab?.url;
795+
if (this.getAttribute(Constants.kCURRENT_URI) != uri)
796+
this.setAttribute(Constants.kCURRENT_URI, uri);
796797

797-
const favIconUri = this.$TST.getAttribute(Constants.kCURRENT_FAVICON_URI) || tab?.favIconUrl;
798-
if (this.getAttribute(Constants.kCURRENT_FAVICON_URI) != favIconUri)
799-
this.setAttribute(Constants.kCURRENT_FAVICON_URI, favIconUri);
798+
const favIconUri = this.$TST.getAttribute(Constants.kCURRENT_FAVICON_URI) || tab?.favIconUrl;
799+
if (this.getAttribute(Constants.kCURRENT_FAVICON_URI) != favIconUri)
800+
this.setAttribute(Constants.kCURRENT_FAVICON_URI, favIconUri);
800801

801-
const level = this.$TST.getAttribute(Constants.kLEVEL) || 0;
802-
if (this.getAttribute(Constants.kLEVEL) != level)
803-
this.setAttribute(Constants.kLEVEL, level);
802+
const level = this.$TST.getAttribute(Constants.kLEVEL) || 0;
803+
if (this.getAttribute(Constants.kLEVEL) != level)
804+
this.setAttribute(Constants.kLEVEL, level);
804805

805-
const id = this.$TST.uniqueId.id;
806-
if (this.getAttribute(Constants.kPERSISTENT_ID) != id)
807-
this.setAttribute(Constants.kPERSISTENT_ID, id);
806+
const id = this.$TST.uniqueId.id;
807+
if (this.getAttribute(Constants.kPERSISTENT_ID) != id)
808+
this.setAttribute(Constants.kPERSISTENT_ID, id);
808809

809-
if (this.$TST.subtreeCollapsed) {
810-
if (!classList.contains(Constants.kTAB_STATE_SUBTREE_COLLAPSED))
811-
classList.add(Constants.kTAB_STATE_SUBTREE_COLLAPSED);
812-
}
813-
else {
814-
if (classList.contains(Constants.kTAB_STATE_SUBTREE_COLLAPSED))
815-
classList.remove(Constants.kTAB_STATE_SUBTREE_COLLAPSED);
810+
if (this.$TST.subtreeCollapsed) {
811+
if (!classList.contains(Constants.kTAB_STATE_SUBTREE_COLLAPSED))
812+
classList.add(Constants.kTAB_STATE_SUBTREE_COLLAPSED);
813+
}
814+
else {
815+
if (classList.contains(Constants.kTAB_STATE_SUBTREE_COLLAPSED))
816+
classList.remove(Constants.kTAB_STATE_SUBTREE_COLLAPSED);
817+
}
816818
}
817819

818820
const group = this.$TST.nativeTabGroup || this.$TST.rawGroup;

webextensions/sidebar/sidebar-tabs.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,23 @@ function reserveToUpdateTabsIndex() {
659659
});
660660
}
661661

662+
function reserveToRefreshNativeTabGroup(id) {
663+
if (reserveToRefreshNativeTabGroup.invoked.has(id))
664+
return;
665+
reserveToRefreshNativeTabGroup.invoked.add(id);
666+
window.requestAnimationFrame(() => {
667+
reserveToRefreshNativeTabGroup.invoked.delete(id);
668+
669+
const windowId = TabsStore.getCurrentWindowId();
670+
const group = TabsStore.windows.get(windowId).tabGroups.get(id);
671+
group.$TST.updateElement(TabUpdateTarget.TabProperties);
672+
for (const tab of Tab.getNativeGroupMemberTabs(windowId, id)) {
673+
tab.$TST.updateElement(TabUpdateTarget.TabProperties);
674+
}
675+
});
676+
}
677+
reserveToRefreshNativeTabGroup.invoked = new Set();
678+
662679

663680
const BUFFER_KEY_PREFIX = 'sidebar-tab-';
664681

@@ -1339,10 +1356,9 @@ BackgroundConnection.onMessage.addListener(async message => {
13391356

13401357
case Constants.kCOMMAND_NOTIFY_TAB_GROUP_UPDATED: {
13411358
const win = TabsStore.windows.get(message.windowId);
1342-
win.tabGroups.get(message.group.id).raw = {
1343-
...win.tabGroups.get(message.group.id),
1344-
...message.group,
1345-
};
1359+
const group = win.tabGroups.get(message.group.id);
1360+
group.$TST.apply(message.group);
1361+
reserveToRefreshNativeTabGroup(message.group.id);
13461362
}; break;
13471363

13481364
case Constants.kCOMMAND_NOTIFY_TAB_GROUP_REMOVED: {

0 commit comments

Comments
 (0)