Browse Source

fix(settings): Return mean color of background image on set

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/42977/head
Ferdinand Thiessen 4 months ago
parent
commit
11dbfa636d
No account linked to committer's email address
2 changed files with 13 additions and 8 deletions
  1. 5
    1
      apps/theming/lib/ImageManager.php
  2. 8
    7
      apps/theming/lib/ThemingDefaults.php

+ 5
- 1
apps/theming/lib/ImageManager.php View File

case 'favicon': case 'favicon':
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter; return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;
case 'background': case 'background':
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
// Removing the background defines its mime as 'backgroundColor'
$mimeSetting = $this->config->getAppValue('theming', 'backgroundMime', '');
if ($mimeSetting !== 'backgroundColor') {
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
}
} }
return ''; return '';
} }

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



/** /**
* Color that is used for highlighting elements like important buttons * Color that is used for highlighting elements like important buttons
* If user theming is enabled then the user defined value is returned
*/ */
public function getColorPrimary(): string { public function getColorPrimary(): string {
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();


// user-defined primary color // user-defined primary color
if (!empty($user)) { if (!empty($user)) {
// we need the background color as a fallback for backwards compatibility with Nextcloud 28 and older
$userBackgroundColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_color', '');
$userPrimaryColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'primary_color', $userBackgroundColor);
$userPrimaryColor = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'primary_color', '');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) { if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
return $userPrimaryColor; return $userPrimaryColor;
} }


/** /**
* Color that is used for the page background (e.g. the header) * Color that is used for the page background (e.g. the header)
* If user theming is enabled then the user defined value is returned
*/ */
public function getColorBackground(): string { public function getColorBackground(): string {
$user = $this->userSession->getUser(); $user = $this->userSession->getUser();
} }


/** /**
* Return the default primary color
* Return the default primary color - only taking admin setting into account
*/ */
public function getDefaultColorPrimary(): string { public function getDefaultColorPrimary(): string {
// try admin color // try admin color
} }


/** /**
* Revert settings to the default value
* Revert admin settings to the default value
* *
* @param string $setting setting which should be reverted * @param string $setting setting which should be reverted
* @return string default value * @return string default value
$returnValue = $this->getSlogan(); $returnValue = $this->getSlogan();
break; break;
case 'primary_color': case 'primary_color':
$returnValue = $this->getDefaultColorPrimary();
$returnValue = BackgroundService::DEFAULT_COLOR;
break; break;
case 'background_color': case 'background_color':
// If a background image is set we revert to the mean image color
if ($this->imageManager->hasImage('background')) { if ($this->imageManager->hasImage('background')) {
$file = $this->imageManager->getImage('background'); $file = $this->imageManager->getImage('background');
$this->backgroundService->setGlobalBackground($file->read());
$returnValue = $this->backgroundService->setGlobalBackground($file->read()) ?? '';
} }
break; break;
case 'logo': case 'logo':

Loading…
Cancel
Save