feat: Fixed folders on new windows not expanding at startup, b=no-bug, c=common, folders, tabs, workspaces

This commit is contained in:
mr. m
2025-12-24 17:34:29 +01:00
parent b3ea7f0e8d
commit 4c2cb60412
9 changed files with 124 additions and 110 deletions

View File

@@ -21,8 +21,8 @@ class ZenSessionStore extends nsZenPreloadedFeature {
if (tabData.zenSyncId || tabData.zenPinnedId) {
tab.setAttribute('id', tabData.zenSyncId || tabData.zenPinnedId);
}
if (tabData.zenHasStaticLabel) {
tab.setAttribute('zen-has-static-label', 'true');
if (tabData.zenStaticLabel) {
tab.zenStaticLabel = tabData.zenStaticLabel;
}
if (tabData.zenHasStaticIcon) {
tab.setAttribute('zen-has-static-icon', 'true');

View File

@@ -1306,12 +1306,12 @@ window.gZenVerticalTabsManager = {
// Check if name is blank, reset if so
// Always remove, so we can always rename and if it's empty,
// it will reset to the original name anyway
this._tabEdited.removeAttribute('zen-has-static-label');
if (hasChanged) {
this._tabEdited.zenStaticLabel = newName;
gBrowser._setTabLabel(this._tabEdited, newName);
this._tabEdited.setAttribute('zen-has-static-label', 'true');
gZenUIManager.showToast('zen-tabs-renamed');
} else {
delete this._tabEdited.zenStaticLabel;
gBrowser.setTabTitle(this._tabEdited);
}

View File

@@ -544,9 +544,7 @@ class nsZenFolders extends nsZenDOMOperatedFeature {
// that we want it to initially be collapsed.
setTimeout(
(folder) => {
gZenPinnedTabManager.promiseInitializedPinned.then(() => {
folder.collapsed = !!options.collapsed;
});
folder.collapsed = !!options.collapsed;
},
0,
folder

View File

@@ -109,6 +109,9 @@ class nsZenWindowSync {
for (let topic of OBSERVING) {
Services.obs.addObserver(this, topic);
}
lazy.SessionStore.promiseAllWindowsRestored.then(() => {
this.#onSessionStoreInitialized();
});
}
uninit() {
@@ -162,6 +165,27 @@ class nsZenWindowSync {
}
}
/**
* Called when the session store has finished initializing for a window.
*
* @param {Window} aWindow - The browser window that has initialized session store.
*/
#onSessionStoreInitialized() {
// For every tab we have in where there's no sync ID, we need to
// assign one and sync it to other windows.
// This should only happen really when updating from an older version
// that didn't have this feature.
this.#runOnAllWindows(null, (aWindow) => {
const { gBrowser } = aWindow;
for (let tab of gBrowser.tabs) {
if (!tab.id) {
tab.id = this.#newTabSyncId;
lazy.TabStateFlusher.flush(tab.linkedBrowser);
}
}
});
}
/**
* @returns {string} A unique tab ID.
*/
@@ -279,6 +303,9 @@ class nsZenWindowSync {
* @returns {MozTabbrowserTab|MozTabbrowserTabGroup|null} The item element if found, otherwise null.
*/
#getItemFromWindow(aWindow, aItemId) {
if (!aItemId) {
return null;
}
return aWindow.document.getElementById(aItemId);
}
@@ -325,9 +352,9 @@ class nsZenWindowSync {
if (flags & SYNC_FLAG_LABEL) {
if (gBrowser.isTab(aOriginalItem)) {
aTargetItem._zenChangeLabelFlag = true;
aTargetItem.zenStaticLabel = aOriginalItem.zenStaticLabel;
gBrowser._setTabLabel(aTargetItem, aOriginalItem.label);
delete aTargetItem._zenChangeLabelFlag;
this.#maybeSyncAttributeChange(aOriginalItem, aTargetItem, 'zen-has-static-label');
} else if (gBrowser.isTabGroup(aOriginalItem)) {
aTargetItem.label = aOriginalItem.label;
}
@@ -493,7 +520,7 @@ class nsZenWindowSync {
}
// Restore the listeners for the swapped in tab.
if (!onClose) {
if (!onClose && filter) {
tabListener = new otherTabBrowser.zenTabProgressListener(aTab, otherBrowser, true, false);
otherTabBrowser._tabListeners.set(aTab, tabListener);
@@ -753,18 +780,21 @@ class nsZenWindowSync {
* Sets the initial pinned state for a tab across all windows.
*
* @param {Object} aTab - The tab to set the pinned state for.
* @returns {Promise} A promise that resolves when the operation is complete.
*/
setPinnedTabState(aTab) {
const state = this.#getTabState(aTab);
const initialState = {
entry: state.entries[state.index - 1],
image: state.image,
};
this.#runOnAllWindows(null, (win) => {
const targetTab = this.#getItemFromWindow(win, aTab.id);
if (targetTab) {
targetTab._zenPinnedInitialState = initialState;
}
return lazy.TabStateFlusher.flush(aTab.linkedBrowser).finally(() => {
const state = this.#getTabState(aTab);
const initialState = {
entry: state.entries[state.index - 1],
image: state.image,
};
this.#runOnAllWindows(null, (win) => {
const targetTab = this.#getItemFromWindow(win, aTab.id);
if (targetTab) {
targetTab._zenPinnedInitialState = initialState;
}
});
});
}

View File

@@ -61,10 +61,6 @@ class ZenPinnedTabsObserver {
}
class nsZenPinnedTabManager extends nsZenDOMOperatedFeature {
promiseInitializedPinned = new Promise((resolve) => {
this._resolvePinnedInitializedInternal = resolve;
});
init() {
if (!this.enabled) {
return;
@@ -797,16 +793,6 @@ class nsZenPinnedTabManager extends nsZenDOMOperatedFeature {
return document.documentElement.getAttribute('zen-sidebar-expanded') === 'true';
}
async updatePinTitle(tab, newTitle, isEdited = true) {
tab.removeAttribute('zen-has-static-label');
if (isEdited) {
gBrowser._setTabLabel(tab, newTitle);
tab.setAttribute('zen-has-static-label', 'true');
} else {
gBrowser.setTabTitle(tab);
}
}
canEssentialBeAdded(tab) {
return (
!(

View File

@@ -1248,7 +1248,7 @@ class nsZenWorkspaces {
if (this.privateWindowOrDisabled) {
return;
}
const workspacesData = this.getWorkspaces();
const workspacesData = this._workspaceCache;
const index = workspacesData.findIndex((ws) => ws.uuid === workspaceData.uuid);
if (index !== -1) {
workspacesData[index] = workspaceData;