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(settings): Return mean color of background image on set
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed May 21, 2024
commit 11dbfa636d746eac4a82460d0677dc6ffe98f068
6 changes: 5 additions & 1 deletion apps/theming/lib/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public function getImageUrl(string $key): string {
case 'favicon':
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;
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', '');

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCP\IConfig::getAppValue has been marked as deprecated
if ($mimeSetting !== 'backgroundColor') {
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
}
}
return '';
}
Expand Down
15 changes: 8 additions & 7 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public function getShortFooter() {

/**
* 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 {
$user = $this->userSession->getUser();
Expand All @@ -215,9 +216,7 @@ public function getColorPrimary(): string {

// user-defined primary color
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)) {
return $userPrimaryColor;
}
Expand All @@ -229,6 +228,7 @@ public function getColorPrimary(): string {

/**
* 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 {
$user = $this->userSession->getUser();
Expand All @@ -253,7 +253,7 @@ public function getColorBackground(): string {
}

/**
* Return the default primary color
* Return the default primary color - only taking admin setting into account
*/
public function getDefaultColorPrimary(): string {
// try admin color
Expand Down Expand Up @@ -478,7 +478,7 @@ public function undoAll(): void {
}

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

Check notice

Code scanning / Psalm

PossiblyFalseArgument

Argument 1 of OCA\Theming\Service\BackgroundService::setGlobalBackground cannot be false, possibly resource|string value expected
}
break;
case 'logo':
Expand Down