Browse Source

fix(theming): Also apply new background colors to guest view

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/42977/head
Ferdinand Thiessen 4 months ago
parent
commit
282f1b1fab
No account linked to committer's email address

+ 2
- 3
apps/theming/lib/Capabilities.php View File

@@ -101,7 +101,8 @@ class Capabilities implements IPublicCapability {
$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';

$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
$backgroundColor = $this->theming->getDefaultColorBackground();
$backgroundColor = $this->theming->getColorBackground();
$backgroundText = $this->theming->getTextColorBackground();
$backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $backgroundColor !== BackgroundService::DEFAULT_COLOR);
$background = $backgroundPlain ? $backgroundColor : $this->url->getAbsoluteURL($this->theming->getBackground());

@@ -114,8 +115,6 @@ class Capabilities implements IPublicCapability {
*/
$color = $this->theming->getColorPrimary();
$colorText = $this->theming->getTextColorPrimary();
$backgroundColor = $this->theming->getColorBackground();
$backgroundText = $this->theming->getTextColorBackground();

$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {

+ 3
- 1
apps/theming/lib/Service/BackgroundService.php View File

@@ -44,6 +44,7 @@ use OCP\PreConditionNotMetException;

class BackgroundService {
public const DEFAULT_COLOR = '#0082c9';
public const DEFAULT_BACKGROUND_COLOR = '#00679e';
public const DEFAULT_ACCESSIBLE_COLOR = '#00679e';

/**
@@ -161,7 +162,7 @@ class BackgroundService {
'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
'description' => 'Background picture of white clouds on in front of a blue sky',
'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
'background_color' => '#00679e',
'background_color' => self::DEFAULT_BACKGROUND_COLOR,
'primary_color' => self::DEFAULT_COLOR,
],
'bernard-spragg-new-zealand-fern.jpg' => [
@@ -219,6 +220,7 @@ class BackgroundService {
public function setDefaultBackground(): void {
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_image');
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'background_color');
$this->config->deleteUserValue($this->userId, Application::APP_ID, 'primary_color');
}

/**

+ 12
- 12
apps/theming/lib/Themes/CommonThemeTrait.php View File

@@ -29,10 +29,12 @@ namespace OCA\Theming\Themes;
use OCA\Theming\AppInfo\Application;
use OCA\Theming\ImageManager;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;

trait CommonThemeTrait {
public Util $util;
public ThemingDefaults $themingDefaults;

/**
* Generate primary-related variables
@@ -89,13 +91,15 @@ trait CommonThemeTrait {
protected function generateGlobalBackgroundVariables(): array {
$backgroundDeleted = $this->config->getAppValue(Application::APP_ID, 'backgroundMime', '') === 'backgroundColor';
$hasCustomLogoHeader = $this->util->isLogoThemed();
$isPrimaryBright = $this->util->invertTextColor($this->primaryColor);

$variables = [];
$backgroundColor = $this->themingDefaults->getColorBackground();

// Default last fallback values
$variables['--image-background-default'] = "url('" . $this->themingDefaults->getBackground() . "')";
$variables['--color-background-plain'] = $this->primaryColor;
$variables = [
'--color-background-plain' => $backgroundColor,
'--color-background-plain-text' => $this->util->invertTextColor($backgroundColor) ? '#000000' : '#ffffff',
'--image-background-default' => "url('" . $this->themingDefaults->getBackground() . "')",
'--background-image-invert-if-bright' => $this->util->invertTextColor($backgroundColor) ? 'invert(100%)' : 'no',
];

// Register image variables only if custom-defined
foreach (ImageManager::SUPPORTED_IMAGE_KEYS as $image) {
@@ -106,17 +110,13 @@ trait CommonThemeTrait {
}
}

// If primary as background has been request or if we have a custom primary colour
// let's not define the background image
// If a background has been requested let's not define the background image
if ($backgroundDeleted) {
$variables['--color-background-plain'] = $this->primaryColor;
$variables['--image-background-plain'] = 'yes';
$variables['--image-background'] = 'no';
// If no background image is set, we need to check against the shown primary colour
$variables['--background-image-invert-if-bright'] = $isPrimaryBright ? 'invert(100%)' : 'no';
$variables['--image-background'] = 'none';
}

if ($hasCustomLogoHeader) {
// prevent inverting the logo on bright colors if customized
$variables['--image-logoheader-custom'] = 'true';
}


+ 8
- 2
apps/theming/lib/ThemingDefaults.php View File

@@ -261,7 +261,13 @@ class ThemingDefaults extends \OC_Defaults {
}

// Fall back to background color
return $this->getDefaultColorBackground();
$defaultColor = $this->config->getAppValue(Application::APP_ID, 'background_color', '');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
return $defaultColor;
}

// worst case fall back to default primary color
return BackgroundService::DEFAULT_COLOR;
}

/**
@@ -270,7 +276,7 @@ class ThemingDefaults extends \OC_Defaults {
public function getDefaultColorBackground(): string {
$defaultColor = $this->config->getAppValue(Application::APP_ID, 'background_color', '');
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
$defaultColor = BackgroundService::DEFAULT_COLOR;
$defaultColor = BackgroundService::DEFAULT_BACKGROUND_COLOR;
}
return $defaultColor;
}

Loading…
Cancel
Save