mirror of
https://github.com/zen-browser/desktop.git
synced 2025-10-06 01:46:35 +00:00
Refactor CSS and JavaScript files for consistency; clean up whitespace and formatting
This commit is contained in:
@@ -7,9 +7,19 @@
|
||||
#listeners = [];
|
||||
|
||||
constructor() {
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabRestorePinnedTabsToPinnedUrl', 'zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url', false);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(lazy, 'zenPinnedTabCloseShortcutBehavior', 'zen.pinned-tab-manager.close-shortcut-behavior', 'switch');
|
||||
ChromeUtils.defineESModuleGetters(lazy, {E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs"});
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
lazy,
|
||||
'zenPinnedTabRestorePinnedTabsToPinnedUrl',
|
||||
'zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url',
|
||||
false
|
||||
);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
lazy,
|
||||
'zenPinnedTabCloseShortcutBehavior',
|
||||
'zen.pinned-tab-manager.close-shortcut-behavior',
|
||||
'switch'
|
||||
);
|
||||
ChromeUtils.defineESModuleGetters(lazy, { E10SUtils: 'resource://gre/modules/E10SUtils.sys.mjs' });
|
||||
this.#listenPinnedTabEvents();
|
||||
}
|
||||
|
||||
@@ -37,7 +47,6 @@
|
||||
}
|
||||
|
||||
class ZenPinnedTabManager extends ZenDOMOperatedFeature {
|
||||
|
||||
init() {
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
@@ -56,7 +65,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
await this._refreshPinnedTabs(newWorkspace,{ init: onInit });
|
||||
await this._refreshPinnedTabs(newWorkspace, { init: onInit });
|
||||
}
|
||||
|
||||
get enabled() {
|
||||
@@ -70,9 +79,9 @@
|
||||
return this._enabled;
|
||||
}
|
||||
|
||||
async _refreshPinnedTabs(currentWorkspace,{ init = false } = {}) {
|
||||
async _refreshPinnedTabs(currentWorkspace, { init = false } = {}) {
|
||||
await this._initializePinsCache();
|
||||
await this._initializePinnedTabs(init,currentWorkspace);
|
||||
await this._initializePinnedTabs(init, currentWorkspace);
|
||||
}
|
||||
|
||||
async _initializePinsCache() {
|
||||
@@ -81,30 +90,31 @@
|
||||
const pins = await ZenPinnedTabsStorage.getPins();
|
||||
|
||||
// Enhance pins with favicons
|
||||
const enhancedPins = await Promise.all(pins.map(async pin => {
|
||||
try {
|
||||
const image = await this.getFaviconAsBase64(Services.io.newURI(pin.url).spec);
|
||||
return {
|
||||
...pin,
|
||||
iconUrl: image || null
|
||||
};
|
||||
} catch(ex) {
|
||||
// If favicon fetch fails, continue without icon
|
||||
return {
|
||||
...pin,
|
||||
iconUrl: null
|
||||
};
|
||||
}
|
||||
}));
|
||||
const enhancedPins = await Promise.all(
|
||||
pins.map(async (pin) => {
|
||||
try {
|
||||
const image = await this.getFaviconAsBase64(Services.io.newURI(pin.url).spec);
|
||||
return {
|
||||
...pin,
|
||||
iconUrl: image || null,
|
||||
};
|
||||
} catch (ex) {
|
||||
// If favicon fetch fails, continue without icon
|
||||
return {
|
||||
...pin,
|
||||
iconUrl: null,
|
||||
};
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this._pinsCache = enhancedPins.sort((a, b) => {
|
||||
if (!a.workspaceUuid && b.workspaceUuid) return -1;
|
||||
if (a.workspaceUuid && !b.workspaceUuid) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
} catch (ex) {
|
||||
console.error("Failed to initialize pins cache:", ex);
|
||||
console.error('Failed to initialize pins cache:', ex);
|
||||
this._pinsCache = [];
|
||||
}
|
||||
|
||||
@@ -121,11 +131,11 @@
|
||||
|
||||
const activeTab = gBrowser.selectedTab;
|
||||
const pinnedTabsByUUID = new Map();
|
||||
const pinsToCreate = new Set(pins.map(p => p.uuid));
|
||||
const pinsToCreate = new Set(pins.map((p) => p.uuid));
|
||||
|
||||
// First pass: identify existing tabs and remove those without pins
|
||||
for (let tab of gBrowser.tabs) {
|
||||
const pinId = tab.getAttribute("zen-pin-id");
|
||||
const pinId = tab.getAttribute('zen-pin-id');
|
||||
if (!pinId) {
|
||||
continue;
|
||||
}
|
||||
@@ -161,7 +171,7 @@
|
||||
userContextId: pin.containerTabId || 0,
|
||||
createLazyBrowser: true,
|
||||
skipLoad: true,
|
||||
noInitialLabel: false
|
||||
noInitialLabel: false,
|
||||
};
|
||||
|
||||
// Create and initialize the tab
|
||||
@@ -177,26 +187,28 @@
|
||||
gBrowser.setIcon(newTab, pin.iconUrl);
|
||||
}
|
||||
|
||||
newTab.setAttribute("zen-pin-id", pin.uuid);
|
||||
newTab.setAttribute('zen-pin-id', pin.uuid);
|
||||
|
||||
if (pin.workspaceUuid) {
|
||||
newTab.setAttribute("zen-workspace-id", pin.workspaceUuid);
|
||||
newTab.setAttribute('zen-workspace-id', pin.workspaceUuid);
|
||||
}
|
||||
|
||||
if (pin.isEssential) {
|
||||
newTab.setAttribute("zen-essential", "true");
|
||||
newTab.setAttribute('zen-essential', 'true');
|
||||
}
|
||||
|
||||
// Initialize browser state if needed
|
||||
if (!newTab.linkedBrowser._remoteAutoRemoved) {
|
||||
let state = {
|
||||
entries: [{
|
||||
url: pin.url,
|
||||
title: pin.title,
|
||||
triggeringPrincipal_base64: E10SUtils.SERIALIZED_SYSTEMPRINCIPAL
|
||||
}],
|
||||
entries: [
|
||||
{
|
||||
url: pin.url,
|
||||
title: pin.title,
|
||||
triggeringPrincipal_base64: E10SUtils.SERIALIZED_SYSTEMPRINCIPAL,
|
||||
},
|
||||
],
|
||||
userContextId: pin.containerTabId || 0,
|
||||
image: pin.iconUrl
|
||||
image: pin.iconUrl,
|
||||
};
|
||||
|
||||
SessionStore.setTabState(newTab, state);
|
||||
@@ -204,7 +216,6 @@
|
||||
|
||||
gBrowser.pinTab(newTab);
|
||||
|
||||
|
||||
newTab.initialize();
|
||||
}
|
||||
|
||||
@@ -219,8 +230,8 @@
|
||||
_shouldShowPin(pin, currentWorkspace, workspaces) {
|
||||
const isEssential = pin.isEssential;
|
||||
const pinWorkspaceUuid = pin.workspaceUuid;
|
||||
const pinContextId = pin.containerTabId ? pin.containerTabId.toString() : "0";
|
||||
const workspaceContextId = currentWorkspace.containerTabId?.toString() || "0";
|
||||
const pinContextId = pin.containerTabId ? pin.containerTabId.toString() : '0';
|
||||
const workspaceContextId = currentWorkspace.containerTabId?.toString() || '0';
|
||||
const containerSpecificEssentials = ZenWorkspaces.containerSpecificEssentials;
|
||||
|
||||
// Handle essential pins
|
||||
@@ -229,14 +240,16 @@
|
||||
return true; // Show all essential pins when containerSpecificEssentials is false
|
||||
}
|
||||
|
||||
if (workspaceContextId !== "0") {
|
||||
if (workspaceContextId !== '0') {
|
||||
// In workspaces with default container: Show essentials that match the container
|
||||
return pinContextId === workspaceContextId;
|
||||
} else {
|
||||
// In workspaces without a default container: Show essentials that aren't in container-specific workspaces
|
||||
// or have userContextId="0" or no userContextId
|
||||
return !pinContextId || pinContextId === "0" || !workspaces.workspaces.some(
|
||||
workspace => workspace.containerTabId === parseInt(pinContextId, 10)
|
||||
return (
|
||||
!pinContextId ||
|
||||
pinContextId === '0' ||
|
||||
!workspaces.workspaces.some((workspace) => workspace.containerTabId === parseInt(pinContextId, 10))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -255,19 +268,19 @@
|
||||
if (!this.enabled) return;
|
||||
const tab = event.target;
|
||||
switch (action) {
|
||||
case "TabPinned":
|
||||
case 'TabPinned':
|
||||
tab._zenClickEventListener = this._zenClickEventListener;
|
||||
tab.addEventListener("click", tab._zenClickEventListener);
|
||||
tab.addEventListener('click', tab._zenClickEventListener);
|
||||
this._setPinnedAttributes(tab);
|
||||
break;
|
||||
case "TabUnpinned":
|
||||
case 'TabUnpinned':
|
||||
this._removePinnedAttributes(tab);
|
||||
if (tab._zenClickEventListener) {
|
||||
tab.removeEventListener("click", tab._zenClickEventListener);
|
||||
tab.removeEventListener('click', tab._zenClickEventListener);
|
||||
delete tab._zenClickEventListener;
|
||||
}
|
||||
break;
|
||||
case "TabMove":
|
||||
case 'TabMove':
|
||||
this._onTabMove(tab);
|
||||
break;
|
||||
default:
|
||||
@@ -288,26 +301,25 @@
|
||||
|
||||
for (let otherTab of gBrowser.tabs) {
|
||||
if (otherTab.pinned && otherTab._tPos > tab.position) {
|
||||
const actualPin = this._pinsCache.find(pin => pin.uuid === otherTab.getAttribute("zen-pin-id"));
|
||||
const actualPin = this._pinsCache.find((pin) => pin.uuid === otherTab.getAttribute('zen-pin-id'));
|
||||
actualPin.position = otherTab._tPos;
|
||||
await ZenPinnedTabsStorage.savePin(actualPin, false);
|
||||
}
|
||||
}
|
||||
|
||||
const actualPin = this._pinsCache.find(pin => pin.uuid === tab.getAttribute("zen-pin-id"));
|
||||
const actualPin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id'));
|
||||
actualPin.position = tab.position;
|
||||
await ZenPinnedTabsStorage.savePin(actualPin);
|
||||
}
|
||||
|
||||
_onTabClick(e) {
|
||||
const tab = e.target?.closest("tab");
|
||||
const tab = e.target?.closest('tab');
|
||||
if (e.button === 1 && tab) {
|
||||
this._onCloseTabShortcut(e, tab);
|
||||
}
|
||||
}
|
||||
|
||||
async resetPinnedTab(tab) {
|
||||
|
||||
if (!tab) {
|
||||
tab = TabContextMenu.contextTab;
|
||||
}
|
||||
@@ -321,23 +333,23 @@
|
||||
|
||||
async replacePinnedUrlWithCurrent() {
|
||||
const tab = TabContextMenu.contextTab;
|
||||
if (!tab || !tab.pinned || !tab.getAttribute("zen-pin-id")) {
|
||||
if (!tab || !tab.pinned || !tab.getAttribute('zen-pin-id')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const browser = tab.linkedBrowser;
|
||||
|
||||
const pin = this._pinsCache.find(pin => pin.uuid === tab.getAttribute("zen-pin-id"));
|
||||
const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id'));
|
||||
|
||||
if (!pin) {
|
||||
return;
|
||||
}
|
||||
|
||||
const userContextId = tab.getAttribute("usercontextid");
|
||||
const userContextId = tab.getAttribute('usercontextid');
|
||||
|
||||
pin.title = tab.label || browser.contentTitle;
|
||||
pin.url = browser.currentURI.spec;
|
||||
pin.workspaceUuid = tab.getAttribute("zen-workspace-id");
|
||||
pin.workspaceUuid = tab.getAttribute('zen-workspace-id');
|
||||
pin.userContextId = userContextId ? parseInt(userContextId, 10) : 0;
|
||||
|
||||
await ZenPinnedTabsStorage.savePin(pin);
|
||||
@@ -346,20 +358,19 @@
|
||||
}
|
||||
|
||||
async _setPinnedAttributes(tab) {
|
||||
|
||||
if (tab.hasAttribute("zen-pin-id")) {
|
||||
if (tab.hasAttribute('zen-pin-id')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const browser = tab.linkedBrowser;
|
||||
|
||||
const uuid = gZenUIManager.generateUuidv4();
|
||||
const userContextId = tab.getAttribute("usercontextid");
|
||||
const userContextId = tab.getAttribute('usercontextid');
|
||||
|
||||
let entry = null;
|
||||
|
||||
if(tab.getAttribute("zen-pinned-entry")) {
|
||||
entry = JSON.parse(tab.getAttribute("zen-pinned-entry"));
|
||||
if (tab.getAttribute('zen-pinned-entry')) {
|
||||
entry = JSON.parse(tab.getAttribute('zen-pinned-entry'));
|
||||
}
|
||||
|
||||
await ZenPinnedTabsStorage.savePin({
|
||||
@@ -367,15 +378,15 @@
|
||||
title: entry?.title || tab.label || browser.contentTitle,
|
||||
url: entry?.url || browser.currentURI.spec,
|
||||
containerTabId: userContextId ? parseInt(userContextId, 10) : 0,
|
||||
workspaceUuid: tab.getAttribute("zen-workspace-id"),
|
||||
isEssential: tab.getAttribute("zen-essential") === "true"
|
||||
workspaceUuid: tab.getAttribute('zen-workspace-id'),
|
||||
isEssential: tab.getAttribute('zen-essential') === 'true',
|
||||
});
|
||||
|
||||
tab.setAttribute("zen-pin-id", uuid);
|
||||
tab.setAttribute('zen-pin-id', uuid);
|
||||
|
||||
// This is used while migrating old pins to new system - we don't want to refresh when migrating
|
||||
if (tab.getAttribute("zen-pinned-entry")) {
|
||||
tab.removeAttribute("zen-pinned-entry");
|
||||
if (tab.getAttribute('zen-pinned-entry')) {
|
||||
tab.removeAttribute('zen-pinned-entry');
|
||||
return;
|
||||
}
|
||||
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
|
||||
@@ -383,19 +394,19 @@
|
||||
}
|
||||
|
||||
async _removePinnedAttributes(tab, isClosing = false) {
|
||||
if(!tab.getAttribute("zen-pin-id") || this._temporarilyUnpiningEssential) {
|
||||
if (!tab.getAttribute('zen-pin-id') || this._temporarilyUnpiningEssential) {
|
||||
this._temporarilyUnpiningEssential = false;
|
||||
return;
|
||||
}
|
||||
|
||||
await ZenPinnedTabsStorage.removePin(tab.getAttribute("zen-pin-id"));
|
||||
await ZenPinnedTabsStorage.removePin(tab.getAttribute('zen-pin-id'));
|
||||
|
||||
if(!isClosing) {
|
||||
tab.removeAttribute("zen-pin-id");
|
||||
if (!isClosing) {
|
||||
tab.removeAttribute('zen-pin-id');
|
||||
|
||||
if (!tab.hasAttribute("zen-workspace-id") && ZenWorkspaces.workspaceEnabled) {
|
||||
if (!tab.hasAttribute('zen-workspace-id') && ZenWorkspaces.workspaceEnabled) {
|
||||
const workspace = await ZenWorkspaces.getActiveWorkspace();
|
||||
tab.setAttribute("zen-workspace-id", workspace.uuid);
|
||||
tab.setAttribute('zen-workspace-id', workspace.uuid);
|
||||
}
|
||||
}
|
||||
const currentWorkspace = await ZenWorkspaces.getActiveWorkspace();
|
||||
@@ -411,9 +422,7 @@
|
||||
}
|
||||
|
||||
_onCloseTabShortcut(event, selectedTab = gBrowser.selectedTab) {
|
||||
if (
|
||||
!selectedTab?.pinned
|
||||
) {
|
||||
if (!selectedTab?.pinned) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -448,19 +457,19 @@
|
||||
}
|
||||
|
||||
_handleTabSwitch(selectedTab) {
|
||||
if(selectedTab !== gBrowser.selectedTab) {
|
||||
if (selectedTab !== gBrowser.selectedTab) {
|
||||
return;
|
||||
}
|
||||
const findNextTab = (direction) =>
|
||||
gBrowser.tabContainer.findNextTab(selectedTab, {
|
||||
direction,
|
||||
filter: tab => !tab.hidden && !tab.pinned,
|
||||
});
|
||||
gBrowser.tabContainer.findNextTab(selectedTab, {
|
||||
direction,
|
||||
filter: (tab) => !tab.hidden && !tab.pinned,
|
||||
});
|
||||
|
||||
let nextTab = findNextTab(1) || findNextTab(-1);
|
||||
|
||||
if (!nextTab) {
|
||||
ZenWorkspaces._createNewTabForWorkspace({ uuid: ZenWorkspaces.activeWorkspace });
|
||||
ZenWorkspaces._createNewTabForWorkspace({ uuid: ZenWorkspaces.activeWorkspace });
|
||||
|
||||
nextTab = findNextTab(1) || findNextTab(-1);
|
||||
}
|
||||
@@ -471,12 +480,12 @@
|
||||
}
|
||||
|
||||
async _resetTabToStoredState(tab) {
|
||||
const id = tab.getAttribute("zen-pin-id");
|
||||
const id = tab.getAttribute('zen-pin-id');
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pin = this._pinsCache.find(pin => pin.uuid === id);
|
||||
const pin = this._pinsCache.find((pin) => pin.uuid === id);
|
||||
if (!pin) {
|
||||
return;
|
||||
}
|
||||
@@ -484,11 +493,13 @@
|
||||
const tabState = SessionStore.getTabState(tab);
|
||||
const state = JSON.parse(tabState);
|
||||
|
||||
state.entries = [{
|
||||
url: pin.url,
|
||||
title: pin.title,
|
||||
triggeringPrincipal_base64: lazy.E10SUtils.SERIALIZED_SYSTEMPRINCIPAL
|
||||
}];
|
||||
state.entries = [
|
||||
{
|
||||
url: pin.url,
|
||||
title: pin.title,
|
||||
triggeringPrincipal_base64: lazy.E10SUtils.SERIALIZED_SYSTEMPRINCIPAL,
|
||||
},
|
||||
];
|
||||
|
||||
state.image = pin.iconUrl || null;
|
||||
state.index = 0;
|
||||
@@ -507,15 +518,15 @@
|
||||
|
||||
// Convert to base64
|
||||
const base64String = btoa(
|
||||
Array.from(array)
|
||||
.map(b => String.fromCharCode(b))
|
||||
.join('')
|
||||
Array.from(array)
|
||||
.map((b) => String.fromCharCode(b))
|
||||
.join('')
|
||||
);
|
||||
|
||||
// Return as a proper data URL
|
||||
return `data:${faviconData.mimeType};base64,${base64String}`;
|
||||
} catch (ex) {
|
||||
// console.error("Failed to get favicon:", ex);
|
||||
// console.error("Failed to get favicon:", ex);
|
||||
return `page-icon:${pageUrl}`; // Use this as a fallback
|
||||
}
|
||||
}
|
||||
@@ -524,9 +535,9 @@
|
||||
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
const tab = tabs[i];
|
||||
tab.setAttribute("zen-essential", "true");
|
||||
if(tab.hasAttribute("zen-workspace-id")) {
|
||||
tab.removeAttribute("zen-workspace-id");
|
||||
tab.setAttribute('zen-essential', 'true');
|
||||
if (tab.hasAttribute('zen-workspace-id')) {
|
||||
tab.removeAttribute('zen-workspace-id');
|
||||
}
|
||||
if (tab.pinned) {
|
||||
this._temporarilyUnpiningEssential = true;
|
||||
@@ -540,9 +551,9 @@
|
||||
const tabs = TabContextMenu.contextTab.multiselected ? gBrowser.selectedTabs : [TabContextMenu.contextTab];
|
||||
for (let i = 0; i < tabs.length; i++) {
|
||||
const tab = tabs[i];
|
||||
tab.removeAttribute("zen-essential");
|
||||
if(ZenWorkspaces.workspaceEnabled && ZenWorkspaces.getActiveWorkspaceFromCache.uuid) {
|
||||
tab.setAttribute("zen-workspace-id", ZenWorkspaces.getActiveWorkspaceFromCache.uuid);
|
||||
tab.removeAttribute('zen-essential');
|
||||
if (ZenWorkspaces.workspaceEnabled && ZenWorkspaces.getActiveWorkspaceFromCache.uuid) {
|
||||
tab.setAttribute('zen-workspace-id', ZenWorkspaces.getActiveWorkspaceFromCache.uuid);
|
||||
}
|
||||
gBrowser.unpinTab(tab);
|
||||
}
|
||||
@@ -589,14 +600,16 @@
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
const isVisible = contextTab.pinned && !contextTab.multiselected;
|
||||
document.getElementById("context_zen-reset-pinned-tab").hidden = !isVisible || !contextTab.getAttribute("zen-pin-id");
|
||||
document.getElementById("context_zen-replace-pinned-url-with-current").hidden = !isVisible;
|
||||
document.getElementById("context_zen-add-essential").hidden = contextTab.getAttribute("zen-essential");
|
||||
document.getElementById("context_zen-remove-essential").hidden = !contextTab.getAttribute("zen-essential");
|
||||
document.getElementById("context_unpinTab").hidden = document.getElementById("context_unpinTab").hidden || contextTab.getAttribute("zen-essential");
|
||||
document.getElementById("context_unpinSelectedTabs").hidden = document.getElementById("context_unpinSelectedTabs").hidden || contextTab.getAttribute("zen-essential");
|
||||
document.getElementById("context_zen-pinned-tab-separator").hidden = !isVisible;
|
||||
const isVisible = contextTab.pinned && !contextTab.multiselected;
|
||||
document.getElementById('context_zen-reset-pinned-tab').hidden = !isVisible || !contextTab.getAttribute('zen-pin-id');
|
||||
document.getElementById('context_zen-replace-pinned-url-with-current').hidden = !isVisible;
|
||||
document.getElementById('context_zen-add-essential').hidden = contextTab.getAttribute('zen-essential');
|
||||
document.getElementById('context_zen-remove-essential').hidden = !contextTab.getAttribute('zen-essential');
|
||||
document.getElementById('context_unpinTab').hidden =
|
||||
document.getElementById('context_unpinTab').hidden || contextTab.getAttribute('zen-essential');
|
||||
document.getElementById('context_unpinSelectedTabs').hidden =
|
||||
document.getElementById('context_unpinSelectedTabs').hidden || contextTab.getAttribute('zen-essential');
|
||||
document.getElementById('context_zen-pinned-tab-separator').hidden = !isVisible;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user