Refactor ZenGradientGenerator class to use constructor instead of init method

This commit is contained in:
mr. M 2024-10-27 20:32:20 +01:00
parent 87e0859cc8
commit 7ae2dee1b2
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB

View file

@ -219,7 +219,7 @@
} }
this.panel.querySelector('.zen-theme-picker-gradient').appendChild(dot); this.panel.querySelector('.zen-theme-picker-gradient').appendChild(dot);
if (!fromWorkspace) { if (!fromWorkspace) {
this.onDarkModeChange(null, true); this.updateCurrentWorkspace(true);
} }
} }
@ -295,7 +295,7 @@
onDotMouseUp(event) { onDotMouseUp(event) {
if (event.button === 2) { if (event.button === 2) {
if (this.numberOfDots < 2 || !event.target.classList.contains('zen-theme-picker-dot')) { if (!event.target.classList.contains('zen-theme-picker-dot')) {
return; return;
} }
event.target.remove(); event.target.remove();
@ -352,7 +352,9 @@
getGradient(colors) { getGradient(colors) {
const themedColors = this.themedColors(colors); const themedColors = this.themedColors(colors);
if (themedColors.length === 1) { if (themedColors.length === 0) {
return "var(--zen-themed-toolbar-bg)";
} else if (themedColors.length === 1) {
return this.getSingleRGBColor(themedColors[0]); return this.getSingleRGBColor(themedColors[0]);
} }
return `linear-gradient(${this.currentRotation}deg, ${themedColors.map(color => this.getSingleRGBColor(color)).join(', ')})`; return `linear-gradient(${this.currentRotation}deg, ${themedColors.map(color => this.getSingleRGBColor(color)).join(', ')})`;
@ -417,9 +419,9 @@
return; return;
} }
browser.gZenThemePicker.currentOpacity = workspaceTheme.opacity || 0.5; browser.gZenThemePicker.currentOpacity = workspaceTheme.opacity ?? 0.5;
browser.gZenThemePicker.currentRotation = workspaceTheme.rotation || 45; browser.gZenThemePicker.currentRotation = workspaceTheme.rotation ?? 45;
browser.gZenThemePicker.currentTexture = workspaceTheme.texture || 0; browser.gZenThemePicker.currentTexture = workspaceTheme.texture ?? 0;
browser.gZenThemePicker.numberOfDots = workspaceTheme.gradientColors.length; browser.gZenThemePicker.numberOfDots = workspaceTheme.gradientColors.length;