feat: Improved startup performance and flashes, p=#10588, c=common, tabs, workspaces

This commit is contained in:
mr. m
2025-09-27 19:04:59 +02:00
committed by GitHub
parent 3d83fed14f
commit 47181da49e
5 changed files with 91 additions and 67 deletions

View File

@@ -0,0 +1,30 @@
# nsBrowserGlue.js
# This component must restrict its registration for the app-startup category
# to the specific list of apps that use it so it doesn't get loaded in xpcshell.
# Thus we restrict it to these apps:
#
# browser: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
#
# The first rule of running code during startup is: don't.
#
# We take performance very seriously and ideally your component/feature should
# initialize only when needed.
#
# If you have established that you really must run code during startup,
# available entrypoints are:
#
# - registering a `browser-idle-startup` category entry for your JS module (or
# even a "best effort" user idle task, see `BrowserGlue.sys.mjs`)
# - registering a `browser-window-delayed-startup` category entry for your JS
# module. **Note that this is invoked for each browser window.**
# - registering a `browser-before-ui-startup` category entry if you really really
# need to. This will run code before the first browser window appears on the
# screen and make Firefox seem slow, so please don't do it unless absolutely
# necessary.
#ifdef XP_UNIX
#ifndef XP_MACOSX
#define UNIX_BUT_NOT_MAC
#endif
#endif

View File

@@ -2,22 +2,25 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
{ {
var gZenStartup = new (class { class ZenStartupManager {
#watermarkIgnoreElements = ['zen-toast-container']; #watermarkIgnoreElements = ['zen-toast-container'];
#hasInitializedLayout = false; #hasInitializedLayout = false;
isReady = false; isReady = false;
async init() { constructor() {
// important: We do this to ensure that some firefox components gZenWorkspaces.init();
// are initialized before we start our own initialization.
// please, do not remove this line and if you do, make sure to window.addEventListener(
// test the startup process. 'MozBeforeInitialXULLayout',
await new Promise((resolve) => setTimeout(resolve, 0)); () => {
this.openWatermark(); this.openWatermark();
this.#zenInitBrowserLayout();
this.#initBrowserBackground(); this.#initBrowserBackground();
this.#changeSidebarLocation(); this.#changeSidebarLocation();
this.#zenInitBrowserLayout(); },
{ once: true }
);
} }
#initBrowserBackground() { #initBrowserBackground() {
@@ -57,7 +60,6 @@
document.getElementById('zen-appcontent-wrapper').prepend(deckTemplate); document.getElementById('zen-appcontent-wrapper').prepend(deckTemplate);
} }
gZenWorkspaces.init();
setTimeout(() => { setTimeout(() => {
gZenUIManager.init(); gZenUIManager.init();
this.#checkForWelcomePage(); this.#checkForWelcomePage();
@@ -223,13 +225,7 @@
}); });
}); });
} }
})(); }
window.addEventListener( window.gZenStartup = new ZenStartupManager();
'MozBeforeInitialXULLayout',
() => {
gZenStartup.init();
},
{ once: true }
);
} }

View File

@@ -10,3 +10,7 @@ DIRS += [
"urlbar", "urlbar",
"toolkit", "toolkit",
] ]
EXTRA_PP_COMPONENTS += [
"ZenComponents.manifest",
]

View File

@@ -418,13 +418,13 @@
overflow-y: auto; overflow-y: auto;
height: 100%; height: 100%;
:root[zen-workspace-id][zen-sidebar-expanded='true'] & { :root[zen-sidebar-expanded='true'] & {
margin-left: calc(-1 * var(--zen-toolbox-padding)); margin-left: calc(-1 * var(--zen-toolbox-padding));
width: calc(100% + var(--zen-toolbox-padding) * 2); width: calc(100% + var(--zen-toolbox-padding) * 2);
} }
} }
:root[zen-workspace-id] #pinned-tabs-container { #pinned-tabs-container {
display: none; display: none;
} }

View File

@@ -51,7 +51,7 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
await Promise.all([this.promiseDBInitialized, this.promisePinnedInitialized]); await Promise.all([this.promiseDBInitialized, this.promisePinnedInitialized]);
} }
async init() { init() {
// Initialize tab selection state // Initialize tab selection state
this._tabSelectionState = { this._tabSelectionState = {
inProgress: false, inProgress: false,
@@ -118,12 +118,8 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
this.popupOpenHandler = this._popupOpenHandler.bind(this); this.popupOpenHandler = this._popupOpenHandler.bind(this);
window.addEventListener('resize', this.onWindowResize.bind(this)); window.addEventListener('resize', this.onWindowResize.bind(this));
this.addPopupListeners();
await this.#waitForPromises(); this.afterLoadInit();
await this._workspaces();
await this.afterLoadInit();
} }
log(...args) { log(...args) {
@@ -136,11 +132,13 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
if (!this._hasInitializedTabsStrip) { if (!this._hasInitializedTabsStrip) {
await this.delayedStartup(); await this.delayedStartup();
} }
this._initializeWorkspaceTabContextMenus(); this.#initializeWorkspaceTabContextMenus();
await this.initializeWorkspaces(); await this.initializeWorkspaces();
await this.promiseSectionsInitialized; await this.promiseSectionsInitialized;
// Non UI related initializations // Non UI related initializations
this.addPopupListeners();
if ( if (
Services.prefs.getBoolPref('zen.workspaces.swipe-actions', false) && Services.prefs.getBoolPref('zen.workspaces.swipe-actions', false) &&
this.workspaceEnabled && this.workspaceEnabled &&
@@ -311,6 +309,7 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
} }
async _createDefaultWorkspaceIfNeeded() { async _createDefaultWorkspaceIfNeeded() {
await this.#waitForPromises();
const workspaces = await this._workspaces(); const workspaces = await this._workspaces();
if (!workspaces.workspaces.length) { if (!workspaces.workspaces.length) {
await this.createAndSaveWorkspace('Space', null, true); await this.createAndSaveWorkspace('Space', null, true);
@@ -401,19 +400,18 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
async initializeTabsStripSections() { async initializeTabsStripSections() {
await SessionStore.promiseInitialized; await SessionStore.promiseInitialized;
await SessionStore.promiseAllWindowsRestored; await SessionStore.promiseAllWindowsRestored;
await gZenSessionStore.promiseInitialized;
const perifery = document.getElementById('tabbrowser-arrowscrollbox-periphery'); const perifery = document.getElementById('tabbrowser-arrowscrollbox-periphery');
perifery.setAttribute('hidden', 'true'); perifery.setAttribute('hidden', 'true');
await new Promise((resolve) => {
setTimeout(async () => {
const tabs = gBrowser.tabContainer.allTabs; const tabs = gBrowser.tabContainer.allTabs;
const workspaces = await this._workspaces(); const workspaces = await this._workspaces();
for (const workspace of workspaces.workspaces) { for (const workspace of workspaces.workspaces) {
await this._createWorkspaceTabsSection(workspace, tabs); await this._createWorkspaceTabsSection(workspace, tabs);
} }
if (tabs.length) { if (tabs.length) {
const defaultSelectedContainer = this.workspaceElement( const defaultSelectedContainer = this.workspaceElement(this.activeWorkspace)?.querySelector(
this.activeWorkspace '.zen-workspace-normal-tabs-section'
)?.querySelector('.zen-workspace-normal-tabs-section'); );
const pinnedContainer = this.workspaceElement(this.activeWorkspace).querySelector( const pinnedContainer = this.workspaceElement(this.activeWorkspace).querySelector(
'.zen-workspace-pinned-tabs-section' '.zen-workspace-pinned-tabs-section'
); );
@@ -438,9 +436,6 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
this.registerPinnedResizeObserver(); this.registerPinnedResizeObserver();
this._fixIndicatorsNames(workspaces); this._fixIndicatorsNames(workspaces);
this._resolveSectionsInitialized(); this._resolveSectionsInitialized();
resolve();
}, 0);
});
} }
getEssentialsSection(container = 0) { getEssentialsSection(container = 0) {
@@ -920,7 +915,6 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
async initializeWorkspaces() { async initializeWorkspaces() {
let activeWorkspace = await this.getActiveWorkspace(); let activeWorkspace = await this.getActiveWorkspace();
this.activeWorkspace = activeWorkspace?.uuid; this.activeWorkspace = activeWorkspace?.uuid;
await gZenSessionStore.promiseInitialized;
try { try {
if (activeWorkspace) { if (activeWorkspace) {
window.gZenThemePicker = new nsZenThemePicker(); window.gZenThemePicker = new nsZenThemePicker();
@@ -2660,7 +2654,7 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
await this.changeWorkspace(nextWorkspace, { whileScrolling }); await this.changeWorkspace(nextWorkspace, { whileScrolling });
} }
_initializeWorkspaceTabContextMenus() { #initializeWorkspaceTabContextMenus() {
if (this.privateWindowOrDisabled) { if (this.privateWindowOrDisabled) {
const commandsToDisable = [ const commandsToDisable = [
'cmd_zenOpenFolderCreation', 'cmd_zenOpenFolderCreation',