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

View File

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