mirror of
https://github.com/zen-browser/desktop.git
synced 2025-10-14 22:06:13 +00:00
no-bug - Improved initial startup performance and loading speeds, c=common, tabs, workspaces, t=perf
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js
|
diff --git a/browser/base/content/browser-init.js b/browser/base/content/browser-init.js
|
||||||
index 3d5173315812589c0b79beec5f0419fc37cb8868..c4216db9e414fbbaead6ecd89b40366b0d8a50c1 100644
|
index bcbfab4a3781ff3c7349115751b3830976eec4bf..1ab08a9344b16cbe791182fce3f6fbf59ca3df91 100644
|
||||||
--- a/browser/base/content/browser-init.js
|
--- a/browser/base/content/browser-init.js
|
||||||
+++ b/browser/base/content/browser-init.js
|
+++ b/browser/base/content/browser-init.js
|
||||||
@@ -175,6 +175,8 @@ var gBrowserInit = {
|
@@ -186,6 +186,8 @@ var gBrowserInit = {
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
@@ -11,11 +11,3 @@ index 3d5173315812589c0b79beec5f0419fc37cb8868..c4216db9e414fbbaead6ecd89b40366b
|
|||||||
gBrowser.addEventListener("DOMUpdateBlockedPopups", e =>
|
gBrowser.addEventListener("DOMUpdateBlockedPopups", e =>
|
||||||
PopupBlockerObserver.handleEvent(e)
|
PopupBlockerObserver.handleEvent(e)
|
||||||
);
|
);
|
||||||
@@ -310,6 +312,7 @@ var gBrowserInit = {
|
|
||||||
TelemetryTimestamps.add("delayedStartupStarted");
|
|
||||||
|
|
||||||
this._cancelDelayedStartup();
|
|
||||||
+ gZenWorkspaces.afterLoadInit();
|
|
||||||
|
|
||||||
gBrowser.addEventListener(
|
|
||||||
"PermissionStateChange",
|
|
||||||
|
@@ -36,7 +36,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async #waitAndCleanup() {
|
async #waitAndCleanup() {
|
||||||
await SessionStore.promiseAllWindowsRestored;
|
|
||||||
await SessionStore.promiseInitialized;
|
await SessionStore.promiseInitialized;
|
||||||
this.#cleanup();
|
this.#cleanup();
|
||||||
}
|
}
|
||||||
|
@@ -65,23 +65,10 @@
|
|||||||
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));
|
this.observer.addPinnedTabListener(this._onPinnedTabEvent.bind(this));
|
||||||
|
|
||||||
this._zenClickEventListener = this._onTabClick.bind(this);
|
this._zenClickEventListener = this._onTabClick.bind(this);
|
||||||
gZenWorkspaces.addChangeListeners(this.onWorkspaceChange.bind(this));
|
|
||||||
|
|
||||||
await ZenPinnedTabsStorage.promiseInitialized;
|
|
||||||
gZenWorkspaces._resolvePinnedInitialized();
|
gZenWorkspaces._resolvePinnedInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
async onWorkspaceChange(newWorkspace, onInit) {
|
|
||||||
if (!this.enabled || PrivateBrowsingUtils.isWindowPrivate(window)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onInit) {
|
|
||||||
await this._refreshPinnedTabs({ init: onInit });
|
|
||||||
this._hasFinishedLoading = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log(message) {
|
log(message) {
|
||||||
if (this._canLog) {
|
if (this._canLog) {
|
||||||
console.log(`[ZenPinnedTabManager] ${message}`);
|
console.log(`[ZenPinnedTabManager] ${message}`);
|
||||||
@@ -149,13 +136,19 @@
|
|||||||
return this._enabled && !gZenWorkspaces.privateWindowOrDisabled;
|
return this._enabled && !gZenWorkspaces.privateWindowOrDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _refreshPinnedTabs({ init = false } = {}) {
|
async refreshPinnedTabs({ init = false } = {}) {
|
||||||
|
await ZenPinnedTabsStorage.promiseInitialized;
|
||||||
await gZenWorkspaces.promiseSectionsInitialized;
|
await gZenWorkspaces.promiseSectionsInitialized;
|
||||||
await this._initializePinsCache();
|
await this._initializePinsCache();
|
||||||
|
(async () => {
|
||||||
|
// Execute in a separate task to avoid blocking the main thread
|
||||||
|
await SessionStore.promiseAllWindowsRestored;
|
||||||
|
await gZenWorkspaces.promiseInitialized;
|
||||||
await this._initializePinnedTabs(init);
|
await this._initializePinnedTabs(init);
|
||||||
if (init) {
|
if (init) {
|
||||||
this._resolveInitializedPinnedCache();
|
this._hasFinishedLoading = true;
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _initializePinsCache() {
|
async _initializePinsCache() {
|
||||||
@@ -439,7 +432,7 @@
|
|||||||
|
|
||||||
await this.savePin(pin);
|
await this.savePin(pin);
|
||||||
this.resetPinChangedUrl(tab);
|
this.resetPinChangedUrl(tab);
|
||||||
await this._refreshPinnedTabs();
|
await this.refreshPinnedTabs();
|
||||||
gZenUIManager.showToast('zen-pinned-tab-replaced');
|
gZenUIManager.showToast('zen-pinned-tab-replaced');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,7 +475,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.onLocationChange(browser);
|
this.onLocationChange(browser);
|
||||||
await this._refreshPinnedTabs();
|
await this.refreshPinnedTabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _removePinnedAttributes(tab, isClosing = false) {
|
async _removePinnedAttributes(tab, isClosing = false) {
|
||||||
@@ -508,7 +501,7 @@
|
|||||||
tab.setAttribute('zen-workspace-id', workspace.uuid);
|
tab.setAttribute('zen-workspace-id', workspace.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this._refreshPinnedTabs();
|
await this.refreshPinnedTabs();
|
||||||
tab.dispatchEvent(
|
tab.dispatchEvent(
|
||||||
new CustomEvent('ZenPinnedTabRemoved', {
|
new CustomEvent('ZenPinnedTabRemoved', {
|
||||||
detail: { tab },
|
detail: { tab },
|
||||||
@@ -958,7 +951,7 @@
|
|||||||
const uuid = tab.getAttribute('zen-pin-id');
|
const uuid = tab.getAttribute('zen-pin-id');
|
||||||
await ZenPinnedTabsStorage.updatePinTitle(uuid, newTitle, isEdited, notifyObservers);
|
await ZenPinnedTabsStorage.updatePinTitle(uuid, newTitle, isEdited, notifyObservers);
|
||||||
|
|
||||||
await this._refreshPinnedTabs();
|
await this.refreshPinnedTabs();
|
||||||
|
|
||||||
const browsers = Services.wm.getEnumerator('navigator:browser');
|
const browsers = Services.wm.getEnumerator('navigator:browser');
|
||||||
|
|
||||||
@@ -1110,8 +1103,4 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.gZenPinnedTabManager = new ZenPinnedTabManager();
|
window.gZenPinnedTabManager = new ZenPinnedTabManager();
|
||||||
|
|
||||||
gZenPinnedTabManager.promisePinnedCacheInitialized = new Promise((resolve) => {
|
|
||||||
gZenPinnedTabManager._resolveInitializedPinnedCache = resolve;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@@ -46,11 +46,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
if (this.privateWindowOrDisabled) {
|
if (this.privateWindowOrDisabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await Promise.all([
|
await Promise.all([this.promiseDBInitialized, this.promisePinnedInitialized]);
|
||||||
this.promiseDBInitialized,
|
|
||||||
this.promisePinnedInitialized,
|
|
||||||
SessionStore.promiseAllWindowsRestored,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
@@ -119,6 +115,8 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
|
|
||||||
window.addEventListener('resize', this.onWindowResize.bind(this));
|
window.addEventListener('resize', this.onWindowResize.bind(this));
|
||||||
this.addPopupListeners();
|
this.addPopupListeners();
|
||||||
|
|
||||||
|
await this.afterLoadInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
log(...args) {
|
log(...args) {
|
||||||
@@ -128,14 +126,15 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async afterLoadInit() {
|
async afterLoadInit() {
|
||||||
await SessionStore.promiseInitialized;
|
|
||||||
if (!this._hasInitializedTabsStrip) {
|
if (!this._hasInitializedTabsStrip) {
|
||||||
await this.delayedStartup();
|
await this.delayedStartup();
|
||||||
}
|
}
|
||||||
await this.promiseSectionsInitialized;
|
|
||||||
this.log('gZenWorkspaces initialized');
|
|
||||||
|
|
||||||
await this.initializeWorkspaces();
|
await this.initializeWorkspaces();
|
||||||
|
await this.promiseSectionsInitialized;
|
||||||
|
|
||||||
|
// Non UI related initializations
|
||||||
|
this._initializeWorkspaceCreationIcons();
|
||||||
|
this._initializeWorkspaceTabContextMenus();
|
||||||
if (
|
if (
|
||||||
Services.prefs.getBoolPref('zen.workspaces.swipe-actions', false) &&
|
Services.prefs.getBoolPref('zen.workspaces.swipe-actions', false) &&
|
||||||
this.workspaceEnabled &&
|
this.workspaceEnabled &&
|
||||||
@@ -297,9 +296,6 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
this._pinnedTabsResizeObserver = new ResizeObserver(this.onPinnedTabsResize.bind(this));
|
this._pinnedTabsResizeObserver = new ResizeObserver(this.onPinnedTabsResize.bind(this));
|
||||||
await this.waitForPromises();
|
await this.waitForPromises();
|
||||||
await this._createDefaultWorkspaceIfNeeded();
|
await this._createDefaultWorkspaceIfNeeded();
|
||||||
await this.initializeTabsStripSections();
|
|
||||||
this._resolveSectionsInitialized();
|
|
||||||
this._initializeEmptyTab();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _createDefaultWorkspaceIfNeeded() {
|
async _createDefaultWorkspaceIfNeeded() {
|
||||||
@@ -375,6 +371,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initializeTabsStripSections() {
|
async initializeTabsStripSections() {
|
||||||
|
await SessionStore.promiseAllWindowsRestored;
|
||||||
const perifery = document.getElementById('tabbrowser-arrowscrollbox-periphery');
|
const perifery = document.getElementById('tabbrowser-arrowscrollbox-periphery');
|
||||||
perifery.setAttribute('hidden', 'true');
|
perifery.setAttribute('hidden', 'true');
|
||||||
const tabs = gBrowser.tabContainer.allTabs;
|
const tabs = gBrowser.tabContainer.allTabs;
|
||||||
@@ -409,6 +406,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
this._hasInitializedTabsStrip = true;
|
this._hasInitializedTabsStrip = true;
|
||||||
this.registerPinnedResizeObserver();
|
this.registerPinnedResizeObserver();
|
||||||
this._fixIndicatorsNames(workspaces);
|
this._fixIndicatorsNames(workspaces);
|
||||||
|
this._resolveSectionsInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
getEssentialsSection(container = 0) {
|
getEssentialsSection(container = 0) {
|
||||||
@@ -836,26 +834,23 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initializeWorkspaces() {
|
async initializeWorkspaces() {
|
||||||
if (this.workspaceEnabled) {
|
|
||||||
this._initializeWorkspaceCreationIcons();
|
|
||||||
this._initializeWorkspaceTabContextMenus();
|
|
||||||
await this.workspaceBookmarks();
|
|
||||||
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
|
|
||||||
let activeWorkspace = await this.getActiveWorkspace();
|
let activeWorkspace = await this.getActiveWorkspace();
|
||||||
this.activeWorkspace = activeWorkspace?.uuid;
|
this.activeWorkspace = activeWorkspace?.uuid;
|
||||||
try {
|
try {
|
||||||
if (activeWorkspace) {
|
if (activeWorkspace) {
|
||||||
window.gZenThemePicker = new ZenThemePicker();
|
window.gZenThemePicker = new ZenThemePicker();
|
||||||
await this.changeWorkspace(activeWorkspace, { onInit: true });
|
await gZenThemePicker.onWorkspaceChange(activeWorkspace);
|
||||||
gBrowser.tabContainer._positionPinnedTabs();
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('gZenWorkspaces: Error initializing theme picker', e);
|
console.error('gZenWorkspaces: Error initializing theme picker', e);
|
||||||
}
|
}
|
||||||
this.onWindowResize();
|
this.onWindowResize();
|
||||||
if (window.gZenSessionStore) {
|
|
||||||
await gZenSessionStore.promiseInitialized;
|
await gZenSessionStore.promiseInitialized;
|
||||||
}
|
await this.initializeTabsStripSections();
|
||||||
|
this._initializeEmptyTab();
|
||||||
|
await this.workspaceBookmarks();
|
||||||
|
await gZenPinnedTabManager.refreshPinnedTabs({ init: true });
|
||||||
|
await this.changeWorkspace(activeWorkspace, { onInit: true });
|
||||||
await this._selectStartPage();
|
await this._selectStartPage();
|
||||||
this._fixTabPositions();
|
this._fixTabPositions();
|
||||||
this._resolveInitialized();
|
this._resolveInitialized();
|
||||||
@@ -869,7 +864,8 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
window.addEventListener('TabPinned', tabUpdateListener);
|
window.addEventListener('TabPinned', tabUpdateListener);
|
||||||
window.addEventListener('TabUnpinned', tabUpdateListener);
|
window.addEventListener('TabUnpinned', tabUpdateListener);
|
||||||
window.addEventListener('aftercustomization', tabUpdateListener);
|
window.addEventListener('aftercustomization', tabUpdateListener);
|
||||||
}
|
|
||||||
|
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
async _selectStartPage() {
|
async _selectStartPage() {
|
||||||
@@ -1412,18 +1408,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _propagateWorkspaceData({ ignoreStrip = false, clearCache = true } = {}) {
|
async _propagateWorkspaceDataForWindow(browser, { ignoreStrip = false, clearCache = true } = {}) {
|
||||||
const currentWindowIsPrivate = this.isPrivateWindow;
|
|
||||||
await this.foreachWindowAsActive(async (browser) => {
|
|
||||||
// Do not update the window if workspaces are not enabled in it.
|
|
||||||
// For example, when the window is in private browsing mode.
|
|
||||||
if (
|
|
||||||
!browser.gZenWorkspaces.workspaceEnabled ||
|
|
||||||
browser.gZenWorkspaces.isPrivateWindow !== currentWindowIsPrivate
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let workspaceList = browser.document.getElementById('PanelUI-zen-workspaces-list');
|
let workspaceList = browser.document.getElementById('PanelUI-zen-workspaces-list');
|
||||||
const createWorkspaceElement = (workspace) => {
|
const createWorkspaceElement = (workspace) => {
|
||||||
let element = browser.document.createXULElement('toolbarbutton');
|
let element = browser.document.createXULElement('toolbarbutton');
|
||||||
@@ -1672,10 +1657,33 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
workspaceList.appendChild(createLastPositionDropTarget());
|
workspaceList.appendChild(createLastPositionDropTarget());
|
||||||
|
|
||||||
if (!ignoreStrip) {
|
if (!ignoreStrip) {
|
||||||
browser.gZenWorkspaces._fixIndicatorsNames(workspaces);
|
browser.gZenWorkspaces._fixIndicatorsNames(workspaces);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _propagateWorkspaceData({ ignoreStrip = false, clearCache = true, onInit = false } = {}) {
|
||||||
|
const currentWindowIsPrivate = this.isPrivateWindow;
|
||||||
|
if (onInit) {
|
||||||
|
if (currentWindowIsPrivate) return;
|
||||||
|
return await this._propagateWorkspaceDataForWindow(this.ownerWindow, {
|
||||||
|
ignoreStrip,
|
||||||
|
clearCache,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await this.foreachWindowAsActive(async (browser) => {
|
||||||
|
// Do not update the window if workspaces are not enabled in it.
|
||||||
|
// For example, when the window is in private browsing mode.
|
||||||
|
if (
|
||||||
|
!browser.gZenWorkspaces.workspaceEnabled ||
|
||||||
|
browser.gZenWorkspaces.isPrivateWindow !== currentWindowIsPrivate
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._propagateWorkspaceDataForWindow(browser, {
|
||||||
|
ignoreStrip,
|
||||||
|
clearCache,
|
||||||
|
}).catch(console.error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2505,7 +2513,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
|||||||
// Update workspace UI
|
// Update workspace UI
|
||||||
await this._updateWorkspacesChangeContextMenu();
|
await this._updateWorkspacesChangeContextMenu();
|
||||||
// gZenUIManager.updateTabsToolbar();
|
// gZenUIManager.updateTabsToolbar();
|
||||||
await this._propagateWorkspaceData({ clearCache: false });
|
await this._propagateWorkspaceData({ clearCache: false, onInit });
|
||||||
|
|
||||||
gZenThemePicker.onWorkspaceChange(workspace);
|
gZenThemePicker.onWorkspaceChange(workspace);
|
||||||
|
|
||||||
|
@@ -584,7 +584,4 @@ var ZenWorkspaceBookmarksStorage = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ZenWorkspacesStorage.promiseDBInitialized = new Promise((resolve) => {
|
ZenWorkspacesStorage.init();
|
||||||
ZenWorkspacesStorage._resolveDBInitialized = resolve;
|
|
||||||
ZenWorkspacesStorage.init();
|
|
||||||
});
|
|
||||||
|
Reference in New Issue
Block a user