Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable23] Properly calculate primary element based on background luminance #32680

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/accessibility/lib/Controller/AccessibilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private function getInjectedVariables(): string {
return $this->injectedVariables;
}
$variables = '';
foreach ($this->defaults->getScssVariables() as $key => $value) {
foreach ($this->defaults->getScssVariables(!$this->isDarkThemeEnabled()) as $key => $value) {
$variables .= '$' . $key . ': ' . $value . ';';
}

Expand All @@ -267,4 +267,18 @@ private function getInjectedVariables(): string {
}
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';
}
}
4 changes: 2 additions & 2 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function getFDroidClientUrl() {
/**
* @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')) {
Expand All @@ -334,7 +334,7 @@ public function getScssVariables() {
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') {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/legacy/OC_Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ public function getColorPrimary() {
/**
* @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 [];
}
Expand Down
2 changes: 1 addition & 1 deletion themes/example/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getColorPrimary() {
* Returns variables to overload defaults from core/css/variables.scss
* @return array
*/
public function getScssVariables() {
public function getScssVariables(bool $brightBackground) {
return [
'color-primary' => '#745bca'
];
Expand Down