diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-02-16 15:25:04 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-05-21 20:36:26 +0200 |
commit | 8028784976f05ca42f2ebc844c2f637085126009 (patch) | |
tree | c38d17d621b991f31075bd32c34aa4dcd6692b6d | |
parent | bd73bccb40069621fb069022329f6083f7fbcfd8 (diff) | |
download | nextcloud-server-8028784976f05ca42f2ebc844c2f637085126009.tar.gz nextcloud-server-8028784976f05ca42f2ebc844c2f637085126009.zip |
fix: cleanup theming app code
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | apps/theming/lib/Capabilities.php | 4 | ||||
-rw-r--r-- | apps/theming/lib/Service/BackgroundService.php | 5 | ||||
-rw-r--r-- | apps/theming/lib/Service/JSDataService.php | 16 | ||||
-rw-r--r-- | apps/theming/lib/Themes/DefaultTheme.php | 6 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 23 | ||||
-rw-r--r-- | lib/private/legacy/OC_Defaults.php | 13 | ||||
-rw-r--r-- | themes/example/defaults.php | 8 |
7 files changed, 45 insertions, 30 deletions
diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index 6a9d11a4e9b..99909fbe952 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -95,10 +95,6 @@ class Capabilities implements IPublicCapability { */ public function getCapabilities() { $color = $this->theming->getDefaultColorPrimary(); - // Same as in DefaultTheme - if ($color === BackgroundService::DEFAULT_COLOR) { - $color = BackgroundService::DEFAULT_ACCESSIBLE_COLOR; - } $colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff'; $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', ''); diff --git a/apps/theming/lib/Service/BackgroundService.php b/apps/theming/lib/Service/BackgroundService.php index 2b1dd635e44..c323a721b60 100644 --- a/apps/theming/lib/Service/BackgroundService.php +++ b/apps/theming/lib/Service/BackgroundService.php @@ -45,7 +45,6 @@ use OCP\PreConditionNotMetException; class BackgroundService { public const DEFAULT_COLOR = '#0082c9'; public const DEFAULT_BACKGROUND_COLOR = '#00679e'; - public const DEFAULT_ACCESSIBLE_COLOR = '#00679e'; /** * One of our shipped background images is used @@ -291,8 +290,9 @@ class BackgroundService { * Called when a new global background (backgroundMime) is uploaded (admin setting) * This sets all necessary app config values * @param resource|string $path + * @return string|null The fallback background color - if any */ - public function setGlobalBackground($path): void { + public function setGlobalBackground($path): string|null { $image = new \OCP\Image(); $handle = is_resource($path) ? $path : fopen($path, 'rb'); @@ -301,6 +301,7 @@ class BackgroundService { if ($meanColor !== false) { $this->config->setAppValue(Application::APP_ID, 'background_color', $meanColor); } + return $meanColor; } } diff --git a/apps/theming/lib/Service/JSDataService.php b/apps/theming/lib/Service/JSDataService.php index 65f91f9dda2..99573dc51b4 100644 --- a/apps/theming/lib/Service/JSDataService.php +++ b/apps/theming/lib/Service/JSDataService.php @@ -44,17 +44,23 @@ class JSDataService implements \JsonSerializable { public function jsonSerialize(): array { return [ 'name' => $this->themingDefaults->getName(), - 'url' => $this->themingDefaults->getBaseUrl(), 'slogan' => $this->themingDefaults->getSlogan(), - 'color' => $this->themingDefaults->getColorPrimary(), // deprecated use primaryColor - 'primaryColor' => $this->themingDefaults->getColorPrimary(), - 'backgroundColor' => $this->themingDefaults->getColorBackground(), - 'defaultColor' => $this->themingDefaults->getDefaultColorPrimary(), + + 'url' => $this->themingDefaults->getBaseUrl(), 'imprintUrl' => $this->themingDefaults->getImprintUrl(), 'privacyUrl' => $this->themingDefaults->getPrivacyUrl(), + + 'primaryColor' => $this->themingDefaults->getColorPrimary(), + 'backgroundColor' => $this->themingDefaults->getColorBackground(), + 'defaultPrimaryColor' => $this->themingDefaults->getDefaultColorPrimary(), + 'defaultBackgroundColor' => $this->themingDefaults->getDefaultColorBackground(), 'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()), + 'cacheBuster' => $this->util->getCacheBuster(), 'enabledThemes' => $this->themesService->getEnabledThemes(), + + // deprecated use primaryColor + 'color' => $this->themingDefaults->getColorPrimary(), '' => 'color is deprecated since Nextcloud 29, use primaryColor instead' ]; } diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php index 68038f053e3..c48cc08f30b 100644 --- a/apps/theming/lib/Themes/DefaultTheme.php +++ b/apps/theming/lib/Themes/DefaultTheme.php @@ -27,7 +27,6 @@ namespace OCA\Theming\Themes; use OCA\Theming\ImageManager; use OCA\Theming\ITheme; -use OCA\Theming\Service\BackgroundService; use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; use OCP\App\IAppManager; @@ -70,11 +69,6 @@ class DefaultTheme implements ITheme { $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary(); $this->primaryColor = $this->themingDefaults->getColorPrimary(); - - // Override primary colors (if set) to improve accessibility - if ($this->primaryColor === BackgroundService::DEFAULT_COLOR) { - $this->primaryColor = BackgroundService::DEFAULT_ACCESSIBLE_COLOR; - } } public function getId(): string { diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 39e7d88de0d..de284ecf092 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -61,7 +61,8 @@ class ThemingDefaults extends \OC_Defaults { private string $entity; private string $productName; private string $url; - private string $color; + private string $backgroundColor; + private string $primaryColor; private string $docBaseUrl; private string $iTunesAppId; @@ -91,7 +92,8 @@ class ThemingDefaults extends \OC_Defaults { $this->entity = parent::getEntity(); $this->productName = parent::getProductName(); $this->url = parent::getBaseUrl(); - $this->color = parent::getColorPrimary(); + $this->primaryColor = parent::getColorPrimary(); + $this->backgroundColor = parent::getColorBackground(); $this->iTunesAppId = parent::getiTunesAppId(); $this->iOSClientUrl = parent::getiOSClientUrl(); $this->AndroidClientUrl = parent::getAndroidClientUrl(); @@ -260,14 +262,8 @@ class ThemingDefaults extends \OC_Defaults { return $defaultColor; } - // Fall back to background color - $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; + // fall back to default primary color + return $this->primaryColor; } /** @@ -275,10 +271,11 @@ 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_BACKGROUND_COLOR; + if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) { + return $defaultColor; } - return $defaultColor; + + return $this->backgroundColor; } /** diff --git a/lib/private/legacy/OC_Defaults.php b/lib/private/legacy/OC_Defaults.php index ce89a642741..01591af8611 100644 --- a/lib/private/legacy/OC_Defaults.php +++ b/lib/private/legacy/OC_Defaults.php @@ -52,6 +52,7 @@ class OC_Defaults { private $defaultDocBaseUrl; private $defaultDocVersion; private $defaultSlogan; + private $defaultColorBackground; private $defaultColorPrimary; private $defaultTextColorPrimary; private $defaultProductName; @@ -70,6 +71,7 @@ class OC_Defaults { $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/'); $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links + $this->defaultColorBackground = '#0069c3'; $this->defaultColorPrimary = '#0082c9'; $this->defaultTextColorPrimary = '#ffffff'; $this->defaultProductName = 'Nextcloud'; @@ -300,6 +302,17 @@ class OC_Defaults { } /** + * Returns primary color + * @return string + */ + public function getColorBackground() { + if ($this->themeExist('getColorBackground')) { + return $this->theme->getColorBackground(); + } + return $this->defaultColorBackground; + } + + /** * @return array scss variables to overwrite */ public function getScssVariables() { diff --git a/themes/example/defaults.php b/themes/example/defaults.php index e0b14cb0cb8..37bce6c3ee6 100644 --- a/themes/example/defaults.php +++ b/themes/example/defaults.php @@ -111,6 +111,14 @@ class OC_Theme { } /** + * Returns background color to be used + * @return string + */ + public function getColorBackground(): string { + return '#3d85c6'; + } + + /** * Returns variables to overload defaults from core/css/variables.scss * @return array */ |