Skip to content

Commit e7ddf60

Browse files
authored
Merge pull request #32510 from nextcloud/fix/theming-colours-primary-24
2 parents cdaf808 + 20efadf commit e7ddf60

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

apps/accessibility/lib/Controller/AccessibilityController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function getInjectedVariables(): string {
219219
return $this->injectedVariables;
220220
}
221221
$variables = '';
222-
foreach ($this->defaults->getScssVariables() as $key => $value) {
222+
foreach ($this->defaults->getScssVariables(!$this->isDarkThemeEnabled()) as $key => $value) {
223223
$variables .= '$' . $key . ': ' . $value . ';';
224224
}
225225

@@ -238,4 +238,18 @@ private function getInjectedVariables(): string {
238238
}
239239
return $variables;
240240
}
241+
242+
/**
243+
* Return true if the dark theme is enabled for the current user
244+
*/
245+
private function isDarkThemeEnabled(): bool {
246+
if (!$this->userSession->isLoggedIn()) {
247+
return false;
248+
}
249+
$user = $this->userSession->getUser();
250+
if (!$user) {
251+
return false;
252+
}
253+
return $this->config->getUserValue($user->getUID(), $this->appName, 'theme', false) === 'dark';
254+
}
241255
}

apps/theming/lib/ThemingDefaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function getFDroidClientUrl() {
315315
/**
316316
* @return array scss variables to overwrite
317317
*/
318-
public function getScssVariables() {
318+
public function getScssVariables(bool $brightBackground = true) {
319319
$cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0');
320320
$cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl());
321321
if ($value = $cache->get('getScssVariables')) {
@@ -339,7 +339,7 @@ public function getScssVariables() {
339339
if ($this->config->getAppValue('theming', 'color', '') !== '') {
340340
$variables['color-primary'] = $this->getColorPrimary();
341341
$variables['color-primary-text'] = $this->getTextColorPrimary();
342-
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary());
342+
$variables['color-primary-element'] = $this->util->elementColor($this->getColorPrimary(), $brightBackground);
343343
}
344344

345345
if ($this->config->getAppValue('theming', 'backgroundMime', '') === 'backgroundColor') {

lib/private/legacy/OC_Defaults.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ public function getColorPrimary() {
311311
/**
312312
* @return array scss variables to overwrite
313313
*/
314-
public function getScssVariables() {
314+
public function getScssVariables(bool $brightBackground = true) {
315315
if ($this->themeExist('getScssVariables')) {
316-
return $this->theme->getScssVariables();
316+
return $this->theme->getScssVariables($brightBackground);
317317
}
318318
return [];
319319
}

themes/example/defaults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getColorPrimary() {
119119
* Returns variables to overload defaults from core/css/variables.scss
120120
* @return array
121121
*/
122-
public function getScssVariables() {
122+
public function getScssVariables(bool $brightBackground) {
123123
return [
124124
'color-primary' => '#745bca'
125125
];

0 commit comments

Comments
 (0)