Skip to content

Commit c3edc53

Browse files
committed
feat(theming): Allow shipped backgrounds to have a dark variant
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 19c8c63 commit c3edc53

File tree

10 files changed

+45
-15
lines changed

10 files changed

+45
-15
lines changed

.reuse/dep5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ Files: cypress/fixtures/image.jpg
239239
Copyright: 2019 Tom Gainor <https://unsplash.com/@its_tgain> <https://unsplash.com/photos/mountain-cliff-under-starry-night-KidY3t8O4PE>
240240
License: LicenseRef-Unsplash
241241

242+
Files: apps/theming/img/background/jenna-kim-the-globe.webp apps/theming/img/background/jenna-kim-the-globe-dark.webp
243+
Copyright: 2024 Nextcloud GmbH
244+
License: CC-BY-SA-4.0
245+
242246
Files: apps/theming/img/background/anatoly-mikhaltsov-butterfly-wing-scale.jpg apps/theming/img/background/preview/anatoly-mikhaltsov-butterfly-wing-scale.jpg
243247
Copyright: 2015 Anatoly Mikhaltsov <https://commons.wikimedia.org/wiki/File:%D0%A7%D0%B5%D1%88%D1%83%D0%B9%D0%BA%D0%B8_%D0%BA%D1%80%D1%8B%D0%BB%D0%B0_%D0%B1%D0%B0%D0%B1%D0%BE%D1%87%D0%BA%D0%B8.jpg>
244248
License: CC-BY-SA-4.0

apps/theming/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ A reference to why it was very difficult to actually find good background pictur
2929

3030
In `img/background/`:
3131

32-
- Default background: [Clouds (Kamil Porembiński, CC BY-SA)](https://www.flickr.com/photos/paszczak000/8715851521/) – original 4k, color modified and sky color changed to Nextcloud blue.
33-
- Default dark mode background: [Pedra azul milky way (Eduardo Neves, CC BY-SA)](https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg) – original 5k.
32+
- Default background: [Globe (Jenna Kim - Nextcloud GmbH, C-BY-SA-4.0)](https://nextcloud.com/trademarks/) - orginal 4k
33+
- [Clouds (Kamil Porembiński, CC BY-SA)](https://www.flickr.com/photos/paszczak000/8715851521/) – original 4k, color modified and sky color changed to Nextcloud blue.
34+
- [Pedra azul milky way (Eduardo Neves, CC BY-SA)](https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg) – original 5k.
3435
- [Soft floral (Hannah MacLean, CC0)](https://stocksnap.io/photo/soft-floral-XOYWCCW5PA) – original 5.5k.
3536
- [Morning fog (Ted Moravec, Public Domain)](https://flickr.com/photos/tmoravec/52392410261) – original 3k.
3637
- [Underwater ocean (Stefanus Martanto Setyo Husodo, CC0)](https://stocksnap.io/photo/underwater-ocean-TJA9LBH4WS) – original 5k.

apps/theming/css/default.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@
9999
--gradient-primary-background: linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
100100
--color-background-plain: #00679e;
101101
--color-background-plain-text: #ffffff;
102-
--image-background: url('/apps/theming/img/background/kamil-porembinski-clouds.jpg');
102+
--image-background: url('/apps/theming/img/background/jenna-kim-the-globe.webp');
103103
}
103 KB
Loading
96.6 KB
Loading

apps/theming/lib/ImageManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,26 @@ public function getImageUrl(string $key): string {
4242
$cacheBusterCounter = $this->config->getAppValue(Application::APP_ID, 'cachebuster', '0');
4343
if ($this->hasImage($key)) {
4444
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => $key ]) . '?v=' . $cacheBusterCounter;
45+
} elseif ($key === 'backgroundDark' && $this->hasImage('background')) {
46+
// Fall back to light variant
47+
return $this->urlGenerator->linkToRoute('theming.Theming.getImage', [ 'key' => 'background' ]) . '?v=' . $cacheBusterCounter;
4548
}
4649

4750
switch ($key) {
4851
case 'logo':
4952
case 'logoheader':
5053
case 'favicon':
5154
return $this->urlGenerator->imagePath('core', 'logo/logo.png') . '?v=' . $cacheBusterCounter;
55+
case 'backgroundDark':
5256
case 'background':
5357
// Removing the background defines its mime as 'backgroundColor'
5458
$mimeSetting = $this->config->getAppValue('theming', 'backgroundMime', '');
5559
if ($mimeSetting !== 'backgroundColor') {
56-
return $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
60+
$image = BackgroundService::DEFAULT_BACKGROUND_IMAGE;
61+
if ($key === 'backgroundDark') {
62+
$image = BackgroundService::SHIPPED_BACKGROUNDS[$image]['dark_variant'] ?? $image;
63+
}
64+
return $this->urlGenerator->linkTo(Application::APP_ID, "img/background/$image");
5765
}
5866
}
5967
return '';

apps/theming/lib/Service/BackgroundService.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BackgroundService {
4444
*/
4545
public const BACKGROUND_COLOR = 'color';
4646

47-
public const DEFAULT_BACKGROUND_IMAGE = 'kamil-porembinski-clouds.jpg';
47+
public const DEFAULT_BACKGROUND_IMAGE = 'jenna-kim-the-globe.webp';
4848

4949
/**
5050
* 'attribution': Name, artist and license
@@ -54,6 +54,21 @@ class BackgroundService {
5454
* 'primary_color': Recommended primary color for this theme / image
5555
*/
5656
public const SHIPPED_BACKGROUNDS = [
57+
'jenna-kim-the-globe.webp' => [
58+
'attribution' => 'Globe (Jenna Kim - Nextcloud GmbH, CC-BY-SA-4.0)',
59+
'description' => 'Background picture of white clouds on in front of a blue sky',
60+
'attribution_url' => 'https://nextcloud.com/trademarks/',
61+
'dark_variant' => 'jenna-kim-the-globe-dark.webp',
62+
'background_color' => self::DEFAULT_BACKGROUND_COLOR,
63+
'primary_color' => self::DEFAULT_COLOR,
64+
],
65+
'kamil-porembinski-clouds.jpg' => [
66+
'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
67+
'description' => 'Background picture of white clouds on in front of a blue sky',
68+
'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
69+
'background_color' => self::DEFAULT_BACKGROUND_COLOR,
70+
'primary_color' => self::DEFAULT_COLOR,
71+
],
5772
'hannah-maclean-soft-floral.jpg' => [
5873
'attribution' => 'Soft floral (Hannah MacLean, CC0)',
5974
'description' => 'Abstract background picture in yellow and white color whith a flower on it',
@@ -138,13 +153,6 @@ class BackgroundService {
138153
'background_color' => '#333f47',
139154
'primary_color' => '#4f6071',
140155
],
141-
'kamil-porembinski-clouds.jpg' => [
142-
'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
143-
'description' => 'Background picture of white clouds on in front of a blue sky',
144-
'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
145-
'background_color' => self::DEFAULT_BACKGROUND_COLOR,
146-
'primary_color' => self::DEFAULT_COLOR,
147-
],
148156
'bernard-spragg-new-zealand-fern.jpg' => [
149157
'attribution' => 'New zealand fern (Bernard Spragg, CC0)',
150158
'description' => 'Abstract background picture of fern leafes',

apps/theming/lib/Themes/CommonThemeTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ trait CommonThemeTrait {
1717
public Util $util;
1818
public ThemingDefaults $themingDefaults;
1919

20+
protected bool $isDarkVariant = false;
21+
2022
/**
2123
* Generate primary-related variables
2224
* This is shared between multiple themes because colorMainBackground and colorMainText
@@ -87,7 +89,7 @@ protected function generateGlobalBackgroundVariables(): array {
8789
$variables["--image-$image"] = "url('" . $imageUrl . "')";
8890
} elseif ($image === 'background') {
8991
// Apply default background if nothing is configured
90-
$variables['--image-background'] = "url('" . $this->themingDefaults->getBackground() . "')";
92+
$variables['--image-background'] = "url('" . $this->themingDefaults->getBackground($this->isDarkVariant) . "')";
9193
}
9294
}
9395

@@ -139,6 +141,10 @@ protected function generateUserBackgroundVariables(): array {
139141

140142
// The user picked a shipped background
141143
if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) {
144+
$shippedBackground = BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage];
145+
if ($this->isDarkVariant && isset($shippedBackground['dark_variant'])) {
146+
$backgroundImage = $shippedBackground['dark_variant'];
147+
}
142148
$variables['--image-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "img/background/$backgroundImage") . "')";
143149
}
144150

apps/theming/lib/Themes/DarkTheme.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class DarkTheme extends DefaultTheme implements ITheme {
1313

14+
protected bool $isDarkVariant = true;
15+
1416
public function getId(): string {
1517
return 'dark';
1618
}

apps/theming/lib/ThemingDefaults.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,11 @@ public function getLogo($useSvg = true): string {
284284
/**
285285
* Themed background image url
286286
*
287+
* @param bool $darkVariant if the dark variant (if available) of the background should be used
287288
* @return string
288289
*/
289-
public function getBackground(): string {
290-
return $this->imageManager->getImageUrl('background');
290+
public function getBackground(bool $darkVariant = false): string {
291+
return $this->imageManager->getImageUrl('background' . ($darkVariant ? 'Dark' : ''));
291292
}
292293

293294
/**

0 commit comments

Comments
 (0)