mirror of
https://github.com/zen-browser/desktop.git
synced 2026-03-31 12:51:59 +00:00
feat: Initialize closed windows if no normal restorable windows have been found, b=no-bug, c=workspaces
This commit is contained in:
@@ -37,7 +37,6 @@ pictureinpicture-minimize-btn =
|
||||
.tooltip = Minimize
|
||||
|
||||
zen-panel-ui-gradient-generator-custom-color = Custom Color
|
||||
zen-panel-ui-gradient-generator-saved-message = Successfully saved the gradient!
|
||||
|
||||
zen-copy-current-url-confirmation = Copied current URL!
|
||||
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
value: true
|
||||
|
||||
- name: zen.session-store.log
|
||||
value: false
|
||||
value: '@IS_TWILIGHT@'
|
||||
|
||||
@@ -108,8 +108,9 @@
|
||||
const tab = movingTabs[i];
|
||||
const tabClone = tab.cloneNode(true);
|
||||
if (tabClone.hasAttribute('zen-essential')) {
|
||||
tabClone.style.minWidth = tab.style.maxWidth = '54px';
|
||||
tabClone.style.minHeight = tab.style.maxHeight = '50px';
|
||||
const rect = tab.getBoundingClientRect();
|
||||
tabClone.style.minWidth = tabClone.style.maxWidth = `${rect.width}px`;
|
||||
tabClone.style.minHeight = tabClone.style.maxHeight = `${rect.height}px`;
|
||||
}
|
||||
if (i > 0) {
|
||||
tabClone.style.transform = `translate(${i * 4}px, -${i * (tabRect.height - 4)}px)`;
|
||||
@@ -682,7 +683,7 @@
|
||||
!draggedTab.hasAttribute('zen-essential') &&
|
||||
draggedTab.getAttribute('zen-workspace-id') != gZenWorkspaces.activeWorkspace
|
||||
) {
|
||||
const movingTabs = draggedTab._dragData.movingTabs;
|
||||
const movingTabs = draggedTab._dragData?.movingTabs || [draggedTab];
|
||||
for (let tab of movingTabs) {
|
||||
tab.setAttribute('zen-workspace-id', gZenWorkspaces.activeWorkspace);
|
||||
}
|
||||
@@ -959,7 +960,6 @@
|
||||
let pinnedTabs = this._tabbrowserTabs.ariaFocusableItems.slice(0, numEssentials);
|
||||
this._fakeEssentialTab = document.createXULElement('vbox');
|
||||
this._fakeEssentialTab.elementIndex = numEssentials;
|
||||
this.#makeDragImageEssential(event);
|
||||
delete dragData.animDropElementIndex;
|
||||
if (draggedTab.hasAttribute('zen-essential')) {
|
||||
draggedTab.style.visibility = 'hidden';
|
||||
@@ -968,6 +968,7 @@
|
||||
gZenWorkspaces.updateTabsContainers();
|
||||
pinnedTabs.push(this._fakeEssentialTab);
|
||||
}
|
||||
this.#makeDragImageEssential(event);
|
||||
let tabsPerRow = 0;
|
||||
let position = RTL_UI
|
||||
? window.windowUtils.getBoundsWithoutFlushing(this._tabbrowserTabs.pinnedTabsContainer)
|
||||
@@ -1190,8 +1191,12 @@
|
||||
tab.setAttribute('zen-essential', 'true');
|
||||
tab.setAttribute('pinned', 'true');
|
||||
tab.setAttribute('selected', 'true');
|
||||
tab.style.minWidth = tab.style.maxWidth = wrapper.style.width = '54px';
|
||||
tab.style.minHeight = tab.style.maxHeight = wrapper.style.height = '50px';
|
||||
const draggedTabRect = window.windowUtils.getBoundsWithoutFlushing(this._fakeEssentialTab);
|
||||
tab.style.minWidth = tab.style.maxWidth = wrapper.style.width = draggedTabRect.width + 'px';
|
||||
tab.style.minHeight =
|
||||
tab.style.maxHeight =
|
||||
wrapper.style.height =
|
||||
draggedTabRect.height + 'px';
|
||||
const offsetY = dragData.offsetY;
|
||||
const offsetX = dragData.offsetX;
|
||||
// Apply a transform translate to the tab in order to center it within the drag image
|
||||
|
||||
@@ -112,21 +112,6 @@ export class nsZenSessionManager {
|
||||
}
|
||||
: null,
|
||||
}));
|
||||
rows = await db.execute('SELECT * FROM zen_pins ORDER BY position ASC');
|
||||
data.pins = rows.map((row) => ({
|
||||
uuid: row.getResultByName('uuid'),
|
||||
title: row.getResultByName('title'),
|
||||
url: row.getResultByName('url'),
|
||||
containerTabId: row.getResultByName('container_id'),
|
||||
workspaceUuid: row.getResultByName('workspace_uuid'),
|
||||
position: row.getResultByName('position'),
|
||||
isEssential: Boolean(row.getResultByName('is_essential')),
|
||||
isGroup: Boolean(row.getResultByName('is_group')),
|
||||
parentUuid: row.getResultByName('folder_parent_uuid'),
|
||||
editedTitle: Boolean(row.getResultByName('edited_title')),
|
||||
folderIcon: row.getResultByName('folder_icon'),
|
||||
isFolderCollapsed: Boolean(row.getResultByName('is_folder_collapsed')),
|
||||
}));
|
||||
this._migrationData = data;
|
||||
} catch {
|
||||
/* ignore errors during migration */
|
||||
@@ -160,71 +145,35 @@ export class nsZenSessionManager {
|
||||
* The initial session state read from the session file.
|
||||
*/
|
||||
onFileRead(initialState) {
|
||||
// If there's no initial state, nothing to restore. This would
|
||||
// happen if the file is empty or corrupted.
|
||||
if (!initialState) {
|
||||
this.log('No initial state to restore!');
|
||||
return;
|
||||
}
|
||||
// For the first time after migration, we restore the tabs
|
||||
// That where going to be restored by SessionStore. The sidebar
|
||||
// object will always be empty after migration because we haven't
|
||||
// gotten the opportunity to save the session yet.
|
||||
if (!Services.prefs.getBoolPref(MIGRATION_PREF, false)) {
|
||||
Services.prefs.setBoolPref(MIGRATION_PREF, true);
|
||||
const pins = this._migrationData?.pins || [];
|
||||
const applyTabsToObject = (obj) => {
|
||||
// Lets add pins that don't exist yet in the sidebar object.
|
||||
obj.tabs = obj.tabs || [];
|
||||
obj.folders = obj.folders || [];
|
||||
for (const pin of pins) {
|
||||
let isGroup = pin.isGroup;
|
||||
let object = {
|
||||
pinned: true,
|
||||
...(isGroup
|
||||
? {
|
||||
workspaceId: pin.workspaceUuid,
|
||||
userIcon: pin.folderIcon,
|
||||
name: pin.title,
|
||||
parentId: pin.parentUuid,
|
||||
collapsed: pin.isFolderCollapsed,
|
||||
id: pin.uuid,
|
||||
emptyTabIds: [],
|
||||
}
|
||||
: {
|
||||
zenSyncId: pin.uuid,
|
||||
groupId: pin.parentUuid,
|
||||
entries: [{ url: pin.url, title: pin.title }],
|
||||
zenStaticLabel: pin.editedTitle,
|
||||
zenEssential: pin.isEssential,
|
||||
userContextId: pin.containerTabId || 0,
|
||||
zenWorkspace: pin.workspaceUuid,
|
||||
title: pin.title,
|
||||
}),
|
||||
};
|
||||
let items = isGroup ? obj.folders : obj.tabs;
|
||||
let index = items.findIndex(
|
||||
(tab) =>
|
||||
tab.zenSyncId === pin.uuid || tab.zenPinnedId === pin.uuid || tab.id === pin.uuid
|
||||
);
|
||||
if (index === -1) {
|
||||
// Add to the start of the tabs array to keep the order
|
||||
items.unshift(object);
|
||||
} else {
|
||||
// Update existing tab data
|
||||
items[index] = { ...object, ...items[index] };
|
||||
}
|
||||
}
|
||||
};
|
||||
this.log('Restoring tabs from Places DB after migration');
|
||||
this.#sidebar = {
|
||||
...this.#sidebar,
|
||||
spaces: this._migrationData?.spaces || [],
|
||||
};
|
||||
applyTabsToObject(this.#sidebar);
|
||||
for (const winData of initialState?.windows || []) {
|
||||
winData.spaces = this._migrationData?.spaces || [];
|
||||
applyTabsToObject(winData);
|
||||
if (!initialState.windows?.length) {
|
||||
let normalClosedWindow = initialState._closedWindows?.find(
|
||||
(win) => !win.isPopup && !win.isTaskbarTab && !win.isPrivate
|
||||
);
|
||||
if (normalClosedWindow) {
|
||||
initialState.windows = [normalClosedWindow];
|
||||
this.log('Restoring tabs from last closed normal window');
|
||||
}
|
||||
}
|
||||
for (const winData of initialState.windows || []) {
|
||||
winData.spaces = this._migrationData?.spaces || [];
|
||||
}
|
||||
return;
|
||||
}
|
||||
// If there's no initial state, nothing to restore. This would
|
||||
// happen if the file is empty or corrupted.
|
||||
if (!initialState) {
|
||||
this.log('No initial state to restore!');
|
||||
return;
|
||||
}
|
||||
// If there are no windows, we create an empty one. By default,
|
||||
@@ -233,6 +182,7 @@ export class nsZenSessionManager {
|
||||
// This would happen on first run after having a single private window
|
||||
// open when quitting the app, for example.
|
||||
if (!initialState.windows?.length) {
|
||||
this.log('No windows found in initial state, creating an empty one');
|
||||
initialState.windows = [{}];
|
||||
}
|
||||
// When we don't have browser.startup.page set to resume session,
|
||||
|
||||
@@ -1310,7 +1310,7 @@ export class nsZenThemePicker extends nsZenMultiWindowFeature {
|
||||
}
|
||||
|
||||
getToolbarColor(isDarkMode = false) {
|
||||
return isDarkMode ? [255, 255, 255, 0.6] : [0, 0, 0, 0.5]; // Default toolbar
|
||||
return isDarkMode ? [255, 255, 255, 0.6] : [0, 0, 0, 0.6]; // Default toolbar
|
||||
}
|
||||
|
||||
async onWorkspaceChange(workspace, skipUpdate = false, theme = null) {
|
||||
@@ -1635,7 +1635,6 @@ export class nsZenThemePicker extends nsZenMultiWindowFeature {
|
||||
if (!skipSave) {
|
||||
currentWorkspace.theme = gradient;
|
||||
gZenWorkspaces.saveWorkspace(currentWorkspace);
|
||||
gZenUIManager.showToast('zen-panel-ui-gradient-generator-saved-message');
|
||||
}
|
||||
|
||||
await this.onWorkspaceChange(currentWorkspace, skipSave, skipSave ? gradient : null);
|
||||
|
||||
@@ -823,7 +823,6 @@ class nsZenWorkspaces {
|
||||
if (!this.currentWindowIsSyncing) {
|
||||
this._workspaceCache = this._tempWorkspace ? [this._tempWorkspace] : [];
|
||||
this.#activeWorkspace = this._tempWorkspace?.uuid;
|
||||
return this._workspaceCache;
|
||||
}
|
||||
return [...this._workspaceCache];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user