From 4f049111b132617c09dbf904159a0483080326d1 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Tue, 1 Jul 2025 01:30:04 +0200 Subject: [PATCH] feat: Added legacy version for gradients picker, b=no-bug, c=common, workspaces --- src/zen/common/ZenUIMigration.mjs | 1 + src/zen/workspaces/ZenGradientGenerator.mjs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/zen/common/ZenUIMigration.mjs b/src/zen/common/ZenUIMigration.mjs index 027b98468..691d2ec13 100644 --- a/src/zen/common/ZenUIMigration.mjs +++ b/src/zen/common/ZenUIMigration.mjs @@ -57,6 +57,7 @@ class nsZenUIMigration { ); const theme = Services.prefs.getIntPref('layout.css.prefers-color-scheme.content-override', 0); Services.prefs.setIntPref('zen.view.window.scheme', theme); + Services.prefs.setIntPref('zen.theme.gradient-legacy-version', 0); } } diff --git a/src/zen/workspaces/ZenGradientGenerator.mjs b/src/zen/workspaces/ZenGradientGenerator.mjs index 7c6b4b1f6..1b3763863 100644 --- a/src/zen/workspaces/ZenGradientGenerator.mjs +++ b/src/zen/workspaces/ZenGradientGenerator.mjs @@ -75,6 +75,9 @@ }); this.dragStartPosition = null; + this.isLegacyVersion = + Services.prefs.getIntPref('zen.theme.gradient-legacy-version', 1) === 0; + ChromeUtils.defineLazyGetter(this, 'panel', () => document.getElementById('PanelUI-zen-gradient-generator') ); @@ -203,7 +206,7 @@ this.useAlgo = algo; this.#currentLightness = lightness; dots = this.calculateCompliments(dots, 'update', this.useAlgo); - this.handleColorPositions(dots); + this.handleColorPositions(dots, true); this.updateCurrentWorkspace(); }); } @@ -702,10 +705,15 @@ return updatedDots; } - handleColorPositions(colorPositions) { + handleColorPositions(colorPositions, ignoreLegacy = false) { colorPositions.sort((a, b) => a.ID - b.ID); const existingPrimaryDot = this.dots.find((d) => d.ID === 0); + if (this.isLegacyVersion && !ignoreLegacy) { + this.isLegacyVersion = false; + Services.prefs.setIntPref('zen.theme.gradient-legacy-version', 1); + } + if (existingPrimaryDot) { existingPrimaryDot.element.style.zIndex = 999; const colorFromPos = this.getColorFromPosition( @@ -981,7 +989,10 @@ // The more transparent, the more white the color will be blended with. In order words, // make the transparency relative to these 2 ends. // e.g. 0% opacity becomes 60% blend, 100% opacity becomes 100% blend - const blendPercentage = Math.max(30, 30 + opacity * 70); + let blendPercentage = Math.max(30, 30 + opacity * 70); + if (this.isLegacyVersion) { + blendPercentage = 100; // Legacy version always blends to 100% + } return colors.map((color) => ({ c: color.isCustom ? color.c : this.blendColors(color.c, colorToBlend, blendPercentage), isCustom: color.isCustom, @@ -1448,8 +1459,9 @@ `rgb(${dominantColor[0]}, ${dominantColor[1]}, ${dominantColor[2]})` ) ); + browser.gZenThemePicker.isLegacyVersion = this.isLegacyVersion; let isDarkMode = this.isDarkMode; - if (!isDefaultTheme) { + if (!isDefaultTheme && !this.isLegacyVersion) { // Check for the primary color isDarkMode = browser.gZenThemePicker.shouldBeDarkMode(dominantColor); browser.document.documentElement.setAttribute('zen-should-be-dark-mode', isDarkMode);