1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-07 21:49:58 +02:00

chore: [security]: Finish up wrapping event listeners and other small fixes, b=(no-bug), c=configs, common, compact-mode, split-view, tabs, workspaces

This commit is contained in:
mr. m 2025-04-23 00:30:56 +02:00
parent 18b4925dd4
commit 6de445eaa1
No known key found for this signature in database
GPG key ID: 419302196C23B258
11 changed files with 168 additions and 134 deletions

View file

@ -37,7 +37,7 @@ if test "$SURFER_COMPAT" = "x86_64"; then
export RUSTFLAGS="-Clink-args=--icf=safe" export RUSTFLAGS="-Clink-args=--icf=safe"
elif test "$SURFER_COMPAT" = "aarch64"; then elif test "$SURFER_COMPAT" = "aarch64"; then
ac_add_options --target=aarch64-pc-windows-msvc ac_add_options --target=aarch64-pc-windows-msvc
ac_add_options --enable-eme=widevine,wmfcdm ac_add_options --enable-eme=widevine
ac_add_options --enable-optimize="-O2 -mtune=cortex-a55 -march=armv8.2-a+simd" ac_add_options --enable-optimize="-O2 -mtune=cortex-a55 -march=armv8.2-a+simd"

View file

@ -1,5 +1,5 @@
<panel flip="side" type="arrow" orient="vertical" id="PanelUI-zen-gradient-generator" position="bottomright topright" mainview="true" side="left" onpopuphidden="gZenThemePicker.handlePanelClose();" onpopupshowing="gZenThemePicker.handlePanelOpen();"> <panel flip="side" type="arrow" orient="vertical" id="PanelUI-zen-gradient-generator" position="bottomright topright" mainview="true" side="left">
<panelmultiview id="PanelUI-zen-gradient-generator-multiview" mainViewId="PanelUI-zen-gradient-generator-view"> <panelmultiview id="PanelUI-zen-gradient-generator-multiview" mainViewId="PanelUI-zen-gradient-generator-view">
<panelview id="PanelUI-zen-gradient-generator-view" class="PanelUI-subView zen-theme-picker" role="document" mainview-with-header="true" has-custom-header="true"> <panelview id="PanelUI-zen-gradient-generator-view" class="PanelUI-subView zen-theme-picker" role="document" mainview-with-header="true" has-custom-header="true">
<hbox> <hbox>
@ -34,7 +34,7 @@
<hbox id="PanelUI-zen-gradient-colors-wrapper"> <hbox id="PanelUI-zen-gradient-colors-wrapper">
<vbox flex="1"> <vbox flex="1">
<label data-l10n-id="zen-panel-ui-gradient-generator-opacity-text"></label> <label data-l10n-id="zen-panel-ui-gradient-generator-opacity-text"></label>
<html:input type="range" min="0" max="1" value="0.5" step="0.05" oninput="gZenThemePicker.onOpacityChange(event);" id="PanelUI-zen-gradient-generator-opacity" /> <html:input type="range" min="0" max="1" value="0.5" step="0.05" id="PanelUI-zen-gradient-generator-opacity" />
</vbox> </vbox>
<vbox id="PanelUI-zen-gradient-generator-texture-wrapper"> <vbox id="PanelUI-zen-gradient-generator-texture-wrapper">
</vbox> </vbox>
@ -45,7 +45,7 @@
<label data-l10n-id="zen-panel-ui-gradient-generator-custom-color"></label> <label data-l10n-id="zen-panel-ui-gradient-generator-custom-color"></label>
<hbox> <hbox>
<html:input type="text" placeholder="#000000" id="PanelUI-zen-gradient-generator-custom-input" /> <html:input type="text" placeholder="#000000" id="PanelUI-zen-gradient-generator-custom-input" />
<toolbarbutton id="PanelUI-zen-gradient-generator-color-custom-add" class="subviewbutton" oncommand="gZenThemePicker.addCustomColor();" data-l10n-id="zen-panel-ui-gradient-generator-custom-color-add"> <toolbarbutton id="PanelUI-zen-gradient-generator-color-custom-add" class="subviewbutton" data-l10n-id="zen-panel-ui-gradient-generator-custom-color-add">
<image></image> <image></image>
</toolbarbutton> </toolbarbutton>
</hbox> </hbox>
@ -57,16 +57,16 @@
</panelmultiview> </panelmultiview>
</panel> </panel>
<panel flip="slide" type="arrow" orient="vertical" id="PanelUI-zen-workspaces" position="bottomright topright" mainview="true" side="left" onpopuphidden="ZenWorkspaces.handlePanelHidden();"> <panel flip="slide" type="arrow" orient="vertical" id="PanelUI-zen-workspaces" position="bottomright topright" mainview="true" side="left">
<panelmultiview id="PanelUI-zen-workspaces-multiview" mainViewId="PanelUI-zen-workspaces-view"> <panelmultiview id="PanelUI-zen-workspaces-multiview" mainViewId="PanelUI-zen-workspaces-view">
<panelview id="PanelUI-zen-workspaces-view" class="PanelUI-subView" role="document" mainview-with-header="true" has-custom-header="true" closemenu="none"> <panelview id="PanelUI-zen-workspaces-view" class="PanelUI-subView" role="document" mainview-with-header="true" has-custom-header="true" closemenu="none">
<vbox> <vbox>
<hbox> <hbox>
<h3 data-l10n-id="zen-panel-ui-workspaces-text" id="PanelUI-zen-workspaces-header"></h3> <h3 data-l10n-id="zen-panel-ui-workspaces-text" id="PanelUI-zen-workspaces-header"></h3>
<toolbarbutton id="PanelUI-zen-workspaces-reorder-mode" oncommand="ZenWorkspaces.toggleReorderMode();" class="subviewbutton"> <toolbarbutton id="PanelUI-zen-workspaces-reorder-mode" class="subviewbutton">
<image></image> <image></image>
</toolbarbutton> </toolbarbutton>
<toolbarbutton id="PanelUI-zen-workspaces-new" oncommand="ZenWorkspaces.openSaveDialog();" class="subviewbutton"> <toolbarbutton id="PanelUI-zen-workspaces-new" class="subviewbutton">
<image></image> <image></image>
</toolbarbutton> </toolbarbutton>
</hbox> </hbox>
@ -78,14 +78,14 @@
<vbox class="PanelUI-zen-workspaces-user-create"> <vbox class="PanelUI-zen-workspaces-user-create">
<h1 data-l10n-id="zen-panel-ui-workspaces-create-text"></h1> <h1 data-l10n-id="zen-panel-ui-workspaces-create-text"></h1>
<hbox class="PanelUI-zen-workspaces-creation-wraper"> <hbox class="PanelUI-zen-workspaces-creation-wraper">
<hbox class="PanelUI-zen-workspaces-icons-container create" onclick="ZenWorkspaces.onWorkspaceIconContainerClick(event);"></hbox> <hbox class="PanelUI-zen-workspaces-icons-container create"></hbox>
<html:input autofocus="true" id="PanelUI-zen-workspaces-create-input" type="text" placeholder="Enter workspace name" oninput="ZenWorkspaces.onWorkspaceCreationNameChange(this);" /> <html:input autofocus="true" id="PanelUI-zen-workspaces-create-input" type="text" placeholder="Enter workspace name" />
</hbox> </hbox>
</vbox> </vbox>
<html:moz-button-group class="panel-footer" id="PanelUI-zen-workspaces-create-footer"> <html:moz-button-group class="panel-footer" id="PanelUI-zen-workspaces-create-footer">
<button disabled="true" default="true" slot="primary" id="PanelUI-zen-workspaces-create-save" oncommand="ZenWorkspaces.saveWorkspaceFromCreate();" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-create-save"> <button disabled="true" default="true" slot="primary" id="PanelUI-zen-workspaces-create-save" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-create-save">
</button> </button>
<button id="PanelUI-zen-workspaces-create-cancel" oncommand="ZenWorkspaces.closeWorkspacesSubView();" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-create-cancel"> <button id="PanelUI-zen-workspaces-create-cancel" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-create-cancel">
</button> </button>
</html:moz-button-group> </html:moz-button-group>
</panelview> </panelview>
@ -93,43 +93,39 @@
<vbox class="PanelUI-zen-workspaces-user-create"> <vbox class="PanelUI-zen-workspaces-user-create">
<h1 data-l10n-id="zen-panel-ui-workspaces-edit-text"></h1> <h1 data-l10n-id="zen-panel-ui-workspaces-edit-text"></h1>
<hbox class="PanelUI-zen-workspaces-creation-wraper"> <hbox class="PanelUI-zen-workspaces-creation-wraper">
<hbox class="PanelUI-zen-workspaces-icons-container edit" onclick="ZenWorkspaces.onWorkspaceIconContainerClick(event);"></hbox> <hbox class="PanelUI-zen-workspaces-icons-container edit"></hbox>
<html:input autofocus="true" id="PanelUI-zen-workspaces-edit-input" type="text" placeholder="Enter workspace name" oninput="ZenWorkspaces.onWorkspaceEditChange();" /> <html:input autofocus="true" id="PanelUI-zen-workspaces-edit-input" type="text" placeholder="Enter workspace name" />
</hbox> </hbox>
</vbox> </vbox>
<html:moz-button-group class="panel-footer" id="PanelUI-zen-workspaces-edit-footer"> <html:moz-button-group class="panel-footer" id="PanelUI-zen-workspaces-edit-footer">
<button disabled="true" default="true" slot="primary" id="PanelUI-zen-workspaces-edit-save" oncommand="ZenWorkspaces.saveWorkspaceFromEdit();" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-edit-save"> <button disabled="true" default="true" slot="primary" id="PanelUI-zen-workspaces-edit-save" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-edit-save">
</button> </button>
<button id="PanelUI-zen-workspaces-edit-cancel" oncommand="ZenWorkspaces.closeWorkspacesSubView();" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-edit-cancel"> <button id="PanelUI-zen-workspaces-edit-cancel" class="footer-button" data-l10n-id="zen-panel-ui-workspaces-edit-cancel">
</button> </button>
</html:moz-button-group> </html:moz-button-group>
</panelview> </panelview>
<panelview id="PanelUI-zen-workspaces-icon-picker" class="PanelUI-subView" role="document" mainview-with-header="true" has-custom-header="true"> <panelview id="PanelUI-zen-workspaces-icon-picker" class="PanelUI-subView" role="document" mainview-with-header="true" has-custom-header="true">
<vbox id="PanelUI-zen-workspaces-icon-picker-wrapper"> <vbox id="PanelUI-zen-workspaces-icon-picker-wrapper">
<html:div id="PanelUI-zen-workspaces-icon-search-bar"> <html:div id="PanelUI-zen-workspaces-icon-search-bar">
<html:input autofocus="true" type="text" id="PanelUI-zen-workspaces-icon-search-input" oninput="ZenWorkspaces.conductSearch();"/> <html:input autofocus="true" type="text" id="PanelUI-zen-workspaces-icon-search-input"/>
</html:div> </html:div>
</vbox> </vbox>
</panelview> </panelview>
</panelmultiview> </panelmultiview>
</panel> </panel>
<menupopup id="zenWorkspaceActionsMenu" <menupopup id="zenWorkspaceActionsMenu">
onpopupshowing="ZenWorkspaces.updateContextMenu(this);" <menuitem id="context_zenOpenWorkspace" data-l10n-id="zen-workspaces-panel-context-open"/>
onpopuphidden="if (event.target == this) ZenWorkspaces.onContextMenuClose();">
<menuitem id="context_zenOpenWorkspace" oncommand="ZenWorkspaces.openWorkspace();" data-l10n-id="zen-workspaces-panel-context-open"/>
<menuseparator/> <menuseparator/>
<menuitem id="context_zenSetAsDefaultWorkspace" oncommand="ZenWorkspaces.setDefaultWorkspace();" data-l10n-id="zen-workspaces-panel-context-set-default"/> <menuitem id="context_zenEditWorkspace" data-l10n-id="zen-workspaces-panel-context-edit"/>
<menuitem id="context_zenEditWorkspace" oncommand="ZenWorkspaces.contextEdit(event);" data-l10n-id="zen-workspaces-panel-context-edit"/>
<menu id="context_zenWorkspacesOpenInContainerTab" <menu id="context_zenWorkspacesOpenInContainerTab"
data-l10n-id="zen-workspaces-panel-context-open-in-container-tab" data-l10n-id="zen-workspaces-panel-context-open-in-container-tab"
selection-type="single" selection-type="single"
node-type="link" node-type="link"
hide-if-private-browsing="true" hide-if-private-browsing="true"
hide-if-usercontext-disabled="true"> hide-if-usercontext-disabled="true">
<menupopup oncommand="ZenWorkspaces.contextChangeContainerTab(event);" <menupopup />
onpopupshowing="return ZenWorkspaces.createContainerTabMenu(event);" />
</menu> </menu>
<menuseparator/> <menuseparator/>
<menuitem id="context_zenDeleteWorkspace" oncommand="ZenWorkspaces.contextDelete(event);" data-l10n-id="zen-workspaces-panel-context-delete"/> <menuitem id="context_zenDeleteWorkspace" data-l10n-id="zen-workspaces-panel-context-delete"/>
</menupopup> </menupopup>

View file

@ -8,6 +8,6 @@
skipintoolbarset="true" skipintoolbarset="true"
context="toolbar-context-menu" context="toolbar-context-menu"
mode="icons"> mode="icons">
<toolbarbutton removable="true" class="chromeclass-toolbar-additional toolbarbutton-1 zen-sidebar-action-button" id="zen-expand-sidebar-button" data-l10n-id="sidebar-zen-expand" cui-areatype="toolbar" oncommand="gZenVerticalTabsManager.toggleExpand();"></toolbarbutton> <toolbarbutton removable="true" class="chromeclass-toolbar-additional toolbarbutton-1 zen-sidebar-action-button" id="zen-expand-sidebar-button" command="cmd_zenToggleSidebar" data-l10n-id="sidebar-zen-expand" cui-areatype="toolbar"></toolbarbutton>
<toolbarbutton id="zen-workspaces-button" class="chromeclass-toolbar-additional" overflows="false" removable="false"></toolbarbutton> <toolbarbutton id="zen-workspaces-button" class="chromeclass-toolbar-additional" overflows="false" removable="false"></toolbarbutton>
</toolbar> </toolbar>

View file

@ -168,10 +168,6 @@
--menu-image: url('open.svg') !important; --menu-image: url('open.svg') !important;
} }
#context_zenSetAsDefaultWorkspace {
--menu-image: url('bookmark-hollow.svg') !important;
}
#context_zenEditWorkspace, #context_zenEditWorkspace,
#zenToolbarThemePicker { #zenToolbarThemePicker {
--menu-image: url('edit-theme.svg') !important; --menu-image: url('edit-theme.svg') !important;

View file

@ -17,6 +17,15 @@ document.addEventListener(
case 'cmd_zenCompactModeShowSidebar': case 'cmd_zenCompactModeShowSidebar':
gZenCompactModeManager.toggleSidebar(); gZenCompactModeManager.toggleSidebar();
break; break;
case 'cmd_zenCompactModeHideSidebar':
gZenCompactModeManager.hideSidebar();
break;
case 'cmd_zenCompactModeHideToolbar':
gZenCompactModeManager.hideToolbar();
break;
case 'cmd_zenCompactModeHideBoth':
gZenCompactModeManager.hideBoth();
break;
case 'cmd_zenCompactModeShowToolbar': case 'cmd_zenCompactModeShowToolbar':
gZenCompactModeManager.toggleToolbar(); gZenCompactModeManager.toggleToolbar();
break; break;
@ -38,6 +47,9 @@ document.addEventListener(
case 'cmd_zenSplitViewUnsplit': case 'cmd_zenSplitViewUnsplit':
gZenViewSplitter.toggleShortcut('unsplit'); gZenViewSplitter.toggleShortcut('unsplit');
break; break;
case 'cmd_zenSplitViewContextMenu':
gZenViewSplitter.contextSplitTabs();
break;
case 'cmd_zenCopyCurrentURLMarkdown': case 'cmd_zenCopyCurrentURLMarkdown':
gZenCommonActions.copyCurrentURLAsMarkdownToClipboard(); gZenCommonActions.copyCurrentURLAsMarkdownToClipboard();
break; break;

View file

@ -106,11 +106,11 @@ var gZenCompactModeManager = {
const fragment = window.MozXULElement.parseXULToFragment(` const fragment = window.MozXULElement.parseXULToFragment(`
<menu id="zen-context-menu-compact-mode" data-l10n-id="zen-toolbar-context-compact-mode"> <menu id="zen-context-menu-compact-mode" data-l10n-id="zen-toolbar-context-compact-mode">
<menupopup> <menupopup>
<menuitem id="zen-context-menu-compact-mode-toggle" data-l10n-id="zen-toolbar-context-compact-mode-enable" type="checkbox" oncommand="gZenCompactModeManager.toggle();"/> <menuitem id="zen-context-menu-compact-mode-toggle" data-l10n-id="zen-toolbar-context-compact-mode-enable" type="checkbox" command="cmd_zenCompactModeToggle"/>
<menuseparator/> <menuseparator/>
<menuitem id="zen-context-menu-compact-mode-hide-sidebar" data-l10n-id="zen-toolbar-context-compact-mode-just-tabs" type="radio" oncommand="gZenCompactModeManager.hideSidebar();"/> <menuitem id="zen-context-menu-compact-mode-hide-sidebar" data-l10n-id="zen-toolbar-context-compact-mode-just-tabs" type="radio" command="cmd_zenCompactModeHideSidebar"/>
<menuitem id="zen-context-menu-compact-mode-hide-toolbar" data-l10n-id="zen-toolbar-context-compact-mode-just-toolbar" type="radio" oncommand="gZenCompactModeManager.hideToolbar();"/> <menuitem id="zen-context-menu-compact-mode-hide-toolbar" data-l10n-id="zen-toolbar-context-compact-mode-just-toolbar" type="radio" command="cmd_zenCompactModeHideToolbar"/>
<menuitem id="zen-context-menu-compact-mode-hide-both" data-l10n-id="zen-toolbar-context-compact-mode-hide-both" type="radio" oncommand="gZenCompactModeManager.hideBoth();"/> <menuitem id="zen-context-menu-compact-mode-hide-both" data-l10n-id="zen-toolbar-context-compact-mode-hide-both" type="radio" command="cmd_zenCompactModeHideBoth"/>
</menupopup> </menupopup>
</menu> </menu>
`); `);

View file

@ -839,7 +839,7 @@ class ZenViewSplitter extends ZenDOMOperatedFeature {
<menuseparator/> <menuseparator/>
<menuitem id="context_zenSplitTabs" <menuitem id="context_zenSplitTabs"
data-lazy-l10n-id="tab-zen-split-tabs" data-lazy-l10n-id="tab-zen-split-tabs"
oncommand="gZenViewSplitter.contextSplitTabs();"/> command="cmd_zenSplitViewContextMenu"/>
<menuseparator/> <menuseparator/>
`); `);
document.getElementById('context_closeDuplicateTabs').after(element); document.getElementById('context_closeDuplicateTabs').after(element);

View file

@ -1267,10 +1267,16 @@
transform: translateX(-100%); transform: translateX(-100%);
&:not(.zen-essentials-container) { &:not(.zen-essentials-container) {
display: flex;
min-width: calc(100% - var(--zen-toolbox-padding) * 2); min-width: calc(100% - var(--zen-toolbox-padding) * 2);
} }
&:not(.zen-current-workspace-indicator):not(.zen-essentials-container) { &:not(.zen-current-workspace-indicator):not(.zen-essentials-container) {
margin: 0 var(--zen-toolbox-padding); margin: 0 var(--zen-toolbox-padding);
} }
&[hidden='true'] {
opacity: 0;
pointer-events: none;
}
} }

View file

@ -35,6 +35,14 @@
this.onDarkModeChange.bind(this) this.onDarkModeChange.bind(this)
); );
this.panel.addEventListener('popupshowing', this.handlePanelOpen.bind(this));
this.panel.addEventListener('popuphidden', this.handlePanelClose.bind(this));
this.panel.addEventListener('command', this.handlePanelCommand.bind(this));
document
.getElementById('PanelUI-zen-gradient-generator-opacity')
.addEventListener('input', this.onOpacityChange.bind(this));
this.initCanvas(); this.initCanvas();
this.initCustomColorInput(); this.initCustomColorInput();
this.initTextureInput(); this.initTextureInput();
@ -404,6 +412,18 @@
await this.updateCurrentWorkspace(); await this.updateCurrentWorkspace();
} }
handlePanelCommand(event) {
const target = event.target.closest('toolbarbutton');
if (!target) {
return;
}
switch (target.id) {
case 'PanelUI-zen-gradient-generator-color-custom-add':
this.addCustomColor();
break;
}
}
spawnDot(relativePosition, primary = false) { spawnDot(relativePosition, primary = false) {
const dotPad = this.panel.querySelector('.zen-theme-picker-gradient'); const dotPad = this.panel.querySelector('.zen-theme-picker-gradient');

View file

@ -91,6 +91,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', ''); this._activeWorkspace = Services.prefs.getStringPref('zen.workspaces.active', '');
window.addEventListener('resize', this.onWindowResize.bind(this)); window.addEventListener('resize', this.onWindowResize.bind(this));
this.addPopupListeners();
} }
async afterLoadInit() { async afterLoadInit() {
@ -259,7 +260,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
async _createDefaultWorkspaceIfNeeded() { async _createDefaultWorkspaceIfNeeded() {
const workspaces = await this._workspaces(); const workspaces = await this._workspaces();
if (!workspaces.workspaces.length) { if (!workspaces.workspaces.length) {
await this.createAndSaveWorkspace('Default', true, null, true); await this.createAndSaveWorkspace('Space', null, true);
this._workspaceCache = null; this._workspaceCache = null;
} }
} }
@ -889,6 +890,87 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return null; return null;
} }
addPopupListeners() {
const popup = document.getElementById('PanelUI-zen-workspaces');
const contextMenu = document.getElementById('zenWorkspaceActionsMenu');
popup.addEventListener('popuphidden', this.handlePanelHidden.bind(this));
popup.addEventListener('command', this.handlePanelCommand.bind(this));
contextMenu.addEventListener('popuphidden', (event) => {
if (event.target === contextMenu) {
this.onContextMenuClose(event);
}
});
contextMenu.addEventListener('onpopupshowing', this.updateContextMenu.bind(this));
contextMenu.addEventListener('command', this.handleContextMenuCommand.bind(this));
const submenu = document.querySelector('#context_zenWorkspacesOpenInContainerTab > menupopup');
if (submenu) {
submenu.addEventListener('popupshowing', this.createContainerTabMenu.bind(this));
submenu.addEventListener('command', this.contextChangeContainerTab.bind(this));
}
const onWorkspaceIconContainerClick = this.onWorkspaceIconContainerClick.bind(this);
for (const element of document.querySelectorAll('.PanelUI-zen-workspaces-icons-container')) {
element.addEventListener('command', onWorkspaceIconContainerClick);
}
document
.getElementById('PanelUI-zen-workspaces-create-input')
.addEventListener('input', this.onWorkspaceCreationNameChange.bind(this));
document
.getElementById('PanelUI-zen-workspaces-edit-input')
.addEventListener('input', this.onWorkspaceEditChange.bind(this));
document
.getElementById('PanelUI-zen-workspaces-icon-search-input')
.addEventListener('input', this.conductSearch.bind(this));
}
handlePanelCommand(event) {
let target = event.target.closest('toolbarbutton');
target ??= event.target.closest('button');
if (!target) {
return;
}
switch (target.id) {
case 'PanelUI-zen-workspaces-reorder-mode':
this.toggleReorderMode();
break;
case 'PanelUI-zen-workspaces-new':
this.openSaveDialog();
break;
case 'PanelUI-zen-workspaces-create-save':
this.saveWorkspaceFromCreate();
break;
case 'PanelUI-zen-workspaces-edit-cancel':
case 'PanelUI-zen-workspaces-create-cancel':
this.closeWorkspacesSubView();
break;
case 'PanelUI-zen-workspaces-edit-save':
this.saveWorkspaceFromEdit();
break;
}
}
handleContextMenuCommand(event) {
const target = event.target.closest('toolbarbutton');
if (!target) {
return;
}
switch (target.id) {
case 'context_zenOpenWorkspace':
this.openWorkspace();
break;
case 'context_zenEditWorkspace':
this.contextEdit(event);
break;
case 'context_zenDeleteWorkspace':
this.contextDelete(event);
break;
}
}
searchIcons(input, icons) { searchIcons(input, icons) {
input = input.toLowerCase(); input = input.toLowerCase();
@ -1042,11 +1124,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
async getActiveWorkspace() { async getActiveWorkspace() {
const workspaces = await this._workspaces(); const workspaces = await this._workspaces();
return ( return workspaces.workspaces.find((workspace) => workspace.uuid === this.activeWorkspace) ?? workspaces.workspaces[0];
workspaces.workspaces.find((workspace) => workspace.uuid === this.activeWorkspace) ??
workspaces.workspaces.find((workspace) => workspace.default) ??
workspaces.workspaces[0]
);
} }
// Workspaces dialog UI management // Workspaces dialog UI management
@ -1157,9 +1235,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
if (this.isWorkspaceActive(workspace)) { if (this.isWorkspaceActive(workspace)) {
element.setAttribute('active', 'true'); element.setAttribute('active', 'true');
} }
if (workspace.default) {
element.setAttribute('default', 'true');
}
let containerGroup = undefined; let containerGroup = undefined;
try { try {
containerGroup = browser.ContextualIdentityService.getPublicIdentities().find( containerGroup = browser.ContextualIdentityService.getPublicIdentities().find(
@ -1519,11 +1594,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} else { } else {
workspaceButton.removeAttribute('active'); workspaceButton.removeAttribute('active');
} }
if (workspace.default) {
workspaceButton.setAttribute('default', 'true');
} else {
workspaceButton.removeAttribute('default');
}
workspaceButton.addEventListener('click', async (event) => { workspaceButton.addEventListener('click', async (event) => {
if (event.button !== 0) { if (event.button !== 0) {
@ -1641,7 +1711,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this._workspaceCreateInput.value = ''; this._workspaceCreateInput.value = '';
let icon = document.querySelector('#PanelUI-zen-workspaces-icon-picker-wrapper [selected]'); let icon = document.querySelector('#PanelUI-zen-workspaces-icon-picker-wrapper [selected]');
icon?.removeAttribute('selected'); icon?.removeAttribute('selected');
await this.createAndSaveWorkspace(workspaceName, false, icon?.label); await this.createAndSaveWorkspace(workspaceName, icon?.label);
this.goToPreviousSubView(); this.goToPreviousSubView();
} }
@ -1662,7 +1732,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
this.goToPreviousSubView(); this.goToPreviousSubView();
} }
onWorkspaceCreationNameChange(event) { onWorkspaceCreationNameChange() {
let button = document.getElementById('PanelUI-zen-workspaces-create-save'); let button = document.getElementById('PanelUI-zen-workspaces-create-save');
if (this._workspaceCreateInput.value === '') { if (this._workspaceCreateInput.value === '') {
button.setAttribute('disabled', 'true'); button.setAttribute('disabled', 'true');
@ -1767,17 +1837,24 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
_updateMarginTopPinnedTabs(arrowscrollbox, pinnedContainer, essentialContainer, workspaceIndicator) { _updateMarginTopPinnedTabs(arrowscrollbox, pinnedContainer, essentialContainer, workspaceIndicator) {
if (arrowscrollbox && !pinnedContainer.hasAttribute('hidden')) { if (arrowscrollbox) {
const essentialsHeight = essentialContainer.getBoundingClientRect().height; const essentialsHeight = essentialContainer.getBoundingClientRect().height;
pinnedContainer.style.marginTop = essentialsHeight + 'px'; pinnedContainer.style.marginTop = essentialsHeight + 'px';
workspaceIndicator.style.marginTop = essentialsHeight + 'px'; workspaceIndicator.style.marginTop = essentialsHeight + 'px';
const arrowMarginTop = pinnedContainer.getBoundingClientRect().height + essentialsHeight + 'px'; let arrowMarginTop = pinnedContainer.getBoundingClientRect().height;
const isActive = arrowscrollbox.getAttribute('active') === 'true';
if (isActive || !this.containerSpecificEssentials) {
document.getElementById('zen-tabs-wrapper').style.marginTop = essentialsHeight + 'px';
pinnedContainer.style.marginTop = '';
} else {
arrowMarginTop += essentialsHeight;
}
if (!true) { if (!true) {
// TODO: // TODO:
gZenUIManager.motion.animate( gZenUIManager.motion.animate(
arrowscrollbox, arrowscrollbox,
{ {
marginTop: [arrowscrollbox.style.marginTop, arrowMarginTop], marginTop: [arrowscrollbox.style.marginTop, arrowMarginTop + 'px'],
}, },
{ {
type: 'spring', type: 'spring',
@ -1786,7 +1863,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
); );
} else { } else {
arrowscrollbox.style.marginTop = arrowMarginTop; arrowscrollbox.style.marginTop = arrowMarginTop + 'px';
} }
} }
} }
@ -2166,10 +2243,9 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
} }
} }
_createWorkspaceData(name, isDefault, icon, tabs, moveTabs = true) { _createWorkspaceData(name, icon, tabs, moveTabs = true) {
let window = { let window = {
uuid: gZenUIManager.generateUuidv4(), uuid: gZenUIManager.generateUuidv4(),
default: isDefault,
icon: icon, icon: icon,
name: name, name: name,
theme: ZenThemePicker.getTheme([]), theme: ZenThemePicker.getTheme([]),
@ -2184,7 +2260,7 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return window; return window;
} }
async createAndSaveWorkspace(name = 'New Workspace', isDefault = false, icon = undefined, dontChange = false) { async createAndSaveWorkspace(name = 'Space', icon = undefined, dontChange = false) {
if (!this.workspaceEnabled) { if (!this.workspaceEnabled) {
return; return;
} }
@ -2192,7 +2268,7 @@ 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, !dontChange); let workspaceData = this._createWorkspaceData(name, icon, extraTabs, !dontChange);
await this.saveWorkspace(workspaceData, dontChange); await this.saveWorkspace(workspaceData, dontChange);
if (!dontChange) { if (!dontChange) {
this.registerPinnedResizeObserver(); this.registerPinnedResizeObserver();
@ -2369,20 +2445,11 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
.setAttribute('active', 'true'); .setAttribute('active', 'true');
const workspaces = await this._workspaces(); const workspaces = await this._workspaces();
let deleteMenuItem = document.getElementById('context_zenDeleteWorkspace'); let deleteMenuItem = document.getElementById('context_zenDeleteWorkspace');
if ( if (workspaces.workspaces.length <= 1) {
workspaces.workspaces.length <= 1 ||
workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId).default
) {
deleteMenuItem.setAttribute('disabled', 'true'); deleteMenuItem.setAttribute('disabled', 'true');
} else { } else {
deleteMenuItem.removeAttribute('disabled'); deleteMenuItem.removeAttribute('disabled');
} }
let defaultMenuItem = document.getElementById('context_zenSetAsDefaultWorkspace');
if (workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId).default) {
defaultMenuItem.setAttribute('disabled', 'true');
} else {
defaultMenuItem.removeAttribute('disabled');
}
let openMenuItem = document.getElementById('context_zenOpenWorkspace'); let openMenuItem = document.getElementById('context_zenOpenWorkspace');
if ( if (
workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId && this.isWorkspaceActive(workspace)) workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId && this.isWorkspaceActive(workspace))
@ -2424,11 +2491,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
return tab; return tab;
} }
async setDefaultWorkspace() {
await ZenWorkspacesStorage.setDefaultWorkspace(this._contextMenuId);
await this._propagateWorkspaceData();
}
async openWorkspace() { async openWorkspace() {
let workspaces = await this._workspaces(); let workspaces = await this._workspaces();
let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId); let workspace = workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId);

View file

@ -21,7 +21,6 @@ var ZenWorkspacesStorage = {
uuid TEXT UNIQUE NOT NULL, uuid TEXT UNIQUE NOT NULL,
name TEXT NOT NULL, name TEXT NOT NULL,
icon TEXT, icon TEXT,
is_default INTEGER NOT NULL DEFAULT 0,
container_id INTEGER, container_id INTEGER,
position INTEGER NOT NULL DEFAULT 0, position INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL, created_at INTEGER NOT NULL,
@ -111,17 +110,6 @@ var ZenWorkspacesStorage = {
await db.executeTransaction(async () => { await db.executeTransaction(async () => {
const now = Date.now(); const now = Date.now();
// Handle default workspace
if (workspace.default) {
await db.execute(`UPDATE zen_workspaces SET is_default = 0 WHERE uuid != :uuid`, { uuid: workspace.uuid });
const unsetDefaultRows = await db.execute(`SELECT uuid FROM zen_workspaces WHERE is_default = 0 AND uuid != :uuid`, {
uuid: workspace.uuid,
});
for (const row of unsetDefaultRows) {
changedUUIDs.add(row.getResultByName('uuid'));
}
}
let newPosition; let newPosition;
if ('position' in workspace && Number.isFinite(workspace.position)) { if ('position' in workspace && Number.isFinite(workspace.position)) {
newPosition = workspace.position; newPosition = workspace.position;
@ -136,10 +124,10 @@ var ZenWorkspacesStorage = {
await db.executeCached( await db.executeCached(
` `
INSERT OR REPLACE INTO zen_workspaces ( INSERT OR REPLACE INTO zen_workspaces (
uuid, name, icon, is_default, container_id, created_at, updated_at, "position", uuid, name, icon, container_id, created_at, updated_at, "position",
theme_type, theme_colors, theme_opacity, theme_rotation, theme_texture theme_type, theme_colors, theme_opacity, theme_rotation, theme_texture
) VALUES ( ) VALUES (
:uuid, :name, :icon, :is_default, :container_id, :uuid, :name, :icon, :container_id,
COALESCE((SELECT created_at FROM zen_workspaces WHERE uuid = :uuid), :now), COALESCE((SELECT created_at FROM zen_workspaces WHERE uuid = :uuid), :now),
:now, :now,
:position, :position,
@ -150,7 +138,6 @@ var ZenWorkspacesStorage = {
uuid: workspace.uuid, uuid: workspace.uuid,
name: workspace.name, name: workspace.name,
icon: workspace.icon || null, icon: workspace.icon || null,
is_default: workspace.default ? 1 : 0,
container_id: workspace.containerTabId || null, container_id: workspace.containerTabId || null,
now, now,
position: newPosition, position: newPosition,
@ -194,7 +181,6 @@ var ZenWorkspacesStorage = {
uuid: row.getResultByName('uuid'), uuid: row.getResultByName('uuid'),
name: row.getResultByName('name'), name: row.getResultByName('name'),
icon: row.getResultByName('icon'), icon: row.getResultByName('icon'),
default: !!row.getResultByName('is_default'),
containerTabId: row.getResultByName('container_id') ?? 0, containerTabId: row.getResultByName('container_id') ?? 0,
position: row.getResultByName('position'), position: row.getResultByName('position'),
theme: row.getResultByName('theme_type') theme: row.getResultByName('theme_type')
@ -249,50 +235,6 @@ var ZenWorkspacesStorage = {
}); });
}, },
async setDefaultWorkspace(uuid, notifyObservers = true) {
const changedUUIDs = [];
await this.lazy.PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.setDefaultWorkspace', async (db) => {
await db.executeTransaction(async () => {
const now = Date.now();
// Unset the default flag for all other workspaces
await db.execute(`UPDATE zen_workspaces SET is_default = 0 WHERE uuid != :uuid`, { uuid });
// Collect UUIDs of workspaces that were unset as default
const unsetDefaultRows = await db.execute(`SELECT uuid FROM zen_workspaces WHERE is_default = 0 AND uuid != :uuid`, {
uuid,
});
for (const row of unsetDefaultRows) {
changedUUIDs.push(row.getResultByName('uuid'));
}
// Set the default flag for the specified workspace
await db.execute(`UPDATE zen_workspaces SET is_default = 1 WHERE uuid = :uuid`, { uuid });
// Record the change for the specified workspace
await db.execute(
`
INSERT OR REPLACE INTO zen_workspaces_changes (uuid, timestamp)
VALUES (:uuid, :timestamp)
`,
{
uuid,
timestamp: Math.floor(now / 1000),
}
);
// Add the main workspace UUID to the changed set
changedUUIDs.push(uuid);
await this.updateLastChangeTimestamp(db);
});
});
if (notifyObservers) {
this._notifyWorkspacesChanged('zen-workspace-updated', changedUUIDs);
}
},
async markChanged(uuid) { async markChanged(uuid) {
await this.lazy.PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.markChanged', async (db) => { await this.lazy.PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.markChanged', async (db) => {
const now = Date.now(); const now = Date.now();