]> source.dussan.org Git - nextcloud-server.git/commitdiff
Properly calculate primary element based on background luminance 32680/head
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Fri, 20 May 2022 07:06:29 +0000 (09:06 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Wed, 1 Jun 2022 05:42:34 +0000 (05:42 +0000)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
apps/accessibility/lib/Controller/AccessibilityController.php
apps/theming/lib/ThemingDefaults.php
lib/private/legacy/OC_Defaults.php
themes/example/defaults.php

index 7a5a82085dc6a6470fe4ab35e14e1d57806b18d9..857aaf8b90f9c0dba4c21758739b830ebe94fcee 100644 (file)
@@ -248,7 +248,7 @@ class AccessibilityController extends Controller {
                        return $this->injectedVariables;
                }
                $variables = '';
-               foreach ($this->defaults->getScssVariables() as $key => $value) {
+               foreach ($this->defaults->getScssVariables(!$this->isDarkThemeEnabled()) as $key => $value) {
                        $variables .= '$' . $key . ': ' . $value . ';';
                }
 
@@ -267,4 +267,18 @@ class AccessibilityController extends Controller {
                }
                return $variables;
        }
+
+       /**
+        * Return true if the dark theme is enabled for the current user
+        */
+       private function isDarkThemeEnabled(): bool {
+               if (!$this->userSession->isLoggedIn()) {
+                       return false;
+               }
+               $user = $this->userSession->getUser();
+               if (!$user) {
+                       return false;
+               }
+               return $this->config->getUserValue($user->getUID(), $this->appName, 'theme', false) === 'dark';
+       }
 }
index 3bfccda4a432238f1c21b4068aea676a9e75fe7b..9adee687944650b8ada79e22b9d26b885af08226 100644 (file)
@@ -310,7 +310,7 @@ class ThemingDefaults extends \OC_Defaults {
        /**
         * @return array scss variables to overwrite
         */
-       public function getScssVariables() {
+       public function getScssVariables(bool $brightBackground = true) {
                $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
                $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl());
                if ($value = $cache->get('getScssVariables')) {
@@ -334,7 +334,7 @@ class ThemingDefaults extends \OC_Defaults {
                if ($this->config->getAppValue('theming', 'color', '') !== '') {
                        $variables['color-primary'] = $this->getColorPrimary();
                        $variables['color-primary-text'] = $this->getTextColorPrimary();
-                       $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
+                       $variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary(), $brightBackground);
                }
 
                if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') {
index 707df7279bb72f03a3057671b9b1b1988b384240..88207e30adc10a8bc902c7f0d5148c950737185f 100644 (file)
@@ -311,9 +311,9 @@ class OC_Defaults {
        /**
         * @return array scss variables to overwrite
         */
-       public function getScssVariables() {
+       public function getScssVariables(bool $brightBackground = true) {
                if ($this->themeExist('getScssVariables')) {
-                       return $this->theme->getScssVariables();
+                       return $this->theme->getScssVariables($brightBackground);
                }
                return [];
        }
index 87d60de2ba739bae3c824d43631d6d978203dba5..a061ce1701d811a1d49e91f109e8d505788eb575 100644 (file)
@@ -119,7 +119,7 @@ class OC_Theme {
         * Returns variables to overload defaults from core/css/variables.scss
         * @return array
         */
-       public function getScssVariables() {
+       public function getScssVariables(bool $brightBackground) {
                return [
                        'color-primary' => '#745bca'
                ];