Skip to content

Commit 8028784

Browse files
committed
fix: cleanup theming app code
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent bd73bcc commit 8028784

File tree

7 files changed

+45
-30
lines changed

7 files changed

+45
-30
lines changed

apps/theming/lib/Capabilities.php

-4
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator
9595
*/
9696
public function getCapabilities() {
9797
$color = $this->theming->getDefaultColorPrimary();
98-
// Same as in DefaultTheme
99-
if ($color === BackgroundService::DEFAULT_COLOR) {
100-
$color = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
101-
}
10298
$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';
10399

104100
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');

apps/theming/lib/Service/BackgroundService.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
class BackgroundService {
4646
public const DEFAULT_COLOR = '#0082c9';
4747
public const DEFAULT_BACKGROUND_COLOR = '#00679e';
48-
public const DEFAULT_ACCESSIBLE_COLOR = '#00679e';
4948

5049
/**
5150
* One of our shipped background images is used
@@ -291,8 +290,9 @@ public function getBackground(): ?ISimpleFile {
291290
* Called when a new global background (backgroundMime) is uploaded (admin setting)
292291
* This sets all necessary app config values
293292
* @param resource|string $path
293+
* @return string|null The fallback background color - if any
294294
*/
295-
public function setGlobalBackground($path): void {
295+
public function setGlobalBackground($path): string|null {
296296
$image = new \OCP\Image();
297297
$handle = is_resource($path) ? $path : fopen($path, 'rb');
298298

@@ -301,6 +301,7 @@ public function setGlobalBackground($path): void {
301301
if ($meanColor !== false) {
302302
$this->config->setAppValue(Application::APP_ID, 'background_color', $meanColor);
303303
}
304+
return $meanColor;
304305
}
305306
}
306307

apps/theming/lib/Service/JSDataService.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,23 @@ public function __construct(
4444
public function jsonSerialize(): array {
4545
return [
4646
'name' => $this->themingDefaults->getName(),
47-
'url' => $this->themingDefaults->getBaseUrl(),
4847
'slogan' => $this->themingDefaults->getSlogan(),
49-
'color' => $this->themingDefaults->getColorPrimary(), // deprecated use primaryColor
50-
'primaryColor' => $this->themingDefaults->getColorPrimary(),
51-
'backgroundColor' => $this->themingDefaults->getColorBackground(),
52-
'defaultColor' => $this->themingDefaults->getDefaultColorPrimary(),
48+
49+
'url' => $this->themingDefaults->getBaseUrl(),
5350
'imprintUrl' => $this->themingDefaults->getImprintUrl(),
5451
'privacyUrl' => $this->themingDefaults->getPrivacyUrl(),
52+
53+
'primaryColor' => $this->themingDefaults->getColorPrimary(),
54+
'backgroundColor' => $this->themingDefaults->getColorBackground(),
55+
'defaultPrimaryColor' => $this->themingDefaults->getDefaultColorPrimary(),
56+
'defaultBackgroundColor' => $this->themingDefaults->getDefaultColorBackground(),
5557
'inverted' => $this->util->invertTextColor($this->themingDefaults->getColorPrimary()),
58+
5659
'cacheBuster' => $this->util->getCacheBuster(),
5760
'enabledThemes' => $this->themesService->getEnabledThemes(),
61+
62+
// deprecated use primaryColor
63+
'color' => $this->themingDefaults->getColorPrimary(),
5864
'' => 'color is deprecated since Nextcloud 29, use primaryColor instead'
5965
];
6066
}

apps/theming/lib/Themes/DefaultTheme.php

-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
use OCA\Theming\ImageManager;
2929
use OCA\Theming\ITheme;
30-
use OCA\Theming\Service\BackgroundService;
3130
use OCA\Theming\ThemingDefaults;
3231
use OCA\Theming\Util;
3332
use OCP\App\IAppManager;
@@ -70,11 +69,6 @@ public function __construct(Util $util,
7069

7170
$this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary();
7271
$this->primaryColor = $this->themingDefaults->getColorPrimary();
73-
74-
// Override primary colors (if set) to improve accessibility
75-
if ($this->primaryColor === BackgroundService::DEFAULT_COLOR) {
76-
$this->primaryColor = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
77-
}
7872
}
7973

8074
public function getId(): string {

apps/theming/lib/ThemingDefaults.php

+10-13
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class ThemingDefaults extends \OC_Defaults {
6161
private string $entity;
6262
private string $productName;
6363
private string $url;
64-
private string $color;
64+
private string $backgroundColor;
65+
private string $primaryColor;
6566
private string $docBaseUrl;
6667

6768
private string $iTunesAppId;
@@ -91,7 +92,8 @@ public function __construct(
9192
$this->entity = parent::getEntity();
9293
$this->productName = parent::getProductName();
9394
$this->url = parent::getBaseUrl();
94-
$this->color = parent::getColorPrimary();
95+
$this->primaryColor = parent::getColorPrimary();
96+
$this->backgroundColor = parent::getColorBackground();
9597
$this->iTunesAppId = parent::getiTunesAppId();
9698
$this->iOSClientUrl = parent::getiOSClientUrl();
9799
$this->AndroidClientUrl = parent::getAndroidClientUrl();
@@ -260,25 +262,20 @@ public function getDefaultColorPrimary(): string {
260262
return $defaultColor;
261263
}
262264

263-
// Fall back to background color
264-
$defaultColor = $this->config->getAppValue(Application::APP_ID, 'background_color', '');
265-
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
266-
return $defaultColor;
267-
}
268-
269-
// worst case fall back to default primary color
270-
return BackgroundService::DEFAULT_COLOR;
265+
// fall back to default primary color
266+
return $this->primaryColor;
271267
}
272268

273269
/**
274270
* Default background color only taking admin setting into account
275271
*/
276272
public function getDefaultColorBackground(): string {
277273
$defaultColor = $this->config->getAppValue(Application::APP_ID, 'background_color', '');
278-
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
279-
$defaultColor = BackgroundService::DEFAULT_BACKGROUND_COLOR;
274+
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $defaultColor)) {
275+
return $defaultColor;
280276
}
281-
return $defaultColor;
277+
278+
return $this->backgroundColor;
282279
}
283280

284281
/**

lib/private/legacy/OC_Defaults.php

+13
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class OC_Defaults {
5252
private $defaultDocBaseUrl;
5353
private $defaultDocVersion;
5454
private $defaultSlogan;
55+
private $defaultColorBackground;
5556
private $defaultColorPrimary;
5657
private $defaultTextColorPrimary;
5758
private $defaultProductName;
@@ -70,6 +71,7 @@ public function __construct() {
7071
$this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/');
7172
$this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
7273
$this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links
74+
$this->defaultColorBackground = '#0069c3';
7375
$this->defaultColorPrimary = '#0082c9';
7476
$this->defaultTextColorPrimary = '#ffffff';
7577
$this->defaultProductName = 'Nextcloud';
@@ -299,6 +301,17 @@ public function getColorPrimary() {
299301
return $this->defaultColorPrimary;
300302
}
301303

304+
/**
305+
* Returns primary color
306+
* @return string
307+
*/
308+
public function getColorBackground() {
309+
if ($this->themeExist('getColorBackground')) {
310+
return $this->theme->getColorBackground();
311+
}
312+
return $this->defaultColorBackground;
313+
}
314+
302315
/**
303316
* @return array scss variables to overwrite
304317
*/

themes/example/defaults.php

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public function getColorPrimary(): string {
110110
return '#745bca';
111111
}
112112

113+
/**
114+
* Returns background color to be used
115+
* @return string
116+
*/
117+
public function getColorBackground(): string {
118+
return '#3d85c6';
119+
}
120+
113121
/**
114122
* Returns variables to overload defaults from core/css/variables.scss
115123
* @return array

0 commit comments

Comments
 (0)