mirror of
https://github.com/zen-browser/desktop.git
synced 2026-04-01 05:11:52 +00:00
chore: Implemented static linting for JS modules, p=#9673, c=common
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
{
|
||||
function parseSinePath(pathStr) {
|
||||
const points = [];
|
||||
const commands = pathStr.match(/[MCL]\s*[\d\s\.\-,]+/g);
|
||||
const commands = pathStr.match(/[MCL]\s*[\d\s.\-,]+/g);
|
||||
if (!commands) return points;
|
||||
|
||||
commands.forEach((command) => {
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
const EXPLICIT_LIGHTNESS_TYPE = 'explicit-lightness';
|
||||
|
||||
class nsZenThemePicker extends ZenMultiWindowFeature {
|
||||
class nsZenThemePicker extends nsZenMultiWindowFeature {
|
||||
static MAX_DOTS = 3;
|
||||
|
||||
currentOpacity = 0.5;
|
||||
@@ -129,7 +129,7 @@
|
||||
XPCOMUtils.defineLazyPreferenceGetter(this, 'darkModeBias', 'zen.theme.dark-mode-bias', 0.25);
|
||||
}
|
||||
|
||||
handleDarkModeChange(event) {
|
||||
handleDarkModeChange() {
|
||||
this.updateCurrentWorkspace();
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@
|
||||
* @return {Array} The RGB representation
|
||||
*/
|
||||
hslToRgb(h, s, l) {
|
||||
const { abs, min, max, round } = Math;
|
||||
const { round } = Math;
|
||||
let r, g, b;
|
||||
|
||||
if (s === 0) {
|
||||
@@ -1346,9 +1346,9 @@
|
||||
{
|
||||
let opacity = browser.gZenThemePicker.currentOpacity;
|
||||
const svg = browser.gZenThemePicker.sliderWavePath;
|
||||
const [_, secondStop, thirdStop] = document.querySelectorAll(
|
||||
'#PanelUI-zen-gradient-generator-slider-wave-gradient stop'
|
||||
);
|
||||
const [secondStop, thirdStop] = document
|
||||
.querySelectorAll('#PanelUI-zen-gradient-generator-slider-wave-gradient stop')
|
||||
.slice(1, 3);
|
||||
// Opacity can only be between MIN_OPACITY to MAX_OPACITY. Make opacity relative to that range
|
||||
if (opacity < MIN_OPACITY) {
|
||||
opacity = 0;
|
||||
@@ -1599,16 +1599,18 @@
|
||||
let newPathData = '';
|
||||
this.#sinePoints.forEach((p) => {
|
||||
switch (p.type) {
|
||||
case 'M':
|
||||
case 'M': {
|
||||
const interpolatedY = referenceY + (p.y - referenceY) * t;
|
||||
newPathData += `M ${p.x} ${interpolatedY} `;
|
||||
break;
|
||||
case 'C':
|
||||
}
|
||||
case 'C': {
|
||||
const y1 = referenceY + (p.y1 - referenceY) * t;
|
||||
const y2 = referenceY + (p.y2 - referenceY) * t;
|
||||
const y = referenceY + (p.y - referenceY) * t;
|
||||
newPathData += `C ${p.x1} ${y1} ${p.x2} ${y2} ${p.x} ${y} `;
|
||||
break;
|
||||
}
|
||||
case 'L':
|
||||
newPathData += `L ${p.x} ${p.y} `;
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
var gZenWorkspaces = new (class extends nsZenMultiWindowFeature {
|
||||
/**
|
||||
* Stores workspace IDs and their last selected tabs.
|
||||
*/
|
||||
@@ -151,7 +151,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
}
|
||||
|
||||
if (!this.privateWindowOrDisabled) {
|
||||
const observerFunction = async function observe(subject) {
|
||||
const observerFunction = async function observe() {
|
||||
this._workspaceBookmarksCache = null;
|
||||
await this.workspaceBookmarks();
|
||||
this._invalidateBookmarkContainers();
|
||||
@@ -242,30 +242,26 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
) {
|
||||
// Only set up URL bar selection if we're switching to a different tab
|
||||
if (gBrowser.selectedTab !== this._emptyTab && selectURLBar) {
|
||||
// Use a Promise-based approach for better sequencing
|
||||
const urlBarSelectionPromise = new Promise((resolve) => {
|
||||
const tabSelectListener = () => {
|
||||
// Remove the event listener first to prevent any chance of multiple executions
|
||||
window.removeEventListener('TabSelect', tabSelectListener);
|
||||
const tabSelectListener = () => {
|
||||
// Remove the event listener first to prevent any chance of multiple executions
|
||||
window.removeEventListener('TabSelect', tabSelectListener);
|
||||
|
||||
// Use requestAnimationFrame to ensure DOM is updated
|
||||
requestAnimationFrame(() => {
|
||||
// Then use setTimeout to ensure browser has time to process tab switch
|
||||
setTimeout(() => {
|
||||
if (gURLBar) {
|
||||
try {
|
||||
gURLBar.select();
|
||||
} catch (e) {
|
||||
console.warn('Error selecting URL bar:', e);
|
||||
}
|
||||
// Use requestAnimationFrame to ensure DOM is updated
|
||||
requestAnimationFrame(() => {
|
||||
// Then use setTimeout to ensure browser has time to process tab switch
|
||||
setTimeout(() => {
|
||||
if (gURLBar) {
|
||||
try {
|
||||
gURLBar.select();
|
||||
} catch (e) {
|
||||
console.warn('Error selecting URL bar:', e);
|
||||
}
|
||||
resolve();
|
||||
}, 50);
|
||||
});
|
||||
};
|
||||
}
|
||||
}, 50);
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener('TabSelect', tabSelectListener, { once: true });
|
||||
});
|
||||
window.addEventListener('TabSelect', tabSelectListener, { once: true });
|
||||
}
|
||||
|
||||
// Safely switch to the empty tab using our debounced method
|
||||
@@ -483,7 +479,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
await new Promise((resolve) => {
|
||||
workspaceWrapper.addEventListener(
|
||||
'ZenWorkspaceAttached',
|
||||
(event) => {
|
||||
() => {
|
||||
this._organizeTabsToWorkspaceSections(
|
||||
workspace,
|
||||
workspaceWrapper.tabsContainer,
|
||||
@@ -589,7 +585,6 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
if (event.deltaMode !== 1) return;
|
||||
|
||||
const isVerticalScroll = event.deltaY && !event.deltaX;
|
||||
const isHorizontalScroll = event.deltaX && !event.deltaY;
|
||||
|
||||
//if the scroll is vertical this checks that a modifier key is used before proceeding
|
||||
if (isVerticalScroll) {
|
||||
@@ -665,7 +660,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
);
|
||||
}
|
||||
|
||||
_popupOpenHandler(event) {
|
||||
_popupOpenHandler() {
|
||||
// If a popup is opened, we should stop the swipe gesture
|
||||
if (this._swipeState?.isGestureActive) {
|
||||
document.documentElement.removeAttribute('swipe-gesture');
|
||||
@@ -788,7 +783,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
|
||||
get shouldHaveWorkspaces() {
|
||||
if (typeof this._shouldHaveWorkspaces === 'undefined') {
|
||||
let chromeFlags = docShell.treeOwner
|
||||
let chromeFlags = window.docShell.treeOwner
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIAppWindow).chromeFlags;
|
||||
this._shouldHaveWorkspaces =
|
||||
@@ -823,7 +818,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
getWorkspaceFromId(id) {
|
||||
try {
|
||||
return this._workspaceCache.workspaces.find((workspace) => workspace.uuid === id);
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1193,7 +1188,9 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
let target;
|
||||
try {
|
||||
target = event.explicitOriginalTarget?.closest('toolbarbutton');
|
||||
} catch (_) {}
|
||||
} catch (e) {
|
||||
console.error('Error getting explicitOriginalTarget in context menu:', e);
|
||||
}
|
||||
this.#contextMenuData = {
|
||||
workspaceId: target?.getAttribute('zen-workspace-id'),
|
||||
originalTarget: target,
|
||||
@@ -1686,7 +1683,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
if (nextWorkspace) {
|
||||
const [nextGradient, nextGrain] =
|
||||
await gZenThemePicker.getGradientForWorkspace(nextWorkspace);
|
||||
const [_, existingGrain] = await gZenThemePicker.getGradientForWorkspace(workspace);
|
||||
const existingGrain = (await gZenThemePicker.getGradientForWorkspace(workspace))[1];
|
||||
const percentage = Math.abs(offsetPixels) / 200;
|
||||
await new Promise((resolve) => {
|
||||
requestAnimationFrame(() => {
|
||||
@@ -1786,7 +1783,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
if (previousBackgroundOpacity) {
|
||||
previousBackgroundOpacity = parseFloat(previousBackgroundOpacity);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
previousBackgroundOpacity = 1;
|
||||
}
|
||||
if (previousBackgroundOpacity == 1 || !previousBackgroundOpacity) {
|
||||
@@ -1794,7 +1791,6 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
} else {
|
||||
previousBackgroundOpacity = 1 - previousBackgroundOpacity;
|
||||
}
|
||||
previousBackgroundOpacity = previousBackgroundOpacity;
|
||||
gZenThemePicker.previousBackgroundOpacity = previousBackgroundOpacity;
|
||||
await new Promise((resolve) => {
|
||||
requestAnimationFrame(() => {
|
||||
@@ -2591,7 +2587,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
|
||||
// Tab browser utilities
|
||||
|
||||
getContextIdIfNeeded(userContextId, fromExternal, allowInheritPrincipal) {
|
||||
getContextIdIfNeeded(userContextId, fromExternal) {
|
||||
if (!this.workspaceEnabled) {
|
||||
return [userContextId, false, undefined];
|
||||
}
|
||||
@@ -2793,7 +2789,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||
}
|
||||
}
|
||||
|
||||
async switchIfNeeded(browser, i) {
|
||||
async switchIfNeeded(browser) {
|
||||
const tab = gBrowser.getTabForBrowser(browser);
|
||||
await this.switchTabIfNeeded(tab);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,9 @@ ZenWorkspacesStore.prototype._validateRecord = function (record) {
|
||||
try {
|
||||
JSON.parse(record.theme_colors);
|
||||
} catch (e) {
|
||||
throw new Error(`Invalid theme_colors JSON for workspace ID ${record.id}`);
|
||||
throw new Error(
|
||||
`Invalid theme_colors JSON for workspace ID ${record.id}. Error: ${e.message}`
|
||||
);
|
||||
}
|
||||
if (record.theme_opacity != null && typeof record.theme_opacity !== 'number') {
|
||||
throw new Error(`Invalid theme_opacity for workspace ID ${record.id}`);
|
||||
@@ -390,7 +392,7 @@ ZenWorkspacesTracker.prototype.observe = async function (subject, topic, data) {
|
||||
break;
|
||||
case 'zen-workspace-removed':
|
||||
case 'zen-workspace-updated':
|
||||
case 'zen-workspace-added':
|
||||
case 'zen-workspace-added': {
|
||||
let workspaceIDs;
|
||||
if (data) {
|
||||
try {
|
||||
@@ -424,6 +426,7 @@ ZenWorkspacesTracker.prototype.observe = async function (subject, topic, data) {
|
||||
this.score += SCORE_INCREMENT_XLARGE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this._log.error(`Error handling ${topic} in observe method`, error);
|
||||
|
||||
Reference in New Issue
Block a user