]> source.dussan.org Git - nextcloud-server.git/commitdiff
Properly calculate primary element based on background luminance 32510/head
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Fri, 20 May 2022 07:06:29 +0000 (09:06 +0200)
committerJohn Molakvoæ (Rebase PR Action) <skjnldsv@users.noreply.github.com>
Tue, 31 May 2022 17:27:12 +0000 (17:27 +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 b3063937a1b81e911945e32e2498399b7e4950ec..189ce3d97622e8122b7a791f8e45c710426fcf1b 100644 (file)
@@ -219,7 +219,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 . ';';
                }
 
@@ -238,4 +238,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 3d7aaee2064a3bd0ba9beb84faae0e0054246473..1001cb78c1893dc5653962245826df1ae9462c52 100644 (file)
@@ -315,7 +315,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')) {
@@ -339,7 +339,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'
                ];