mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 14:10:00 +02:00
Made the code look cleaner
This commit is contained in:
parent
5822df61e5
commit
76d22a1f15
9 changed files with 429 additions and 410 deletions
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
var gZenOperatingSystemCommonUtils = {
|
var gZenOperatingSystemCommonUtils = {
|
||||||
kZenOSToSmallName: {
|
kZenOSToSmallName: {
|
||||||
WINNT: 'windows',
|
WINNT: 'windows',
|
||||||
|
@ -40,3 +39,9 @@ class ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ZenDOMOperatedFeature {
|
||||||
|
constructor() {
|
||||||
|
window.addEventListener('DOMContentLoaded', this.init.bind(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
|
|
||||||
const lazyCompactMode = {};
|
const lazyCompactMode = {};
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
lazyCompactMode,
|
lazyCompactMode,
|
||||||
"COMPACT_MODE_FLASH_DURATION",
|
'COMPACT_MODE_FLASH_DURATION',
|
||||||
"zen.view.compact.toolbar-flash-popup.duration",
|
'zen.view.compact.toolbar-flash-popup.duration',
|
||||||
800
|
800
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ var gZenCompactModeManager = {
|
||||||
|
|
||||||
get sidebar() {
|
get sidebar() {
|
||||||
if (!this._sidebar) {
|
if (!this._sidebar) {
|
||||||
this._sidebar= document.getElementById('navigator-toolbox');
|
this._sidebar = document.getElementById('navigator-toolbox');
|
||||||
}
|
}
|
||||||
return this._sidebar;
|
return this._sidebar;
|
||||||
},
|
},
|
||||||
|
@ -90,7 +89,8 @@ var gZenCompactModeManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
updateContextMenu() {
|
updateContextMenu() {
|
||||||
document.getElementById('zen-context-menu-compact-mode-toggle')
|
document
|
||||||
|
.getElementById('zen-context-menu-compact-mode-toggle')
|
||||||
.setAttribute('checked', Services.prefs.getBoolPref('zen.view.compact'));
|
.setAttribute('checked', Services.prefs.getBoolPref('zen.view.compact'));
|
||||||
|
|
||||||
const hideTabBar = Services.prefs.getBoolPref('zen.view.compact.hide-tabbar');
|
const hideTabBar = Services.prefs.getBoolPref('zen.view.compact.hide-tabbar');
|
||||||
|
@ -104,14 +104,13 @@ var gZenCompactModeManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
_disableTabsOnHoverIfConflict() {
|
_disableTabsOnHoverIfConflict() {
|
||||||
if (Services.prefs.getBoolPref('zen.view.compact')
|
if (Services.prefs.getBoolPref('zen.view.compact') && Services.prefs.getBoolPref('zen.view.compact.hide-tabbar')) {
|
||||||
&& Services.prefs.getBoolPref('zen.view.compact.hide-tabbar')) {
|
|
||||||
Services.prefs.setBoolPref('zen.view.sidebar-expanded.on-hover', false);
|
Services.prefs.setBoolPref('zen.view.sidebar-expanded.on-hover', false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
return this.preference = !this.prefefence;
|
return (this.preference = !this.prefefence);
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateSidebarIsOnRight() {
|
_updateSidebarIsOnRight() {
|
||||||
|
@ -133,12 +132,12 @@ var gZenCompactModeManager = {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
element: this.sidebar,
|
element: this.sidebar,
|
||||||
screenEdge: this.sidebarIsOnRight ? "right" : "left",
|
screenEdge: this.sidebarIsOnRight ? 'right' : 'left',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
element: document.getElementById('zen-appcontent-navbar-container'),
|
element: document.getElementById('zen-appcontent-navbar-container'),
|
||||||
screenEdge:"top",
|
screenEdge: 'top',
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -181,7 +180,7 @@ var gZenCompactModeManager = {
|
||||||
|
|
||||||
target.addEventListener('mouseleave', (event) => {
|
target.addEventListener('mouseleave', (event) => {
|
||||||
if (this.hoverableElements[i].keepHoverDuration) {
|
if (this.hoverableElements[i].keepHoverDuration) {
|
||||||
this.flashElement(target, keepHoverDuration, "has-hover" + target.id, 'zen-has-hover');
|
this.flashElement(target, keepHoverDuration, 'has-hover' + target.id, 'zen-has-hover');
|
||||||
} else {
|
} else {
|
||||||
this._removeHoverFrames[target.id] = window.requestAnimationFrame(() => target.removeAttribute('zen-has-hover'));
|
this._removeHoverFrames[target.id] = window.requestAnimationFrame(() => target.removeAttribute('zen-has-hover'));
|
||||||
}
|
}
|
||||||
|
@ -194,18 +193,22 @@ var gZenCompactModeManager = {
|
||||||
for (let entry of this.hoverableElements) {
|
for (let entry of this.hoverableElements) {
|
||||||
if (screenEdgeCrossed !== entry.screenEdge) continue;
|
if (screenEdgeCrossed !== entry.screenEdge) continue;
|
||||||
const target = entry.element;
|
const target = entry.element;
|
||||||
const boundAxis = (entry.screenEdge === "right" || entry.screenEdge === "left" ? "y" : "x");
|
const boundAxis = entry.screenEdge === 'right' || entry.screenEdge === 'left' ? 'y' : 'x';
|
||||||
if (!this._positionInBounds(boundAxis, target, event.pageX, event.pageY, 7)) {
|
if (!this._positionInBounds(boundAxis, target, event.pageX, event.pageY, 7)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
window.cancelAnimationFrame(this._removeHoverFrames[target.id]);
|
window.cancelAnimationFrame(this._removeHoverFrames[target.id]);
|
||||||
|
|
||||||
this.flashElement(target, this.hideAfterHoverDuration, "has-hover" + target.id, 'zen-has-hover');
|
this.flashElement(target, this.hideAfterHoverDuration, 'has-hover' + target.id, 'zen-has-hover');
|
||||||
document.addEventListener('mousemove', () => {
|
document.addEventListener(
|
||||||
|
'mousemove',
|
||||||
|
() => {
|
||||||
if (target.matches(':hover')) return;
|
if (target.matches(':hover')) return;
|
||||||
target.removeAttribute('zen-has-hover');
|
target.removeAttribute('zen-has-hover');
|
||||||
this.clearFlashTimeout('has-hover' + target.id);
|
this.clearFlashTimeout('has-hover' + target.id);
|
||||||
}, {once: true});
|
},
|
||||||
|
{ once: true }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -214,15 +217,15 @@ var gZenCompactModeManager = {
|
||||||
const targetBox = element.getBoundingClientRect();
|
const targetBox = element.getBoundingClientRect();
|
||||||
posX = Math.max(targetBox.left, Math.min(posX, targetBox.right));
|
posX = Math.max(targetBox.left, Math.min(posX, targetBox.right));
|
||||||
posY = Math.max(targetBox.top, Math.min(posY, targetBox.bottom));
|
posY = Math.max(targetBox.top, Math.min(posY, targetBox.bottom));
|
||||||
return ["top", "bottom", "left", "right"].find((edge, i) => {
|
return ['top', 'bottom', 'left', 'right'].find((edge, i) => {
|
||||||
const distance = Math.abs((i < 2 ? posY : posX) - targetBox[edge]);
|
const distance = Math.abs((i < 2 ? posY : posX) - targetBox[edge]);
|
||||||
return distance <= maxDistance;
|
return distance <= maxDistance;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_positionInBounds(axis = "x", element, x, y, error = 0) {
|
_positionInBounds(axis = 'x', element, x, y, error = 0) {
|
||||||
const bBox = element.getBoundingClientRect();
|
const bBox = element.getBoundingClientRect();
|
||||||
if (axis === "y") return bBox.top - error < y && y < bBox.bottom + error;
|
if (axis === 'y') return bBox.top - error < y && y < bBox.bottom + error;
|
||||||
else return bBox.left - error < x && x < bBox.right + error;
|
else return bBox.left - error < x && x < bBox.right + error;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const KEYCODE_MAP = {
|
const KEYCODE_MAP = {
|
||||||
F1: 'VK_F1',
|
F1: 'VK_F1',
|
||||||
F2: 'VK_F2',
|
F2: 'VK_F2',
|
||||||
|
@ -26,75 +25,75 @@ const KEYCODE_MAP = {
|
||||||
|
|
||||||
const defaultKeyboardGroups = {
|
const defaultKeyboardGroups = {
|
||||||
windowAndTabManagement: [
|
windowAndTabManagement: [
|
||||||
"zen-window-new-shortcut",
|
'zen-window-new-shortcut',
|
||||||
"zen-tab-new-shortcut",
|
'zen-tab-new-shortcut',
|
||||||
"zen-key-enter-full-screen",
|
'zen-key-enter-full-screen',
|
||||||
"zen-key-exit-full-screen",
|
'zen-key-exit-full-screen',
|
||||||
"zen-quit-app-shortcut",
|
'zen-quit-app-shortcut',
|
||||||
"zen-close-tab-shortcut",
|
'zen-close-tab-shortcut',
|
||||||
"zen-close-shortcut",
|
'zen-close-shortcut',
|
||||||
"id:key_selectTab1",
|
'id:key_selectTab1',
|
||||||
"id:key_selectTab2",
|
'id:key_selectTab2',
|
||||||
"id:key_selectTab3",
|
'id:key_selectTab3',
|
||||||
"id:key_selectTab4",
|
'id:key_selectTab4',
|
||||||
"id:key_selectTab5",
|
'id:key_selectTab5',
|
||||||
"id:key_selectTab6",
|
'id:key_selectTab6',
|
||||||
"id:key_selectTab7",
|
'id:key_selectTab7',
|
||||||
"id:key_selectTab8",
|
'id:key_selectTab8',
|
||||||
"id:key_selectLastTab",
|
'id:key_selectLastTab',
|
||||||
],
|
],
|
||||||
navigation: [
|
navigation: [
|
||||||
"zen-nav-back-shortcut-alt",
|
'zen-nav-back-shortcut-alt',
|
||||||
"zen-nav-fwd-shortcut-alt",
|
'zen-nav-fwd-shortcut-alt',
|
||||||
"zen-nav-reload-shortcut-2",
|
'zen-nav-reload-shortcut-2',
|
||||||
"zen-nav-reload-shortcut-skip-cache",
|
'zen-nav-reload-shortcut-skip-cache',
|
||||||
"zen-nav-reload-shortcut",
|
'zen-nav-reload-shortcut',
|
||||||
"zen-key-stop",
|
'zen-key-stop',
|
||||||
"zen-window-new-shortcut",
|
'zen-window-new-shortcut',
|
||||||
"zen-private-browsing-shortcut",
|
'zen-private-browsing-shortcut',
|
||||||
"id:goHome",
|
'id:goHome',
|
||||||
"id:key_gotoHistory",
|
'id:key_gotoHistory',
|
||||||
"id:goBackKb",
|
'id:goBackKb',
|
||||||
"id:goForwardKb",
|
'id:goForwardKb',
|
||||||
],
|
],
|
||||||
searchAndFind: [
|
searchAndFind: [
|
||||||
"zen-search-focus-shortcut",
|
'zen-search-focus-shortcut',
|
||||||
"zen-search-focus-shortcut-alt",
|
'zen-search-focus-shortcut-alt',
|
||||||
"zen-find-shortcut",
|
'zen-find-shortcut',
|
||||||
"zen-search-find-again-shortcut-2",
|
'zen-search-find-again-shortcut-2',
|
||||||
"zen-search-find-again-shortcut",
|
'zen-search-find-again-shortcut',
|
||||||
"zen-search-find-again-shortcut-prev",
|
'zen-search-find-again-shortcut-prev',
|
||||||
],
|
],
|
||||||
pageOperations: [
|
pageOperations: [
|
||||||
"zen-location-open-shortcut",
|
'zen-location-open-shortcut',
|
||||||
"zen-location-open-shortcut-alt",
|
'zen-location-open-shortcut-alt',
|
||||||
"zen-save-page-shortcut",
|
'zen-save-page-shortcut',
|
||||||
"zen-print-shortcut",
|
'zen-print-shortcut',
|
||||||
"zen-page-source-shortcut",
|
'zen-page-source-shortcut',
|
||||||
"zen-page-info-shortcut",
|
'zen-page-info-shortcut',
|
||||||
"zen-reader-mode-toggle-shortcut-other",
|
'zen-reader-mode-toggle-shortcut-other',
|
||||||
"zen-picture-in-picture-toggle-shortcut"
|
'zen-picture-in-picture-toggle-shortcut',
|
||||||
],
|
],
|
||||||
historyAndBookmarks: [
|
historyAndBookmarks: [
|
||||||
"zen-history-show-all-shortcut",
|
'zen-history-show-all-shortcut',
|
||||||
"zen-bookmark-this-page-shortcut",
|
'zen-bookmark-this-page-shortcut',
|
||||||
"zen-bookmark-show-library-shortcut"
|
'zen-bookmark-show-library-shortcut',
|
||||||
],
|
],
|
||||||
mediaAndDisplay: [
|
mediaAndDisplay: [
|
||||||
"zen-mute-toggle-shortcut",
|
'zen-mute-toggle-shortcut',
|
||||||
"zen-full-zoom-reduce-shortcut",
|
'zen-full-zoom-reduce-shortcut',
|
||||||
"zen-full-zoom-enlarge-shortcut",
|
'zen-full-zoom-enlarge-shortcut',
|
||||||
"zen-full-zoom-reset-shortcut",
|
'zen-full-zoom-reset-shortcut',
|
||||||
"zen-bidi-switch-direction-shortcut",
|
'zen-bidi-switch-direction-shortcut',
|
||||||
"zen-screenshot-shortcut"
|
'zen-screenshot-shortcut',
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const fixedL10nIds = {
|
const fixedL10nIds = {
|
||||||
cmd_findPrevious: 'zen-search-find-again-shortcut-prev',
|
cmd_findPrevious: 'zen-search-find-again-shortcut-prev',
|
||||||
"Browser:ReloadSkipCache": "zen-nav-reload-shortcut-skip-cache",
|
'Browser:ReloadSkipCache': 'zen-nav-reload-shortcut-skip-cache',
|
||||||
cmd_close: "zen-close-tab-shortcut",
|
cmd_close: 'zen-close-tab-shortcut',
|
||||||
"History:RestoreLastClosedTabOrWindowOrSession": "zen-restore-last-closed-tab-shortcut",
|
'History:RestoreLastClosedTabOrWindowOrSession': 'zen-restore-last-closed-tab-shortcut',
|
||||||
};
|
};
|
||||||
|
|
||||||
const ZEN_COMPACT_MODE_SHORTCUTS_GROUP = 'zen-compact-mode';
|
const ZEN_COMPACT_MODE_SHORTCUTS_GROUP = 'zen-compact-mode';
|
||||||
|
@ -106,7 +105,9 @@ const VALID_SHORTCUT_GROUPS = [
|
||||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||||
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
||||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||||
...Object.keys(defaultKeyboardGroups), ZEN_OTHER_SHORTCUTS_GROUP, 'other'
|
...Object.keys(defaultKeyboardGroups),
|
||||||
|
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||||
|
'other',
|
||||||
];
|
];
|
||||||
|
|
||||||
class KeyShortcutModifiers {
|
class KeyShortcutModifiers {
|
||||||
|
@ -159,7 +160,7 @@ class KeyShortcutModifiers {
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to avoid any future changes to the object
|
// used to avoid any future changes to the object
|
||||||
static fromObject({ctrl = false, alt = false, shift = false, meta = false, accel = false}) {
|
static fromObject({ ctrl = false, alt = false, shift = false, meta = false, accel = false }) {
|
||||||
return new KeyShortcutModifiers(ctrl, alt, shift, meta, accel);
|
return new KeyShortcutModifiers(ctrl, alt, shift, meta, accel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,10 +193,9 @@ class KeyShortcutModifiers {
|
||||||
this.#alt == other.#alt &&
|
this.#alt == other.#alt &&
|
||||||
this.#shift == other.#shift &&
|
this.#shift == other.#shift &&
|
||||||
this.#control == other.#control &&
|
this.#control == other.#control &&
|
||||||
(AppConstants.platform == 'macosx' ?
|
(AppConstants.platform == 'macosx'
|
||||||
(this.#meta || this.#accel) == (other.#meta || other.#accel) :
|
? (this.#meta || this.#accel) == (other.#meta || other.#accel)
|
||||||
(this.#meta == other.#meta && this.#accel == other.#accel)
|
: this.#meta == other.#meta && this.#accel == other.#accel)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ class KeyShortcut {
|
||||||
// Find inside defaultKeyboardGroups
|
// Find inside defaultKeyboardGroups
|
||||||
for (let group of Object.keys(defaultKeyboardGroups)) {
|
for (let group of Object.keys(defaultKeyboardGroups)) {
|
||||||
for (let shortcut of defaultKeyboardGroups[group]) {
|
for (let shortcut of defaultKeyboardGroups[group]) {
|
||||||
if (shortcut == l10nId || shortcut == "id:" + id) {
|
if (shortcut == l10nId || shortcut == 'id:' + id) {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -472,12 +472,7 @@ class KeyShortcut {
|
||||||
}
|
}
|
||||||
|
|
||||||
isUserEditable() {
|
isUserEditable() {
|
||||||
if (
|
if (!this.#id || this.#internal || this.#reserved || (this.#group == FIREFOX_SHORTCUTS_GROUP && this.#disabled)) {
|
||||||
!this.#id ||
|
|
||||||
this.#internal ||
|
|
||||||
this.#reserved ||
|
|
||||||
(this.#group == FIREFOX_SHORTCUTS_GROUP && this.#disabled)
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -502,9 +497,7 @@ class KeyShortcut {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ZenKeyboardShortcutsLoader {
|
class ZenKeyboardShortcutsLoader {
|
||||||
|
constructor() {}
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
|
|
||||||
get shortcutsFile() {
|
get shortcutsFile() {
|
||||||
return PathUtils.join(PathUtils.profileDir, 'zen-keyboard-shortcuts.json');
|
return PathUtils.join(PathUtils.profileDir, 'zen-keyboard-shortcuts.json');
|
||||||
|
@ -555,7 +548,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'C',
|
'C',
|
||||||
'',
|
'',
|
||||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenCompactModeManager.toggle()',
|
'code:gZenCompactModeManager.toggle()',
|
||||||
'zen-compact-mode-shortcut-toggle'
|
'zen-compact-mode-shortcut-toggle'
|
||||||
)
|
)
|
||||||
|
@ -566,7 +559,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'S',
|
'S',
|
||||||
'',
|
'',
|
||||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenCompactModeManager.toggleSidebar()',
|
'code:gZenCompactModeManager.toggleSidebar()',
|
||||||
'zen-compact-mode-shortcut-show-sidebar'
|
'zen-compact-mode-shortcut-show-sidebar'
|
||||||
)
|
)
|
||||||
|
@ -577,7 +570,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'T',
|
'T',
|
||||||
'',
|
'',
|
||||||
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
ZEN_COMPACT_MODE_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenCompactModeManager.toggleToolbar()',
|
'code:gZenCompactModeManager.toggleToolbar()',
|
||||||
'zen-compact-mode-shortcut-show-toolbar'
|
'zen-compact-mode-shortcut-show-toolbar'
|
||||||
)
|
)
|
||||||
|
@ -603,7 +596,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'E',
|
'E',
|
||||||
'',
|
'',
|
||||||
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:ZenWorkspaces.changeWorkspaceShortcut()',
|
'code:ZenWorkspaces.changeWorkspaceShortcut()',
|
||||||
'zen-workspace-shortcut-forward'
|
'zen-workspace-shortcut-forward'
|
||||||
)
|
)
|
||||||
|
@ -614,7 +607,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'Q',
|
'Q',
|
||||||
'',
|
'',
|
||||||
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
ZEN_WORKSPACE_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:ZenWorkspaces.changeWorkspaceShortcut(-1)',
|
'code:ZenWorkspaces.changeWorkspaceShortcut(-1)',
|
||||||
'zen-workspace-shortcut-backward'
|
'zen-workspace-shortcut-backward'
|
||||||
)
|
)
|
||||||
|
@ -627,7 +620,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'P',
|
'P',
|
||||||
'',
|
'',
|
||||||
ZEN_OTHER_SHORTCUTS_GROUP,
|
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({alt: true}),
|
KeyShortcutModifiers.fromObject({ alt: true }),
|
||||||
'code:gZenBrowserManagerSidebar.toggle()',
|
'code:gZenBrowserManagerSidebar.toggle()',
|
||||||
'zen-web-panel-shortcut-toggle'
|
'zen-web-panel-shortcut-toggle'
|
||||||
)
|
)
|
||||||
|
@ -638,7 +631,7 @@ function zenGetDefaultShortcuts() {
|
||||||
'B',
|
'B',
|
||||||
'',
|
'',
|
||||||
ZEN_OTHER_SHORTCUTS_GROUP,
|
ZEN_OTHER_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({alt: true}),
|
KeyShortcutModifiers.fromObject({ alt: true }),
|
||||||
'code:gZenVerticalTabsManager.toggleExpand()',
|
'code:gZenVerticalTabsManager.toggleExpand()',
|
||||||
'zen-sidebar-shortcut-toggle'
|
'zen-sidebar-shortcut-toggle'
|
||||||
)
|
)
|
||||||
|
@ -651,8 +644,8 @@ function zenGetDefaultShortcuts() {
|
||||||
'G',
|
'G',
|
||||||
'',
|
'',
|
||||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenViewSplitter.toggleShortcut(\'grid\')',
|
"code:gZenViewSplitter.toggleShortcut('grid')",
|
||||||
'zen-split-view-shortcut-grid'
|
'zen-split-view-shortcut-grid'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -662,8 +655,8 @@ function zenGetDefaultShortcuts() {
|
||||||
'V',
|
'V',
|
||||||
'',
|
'',
|
||||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenViewSplitter.toggleShortcut(\'vsep\')',
|
"code:gZenViewSplitter.toggleShortcut('vsep')",
|
||||||
'zen-split-view-shortcut-vertical'
|
'zen-split-view-shortcut-vertical'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -673,8 +666,8 @@ function zenGetDefaultShortcuts() {
|
||||||
'H',
|
'H',
|
||||||
'',
|
'',
|
||||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenViewSplitter.toggleShortcut(\'hsep\')',
|
"code:gZenViewSplitter.toggleShortcut('hsep')",
|
||||||
'zen-split-view-shortcut-horizontal'
|
'zen-split-view-shortcut-horizontal'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -684,8 +677,8 @@ function zenGetDefaultShortcuts() {
|
||||||
'U',
|
'U',
|
||||||
'',
|
'',
|
||||||
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
ZEN_SPLIT_VIEW_SHORTCUTS_GROUP,
|
||||||
KeyShortcutModifiers.fromObject({accel: true, alt: true}),
|
KeyShortcutModifiers.fromObject({ accel: true, alt: true }),
|
||||||
'code:gZenViewSplitter.toggleShortcut(\'unsplit\')',
|
"code:gZenViewSplitter.toggleShortcut('unsplit')",
|
||||||
'zen-split-view-shortcut-unsplit'
|
'zen-split-view-shortcut-unsplit'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -696,8 +689,7 @@ function zenGetDefaultShortcuts() {
|
||||||
class ZenKeyboardShortcutsVersioner {
|
class ZenKeyboardShortcutsVersioner {
|
||||||
static LATEST_KBS_VERSION = 1;
|
static LATEST_KBS_VERSION = 1;
|
||||||
|
|
||||||
constructor() {
|
constructor() {}
|
||||||
}
|
|
||||||
|
|
||||||
get version() {
|
get version() {
|
||||||
return Services.prefs.getIntPref('zen.keyboard.shortcuts.version', 0);
|
return Services.prefs.getIntPref('zen.keyboard.shortcuts.version', 0);
|
||||||
|
@ -728,7 +720,12 @@ class ZenKeyboardShortcutsVersioner {
|
||||||
|
|
||||||
if (this.isVersionOutdated()) {
|
if (this.isVersionOutdated()) {
|
||||||
const version = this.version;
|
const version = this.version;
|
||||||
console.info('Zen CKS: Migrating shortcuts from version', version, 'to', ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION);
|
console.info(
|
||||||
|
'Zen CKS: Migrating shortcuts from version',
|
||||||
|
version,
|
||||||
|
'to',
|
||||||
|
ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION
|
||||||
|
);
|
||||||
const newData = this.migrate(data, version);
|
const newData = this.migrate(data, version);
|
||||||
this.version = ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
this.version = ZenKeyboardShortcutsVersioner.LATEST_KBS_VERSION;
|
||||||
return newData;
|
return newData;
|
||||||
|
@ -748,7 +745,7 @@ class ZenKeyboardShortcutsVersioner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var gZenKeyboardShortcutsManager = {
|
var ZenKeyboardShortcutsManager = {
|
||||||
loader: new ZenKeyboardShortcutsLoader(),
|
loader: new ZenKeyboardShortcutsLoader(),
|
||||||
async init() {
|
async init() {
|
||||||
if (window.location.href == 'chrome://browser/content/browser.xhtml') {
|
if (window.location.href == 'chrome://browser/content/browser.xhtml') {
|
||||||
|
@ -766,7 +763,7 @@ var gZenKeyboardShortcutsManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async _loadSaved() {
|
async _loadSaved() {
|
||||||
var innerLoad = async() => {
|
var innerLoad = async () => {
|
||||||
let data = await this.loader.load();
|
let data = await this.loader.load();
|
||||||
if (!data || data.length == 0) {
|
if (!data || data.length == 0) {
|
||||||
return zenGetDefaultShortcuts();
|
return zenGetDefaultShortcuts();
|
||||||
|
@ -778,12 +775,10 @@ var gZenKeyboardShortcutsManager = {
|
||||||
console.error('Zen CKS: Error parsing saved shortcuts. Resetting to defaults...', e);
|
console.error('Zen CKS: Error parsing saved shortcuts. Resetting to defaults...', e);
|
||||||
return zenGetDefaultShortcuts();
|
return zenGetDefaultShortcuts();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const loadedShortcuts = await innerLoad();
|
const loadedShortcuts = await innerLoad();
|
||||||
this.versioner = new ZenKeyboardShortcutsVersioner(
|
this.versioner = new ZenKeyboardShortcutsVersioner(loadedShortcuts);
|
||||||
loadedShortcuts,
|
|
||||||
);
|
|
||||||
return loadedShortcuts;
|
return loadedShortcuts;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -881,7 +876,7 @@ var gZenKeyboardShortcutsManager = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetShortcut.getModifiers().equals(modifiers) && targetShortcut.getKeyNameOrCode() == shortcut) {
|
if (targetShortcut.getModifiers().equals(modifiers) && targetShortcut.getKeyNameOrCode() == shortcut) {
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
var gZenBrowserManagerSidebar = {
|
class ZenBrowserManagerSidebar extends ZenDOMOperatedFeature {
|
||||||
_sidebarElement: null,
|
_sidebarElement = null;
|
||||||
_currentPanel: null,
|
_currentPanel = null;
|
||||||
_lastOpenedPanel: null,
|
_lastOpenedPanel = null;
|
||||||
_hasChangedConfig: true,
|
_hasChangedConfig = true;
|
||||||
_splitterElement: null,
|
_splitterElement = null;
|
||||||
_hSplitterElement: null,
|
_hSplitterElement = null;
|
||||||
_hasRegisteredPinnedClickOutside: false,
|
_hasRegisteredPinnedClickOutside = false;
|
||||||
_isDragging: false,
|
_isDragging = false;
|
||||||
contextTab: null,
|
contextTab = null;
|
||||||
sidebar: null,
|
sidebar = null;
|
||||||
forwardButton: null,
|
forwardButton = null;
|
||||||
backButton: null,
|
backButton = null;
|
||||||
progressListener: null,
|
progressListener = null;
|
||||||
|
|
||||||
DEFAULT_MOBILE_USER_AGENT: 'Mozilla/5.0 (Android 12; Mobile; rv:129.0) Gecko/20100101 Firefox/131.0',
|
DEFAULT_MOBILE_USER_AGENT = 'Mozilla/5.0 (Android 12; Mobile; rv:129.0) Gecko/20100101 Firefox/131.0';
|
||||||
MAX_SIDEBAR_PANELS: 9, // +1 for the add panel button
|
MAX_SIDEBAR_PANELS = 9; // +1 for the add panel button
|
||||||
MAX_RUNS: 3,
|
MAX_RUNS = 3;
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
ChromeUtils.defineLazyGetter(this, 'sidebar', () => document.getElementById('zen-sidebar-web-panel'));
|
ChromeUtils.defineLazyGetter(this, 'sidebar', () => document.getElementById('zen-sidebar-web-panel'));
|
||||||
|
@ -30,24 +30,21 @@ var gZenBrowserManagerSidebar = {
|
||||||
this.listenForPrefChanges();
|
this.listenForPrefChanges();
|
||||||
this.insertIntoContextMenu();
|
this.insertIntoContextMenu();
|
||||||
this.addPositioningListeners();
|
this.addPositioningListeners();
|
||||||
},
|
}
|
||||||
|
|
||||||
onlySafeWidthAndHeight() {
|
onlySafeWidthAndHeight() {
|
||||||
const panel = document.getElementById('zen-sidebar-web-panel');
|
const panel = document.getElementById('zen-sidebar-web-panel');
|
||||||
const width = panel.style.width;
|
const width = panel.style.width;
|
||||||
const height = panel.style.height;
|
const height = panel.style.height;
|
||||||
panel.setAttribute('style', "");
|
panel.setAttribute('style', '');
|
||||||
panel.style.width = width;
|
panel.style.width = width;
|
||||||
panel.style.height = height;
|
panel.style.height = height;
|
||||||
},
|
}
|
||||||
|
|
||||||
initProgressListener() {
|
initProgressListener() {
|
||||||
this.progressListener = {
|
this.progressListener = {
|
||||||
QueryInterface: ChromeUtils.generateQI([
|
QueryInterface: ChromeUtils.generateQI(['nsIWebProgressListener', 'nsISupportsWeakReference']),
|
||||||
"nsIWebProgressListener",
|
onLocationChange: function (aWebProgress, aRequest, aLocation, aFlags) {
|
||||||
"nsISupportsWeakReference",
|
|
||||||
]),
|
|
||||||
onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
|
|
||||||
const browser = this._getCurrentBrowser();
|
const browser = this._getCurrentBrowser();
|
||||||
if (!browser) return;
|
if (!browser) return;
|
||||||
const forwardDisabled = this.forwardButton.hasAttribute('disabled');
|
const forwardDisabled = this.forwardButton.hasAttribute('disabled');
|
||||||
|
@ -68,8 +65,8 @@ var gZenBrowserManagerSidebar = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.bind(gZenBrowserManagerSidebar),
|
}.bind(gZenBrowserManagerSidebar),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
get sidebarData() {
|
get sidebarData() {
|
||||||
let services = Services.prefs.getStringPref('zen.sidebar.data');
|
let services = Services.prefs.getStringPref('zen.sidebar.data');
|
||||||
|
@ -77,35 +74,36 @@ var gZenBrowserManagerSidebar = {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return JSON.parse(services);
|
return JSON.parse(services);
|
||||||
},
|
}
|
||||||
|
|
||||||
get shouldCloseOnBlur() {
|
get shouldCloseOnBlur() {
|
||||||
return Services.prefs.getBoolPref('zen.sidebar.close-on-blur');
|
return Services.prefs.getBoolPref('zen.sidebar.close-on-blur');
|
||||||
},
|
}
|
||||||
|
|
||||||
listenForPrefChanges() {
|
listenForPrefChanges() {
|
||||||
Services.prefs.addObserver('zen.sidebar.data', this.handleEvent.bind(this));
|
Services.prefs.addObserver('zen.sidebar.data', this.handleEvent.bind(this));
|
||||||
Services.prefs.addObserver('zen.sidebar.enabled', this.handleEvent.bind(this));
|
Services.prefs.addObserver('zen.sidebar.enabled', this.handleEvent.bind(this));
|
||||||
|
|
||||||
this.handleEvent();
|
this.handleEvent();
|
||||||
},
|
}
|
||||||
|
|
||||||
addPositioningListeners() {
|
addPositioningListeners() {
|
||||||
this.sidebar.querySelectorAll('.zen-sidebar-web-panel-splitter')
|
this.sidebar
|
||||||
.forEach(s => s.addEventListener('mousedown', this.handleSplitterMouseDown.bind(this)));
|
.querySelectorAll('.zen-sidebar-web-panel-splitter')
|
||||||
|
.forEach((s) => s.addEventListener('mousedown', this.handleSplitterMouseDown.bind(this)));
|
||||||
this.sidebarHeader.addEventListener('mousedown', this.handleDragPanel.bind(this));
|
this.sidebarHeader.addEventListener('mousedown', this.handleDragPanel.bind(this));
|
||||||
window.addEventListener('resize', this.onWindowResize.bind(this));
|
window.addEventListener('resize', this.onWindowResize.bind(this));
|
||||||
},
|
}
|
||||||
|
|
||||||
handleSplitterMouseDown(mouseDownEvent) {
|
handleSplitterMouseDown(mouseDownEvent) {
|
||||||
if (this._isDragging) return
|
if (this._isDragging) return;
|
||||||
this._isDragging = true;
|
this._isDragging = true;
|
||||||
|
|
||||||
const isHorizontal = mouseDownEvent.target.getAttribute('orient') === 'horizontal';
|
const isHorizontal = mouseDownEvent.target.getAttribute('orient') === 'horizontal';
|
||||||
setCursor(isHorizontal ? 'n-resize' : 'ew-resize');
|
setCursor(isHorizontal ? 'n-resize' : 'ew-resize');
|
||||||
const reverse = ['left', 'top'].includes(mouseDownEvent.target.getAttribute('side'));
|
const reverse = ['left', 'top'].includes(mouseDownEvent.target.getAttribute('side'));
|
||||||
const direction = isHorizontal ? "height" : "width";
|
const direction = isHorizontal ? 'height' : 'width';
|
||||||
const axis = isHorizontal ? "Y" : "X";
|
const axis = isHorizontal ? 'Y' : 'X';
|
||||||
|
|
||||||
const computedStyle = window.getComputedStyle(this.sidebar);
|
const computedStyle = window.getComputedStyle(this.sidebar);
|
||||||
const maxSize = parseInt(computedStyle.getPropertyValue(`max-${direction}`).match(/(\d+)px/)?.[1]) || Infinity;
|
const maxSize = parseInt(computedStyle.getPropertyValue(`max-${direction}`).match(/(\d+)px/)?.[1]) || Infinity;
|
||||||
|
@ -115,7 +113,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
|
|
||||||
const startPos = mouseDownEvent[`screen${axis}`];
|
const startPos = mouseDownEvent[`screen${axis}`];
|
||||||
|
|
||||||
const toAdjust = isHorizontal ? "top" : "left";
|
const toAdjust = isHorizontal ? 'top' : 'left';
|
||||||
const sidebarPosStart = parseInt(this.sidebar.style[toAdjust].match(/\d+/));
|
const sidebarPosStart = parseInt(this.sidebar.style[toAdjust].match(/\d+/));
|
||||||
|
|
||||||
let mouseMove = function (e) {
|
let mouseMove = function (e) {
|
||||||
|
@ -128,29 +126,33 @@ var gZenBrowserManagerSidebar = {
|
||||||
const wrapperBox = this.sidebarWrapper.getBoundingClientRect();
|
const wrapperBox = this.sidebarWrapper.getBoundingClientRect();
|
||||||
let maxWrapperSize = Infinity;
|
let maxWrapperSize = Infinity;
|
||||||
if (this.isFloating) {
|
if (this.isFloating) {
|
||||||
maxWrapperSize = reverse ? (sidebarPosStart + sidebarSizeStart) : (wrapperBox[direction] - sidebarPosStart);
|
maxWrapperSize = reverse ? sidebarPosStart + sidebarSizeStart : wrapperBox[direction] - sidebarPosStart;
|
||||||
}
|
}
|
||||||
newSize = Math.max(minSize, Math.min(currentMax, maxWrapperSize,newSize));
|
newSize = Math.max(minSize, Math.min(currentMax, maxWrapperSize, newSize));
|
||||||
|
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
const actualMoved = newSize - sidebarSizeStart;
|
const actualMoved = newSize - sidebarSizeStart;
|
||||||
this.sidebar.style[toAdjust] = (sidebarPosStart - actualMoved) + 'px';
|
this.sidebar.style[toAdjust] = sidebarPosStart - actualMoved + 'px';
|
||||||
}
|
}
|
||||||
this.sidebar.style[direction] = `${newSize}px`;
|
this.sidebar.style[direction] = `${newSize}px`;
|
||||||
});
|
});
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
document.addEventListener('mousemove', mouseMove);
|
document.addEventListener('mousemove', mouseMove);
|
||||||
document.addEventListener('mouseup', () => {
|
document.addEventListener(
|
||||||
|
'mouseup',
|
||||||
|
() => {
|
||||||
document.removeEventListener('mousemove', mouseMove);
|
document.removeEventListener('mousemove', mouseMove);
|
||||||
this._isDragging = false;
|
this._isDragging = false;
|
||||||
setCursor('auto');
|
setCursor('auto');
|
||||||
}, {once: true});
|
|
||||||
},
|
},
|
||||||
|
{ once: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
handleDragPanel(mouseDownEvent) {
|
handleDragPanel(mouseDownEvent) {
|
||||||
if (this.sidebarHeaderButtons.find(b => b.contains(mouseDownEvent.target))) {
|
if (this.sidebarHeaderButtons.find((b) => b.contains(mouseDownEvent.target))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._isDragging = true;
|
this._isDragging = true;
|
||||||
|
@ -177,13 +179,16 @@ var gZenBrowserManagerSidebar = {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', moveListener);
|
document.addEventListener('mousemove', moveListener);
|
||||||
document.addEventListener('mouseup', () => {
|
document.addEventListener(
|
||||||
|
'mouseup',
|
||||||
|
() => {
|
||||||
document.removeEventListener('mousemove', moveListener);
|
document.removeEventListener('mousemove', moveListener);
|
||||||
this._isDragging = false;
|
this._isDragging = false;
|
||||||
}, {once: true});
|
|
||||||
},
|
},
|
||||||
|
{ once: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onWindowResize() {
|
onWindowResize() {
|
||||||
if (!this.isFloating) return;
|
if (!this.isFloating) return;
|
||||||
|
@ -193,16 +198,16 @@ var gZenBrowserManagerSidebar = {
|
||||||
const sidebarRect = this.sidebar.getBoundingClientRect();
|
const sidebarRect = this.sidebar.getBoundingClientRect();
|
||||||
|
|
||||||
if (sidebarRect.height < wrapperRect.height && top + sidebarRect.height > wrapperRect.height) {
|
if (sidebarRect.height < wrapperRect.height && top + sidebarRect.height > wrapperRect.height) {
|
||||||
this.sidebar.style.top = (wrapperRect.height - sidebarRect.height) + 'px';
|
this.sidebar.style.top = wrapperRect.height - sidebarRect.height + 'px';
|
||||||
}
|
}
|
||||||
if (sidebarRect.width < wrapperRect.width && left + sidebarRect.width > wrapperRect.width) {
|
if (sidebarRect.width < wrapperRect.width && left + sidebarRect.width > wrapperRect.width) {
|
||||||
this.sidebar.style.left = (wrapperRect.width - sidebarRect.width) + 'px';
|
this.sidebar.style.left = wrapperRect.width - sidebarRect.width + 'px';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
get isFloating() {
|
get isFloating() {
|
||||||
return document.getElementById('zen-sidebar-web-panel').hasAttribute('pinned');
|
return document.getElementById('zen-sidebar-web-panel').hasAttribute('pinned');
|
||||||
},
|
}
|
||||||
|
|
||||||
handleEvent() {
|
handleEvent() {
|
||||||
this._hasChangedConfig = true;
|
this._hasChangedConfig = true;
|
||||||
|
@ -229,7 +234,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
this._closeSidebarPanel();
|
this._closeSidebarPanel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleClickOutside(event) {
|
_handleClickOutside(event) {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
|
@ -248,7 +253,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.close();
|
this.close();
|
||||||
},
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
if (!this._currentPanel) {
|
if (!this._currentPanel) {
|
||||||
|
@ -259,20 +264,20 @@ var gZenBrowserManagerSidebar = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.close();
|
this.close();
|
||||||
},
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
sidebar.removeAttribute('hidden');
|
sidebar.removeAttribute('hidden');
|
||||||
this.update();
|
this.update();
|
||||||
},
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
this._updateWebPanels();
|
this._updateWebPanels();
|
||||||
this._updateSidebarButton();
|
this._updateSidebarButton();
|
||||||
this._updateWebPanel();
|
this._updateWebPanel();
|
||||||
this._updateButtons();
|
this._updateButtons();
|
||||||
},
|
}
|
||||||
|
|
||||||
_updateSidebarButton() {
|
_updateSidebarButton() {
|
||||||
let button = document.getElementById('zen-sidepanel-button');
|
let button = document.getElementById('zen-sidepanel-button');
|
||||||
|
@ -282,7 +287,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
} else {
|
} else {
|
||||||
button.removeAttribute('open');
|
button.removeAttribute('open');
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_updateWebPanels() {
|
_updateWebPanels() {
|
||||||
if (Services.prefs.getBoolPref('zen.sidebar.enabled')) {
|
if (Services.prefs.getBoolPref('zen.sidebar.enabled')) {
|
||||||
|
@ -322,7 +327,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
} else {
|
} else {
|
||||||
addButton.setAttribute('hidden', 'true');
|
addButton.setAttribute('hidden', 'true');
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
async _openAddPanelDialog() {
|
async _openAddPanelDialog() {
|
||||||
let dialogURL = 'chrome://browser/content/places/zenNewWebPanel.xhtml';
|
let dialogURL = 'chrome://browser/content/places/zenNewWebPanel.xhtml';
|
||||||
|
@ -334,26 +339,26 @@ var gZenBrowserManagerSidebar = {
|
||||||
} else {
|
} else {
|
||||||
aParentWindow.openDialog(dialogURL, '', features, {});
|
aParentWindow.openDialog(dialogURL, '', features, {});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_setPinnedToElements() {
|
_setPinnedToElements() {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
sidebar.setAttribute('pinned', 'true');
|
sidebar.setAttribute('pinned', 'true');
|
||||||
document.getElementById('zen-sidebar-web-panel-pinned').setAttribute('pinned', 'true');
|
document.getElementById('zen-sidebar-web-panel-pinned').setAttribute('pinned', 'true');
|
||||||
},
|
}
|
||||||
|
|
||||||
_removePinnedFromElements() {
|
_removePinnedFromElements() {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
sidebar.removeAttribute('pinned');
|
sidebar.removeAttribute('pinned');
|
||||||
document.getElementById('zen-sidebar-web-panel-pinned').removeAttribute('pinned');
|
document.getElementById('zen-sidebar-web-panel-pinned').removeAttribute('pinned');
|
||||||
},
|
}
|
||||||
|
|
||||||
_closeSidebarPanel() {
|
_closeSidebarPanel() {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
sidebar.setAttribute('hidden', 'true');
|
sidebar.setAttribute('hidden', 'true');
|
||||||
this._lastOpenedPanel = this._currentPanel;
|
this._lastOpenedPanel = this._currentPanel;
|
||||||
this._currentPanel = null;
|
this._currentPanel = null;
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleClick(event) {
|
_handleClick(event) {
|
||||||
let target = event.target;
|
let target = event.target;
|
||||||
|
@ -363,7 +368,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
}
|
}
|
||||||
this._currentPanel = panelId;
|
this._currentPanel = panelId;
|
||||||
this._updateWebPanel();
|
this._updateWebPanel();
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleDragStart(event) {
|
_handleDragStart(event) {
|
||||||
this.__dragingElement = event.target;
|
this.__dragingElement = event.target;
|
||||||
|
@ -373,9 +378,9 @@ var gZenBrowserManagerSidebar = {
|
||||||
event.dataTransfer.effectAllowed = 'move';
|
event.dataTransfer.effectAllowed = 'move';
|
||||||
event.dataTransfer.setData('text/html', event.target.innerHTML);
|
event.dataTransfer.setData('text/html', event.target.innerHTML);
|
||||||
event.dataTransfer.setData('text/plain', event.target.id);
|
event.dataTransfer.setData('text/plain', event.target.id);
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleDragOver(event) {},
|
_handleDragOver(event) {}
|
||||||
|
|
||||||
_handleDragEnter(event) {
|
_handleDragEnter(event) {
|
||||||
if (typeof this.__dragingElement === 'undefined') {
|
if (typeof this.__dragingElement === 'undefined') {
|
||||||
|
@ -389,7 +394,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
}
|
}
|
||||||
target.after(this.__dragingElement);
|
target.after(this.__dragingElement);
|
||||||
this.__dragingIndex = elIndex + 1;
|
this.__dragingIndex = elIndex + 1;
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleDragEnd(event) {
|
_handleDragEnd(event) {
|
||||||
event.target.style.opacity = '1';
|
event.target.style.opacity = '1';
|
||||||
|
@ -405,7 +410,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
this._currentPanel = this.__dragingElement.getAttribute('zen-sidebar-id');
|
this._currentPanel = this.__dragingElement.getAttribute('zen-sidebar-id');
|
||||||
this.open();
|
this.open();
|
||||||
this.__dragingElement = undefined;
|
this.__dragingElement = undefined;
|
||||||
},
|
}
|
||||||
|
|
||||||
_createNewPanel(url) {
|
_createNewPanel(url) {
|
||||||
let data = this.sidebarData;
|
let data = this.sidebarData;
|
||||||
|
@ -418,7 +423,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||||
this._currentPanel = newName;
|
this._currentPanel = newName;
|
||||||
this.open();
|
this.open();
|
||||||
},
|
}
|
||||||
|
|
||||||
_updateButtons() {
|
_updateButtons() {
|
||||||
for (let button of this.sidebarElement.querySelectorAll('.zen-sidebar-panel-button')) {
|
for (let button of this.sidebarElement.querySelectorAll('.zen-sidebar-panel-button')) {
|
||||||
|
@ -428,7 +433,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
button.removeAttribute('selected');
|
button.removeAttribute('selected');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_hideAllWebPanels() {
|
_hideAllWebPanels() {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
|
@ -436,11 +441,11 @@ var gZenBrowserManagerSidebar = {
|
||||||
browser.setAttribute('hidden', 'true');
|
browser.setAttribute('hidden', 'true');
|
||||||
browser.docShellIsActive = false;
|
browser.docShellIsActive = false;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
get introductionPanel() {
|
get introductionPanel() {
|
||||||
return document.getElementById('zen-sidebar-introduction-panel');
|
return document.getElementById('zen-sidebar-introduction-panel');
|
||||||
},
|
}
|
||||||
|
|
||||||
_updateWebPanel() {
|
_updateWebPanel() {
|
||||||
this._updateButtons();
|
this._updateButtons();
|
||||||
|
@ -470,7 +475,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
browser.reload();
|
browser.reload();
|
||||||
}
|
}
|
||||||
browser.docShellIsActive = true;
|
browser.docShellIsActive = true;
|
||||||
},
|
}
|
||||||
|
|
||||||
_getWebPanelData(id) {
|
_getWebPanelData(id) {
|
||||||
let data = this.sidebarData;
|
let data = this.sidebarData;
|
||||||
|
@ -482,7 +487,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
id: id,
|
id: id,
|
||||||
...panel,
|
...panel,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
|
|
||||||
_createWebPanelBrowser(data) {
|
_createWebPanelBrowser(data) {
|
||||||
const titleContainer = document.getElementById('zen-sidebar-web-panel-title');
|
const titleContainer = document.getElementById('zen-sidebar-web-panel-title');
|
||||||
|
@ -512,7 +517,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
return browser;
|
return browser;
|
||||||
},
|
}
|
||||||
|
|
||||||
_getWebPanelIcon(url, element) {
|
_getWebPanelIcon(url, element) {
|
||||||
let { preferredURI } = Services.uriFixup.getFixupURIInfo(url);
|
let { preferredURI } = Services.uriFixup.getFixupURIInfo(url);
|
||||||
|
@ -527,50 +532,50 @@ var gZenBrowserManagerSidebar = {
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
_getBrowserById(id) {
|
_getBrowserById(id) {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
return sidebar.querySelector(`browser[zen-sidebar-id="${id}"]`);
|
return sidebar.querySelector(`browser[zen-sidebar-id="${id}"]`);
|
||||||
},
|
}
|
||||||
|
|
||||||
_getCurrentBrowser() {
|
_getCurrentBrowser() {
|
||||||
return this._getBrowserById(this._currentPanel);
|
return this._getBrowserById(this._currentPanel);
|
||||||
},
|
}
|
||||||
|
|
||||||
reload() {
|
reload() {
|
||||||
let browser = this._getCurrentBrowser();
|
let browser = this._getCurrentBrowser();
|
||||||
if (browser) {
|
if (browser) {
|
||||||
browser.reload();
|
browser.reload();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
forward() {
|
forward() {
|
||||||
let browser = this._getCurrentBrowser();
|
let browser = this._getCurrentBrowser();
|
||||||
if (browser) {
|
if (browser) {
|
||||||
browser.goForward();
|
browser.goForward();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
back() {
|
back() {
|
||||||
let browser = this._getCurrentBrowser();
|
let browser = this._getCurrentBrowser();
|
||||||
if (browser) {
|
if (browser) {
|
||||||
browser.goBack();
|
browser.goBack();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
home() {
|
home() {
|
||||||
let browser = this._getCurrentBrowser();
|
let browser = this._getCurrentBrowser();
|
||||||
if (browser) {
|
if (browser) {
|
||||||
browser.gotoIndex();
|
browser.gotoIndex();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this._hideAllWebPanels();
|
this._hideAllWebPanels();
|
||||||
this._closeSidebarPanel();
|
this._closeSidebarPanel();
|
||||||
this._updateSidebarButton();
|
this._updateSidebarButton();
|
||||||
},
|
}
|
||||||
|
|
||||||
togglePinned(elem) {
|
togglePinned(elem) {
|
||||||
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
let sidebar = document.getElementById('zen-sidebar-web-panel');
|
||||||
|
@ -580,49 +585,49 @@ var gZenBrowserManagerSidebar = {
|
||||||
this._setPinnedToElements();
|
this._setPinnedToElements();
|
||||||
}
|
}
|
||||||
this.update();
|
this.update();
|
||||||
},
|
}
|
||||||
|
|
||||||
get sidebarElement() {
|
get sidebarElement() {
|
||||||
if (!this._sidebarElement) {
|
if (!this._sidebarElement) {
|
||||||
this._sidebarElement = document.getElementById('zen-sidebar-panels-sites');
|
this._sidebarElement = document.getElementById('zen-sidebar-panels-sites');
|
||||||
}
|
}
|
||||||
return this._sidebarElement;
|
return this._sidebarElement;
|
||||||
},
|
}
|
||||||
|
|
||||||
get splitterElement() {
|
get splitterElement() {
|
||||||
if (!this._splitterElement) {
|
if (!this._splitterElement) {
|
||||||
this._splitterElement = document.getElementById('zen-sidebar-web-panel-splitter');
|
this._splitterElement = document.getElementById('zen-sidebar-web-panel-splitter');
|
||||||
}
|
}
|
||||||
return this._splitterElement;
|
return this._splitterElement;
|
||||||
},
|
}
|
||||||
|
|
||||||
get hSplitterElement() {
|
get hSplitterElement() {
|
||||||
if (!this._hSplitterElement) {
|
if (!this._hSplitterElement) {
|
||||||
this._hSplitterElement = document.getElementById('zen-sidebar-web-panel-hsplitter');
|
this._hSplitterElement = document.getElementById('zen-sidebar-web-panel-hsplitter');
|
||||||
}
|
}
|
||||||
return this._hSplitterElement;
|
return this._hSplitterElement;
|
||||||
},
|
}
|
||||||
|
|
||||||
get sidebarHeader() {
|
get sidebarHeader() {
|
||||||
if (!this._sidebarHeader) {
|
if (!this._sidebarHeader) {
|
||||||
this._sidebarHeader = document.getElementById('zen-sidebar-web-header');
|
this._sidebarHeader = document.getElementById('zen-sidebar-web-header');
|
||||||
}
|
}
|
||||||
return this._sidebarHeader;
|
return this._sidebarHeader;
|
||||||
},
|
}
|
||||||
|
|
||||||
get sidebarWrapper() {
|
get sidebarWrapper() {
|
||||||
if (!this._sideBarWrapper) {
|
if (!this._sideBarWrapper) {
|
||||||
this._sideBarWrapper = document.getElementById('zen-sidebar-web-panel-wrapper');
|
this._sideBarWrapper = document.getElementById('zen-sidebar-web-panel-wrapper');
|
||||||
}
|
}
|
||||||
return this._sideBarWrapper;
|
return this._sideBarWrapper;
|
||||||
},
|
}
|
||||||
|
|
||||||
get sidebarHeaderButtons() {
|
get sidebarHeaderButtons() {
|
||||||
if (!this._sidebarHeaderButtons) {
|
if (!this._sidebarHeaderButtons) {
|
||||||
this._sidebarHeaderButtons = [...this.sidebarHeader.querySelectorAll('.toolbarbutton-1')];
|
this._sidebarHeaderButtons = [...this.sidebarHeader.querySelectorAll('.toolbarbutton-1')];
|
||||||
}
|
}
|
||||||
return this._sidebarHeaderButtons;
|
return this._sidebarHeaderButtons;
|
||||||
},
|
}
|
||||||
|
|
||||||
// Context menu
|
// Context menu
|
||||||
|
|
||||||
|
@ -656,7 +661,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('context_zenUnloadWebPanel').removeAttribute('disabled');
|
document.getElementById('context_zenUnloadWebPanel').removeAttribute('disabled');
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
contextOpenNewTab() {
|
contextOpenNewTab() {
|
||||||
let browser = this._getBrowserById(this.contextTab);
|
let browser = this._getBrowserById(this.contextTab);
|
||||||
|
@ -665,7 +670,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
let url = browser == null ? panel.url : browser.currentURI.spec;
|
let url = browser == null ? panel.url : browser.currentURI.spec;
|
||||||
gZenUIManager.openAndChangeToTab(url);
|
gZenUIManager.openAndChangeToTab(url);
|
||||||
this.close();
|
this.close();
|
||||||
},
|
}
|
||||||
|
|
||||||
contextToggleMuteAudio() {
|
contextToggleMuteAudio() {
|
||||||
let browser = this._getBrowserById(this.contextTab);
|
let browser = this._getBrowserById(this.contextTab);
|
||||||
|
@ -674,7 +679,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
} else {
|
} else {
|
||||||
browser.mute();
|
browser.mute();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
contextToggleUserAgent() {
|
contextToggleUserAgent() {
|
||||||
let browser = this._getBrowserById(this.contextTab);
|
let browser = this._getBrowserById(this.contextTab);
|
||||||
|
@ -683,7 +688,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
data.data[this.contextTab].ua = !data.data[this.contextTab].ua;
|
data.data[this.contextTab].ua = !data.data[this.contextTab].ua;
|
||||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||||
browser.reload();
|
browser.reload();
|
||||||
},
|
}
|
||||||
|
|
||||||
contextDelete() {
|
contextDelete() {
|
||||||
let data = this.sidebarData;
|
let data = this.sidebarData;
|
||||||
|
@ -698,7 +703,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
this._lastOpenedPanel = null;
|
this._lastOpenedPanel = null;
|
||||||
this.update();
|
this.update();
|
||||||
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
Services.prefs.setStringPref('zen.sidebar.data', JSON.stringify(data));
|
||||||
},
|
}
|
||||||
|
|
||||||
contextUnload() {
|
contextUnload() {
|
||||||
let browser = this._getBrowserById(this.contextTab);
|
let browser = this._getBrowserById(this.contextTab);
|
||||||
|
@ -707,7 +712,7 @@ var gZenBrowserManagerSidebar = {
|
||||||
this._closeSidebarPanel();
|
this._closeSidebarPanel();
|
||||||
this.close();
|
this.close();
|
||||||
this._lastOpenedPanel = null;
|
this._lastOpenedPanel = null;
|
||||||
},
|
}
|
||||||
|
|
||||||
insertIntoContextMenu() {
|
insertIntoContextMenu() {
|
||||||
const sibling = document.getElementById('context-stripOnShareLink');
|
const sibling = document.getElementById('context-stripOnShareLink');
|
||||||
|
@ -717,12 +722,12 @@ var gZenBrowserManagerSidebar = {
|
||||||
menuitem.setAttribute('oncommand', 'gZenBrowserManagerSidebar.addPanelFromContextMenu();');
|
menuitem.setAttribute('oncommand', 'gZenBrowserManagerSidebar.addPanelFromContextMenu();');
|
||||||
menuitem.setAttribute('data-l10n-id', 'zen-web-side-panel-context-add-to-panel');
|
menuitem.setAttribute('data-l10n-id', 'zen-web-side-panel-context-add-to-panel');
|
||||||
sibling.insertAdjacentElement('afterend', menuitem);
|
sibling.insertAdjacentElement('afterend', menuitem);
|
||||||
},
|
}
|
||||||
|
|
||||||
addPanelFromContextMenu() {
|
addPanelFromContextMenu() {
|
||||||
const url = gContextMenu.linkURL || gContextMenu.target.ownerDocument.location.href;
|
const url = gContextMenu.linkURL || gContextMenu.target.ownerDocument.location.href;
|
||||||
this._createNewPanel(url);
|
this._createNewPanel(url);
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
gZenBrowserManagerSidebar.init();
|
window.gZenBrowserManagerSidebar = new ZenBrowserManagerSidebar();
|
||||||
|
|
|
@ -1,52 +1,36 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
const lazy = {};
|
const lazy = {};
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenTabUnloaderEnabled', 'zen.tab-unloader.enabled', false);
|
||||||
lazy,
|
|
||||||
"zenTabUnloaderEnabled",
|
|
||||||
"zen.tab-unloader.enabled",
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenTabUnloaderTimeout', 'zen.tab-unloader.timeout-minutes', 20);
|
||||||
lazy,
|
|
||||||
"zenTabUnloaderTimeout",
|
|
||||||
"zen.tab-unloader.timeout-minutes",
|
|
||||||
20
|
|
||||||
);
|
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenTabUnloaderExcludedUrls', 'zen.tab-unloader.excluded-urls', '');
|
||||||
lazy,
|
|
||||||
"zenTabUnloaderExcludedUrls",
|
|
||||||
"zen.tab-unloader.excluded-urls",
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
const ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS = [
|
const ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS = [
|
||||||
"^about:",
|
'^about:',
|
||||||
"^chrome:",
|
'^chrome:',
|
||||||
"^devtools:",
|
'^devtools:',
|
||||||
"^file:",
|
'^file:',
|
||||||
"^resource:",
|
'^resource:',
|
||||||
"^view-source:",
|
'^view-source:',
|
||||||
"^view-image:",
|
'^view-image:',
|
||||||
];
|
];
|
||||||
|
|
||||||
class ZenTabsObserver {
|
class ZenTabsObserver {
|
||||||
static ALL_EVENTS = [
|
static ALL_EVENTS = [
|
||||||
"TabAttrModified",
|
'TabAttrModified',
|
||||||
"TabPinned",
|
'TabPinned',
|
||||||
"TabUnpinned",
|
'TabUnpinned',
|
||||||
"TabBrowserInserted",
|
'TabBrowserInserted',
|
||||||
"TabBrowserDiscarded",
|
'TabBrowserDiscarded',
|
||||||
"TabShow",
|
'TabShow',
|
||||||
"TabHide",
|
'TabHide',
|
||||||
"TabOpen",
|
'TabOpen',
|
||||||
"TabClose",
|
'TabClose',
|
||||||
"TabSelect",
|
'TabSelect',
|
||||||
"TabMultiSelect",
|
'TabMultiSelect',
|
||||||
]
|
];
|
||||||
|
|
||||||
#listeners = [];
|
#listeners = [];
|
||||||
|
|
||||||
|
@ -59,7 +43,7 @@
|
||||||
for (const event of ZenTabsObserver.ALL_EVENTS) {
|
for (const event of ZenTabsObserver.ALL_EVENTS) {
|
||||||
window.addEventListener(event, eventListener);
|
window.addEventListener(event, eventListener);
|
||||||
}
|
}
|
||||||
window.addEventListener("unload", () => {
|
window.addEventListener('unload', () => {
|
||||||
for (const event of ZenTabsObserver.ALL_EVENTS) {
|
for (const event of ZenTabsObserver.ALL_EVENTS) {
|
||||||
window.removeEventListener(event, eventListener);
|
window.removeEventListener(event, eventListener);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +79,7 @@
|
||||||
get lazyExcludeUrls() {
|
get lazyExcludeUrls() {
|
||||||
return [
|
return [
|
||||||
...ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS,
|
...ZEN_TAB_UNLOADER_DEFAULT_EXCLUDED_URLS,
|
||||||
...lazy.zenTabUnloaderExcludedUrls.split(",").map(url => url.trim())
|
...lazy.zenTabUnloaderExcludedUrls.split(',').map((url) => url.trim()),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +104,7 @@
|
||||||
const excludedUrls = this.lazyExcludeUrls;
|
const excludedUrls = this.lazyExcludeUrls;
|
||||||
if (!this.arraysEqual(this.#excludedUrls, excludedUrls) || !this.#compiledExcludedUrls.length) {
|
if (!this.arraysEqual(this.#excludedUrls, excludedUrls) || !this.#compiledExcludedUrls.length) {
|
||||||
this.#excludedUrls = excludedUrls;
|
this.#excludedUrls = excludedUrls;
|
||||||
this.#compiledExcludedUrls = excludedUrls.map(url => new RegExp(url));
|
this.#compiledExcludedUrls = excludedUrls.map((url) => new RegExp(url));
|
||||||
}
|
}
|
||||||
return this.#compiledExcludedUrls;
|
return this.#compiledExcludedUrls;
|
||||||
}
|
}
|
||||||
|
@ -136,16 +120,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ZenTabUnloader extends ZenDOMOperatedFeature {
|
||||||
|
static ACTIVITY_MODIFIERS = ['muted', 'soundplaying', 'label', 'attention'];
|
||||||
|
|
||||||
class ZenTabUnloader {
|
init() {
|
||||||
static ACTIVITY_MODIFIERS = [
|
|
||||||
"muted",
|
|
||||||
"soundplaying",
|
|
||||||
"label",
|
|
||||||
"attention",
|
|
||||||
]
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
if (!lazy.zenTabUnloaderEnabled) {
|
if (!lazy.zenTabUnloaderEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -158,28 +136,28 @@
|
||||||
onTabEvent(action, event) {
|
onTabEvent(action, event) {
|
||||||
const tab = event.target;
|
const tab = event.target;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "TabPinned":
|
case 'TabPinned':
|
||||||
case "TabUnpinned":
|
case 'TabUnpinned':
|
||||||
case "TabBrowserInserted":
|
case 'TabBrowserInserted':
|
||||||
case "TabBrowserDiscarded":
|
case 'TabBrowserDiscarded':
|
||||||
case "TabShow":
|
case 'TabShow':
|
||||||
case "TabHide":
|
case 'TabHide':
|
||||||
break;
|
break;
|
||||||
case "TabAttrModified":
|
case 'TabAttrModified':
|
||||||
this.handleTabAttrModified(tab, event);
|
this.handleTabAttrModified(tab, event);
|
||||||
break;
|
break;
|
||||||
case "TabOpen":
|
case 'TabOpen':
|
||||||
this.handleTabOpen(tab);
|
this.handleTabOpen(tab);
|
||||||
break;
|
break;
|
||||||
case "TabClose":
|
case 'TabClose':
|
||||||
this.handleTabClose(tab);
|
this.handleTabClose(tab);
|
||||||
break;
|
break;
|
||||||
case "TabSelect":
|
case 'TabSelect':
|
||||||
case "TabMultiSelect":
|
case 'TabMultiSelect':
|
||||||
this.updateTabActivity(tab);
|
this.updateTabActivity(tab);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn("ZenTabUnloader: Unhandled tab event", action);
|
console.warn('ZenTabUnloader: Unhandled tab event', action);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,11 +238,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
canUnloadTab(tab, currentTimestamp, excludedUrls) {
|
canUnloadTab(tab, currentTimestamp, excludedUrls) {
|
||||||
if (tab.pinned || tab.selected || tab.multiselected
|
if (
|
||||||
|| tab.hasAttribute("busy") || tab.hasAttribute("pending")
|
tab.pinned ||
|
||||||
|| !tab.linkedPanel || tab.splitView || tab.attention || tab.soundPlaying
|
tab.selected ||
|
||||||
|| tab.zenIgnoreUnload
|
tab.multiselected ||
|
||||||
|| excludedUrls.some(url => url.test(tab.linkedBrowser.currentURI.spec))) {
|
tab.hasAttribute('busy') ||
|
||||||
|
tab.hasAttribute('pending') ||
|
||||||
|
!tab.linkedPanel ||
|
||||||
|
tab.splitView ||
|
||||||
|
tab.attention ||
|
||||||
|
tab.soundPlaying ||
|
||||||
|
tab.zenIgnoreUnload ||
|
||||||
|
excludedUrls.some((url) => url.test(tab.linkedBrowser.currentURI.spec))
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const lastActivity = tab.lastActivity;
|
const lastActivity = tab.lastActivity;
|
||||||
|
|
|
@ -69,7 +69,9 @@ var ZenThemesCommon = {
|
||||||
return newThemePreferences;
|
return newThemePreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
return preferences.filter(({ disabledOn = [] }) => !disabledOn.includes(gZenOperatingSystemCommonUtils.currentOperatingSystem));
|
return preferences.filter(
|
||||||
|
({ disabledOn = [] }) => !disabledOn.includes(gZenOperatingSystemCommonUtils.currentOperatingSystem)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
throttle(mainFunction, delay) {
|
throttle(mainFunction, delay) {
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
var gZenViewSplitter = new class {
|
class ZenViewSplitter extends ZenDOMOperatedFeature {
|
||||||
constructor() {
|
currentView = -1;
|
||||||
this._data = [];
|
canChangeTabOnHover = false;
|
||||||
this.currentView = -1;
|
|
||||||
this._tabBrowserPanel = null;
|
|
||||||
this.__modifierElement = null;
|
|
||||||
this.__hasSetMenuListener = false;
|
|
||||||
this.canChangeTabOnHover = null;
|
|
||||||
|
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
_data = [];
|
||||||
this,
|
_tabBrowserPanel = null;
|
||||||
"canChangeTabOnHover",
|
__modifierElement = null;
|
||||||
"zen.splitView.change-on-hover",
|
__hasSetMenuListener = false;
|
||||||
false
|
|
||||||
);
|
init() {
|
||||||
|
XPCOMUtils.defineLazyPreferenceGetter(this, 'canChangeTabOnHover', 'zen.splitView.change-on-hover', false);
|
||||||
|
|
||||||
window.addEventListener('TabClose', this.handleTabClose.bind(this));
|
window.addEventListener('TabClose', this.handleTabClose.bind(this));
|
||||||
this.initializeContextMenu();
|
this.initializeContextMenu();
|
||||||
|
@ -326,7 +322,7 @@ var gZenViewSplitter = new class {
|
||||||
this.setTabsDocShellState(splitData.tabs, true);
|
this.setTabsDocShellState(splitData.tabs, true);
|
||||||
this.updateSplitViewButton(false);
|
this.updateSplitViewButton(false);
|
||||||
this.updateGridSizes(splitData);
|
this.updateGridSizes(splitData);
|
||||||
this.applySplitters(splitData.widths.length , splitData.heights.length);
|
this.applySplitters(splitData.widths.length, splitData.heights.length);
|
||||||
this.applyGridSizes();
|
this.applyGridSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,10 +362,10 @@ var gZenViewSplitter = new class {
|
||||||
splitter.setAttribute('gridIdx', gridIdx);
|
splitter.setAttribute('gridIdx', gridIdx);
|
||||||
splitter.style.gridArea = `${orient === 'vertical' ? 'v' : 'h'}Splitter${i}`;
|
splitter.style.gridArea = `${orient === 'vertical' ? 'v' : 'h'}Splitter${i}`;
|
||||||
splitter.addEventListener('mousedown', this.handleSplitterMouseDown);
|
splitter.addEventListener('mousedown', this.handleSplitterMouseDown);
|
||||||
this.tabBrowserPanel.insertAdjacentElement("afterbegin", splitter);
|
this.tabBrowserPanel.insertAdjacentElement('afterbegin', splitter);
|
||||||
}
|
};
|
||||||
for (let i = 1; i <= vSplittersNeeded; i++) {
|
for (let i = 1; i <= vSplittersNeeded; i++) {
|
||||||
insertSplitter(i, 'vertical', Math.floor((i - 1) /nrOfRows) + 1);
|
insertSplitter(i, 'vertical', Math.floor((i - 1) / nrOfRows) + 1);
|
||||||
}
|
}
|
||||||
for (let i = 1; i <= hSplittersNeeded; i++) {
|
for (let i = 1; i <= hSplittersNeeded; i++) {
|
||||||
insertSplitter(i, 'horizontal', i);
|
insertSplitter(i, 'horizontal', i);
|
||||||
|
@ -403,8 +399,8 @@ var gZenViewSplitter = new class {
|
||||||
|
|
||||||
removeSplitters() {
|
removeSplitters() {
|
||||||
[...gZenViewSplitter.tabBrowserPanel.children]
|
[...gZenViewSplitter.tabBrowserPanel.children]
|
||||||
.filter(e => e.classList.contains('zen-split-view-splitter'))
|
.filter((e) => e.classList.contains('zen-split-view-splitter'))
|
||||||
.forEach(s => s.remove());
|
.forEach((s) => s.remove());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -419,10 +415,18 @@ var gZenViewSplitter = new class {
|
||||||
return this.calculateGridAreasForGrid(tabs);
|
return this.calculateGridAreasForGrid(tabs);
|
||||||
}
|
}
|
||||||
if (gridType === 'vsep') {
|
if (gridType === 'vsep') {
|
||||||
return `'${tabs.slice(0, -1).map((_, j) => `tab${j + 1} vSplitter${j + 1}`).join(' ')} tab${tabs.length}'`;
|
return `'${tabs
|
||||||
|
.slice(0, -1)
|
||||||
|
.map((_, j) => `tab${j + 1} vSplitter${j + 1}`)
|
||||||
|
.join(' ')} tab${tabs.length}'`;
|
||||||
}
|
}
|
||||||
if (gridType === 'hsep') {
|
if (gridType === 'hsep') {
|
||||||
return tabs.slice(0, -1).map((_, j) => `'tab${j + 1}' 'hSplitter${j + 1}'`).join(' ') + `'tab${tabs.length}`;
|
return (
|
||||||
|
tabs
|
||||||
|
.slice(0, -1)
|
||||||
|
.map((_, j) => `'tab${j + 1}' 'hSplitter${j + 1}'`)
|
||||||
|
.join(' ') + `'tab${tabs.length}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -510,7 +514,8 @@ var gZenViewSplitter = new class {
|
||||||
const dragFunc = (dEvent) => {
|
const dragFunc = (dEvent) => {
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const movementX = dEvent[clientAxis] - prevPosition;
|
const movementX = dEvent[clientAxis] - prevPosition;
|
||||||
let percentageChange = (movementX / this.tabBrowserPanel.getBoundingClientRect()[isVertical ? 'width' : 'height']) * 100;
|
let percentageChange =
|
||||||
|
(movementX / this.tabBrowserPanel.getBoundingClientRect()[isVertical ? 'width' : 'height']) * 100;
|
||||||
|
|
||||||
const currentSize = splitData[dimension][gridIdx - 1];
|
const currentSize = splitData[dimension][gridIdx - 1];
|
||||||
const neighborSize = splitData[dimension][gridIdx];
|
const neighborSize = splitData[dimension][gridIdx];
|
||||||
|
@ -530,16 +535,16 @@ var gZenViewSplitter = new class {
|
||||||
this.applyGridSizes();
|
this.applyGridSizes();
|
||||||
if (!max) prevPosition = dEvent[clientAxis];
|
if (!max) prevPosition = dEvent[clientAxis];
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
const stopListeners = () => {
|
const stopListeners = () => {
|
||||||
removeEventListener('mousemove', dragFunc);
|
removeEventListener('mousemove', dragFunc);
|
||||||
removeEventListener('mouseup', stopListeners);
|
removeEventListener('mouseup', stopListeners);
|
||||||
setCursor('auto');
|
setCursor('auto');
|
||||||
}
|
};
|
||||||
addEventListener('mousemove', dragFunc);
|
addEventListener('mousemove', dragFunc);
|
||||||
addEventListener('mouseup', stopListeners);
|
addEventListener('mouseup', stopListeners);
|
||||||
setCursor(isVertical ? 'ew-resize' : 'n-resize');
|
setCursor(isVertical ? 'ew-resize' : 'n-resize');
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the grid column and row sizes
|
* Applies the grid column and row sizes
|
||||||
|
@ -549,13 +554,15 @@ var gZenViewSplitter = new class {
|
||||||
const columnGap = 'var(--zen-split-column-gap)';
|
const columnGap = 'var(--zen-split-column-gap)';
|
||||||
const rowGap = 'var(--zen-split-row-gap)';
|
const rowGap = 'var(--zen-split-row-gap)';
|
||||||
|
|
||||||
this.tabBrowserPanel.style.gridTemplateColumns = splitData.widths.slice(0, -1).map(
|
this.tabBrowserPanel.style.gridTemplateColumns = splitData.widths
|
||||||
(w) => `calc(${w}% - ${columnGap} * ${splitData.widths.length - 1}/${splitData.widths.length}) ${columnGap}`
|
.slice(0, -1)
|
||||||
).join(' ');
|
.map((w) => `calc(${w}% - ${columnGap} * ${splitData.widths.length - 1}/${splitData.widths.length}) ${columnGap}`)
|
||||||
|
.join(' ');
|
||||||
|
|
||||||
this.tabBrowserPanel.style.gridTemplateRows = splitData.heights.slice(0, -1).map(
|
this.tabBrowserPanel.style.gridTemplateRows = splitData.heights
|
||||||
(h) => `calc(${h}% - ${rowGap} * ${splitData.heights.length - 1}/${splitData.heights.length}) ${rowGap}`
|
.slice(0, -1)
|
||||||
).join(' ');
|
.map((h) => `calc(${h}% - ${rowGap} * ${splitData.heights.length - 1}/${splitData.heights.length}) ${rowGap}`)
|
||||||
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -740,4 +747,6 @@ var gZenViewSplitter = new class {
|
||||||
: [gBrowser.selectedTab, tabs[nextTabIndex]];
|
: [gBrowser.selectedTab, tabs[nextTabIndex]];
|
||||||
this.splitTabs(selected_tabs, gridType);
|
this.splitTabs(selected_tabs, gridType);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
window.gZenViewSplitter = new ZenViewSplitter();
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
|
var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
|
||||||
/**
|
/**
|
||||||
* Stores workspace IDs and their last selected tabs.
|
* Stores workspace IDs and their last selected tabs.
|
||||||
*/
|
*/
|
||||||
_lastSelectedWorkspaceTabs = {}
|
_lastSelectedWorkspaceTabs = {};
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
if (!this.shouldHaveWorkspaces) {
|
if (!this.shouldHaveWorkspaces) {
|
||||||
|
@ -13,8 +12,8 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
console.info('ZenWorkspaces: Initializing ZenWorkspaces...');
|
console.info('ZenWorkspaces: Initializing ZenWorkspaces...');
|
||||||
XPCOMUtils.defineLazyPreferenceGetter(
|
XPCOMUtils.defineLazyPreferenceGetter(
|
||||||
this,
|
this,
|
||||||
"shouldShowIconStrip",
|
'shouldShowIconStrip',
|
||||||
"zen.workspaces.show-icon-strip",
|
'zen.workspaces.show-icon-strip',
|
||||||
true,
|
true,
|
||||||
this._expandWorkspacesStrip.bind(this)
|
this._expandWorkspacesStrip.bind(this)
|
||||||
);
|
);
|
||||||
|
@ -27,9 +26,11 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
get shouldHaveWorkspaces() {
|
get shouldHaveWorkspaces() {
|
||||||
if (typeof this._shouldHaveWorkspaces === 'undefined') {
|
if (typeof this._shouldHaveWorkspaces === 'undefined') {
|
||||||
let docElement = document.documentElement;
|
let docElement = document.documentElement;
|
||||||
this._shouldHaveWorkspaces = !(docElement.hasAttribute('privatebrowsingmode')
|
this._shouldHaveWorkspaces = !(
|
||||||
|| docElement.getAttribute('chromehidden').includes('toolbar')
|
docElement.hasAttribute('privatebrowsingmode') ||
|
||||||
|| docElement.getAttribute('chromehidden').includes('menubar'));
|
docElement.getAttribute('chromehidden').includes('toolbar') ||
|
||||||
|
docElement.getAttribute('chromehidden').includes('menubar')
|
||||||
|
);
|
||||||
return this._shouldHaveWorkspaces;
|
return this._shouldHaveWorkspaces;
|
||||||
}
|
}
|
||||||
return this._shouldHaveWorkspaces;
|
return this._shouldHaveWorkspaces;
|
||||||
|
@ -45,7 +46,7 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
|
|
||||||
getActiveWorkspaceFromCache() {
|
getActiveWorkspaceFromCache() {
|
||||||
try {
|
try {
|
||||||
const activeWorkspaceId = Services.prefs.getStringPref("zen.workspaces.active", "");
|
const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', '');
|
||||||
return this._workspaceCache.workspaces.find((workspace) => workspace.uuid === activeWorkspaceId);
|
return this._workspaceCache.workspaces.find((workspace) => workspace.uuid === activeWorkspaceId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -56,17 +57,17 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
if (!this._workspaceCache) {
|
if (!this._workspaceCache) {
|
||||||
this._workspaceCache = { workspaces: await ZenWorkspacesStorage.getWorkspaces() };
|
this._workspaceCache = { workspaces: await ZenWorkspacesStorage.getWorkspaces() };
|
||||||
// Get the active workspace ID from preferences
|
// Get the active workspace ID from preferences
|
||||||
const activeWorkspaceId = Services.prefs.getStringPref("zen.workspaces.active", "");
|
const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', '');
|
||||||
|
|
||||||
if (activeWorkspaceId) {
|
if (activeWorkspaceId) {
|
||||||
const activeWorkspace = this._workspaceCache.workspaces.find(w => w.uuid === activeWorkspaceId);
|
const activeWorkspace = this._workspaceCache.workspaces.find((w) => w.uuid === activeWorkspaceId);
|
||||||
// Set the active workspace ID to the first one if the one with selected id doesn't exist
|
// Set the active workspace ID to the first one if the one with selected id doesn't exist
|
||||||
if (!activeWorkspace) {
|
if (!activeWorkspace) {
|
||||||
Services.prefs.setStringPref("zen.workspaces.active", this._workspaceCache.workspaces[0]?.uuid);
|
Services.prefs.setStringPref('zen.workspaces.active', this._workspaceCache.workspaces[0]?.uuid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Set the active workspace ID to the first one if active workspace doesn't exist
|
// Set the active workspace ID to the first one if active workspace doesn't exist
|
||||||
Services.prefs.setStringPref("zen.workspaces.active", this._workspaceCache.workspaces[0]?.uuid);
|
Services.prefs.setStringPref('zen.workspaces.active', this._workspaceCache.workspaces[0]?.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this._workspaceCache;
|
return this._workspaceCache;
|
||||||
|
@ -101,11 +102,11 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
let activeWorkspace = await this.getActiveWorkspace();
|
let activeWorkspace = await this.getActiveWorkspace();
|
||||||
if (!activeWorkspace) {
|
if (!activeWorkspace) {
|
||||||
activeWorkspace = workspaces.workspaces.find((workspace) => workspace.default);
|
activeWorkspace = workspaces.workspaces.find((workspace) => workspace.default);
|
||||||
Services.prefs.setStringPref("zen.workspaces.active", activeWorkspace.uuid);
|
Services.prefs.setStringPref('zen.workspaces.active', activeWorkspace.uuid);
|
||||||
}
|
}
|
||||||
if (!activeWorkspace) {
|
if (!activeWorkspace) {
|
||||||
activeWorkspace = workspaces.workspaces[0];
|
activeWorkspace = workspaces.workspaces[0];
|
||||||
Services.prefs.setStringPref("zen.workspaces.active", activeWorkspace.uuid);
|
Services.prefs.setStringPref('zen.workspaces.active', activeWorkspace.uuid);
|
||||||
}
|
}
|
||||||
this.changeWorkspace(activeWorkspace, true);
|
this.changeWorkspace(activeWorkspace, true);
|
||||||
}
|
}
|
||||||
|
@ -129,9 +130,9 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_kIcons = JSON.parse(Services.prefs.getStringPref("zen.workspaces.icons")).map((icon) => (
|
_kIcons = JSON.parse(Services.prefs.getStringPref('zen.workspaces.icons')).map((icon) =>
|
||||||
(typeof Intl.Segmenter !== 'undefined') ? new Intl.Segmenter().segment(icon).containing().segment : Array.from(icon)[0]
|
typeof Intl.Segmenter !== 'undefined' ? new Intl.Segmenter().segment(icon).containing().segment : Array.from(icon)[0]
|
||||||
))
|
);
|
||||||
|
|
||||||
_initializeWorkspaceCreationIcons() {
|
_initializeWorkspaceCreationIcons() {
|
||||||
let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container');
|
let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container');
|
||||||
|
@ -192,14 +193,14 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
isWorkspaceActive(workspace) {
|
isWorkspaceActive(workspace) {
|
||||||
const activeWorkspaceId = Services.prefs.getStringPref("zen.workspaces.active", "");
|
const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', '');
|
||||||
return workspace.uuid === activeWorkspaceId;
|
return workspace.uuid === activeWorkspaceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getActiveWorkspace() {
|
async getActiveWorkspace() {
|
||||||
const workspaces = await this._workspaces();
|
const workspaces = await this._workspaces();
|
||||||
const activeWorkspaceId = Services.prefs.getStringPref("zen.workspaces.active", "");
|
const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', '');
|
||||||
return workspaces.workspaces.find(workspace => workspace.uuid === activeWorkspaceId);
|
return workspaces.workspaces.find((workspace) => workspace.uuid === activeWorkspaceId);
|
||||||
}
|
}
|
||||||
// Workspaces dialog UI management
|
// Workspaces dialog UI management
|
||||||
|
|
||||||
|
@ -248,13 +249,12 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
get shouldShowContainers() {
|
get shouldShowContainers() {
|
||||||
return Services.prefs.getBoolPref('privacy.userContext.ui.enabled') &&
|
return (
|
||||||
ContextualIdentityService.getPublicIdentities().length > 0;
|
Services.prefs.getBoolPref('privacy.userContext.ui.enabled') && ContextualIdentityService.getPublicIdentities().length > 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _propagateWorkspaceData({
|
async _propagateWorkspaceData({ ignoreStrip = false } = {}) {
|
||||||
ignoreStrip = false
|
|
||||||
} = {}) {
|
|
||||||
await this.foreachWindowAsActive(async (browser) => {
|
await this.foreachWindowAsActive(async (browser) => {
|
||||||
let currentContainer = browser.document.getElementById('PanelUI-zen-workspaces-current-info');
|
let currentContainer = browser.document.getElementById('PanelUI-zen-workspaces-current-info');
|
||||||
let workspaceList = browser.document.getElementById('PanelUI-zen-workspaces-list');
|
let workspaceList = browser.document.getElementById('PanelUI-zen-workspaces-list');
|
||||||
|
@ -301,7 +301,9 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
|
|
||||||
childs.querySelector('.zen-workspace-actions').addEventListener('command', (event) => {
|
childs.querySelector('.zen-workspace-actions').addEventListener('command', (event) => {
|
||||||
let button = event.target;
|
let button = event.target;
|
||||||
browser.ZenWorkspaces._contextMenuId = button.closest('toolbarbutton[zen-workspace-id]').getAttribute('zen-workspace-id');
|
browser.ZenWorkspaces._contextMenuId = button
|
||||||
|
.closest('toolbarbutton[zen-workspace-id]')
|
||||||
|
.getAttribute('zen-workspace-id');
|
||||||
const popup = button.ownerDocument.getElementById('zenWorkspaceActionsMenu');
|
const popup = button.ownerDocument.getElementById('zenWorkspaceActionsMenu');
|
||||||
popup.openPopup(button, 'after_end');
|
popup.openPopup(button, 'after_end');
|
||||||
});
|
});
|
||||||
|
@ -353,7 +355,7 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
let target = document.getElementById('zen-workspaces-button');
|
let target = document.getElementById('zen-workspaces-button');
|
||||||
let panel = document.getElementById('PanelUI-zen-workspaces');
|
let panel = document.getElementById('PanelUI-zen-workspaces');
|
||||||
await this._propagateWorkspaceData({
|
await this._propagateWorkspaceData({
|
||||||
ignoreStrip: true
|
ignoreStrip: true,
|
||||||
});
|
});
|
||||||
PanelMultiView.openPopup(panel, target, {
|
PanelMultiView.openPopup(panel, target, {
|
||||||
position: 'bottomright topright',
|
position: 'bottomright topright',
|
||||||
|
@ -407,10 +409,13 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
newWorkspacesButton.appendChild(button);
|
newWorkspacesButton.appendChild(button);
|
||||||
}
|
}
|
||||||
// Listen for context menu events and open the all workspaces dialog
|
// Listen for context menu events and open the all workspaces dialog
|
||||||
newWorkspacesButton.addEventListener('contextmenu', ((event) => {
|
newWorkspacesButton.addEventListener(
|
||||||
|
'contextmenu',
|
||||||
|
((event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
browser.ZenWorkspaces.openWorkspacesDialog(event);
|
browser.ZenWorkspaces.openWorkspacesDialog(event);
|
||||||
}).bind(this));
|
}).bind(this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
workspaceList.after(newWorkspacesButton);
|
workspaceList.after(newWorkspacesButton);
|
||||||
|
@ -440,7 +445,6 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
icon.className = 'zen-workspace-sidebar-icon';
|
icon.className = 'zen-workspace-sidebar-icon';
|
||||||
icon.textContent = this.getWorkspaceIcon(activeWorkspace);
|
icon.textContent = this.getWorkspaceIcon(activeWorkspace);
|
||||||
|
|
||||||
|
|
||||||
// use text content instead of innerHTML to avoid XSS
|
// use text content instead of innerHTML to avoid XSS
|
||||||
const name = browser.document.createElement('div');
|
const name = browser.document.createElement('div');
|
||||||
name.className = 'zen-workspace-sidebar-name';
|
name.className = 'zen-workspace-sidebar-name';
|
||||||
|
@ -571,7 +575,7 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Services.prefs.setStringPref("zen.workspaces.active", window.uuid);
|
Services.prefs.setStringPref('zen.workspaces.active', window.uuid);
|
||||||
|
|
||||||
const shouldAllowPinnedTabs = this._shouldAllowPinTab;
|
const shouldAllowPinnedTabs = this._shouldAllowPinTab;
|
||||||
await this.foreachWindowAsActive(async (browser) => {
|
await this.foreachWindowAsActive(async (browser) => {
|
||||||
|
@ -579,7 +583,10 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
let firstTab = undefined;
|
let firstTab = undefined;
|
||||||
console.info('ZenWorkspaces: Changing workspace to', window.uuid);
|
console.info('ZenWorkspaces: Changing workspace to', window.uuid);
|
||||||
for (let tab of browser.gBrowser.tabs) {
|
for (let tab of browser.gBrowser.tabs) {
|
||||||
if ((tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) || !tab.hasAttribute('zen-workspace-id')) {
|
if (
|
||||||
|
(tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) ||
|
||||||
|
!tab.hasAttribute('zen-workspace-id')
|
||||||
|
) {
|
||||||
if (!firstTab) {
|
if (!firstTab) {
|
||||||
firstTab = tab;
|
firstTab = tab;
|
||||||
} else if (browser.gBrowser.selectedTab === tab) {
|
} else if (browser.gBrowser.selectedTab === tab) {
|
||||||
|
@ -689,7 +696,7 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
|
|
||||||
// Context menu management
|
// Context menu management
|
||||||
|
|
||||||
_contextMenuId = null
|
_contextMenuId = null;
|
||||||
async updateContextMenu(_) {
|
async updateContextMenu(_) {
|
||||||
console.assert(this._contextMenuId, 'No context menu ID set');
|
console.assert(this._contextMenuId, 'No context menu ID set');
|
||||||
document
|
document
|
||||||
|
@ -712,7 +719,9 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
defaultMenuItem.removeAttribute('disabled');
|
defaultMenuItem.removeAttribute('disabled');
|
||||||
}
|
}
|
||||||
let openMenuItem = document.getElementById('context_zenOpenWorkspace');
|
let openMenuItem = document.getElementById('context_zenOpenWorkspace');
|
||||||
if (workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId && this.isWorkspaceActive(workspace))) {
|
if (
|
||||||
|
workspaces.workspaces.find((workspace) => workspace.uuid === this._contextMenuId && this.isWorkspaceActive(workspace))
|
||||||
|
) {
|
||||||
openMenuItem.setAttribute('disabled', 'true');
|
openMenuItem.setAttribute('disabled', 'true');
|
||||||
} else {
|
} else {
|
||||||
openMenuItem.removeAttribute('disabled');
|
openMenuItem.removeAttribute('disabled');
|
||||||
|
@ -774,7 +783,8 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
let activeWorkspace = await this.getActiveWorkspace();
|
let activeWorkspace = await this.getActiveWorkspace();
|
||||||
let workspaceIndex = workspaces.workspaces.indexOf(activeWorkspace);
|
let workspaceIndex = workspaces.workspaces.indexOf(activeWorkspace);
|
||||||
// note: offset can be negative
|
// note: offset can be negative
|
||||||
let nextWorkspace = workspaces.workspaces[(workspaceIndex + offset + workspaces.workspaces.length) % workspaces.workspaces.length];
|
let nextWorkspace =
|
||||||
|
workspaces.workspaces[(workspaceIndex + offset + workspaces.workspaces.length) % workspaces.workspaces.length];
|
||||||
await this.changeWorkspace(nextWorkspace);
|
await this.changeWorkspace(nextWorkspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,8 +832,7 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
getContextIdIfNeeded(userContextId) {
|
getContextIdIfNeeded(userContextId) {
|
||||||
const activeWorkspace = this.getActiveWorkspaceFromCache();
|
const activeWorkspace = this.getActiveWorkspaceFromCache();
|
||||||
const activeWorkspaceUserContextId = activeWorkspace?.containerTabId;
|
const activeWorkspaceUserContextId = activeWorkspace?.containerTabId;
|
||||||
if ((typeof userContextId !== 'undefined' && userContextId !== activeWorkspaceUserContextId)
|
if ((typeof userContextId !== 'undefined' && userContextId !== activeWorkspaceUserContextId) || !this.workspaceEnabled) {
|
||||||
|| !this.workspaceEnabled) {
|
|
||||||
return [userContextId, false];
|
return [userContextId, false];
|
||||||
}
|
}
|
||||||
return [activeWorkspaceUserContextId, true];
|
return [activeWorkspaceUserContextId, true];
|
||||||
|
@ -838,5 +847,4 @@ var ZenWorkspaces = new class extends ZenMultiWindowFeature {
|
||||||
const workspaceToSwitch = workspaces.workspaces[index];
|
const workspaceToSwitch = workspaces.workspaces[index];
|
||||||
await this.changeWorkspace(workspaceToSwitch);
|
await this.changeWorkspace(workspaceToSwitch);
|
||||||
}
|
}
|
||||||
};
|
})();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ var ZenWorkspacesStorage = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async _ensureTable() {
|
async _ensureTable() {
|
||||||
await PlacesUtils.withConnectionWrapper("ZenWorkspacesStorage._ensureTable", async db => {
|
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage._ensureTable', async (db) => {
|
||||||
await db.execute(`
|
await db.execute(`
|
||||||
CREATE TABLE IF NOT EXISTS zen_workspaces (
|
CREATE TABLE IF NOT EXISTS zen_workspaces (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
|
@ -37,9 +37,10 @@ var ZenWorkspacesStorage = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveWorkspace(workspace) {
|
async saveWorkspace(workspace) {
|
||||||
await PlacesUtils.withConnectionWrapper("ZenWorkspacesStorage.saveWorkspace", async db => {
|
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.saveWorkspace', async (db) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
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
|
uuid, name, icon, is_default, container_id, created_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
|
@ -47,14 +48,16 @@ var ZenWorkspacesStorage = {
|
||||||
COALESCE((SELECT created_at FROM zen_workspaces WHERE uuid = :uuid), :now),
|
COALESCE((SELECT created_at FROM zen_workspaces WHERE uuid = :uuid), :now),
|
||||||
:now
|
:now
|
||||||
)
|
)
|
||||||
`, {
|
`,
|
||||||
|
{
|
||||||
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,
|
is_default: workspace.default ? 1 : 0,
|
||||||
container_id: workspace.containerTabId || null,
|
container_id: workspace.containerTabId || null,
|
||||||
now
|
now,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -63,29 +66,32 @@ var ZenWorkspacesStorage = {
|
||||||
const rows = await db.execute(`
|
const rows = await db.execute(`
|
||||||
SELECT * FROM zen_workspaces ORDER BY created_at ASC
|
SELECT * FROM zen_workspaces ORDER BY created_at ASC
|
||||||
`);
|
`);
|
||||||
return rows.map(row => ({
|
return rows.map((row) => ({
|
||||||
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"),
|
default: !!row.getResultByName('is_default'),
|
||||||
containerTabId: row.getResultByName("container_id")
|
containerTabId: row.getResultByName('container_id'),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
async removeWorkspace(uuid) {
|
async removeWorkspace(uuid) {
|
||||||
await PlacesUtils.withConnectionWrapper("ZenWorkspacesStorage.removeWorkspace", async db => {
|
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.removeWorkspace', async (db) => {
|
||||||
await db.execute(`
|
await db.execute(
|
||||||
|
`
|
||||||
DELETE FROM zen_workspaces WHERE uuid = :uuid
|
DELETE FROM zen_workspaces WHERE uuid = :uuid
|
||||||
`, { uuid });
|
`,
|
||||||
|
{ uuid }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async setDefaultWorkspace(uuid) {
|
async setDefaultWorkspace(uuid) {
|
||||||
await PlacesUtils.withConnectionWrapper("ZenWorkspacesStorage.setDefaultWorkspace", async db => {
|
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.setDefaultWorkspace', async (db) => {
|
||||||
await db.executeTransaction(async function() {
|
await db.executeTransaction(async function () {
|
||||||
await db.execute(`UPDATE zen_workspaces SET is_default = 0`);
|
await db.execute(`UPDATE zen_workspaces SET is_default = 0`);
|
||||||
await db.execute(`UPDATE zen_workspaces SET is_default = 1 WHERE uuid = :uuid`, { uuid });
|
await db.execute(`UPDATE zen_workspaces SET is_default = 1 WHERE uuid = :uuid`, { uuid });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue