aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/lib/Themes/CommonThemeTrait.php
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-01-19 22:48:27 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2024-05-21 20:36:21 +0200
commitde938bb401bd04af02798417dfa5d96fee057ef1 (patch)
treee79ba02258f34e6371935737a4861e6f7ef6179d /apps/theming/lib/Themes/CommonThemeTrait.php
parent0211feb94647a0e329030b66bc4c5b4304d10a0f (diff)
downloadnextcloud-server-de938bb401bd04af02798417dfa5d96fee057ef1.tar.gz
nextcloud-server-de938bb401bd04af02798417dfa5d96fee057ef1.zip
feat(theming): Separate background and primary color
While the primary color is intended to highlight elements, it can not always be used as the background color. So now primary is independent from background a user set, the background color is, if not set directly, calculated as the mean color of the background image. That color is then used as a fallback if the background image could not be loaded and for calculating the color of the text used on the app menu and dashboard (they render directly on the background). Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/theming/lib/Themes/CommonThemeTrait.php')
-rw-r--r--apps/theming/lib/Themes/CommonThemeTrait.php44
1 files changed, 16 insertions, 28 deletions
diff --git a/apps/theming/lib/Themes/CommonThemeTrait.php b/apps/theming/lib/Themes/CommonThemeTrait.php
index cf2427e823e..6d74a7bcdfc 100644
--- a/apps/theming/lib/Themes/CommonThemeTrait.php
+++ b/apps/theming/lib/Themes/CommonThemeTrait.php
@@ -130,49 +130,37 @@ trait CommonThemeTrait {
if ($user !== null
&& !$this->themingDefaults->isUserThemingDisabled()
&& $this->appManager->isEnabledForUser(Application::APP_ID)) {
- $adminBackgroundDeleted = $this->config->getAppValue(Application::APP_ID, 'backgroundMime', '') === 'backgroundColor';
$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
+ $backgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', $this->themingDefaults->getColorPrimary());
+
$currentVersion = (int)$this->config->getUserValue($user->getUID(), Application::APP_ID, 'userCacheBuster', '0');
- $isPrimaryBright = $this->util->invertTextColor($this->primaryColor);
+ $isBackgroundBright = $this->util->invertTextColor($backgroundColor);
+ $backgroundTextColor = $this->util->invertTextColor($backgroundColor) ? '#000000' : '#ffffff';
+
+ $variables = [
+ '--color-background-plain' => $backgroundColor,
+ '--color-background-plain-text' => $backgroundTextColor,
+ '--background-image-invert-if-bright' => $isBackgroundBright ? 'invert(100%)' : 'no',
+ ];
// The user removed the background
if ($backgroundImage === BackgroundService::BACKGROUND_DISABLED) {
- return [
- // Might be defined already by admin theming, needs to be overridden
- '--image-background' => 'none',
- '--color-background-plain' => $this->primaryColor,
- // If no background image is set, we need to check against the shown primary colour
- '--background-image-invert-if-bright' => $isPrimaryBright ? 'invert(100%)' : 'no',
- ];
+ // Might be defined already by admin theming, needs to be overridden
+ $variables['--image-background'] = 'none';
}
// The user uploaded a custom background
if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {
$cacheBuster = substr(sha1($user->getUID() . '_' . $currentVersion), 0, 8);
- return [
- '--image-background' => "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "?v=$cacheBuster')",
- '--color-background-plain' => $this->themingDefaults->getColorPrimary(),
- '--background-image-invert-if-bright' => $isPrimaryBright ? 'invert(100%)' : 'no',
- ];
- }
-
- // The user is using the default background and admin removed the background image
- if ($backgroundImage === BackgroundService::BACKGROUND_DEFAULT && $adminBackgroundDeleted) {
- return [
- // --image-background is not defined in this case
- '--color-background-plain' => $this->primaryColor,
- '--background-image-invert-if-bright' => $isPrimaryBright ? 'invert(100%)' : 'no',
- ];
+ $variables['--image-background'] = "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "?v=$cacheBuster')";
}
// The user picked a shipped background
if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) {
- return [
- '--image-background' => "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "img/background/$backgroundImage") . "')",
- '--color-background-plain' => $this->primaryColor,
- '--background-image-invert-if-bright' => BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage]['theming'] ?? null === BackgroundService::THEMING_MODE_DARK ? 'invert(100%)' : 'no',
- ];
+ $variables['--image-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "img/background/$backgroundImage") . "')";
}
+
+ return $variables;
}
return [];