From 064fa10ecfe4725398895a21ab8bafd171e2eadd Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Thu, 20 Oct 2022 16:03:19 +0200 Subject: Extract colour from custom background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- apps/theming/lib/Controller/UserThemeController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'apps/theming/lib/Controller') diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php index 888ab9a0ca8..112a8a23638 100644 --- a/apps/theming/lib/Controller/UserThemeController.php +++ b/apps/theming/lib/Controller/UserThemeController.php @@ -168,9 +168,15 @@ class UserThemeController extends OCSController { /** * @NoAdminRequired */ - public function setBackground(string $type = BackgroundService::BACKGROUND_DEFAULT, string $value = ''): JSONResponse { + public function setBackground(string $type = BackgroundService::BACKGROUND_DEFAULT, string $value = '', string $color = null): JSONResponse { $currentVersion = (int)$this->config->getUserValue($this->userId, Application::APP_ID, 'userCacheBuster', '0'); + // Set color if provided + if ($color) { + $this->backgroundService->setColorBackground($color); + } + + // Set background image if provided try { switch ($type) { case BackgroundService::BACKGROUND_SHIPPED: @@ -179,14 +185,13 @@ class UserThemeController extends OCSController { case BackgroundService::BACKGROUND_CUSTOM: $this->backgroundService->setFileBackground($value); break; - case 'color': - $this->backgroundService->setColorBackground($value); - break; case BackgroundService::BACKGROUND_DEFAULT: $this->backgroundService->setDefaultBackground(); break; default: - return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST); + if (!$color) { + return new JSONResponse(['error' => 'Invalid type provided'], Http::STATUS_BAD_REQUEST); + } } } catch (\InvalidArgumentException $e) { return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); -- cgit v1.2.3