Implement tab pinning functionality and default workspace creation logic

This commit is contained in:
mr. M
2025-02-21 12:28:32 +01:00
parent 6b306daf21
commit dee0016836
2 changed files with 51 additions and 45 deletions

View File

@@ -1,4 +1,7 @@
{ {
var _tabsToPin = [];
var _tabsToPinEssentials = [];
function clearBrowserElements() { function clearBrowserElements() {
for (const element of document.getElementById('browser').children) { for (const element of document.getElementById('browser').children) {
element.style.display = 'none'; element.style.display = 'none';
@@ -45,13 +48,7 @@
const tab = window.gBrowser.addTrustedTab(url, { const tab = window.gBrowser.addTrustedTab(url, {
inBackground: true, inBackground: true,
}); });
setTimeout( _tabsToPin.push(tab);
(tab) => {
gBrowser.pinTab(tab);
},
1000,
tab
);
} }
} }
@@ -177,10 +174,7 @@
async next() { async next() {
if (this._currentPage !== -1) { if (this._currentPage !== -1) {
const previousPage = this._pages[this._currentPage]; const previousPage = this._pages[this._currentPage];
const promises = [ const promises = [this.fadeOutTitles(), this.fadeOutButtons()];
this.fadeOutTitles(),
this.fadeOutButtons(),
];
if (!previousPage.dontFadeOut) { if (!previousPage.dontFadeOut) {
promises.push(this.fadeOutContent()); promises.push(this.fadeOutContent());
} }
@@ -204,6 +198,7 @@
await animate('#zen-welcome-page-content', { x: [0, '100%'] }, { bounce: 0 }); await animate('#zen-welcome-page-content', { x: [0, '100%'] }, { bounce: 0 });
document.getElementById('zen-welcome-page-content').remove(); document.getElementById('zen-welcome-page-content').remove();
await this.animHeart(); await this.animHeart();
this._pinRemainingTabs();
await animate('#zen-welcome-pages', { opacity: [1, 0] }); await animate('#zen-welcome-pages', { opacity: [1, 0] });
document.getElementById('zen-welcome').remove(); document.getElementById('zen-welcome').remove();
document.documentElement.removeAttribute('zen-welcome-stage'); document.documentElement.removeAttribute('zen-welcome-stage');
@@ -216,6 +211,15 @@
gZenUIManager.showToast('zen-welcome-finished'); gZenUIManager.showToast('zen-welcome-finished');
} }
_pinRemainingTabs() {
for (const tab of _tabsToPin) {
gBrowser.pinTab(tab);
}
for (const tab of _tabsToPinEssentials) {
gZenPinnedTabManager.addToEssentials(tab);
}
}
async animHeart() { async animHeart() {
const heart = document.createElement('div'); const heart = document.createElement('div');
heart.id = 'zen-welcome-heart'; heart.id = 'zen-welcome-heart';
@@ -438,13 +442,7 @@
const createdTab = window.gBrowser.addTrustedTab(url, { const createdTab = window.gBrowser.addTrustedTab(url, {
inBackground: true, inBackground: true,
}); });
setTimeout( _tabsToPinEssentials.push(createdTab);
(tab) => {
gZenPinnedTabManager.addToEssentials(tab);
},
1000,
createdTab
);
} }
openInitialPinTab(); openInitialPinTab();
openWelcomeTab(); openWelcomeTab();

View File

@@ -124,11 +124,20 @@ var ZenWorkspaces = 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.initializeTabsStripSections(); await this.initializeTabsStripSections();
this._resolveSectionsInitialized(); this._resolveSectionsInitialized();
this._initializeEmptyTab(); this._initializeEmptyTab();
} }
async _createDefaultWorkspaceIfNeeded() {
const workspaces = await this._workspaces();
if (!workspaces.workspaces.length) {
await this.createAndSaveWorkspace('Default Workspace', true, '🏠', true);
this._workspaceCache = null;
}
}
_initializeEmptyTab() { _initializeEmptyTab() {
gBrowser._forZenEmptyTab = true; gBrowser._forZenEmptyTab = true;
this._emptyTab = gBrowser.addTrustedTab('about:blank', { inBackground: true }); this._emptyTab = gBrowser.addTrustedTab('about:blank', { inBackground: true });
@@ -570,14 +579,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this)); window.addEventListener('TabBrowserInserted', this.onTabBrowserInserted.bind(this));
window.addEventListener('TabOpen', this.updateTabsContainers.bind(this)); window.addEventListener('TabOpen', this.updateTabsContainers.bind(this));
window.addEventListener('TabClose', this.updateTabsContainers.bind(this)); window.addEventListener('TabClose', this.updateTabsContainers.bind(this));
let workspaces = await this._workspaces(); let activeWorkspace = await this.getActiveWorkspace();
let activeWorkspace = null; this.activeWorkspace = activeWorkspace?.uuid;
if (workspaces.workspaces.length === 0) {
activeWorkspace = await this.createAndSaveWorkspace('Default Workspace', true, '🏠');
} else {
activeWorkspace = await this.getActiveWorkspace();
this.activeWorkspace = activeWorkspace?.uuid;
}
try { try {
if (activeWorkspace) { if (activeWorkspace) {
window.gZenThemePicker = new ZenThemePicker(); window.gZenThemePicker = new ZenThemePicker();
@@ -599,7 +602,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return; return;
} }
const currentTabUrl = currentTab.linkedBrowser?.currentURI.spec; const currentTabUrl = currentTab.linkedBrowser?.currentURI.spec;
console.log('ZenWorkspaces: Current tab URL', currentTabUrl);
if (currentTabUrl === 'about:blank' || currentTabUrl === 'about:newtab' || currentTabUrl === 'about:home') { if (currentTabUrl === 'about:blank' || currentTabUrl === 'about:newtab' || currentTabUrl === 'about:home') {
this.selectEmptyTab(); this.selectEmptyTab();
gBrowser.removeTab(currentTab); gBrowser.removeTab(currentTab);
@@ -785,10 +787,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
}); });
} }
async saveWorkspace(workspaceData) { async saveWorkspace(workspaceData, preventPropagation = false) {
await ZenWorkspacesStorage.saveWorkspace(workspaceData); await ZenWorkspacesStorage.saveWorkspace(workspaceData);
await this._propagateWorkspaceData(); if (!preventPropagation) {
await this._updateWorkspacesChangeContextMenu(); await this._propagateWorkspaceData();
await this._updateWorkspacesChangeContextMenu();
}
} }
async removeWorkspace(windowID) { async removeWorkspace(windowID) {
@@ -1799,7 +1803,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
} }
_createWorkspaceData(name, isDefault, icon, tabs) { _createWorkspaceData(name, isDefault, icon, tabs, moveTabs = true) {
let window = { let window = {
uuid: gZenUIManager.generateUuidv4(), uuid: gZenUIManager.generateUuidv4(),
default: isDefault, default: isDefault,
@@ -1807,15 +1811,17 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
name: name, name: name,
theme: ZenThemePicker.getTheme([]), theme: ZenThemePicker.getTheme([]),
}; };
this._prepareNewWorkspace(window); if (moveTabs) {
const perifery = document.querySelector('#tabbrowser-arrowscrollbox-periphery[hidden]'); this._prepareNewWorkspace(window);
perifery?.removeAttribute('hidden'); const perifery = document.querySelector('#tabbrowser-arrowscrollbox-periphery[hidden]');
this._createWorkspaceTabsSection(window, tabs, perifery); perifery?.removeAttribute('hidden');
perifery.setAttribute('hidden', 'true'); this._createWorkspaceTabsSection(window, tabs, perifery);
perifery.setAttribute('hidden', 'true');
}
return window; return window;
} }
async createAndSaveWorkspace(name = 'New Workspace', isDefault = false, icon = undefined) { async createAndSaveWorkspace(name = 'New Workspace', isDefault = false, icon = undefined, dontChange = false) {
if (!this.workspaceEnabled) { if (!this.workspaceEnabled) {
return; return;
} }
@@ -1823,15 +1829,17 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
const extraTabs = Array.from(gBrowser.tabContainer.arrowScrollbox.children).filter( const extraTabs = Array.from(gBrowser.tabContainer.arrowScrollbox.children).filter(
(child) => child.tagName === 'tab' && !child.hasAttribute('zen-workspace-id') (child) => child.tagName === 'tab' && !child.hasAttribute('zen-workspace-id')
); );
let workspaceData = this._createWorkspaceData(name, isDefault, icon, extraTabs); let workspaceData = this._createWorkspaceData(name, isDefault, icon, extraTabs, !dontChange);
await this.saveWorkspace(workspaceData); await this.saveWorkspace(workspaceData, dontChange);
this.registerPinnedResizeObserver(); if (!dontChange) {
let changed = extraTabs.length > 0; this.registerPinnedResizeObserver();
if (changed) { let changed = extraTabs.length > 0;
gBrowser.tabContainer._invalidateCachedTabs(); if (changed) {
gBrowser.selectedTab = extraTabs[0]; gBrowser.tabContainer._invalidateCachedTabs();
gBrowser.selectedTab = extraTabs[0];
}
await this.changeWorkspace(workspaceData);
} }
await this.changeWorkspace(workspaceData);
return workspaceData; return workspaceData;
} }