Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix(theming): Also apply new background colors to guest view
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed May 21, 2024
commit 282f1b1faba5c3d4a27fc6254badd9e75864e225
5 changes: 2 additions & 3 deletions apps/theming/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public function getCapabilities() {
$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());

Expand All @@ -114,8 +115,6 @@ public function getCapabilities() {
*/
$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) {
Expand Down
4 changes: 3 additions & 1 deletion apps/theming/lib/Service/BackgroundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

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

/**
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -219,6 +220,7 @@ public function __construct(
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');

Check notice

Code scanning / Psalm

PossiblyNullArgument

Argument 1 of OCP\IConfig::deleteUserValue cannot be null, possibly null value provided
}

/**
Expand Down
24 changes: 12 additions & 12 deletions apps/theming/lib/Themes/CommonThemeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
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
Expand Down Expand Up @@ -89,13 +91,15 @@ protected function generatePrimaryVariables(string $colorMainBackground, string
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) {
Expand All @@ -106,17 +110,13 @@ protected function generateGlobalBackgroundVariables(): array {
}
}

// 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';
}

Expand Down
10 changes: 8 additions & 2 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ public function getDefaultColorPrimary(): string {
}

// 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;
}

/**
Expand All @@ -270,7 +276,7 @@ public function getDefaultColorPrimary(): string {
public function getDefaultColorBackground(): string {
$defaultColor = $this->config->getAppValue(Application::APP_ID, 'background_color', '');

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCP\IConfig::getAppValue has been marked as deprecated
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
$defaultColor = BackgroundService::DEFAULT_COLOR;
$defaultColor = BackgroundService::DEFAULT_BACKGROUND_COLOR;
}
return $defaultColor;
}
Expand Down