diff --git a/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php b/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php index 380527ee02461..ecd9e6ce2813b 100644 --- a/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php +++ b/apps/theming/lib/Listener/BeforeTemplateRenderedListener.php @@ -45,19 +45,22 @@ class BeforeTemplateRenderedListener implements IEventListener { private ThemeInjectionService $themeInjectionService; private IUserSession $userSession; private IConfig $config; + private BackgroundService $backgroundService; public function __construct( IInitialState $initialState, ContainerInterface $container, ThemeInjectionService $themeInjectionService, IUserSession $userSession, - IConfig $config + IConfig $config, + BackgroundService $backgroundService, ) { $this->initialState = $initialState; $this->container = $container; $this->themeInjectionService = $themeInjectionService; $this->userSession = $userSession; $this->config = $config; + $this->backgroundService = $backgroundService; } public function handle(Event $event): void { @@ -112,7 +115,7 @@ public function handle(Event $event): void { /** List of all shipped backgrounds */ $this->initialState->provideInitialState( 'shippedBackgrounds', - BackgroundService::SHIPPED_BACKGROUNDS, + $this->backgroundService->getShippedBackgrounds(), ); } diff --git a/apps/theming/lib/Service/BackgroundService.php b/apps/theming/lib/Service/BackgroundService.php index c385bc7b072cf..527697a73b519 100644 --- a/apps/theming/lib/Service/BackgroundService.php +++ b/apps/theming/lib/Service/BackgroundService.php @@ -39,6 +39,7 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; +use OCP\IL10N; use OCP\Lock\LockedException; use OCP\PreConditionNotMetException; @@ -54,121 +55,20 @@ class BackgroundService { public const BACKGROUND_DISABLED = 'disabled'; public const DEFAULT_BACKGROUND_IMAGE = 'kamil-porembinski-clouds.jpg'; - public const SHIPPED_BACKGROUNDS = [ - 'hannah-maclean-soft-floral.jpg' => [ - 'attribution' => 'Soft floral (Hannah MacLean, CC0)', - 'attribution_url' => 'https://stocksnap.io/photo/soft-floral-XOYWCCW5PA', - 'theming' => self::THEMING_MODE_DARK, - 'primary_color' => '#9f652f', - ], - 'ted-moravec-morning-fog.jpg' => [ - 'attribution' => 'Morning fog (Ted Moravec, Public Domain)', - 'attribution_url' => 'https://flickr.com/photos/tmoravec/52392410261', - 'theming' => self::THEMING_MODE_DARK, - 'primary_color' => '#114c3b', - ], - 'stefanus-martanto-setyo-husodo-underwater-ocean.jpg' => [ - 'attribution' => 'Underwater ocean (Stefanus Martanto Setyo Husodo, CC0)', - 'attribution_url' => 'https://stocksnap.io/photo/underwater-ocean-TJA9LBH4WS', - 'primary_color' => '#04577e', - ], - 'zoltan-voros-rhythm-and-blues.jpg' => [ - 'attribution' => 'Rhythm and blues (Zoltán Vörös, CC BY)', - 'attribution_url' => 'https://flickr.com/photos/v923z/51634409289/', - 'primary_color' => '#1c243c', - ], - 'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [ - 'attribution' => 'Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)', - 'attribution_url' => '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', - 'primary_color' => '#a53c17', - ], - 'bernie-cetonia-aurata-take-off-composition.jpg' => [ - 'attribution' => 'Cetonia aurata take off composition (Bernie, Public Domain)', - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg', - 'theming' => self::THEMING_MODE_DARK, - 'primary_color' => '#56633d', - ], - 'dejan-krsmanovic-ribbed-red-metal.jpg' => [ - 'attribution' => 'Ribbed red metal (Dejan Krsmanovic, CC BY)', - 'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/', - 'primary_color' => '#9c4236', - ], - 'eduardo-neves-pedra-azul.jpg' => [ - 'attribution' => 'Pedra azul milky way (Eduardo Neves, CC BY-SA)', - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg', - 'primary_color' => '#4f6071', - ], - 'european-space-agency-barents-bloom.jpg' => [ - 'attribution' => 'Barents bloom (European Space Agency, CC BY-SA)', - 'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom', - 'primary_color' => '#396475', - ], - 'hannes-fritz-flippity-floppity.jpg' => [ - 'attribution' => 'Flippity floppity (Hannes Fritz, CC BY-SA)', - 'attribution_url' => 'http://hannes.photos/flippity-floppity', - 'primary_color' => '#98415a', - ], - 'hannes-fritz-roulette.jpg' => [ - 'attribution' => 'Roulette (Hannes Fritz, CC BY-SA)', - 'attribution_url' => 'http://hannes.photos/roulette', - 'primary_color' => '#845334', - ], - 'hannes-fritz-sea-spray.jpg' => [ - 'attribution' => 'Sea spray (Hannes Fritz, CC BY-SA)', - 'attribution_url' => 'http://hannes.photos/sea-spray', - 'primary_color' => '#4f6071', - ], - 'kamil-porembinski-clouds.jpg' => [ - 'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)', - 'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/', - 'primary_color' => self::DEFAULT_COLOR, - ], - 'bernard-spragg-new-zealand-fern.jpg' => [ - 'attribution' => 'New zealand fern (Bernard Spragg, CC0)', - 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg', - 'primary_color' => '#316b26', - ], - 'rawpixel-pink-tapioca-bubbles.jpg' => [ - 'attribution' => 'Pink tapioca bubbles (Rawpixel, CC BY)', - 'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/', - 'theming' => self::THEMING_MODE_DARK, - 'primary_color' => '#7b4e7e', - ], - 'nasa-waxing-crescent-moon.jpg' => [ - 'attribution' => 'Waxing crescent moon (NASA, Public Domain)', - 'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon', - 'primary_color' => '#005ac1', - ], - 'tommy-chau-already.jpg' => [ - 'attribution' => 'Cityscape (Tommy Chau, CC BY)', - 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368', - 'primary_color' => '#6a2af4', - ], - 'tommy-chau-lion-rock-hill.jpg' => [ - 'attribution' => 'Lion rock hill (Tommy Chau, CC BY)', - 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246', - 'theming' => self::THEMING_MODE_DARK, - 'primary_color' => '#7f4f70', - ], - 'lali-masriera-yellow-bricks.jpg' => [ - 'attribution' => 'Yellow bricks (Lali Masriera, CC BY)', - 'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447', - 'theming' => self::THEMING_MODE_DARK, - 'primary_color' => '#7f5700', - ], - ]; private IRootFolder $rootFolder; private IAppData $appData; private IConfig $config; private string $userId; private ThemingDefaults $themingDefaults; + protected IL10N $l10n; public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, ?string $userId, - ThemingDefaults $themingDefaults) { + ThemingDefaults $themingDefaults, + IL10N $l10n) { if ($userId === null) { return; } @@ -178,6 +78,7 @@ public function __construct(IRootFolder $rootFolder, $this->userId = $userId; $this->appData = $appData; $this->themingDefaults = $themingDefaults; + $this->l10n = $l10n; } public function setDefaultBackground(): void { @@ -209,11 +110,11 @@ public function setFileBackground($path): void { } public function setShippedBackground($fileName): void { - if (!array_key_exists($fileName, self::SHIPPED_BACKGROUNDS)) { + if (!array_key_exists($fileName, $this->getShippedBackgrounds())) { throw new InvalidArgumentException('The given file name is invalid'); } $this->config->setUserValue($this->userId, Application::APP_ID, 'background_image', $fileName); - $this->setColorBackground(self::SHIPPED_BACKGROUNDS[$fileName]['primary_color']); + $this->setColorBackground($this->getShippedBackgrounds()[$fileName]['primary_color']); } public function setColorBackground(string $color): void { @@ -257,4 +158,129 @@ private function getAppDataFolder(): ISimpleFolder { return $rootFolder->newFolder($this->userId); } } + + public function getShippedBackgrounds(): array { + return [ + 'hannah-maclean-soft-floral.jpg' => [ + 'attribution' => $this->l10n->t('Soft floral (Hannah MacLean, CC0)'), + 'description' => $this->l10n->t('Abstract picture in yellow and white color whith a flower on it'), + 'attribution_url' => 'https://stocksnap.io/photo/soft-floral-XOYWCCW5PA', + 'theming' => self::THEMING_MODE_DARK, + 'primary_color' => '#9f652f', + ], + 'ted-moravec-morning-fog.jpg' => [ + 'attribution' => $this->l10n->t('Morning fog (Ted Moravec, Public Domain)'), + 'description' => $this->l10n->t('Picture of a forest shrouded in fog'), + 'attribution_url' => 'https://flickr.com/photos/tmoravec/52392410261', + 'theming' => self::THEMING_MODE_DARK, + 'primary_color' => '#114c3b', + ], + 'stefanus-martanto-setyo-husodo-underwater-ocean.jpg' => [ + 'attribution' => $this->l10n->t('Underwater ocean (Stefanus Martanto Setyo Husodo, CC0)'), + 'description' => $this->l10n->t('Picture of an underwater ocean'), + 'attribution_url' => 'https://stocksnap.io/photo/underwater-ocean-TJA9LBH4WS', + 'primary_color' => '#04577e', + ], + 'zoltan-voros-rhythm-and-blues.jpg' => [ + 'attribution' => $this->l10n->t('Rhythm and blues (Zoltán Vörös, CC BY)'), + 'description' => $this->l10n->t('Abstract picture of sand dunes during night'), + 'attribution_url' => 'https://flickr.com/photos/v923z/51634409289/', + 'primary_color' => '#1c243c', + ], + 'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [ + 'attribution' => $this->l10n->t('Butterfly wing scale (Anatoly Mikhaltsov, CC BY-SA)'), + 'description' => $this->l10n->t('Picture of a red-ish butterfly wing under microscope'), + 'attribution_url' => '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', + 'primary_color' => '#a53c17', + ], + 'bernie-cetonia-aurata-take-off-composition.jpg' => [ + 'attribution' => $this->l10n->t('Cetonia aurata take off composition (Bernie, Public Domain)'), + 'description' => $this->l10n->t('Montage of a cetonia aurata bug that takes off with white background'), + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Cetonia_aurata_take_off_composition_05172009.jpg', + 'theming' => self::THEMING_MODE_DARK, + 'primary_color' => '#56633d', + ], + 'dejan-krsmanovic-ribbed-red-metal.jpg' => [ + 'attribution' => $this->l10n->t('Ribbed red metal (Dejan Krsmanovic, CC BY)'), + 'description' => $this->l10n->t('Abstract picture of red ribbed metal with two horizontal white elements on top of it'), + 'attribution_url' => 'https://www.flickr.com/photos/dejankrsmanovic/42971456774/', + 'primary_color' => '#9c4236', + ], + 'eduardo-neves-pedra-azul.jpg' => [ + 'attribution' => $this->l10n->t('Pedra azul milky way (Eduardo Neves, CC BY-SA)'), + 'description' => $this->l10n->t('Picture of the milky way during night with a mountain in front of it'), + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:Pedra_Azul_Milky_Way.jpg', + 'primary_color' => '#4f6071', + ], + 'european-space-agency-barents-bloom.jpg' => [ + 'attribution' => $this->l10n->t('Barents bloom (European Space Agency, CC BY-SA)'), + 'description' => $this->l10n->t('Abstract picture of blooming barents in blue and green colors'), + 'attribution_url' => 'https://www.esa.int/ESA_Multimedia/Images/2016/08/Barents_bloom', + 'primary_color' => '#396475', + ], + 'hannes-fritz-flippity-floppity.jpg' => [ + 'attribution' => $this->l10n->t('Flippity floppity (Hannes Fritz, CC BY-SA)'), + 'description' => $this->l10n->t('Abstract picture of many pairs of flip flops hanging on a wall in multiple colors'), + 'attribution_url' => 'http://hannes.photos/flippity-floppity', + 'primary_color' => '#98415a', + ], + 'hannes-fritz-roulette.jpg' => [ + 'attribution' => $this->l10n->t('Roulette (Hannes Fritz, CC BY-SA)'), + 'description' => $this->l10n->t('Picture of a rotating giant wheel during night'), + 'attribution_url' => 'http://hannes.photos/roulette', + 'primary_color' => '#845334', + ], + 'hannes-fritz-sea-spray.jpg' => [ + 'attribution' => $this->l10n->t('Sea spray (Hannes Fritz, CC BY-SA)'), + 'description' => $this->l10n->t('Picture of a stone coast with fog and sea behind it'), + 'attribution_url' => 'http://hannes.photos/sea-spray', + 'primary_color' => '#4f6071', + ], + 'kamil-porembinski-clouds.jpg' => [ + 'attribution' => $this->l10n->t('Clouds (Kamil Porembiński, CC BY-SA)'), + 'description' => $this->l10n->t('Picture of white clouds on in front of a blue sky'), + 'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/', + 'primary_color' => self::DEFAULT_COLOR, + ], + 'bernard-spragg-new-zealand-fern.jpg' => [ + 'attribution' => $this->l10n->t('New zealand fern (Bernard Spragg, CC0)'), + 'description' => $this->l10n->t('Abstract picture of fern leafes'), + 'attribution_url' => 'https://commons.wikimedia.org/wiki/File:NZ_Fern.(Blechnum_chambersii)_(11263534936).jpg', + 'primary_color' => '#316b26', + ], + 'rawpixel-pink-tapioca-bubbles.jpg' => [ + 'attribution' => $this->l10n->t('Pink tapioca bubbles (Rawpixel, CC BY)'), + 'description' => $this->l10n->t('Abstract picture of pink tapioca bubbles'), + 'attribution_url' => 'https://www.flickr.com/photos/byrawpixel/27665140298/in/photostream/', + 'theming' => self::THEMING_MODE_DARK, + 'primary_color' => '#7b4e7e', + ], + 'nasa-waxing-crescent-moon.jpg' => [ + 'attribution' => $this->l10n->t('Waxing crescent moon (NASA, Public Domain)'), + 'description' => $this->l10n->t('Picture of glowing earth in foreground and moon in the background'), + 'attribution_url' => 'https://www.nasa.gov/image-feature/a-waxing-crescent-moon', + 'primary_color' => '#005ac1', + ], + 'tommy-chau-already.jpg' => [ + 'attribution' => $this->l10n->t('Cityscape (Tommy Chau, CC BY)'), + 'description' => $this->l10n->t('Picture of a skyscraper city during night'), + 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/16910999368', + 'primary_color' => '#6a2af4', + ], + 'tommy-chau-lion-rock-hill.jpg' => [ + 'attribution' => $this->l10n->t('Lion rock hill (Tommy Chau, CC BY)'), + 'description' => $this->l10n->t('Picture of mountains during sunset or sunrise'), + 'attribution_url' => 'https://www.flickr.com/photos/90975693@N05/17136440246', + 'theming' => self::THEMING_MODE_DARK, + 'primary_color' => '#7f4f70', + ], + 'lali-masriera-yellow-bricks.jpg' => [ + 'attribution' => $this->l10n->t('Yellow bricks (Lali Masriera, CC BY)'), + 'description' => $this->l10n->t('Picture of yellow bricks with some yellow tubes'), + 'attribution_url' => 'https://www.flickr.com/photos/visualpanic/3982464447', + 'theming' => self::THEMING_MODE_DARK, + 'primary_color' => '#7f5700', + ], + ]; + } } diff --git a/apps/theming/lib/Themes/CommonThemeTrait.php b/apps/theming/lib/Themes/CommonThemeTrait.php index 66775500f659c..652fb9888671d 100644 --- a/apps/theming/lib/Themes/CommonThemeTrait.php +++ b/apps/theming/lib/Themes/CommonThemeTrait.php @@ -122,7 +122,7 @@ protected function generateGlobalBackgroundVariables(): array { /** * Generate user theming background-related variables */ - protected function generateUserBackgroundVariables(): array { + protected function generateUserBackgroundVariables(BackgroundService $backgroundService): array { $user = $this->userSession->getUser(); if ($user !== null && !$this->themingDefaults->isUserThemingDisabled() @@ -162,11 +162,11 @@ protected function generateUserBackgroundVariables(): array { } // The user picked a shipped background - if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) { + if (isset($backgroundService->getShippedBackgrounds()[$backgroundImage])) { return [ '--image-background' => "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "img/background/$backgroundImage") . "')", '--color-background-plain' => $this->themingDefaults->getColorPrimary(), - '--background-image-invert-if-bright' => BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage]['theming'] ?? null === BackgroundService::THEMING_MODE_DARK ? 'invert(100%)' : 'no', + '--background-image-invert-if-bright' => $backgroundService->getShippedBackgrounds()[$backgroundImage]['theming'] ?? null === BackgroundService::THEMING_MODE_DARK ? 'invert(100%)' : 'no', ]; } } diff --git a/apps/theming/lib/Themes/DefaultTheme.php b/apps/theming/lib/Themes/DefaultTheme.php index e2bd31548ca6e..775702aab7f55 100644 --- a/apps/theming/lib/Themes/DefaultTheme.php +++ b/apps/theming/lib/Themes/DefaultTheme.php @@ -46,6 +46,7 @@ class DefaultTheme implements ITheme { public IConfig $config; public IL10N $l; public IAppManager $appManager; + public BackgroundService $backgroundService; public string $defaultPrimaryColor; public string $primaryColor; @@ -57,7 +58,8 @@ public function __construct(Util $util, ImageManager $imageManager, IConfig $config, IL10N $l, - IAppManager $appManager) { + IAppManager $appManager, + BackgroundService $backgroundService) { $this->util = $util; $this->themingDefaults = $themingDefaults; $this->userSession = $userSession; @@ -66,6 +68,7 @@ public function __construct(Util $util, $this->config = $config; $this->l = $l; $this->appManager = $appManager; + $this->backgroundService = $backgroundService; $this->defaultPrimaryColor = $this->themingDefaults->getDefaultColorPrimary(); $this->primaryColor = $this->themingDefaults->getColorPrimary(); @@ -210,7 +213,7 @@ public function getCSSVariables(): array { // Primary variables $variables = array_merge($variables, $this->generatePrimaryVariables($colorMainBackground, $colorMainText)); $variables = array_merge($variables, $this->generateGlobalBackgroundVariables()); - $variables = array_merge($variables, $this->generateUserBackgroundVariables()); + $variables = array_merge($variables, $this->generateUserBackgroundVariables($this->backgroundService)); return $variables; } diff --git a/apps/theming/src/components/BackgroundSettings.vue b/apps/theming/src/components/BackgroundSettings.vue index f7dfefad01763..0a8c49be45e34 100644 --- a/apps/theming/src/components/BackgroundSettings.vue +++ b/apps/theming/src/components/BackgroundSettings.vue @@ -87,7 +87,7 @@