diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2022-12-08 09:46:59 +0100 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2022-12-08 17:52:50 +0100 |
commit | 1acd42e10ce13d253516efb722f7d05e74fa46e9 (patch) | |
tree | fa04592316f60f454794d761567e25038fc80ce0 /apps/theming/lib | |
parent | fabcd68a5e2c4909dc58d35e756acb0675e61311 (diff) | |
download | nextcloud-server-1acd42e10ce13d253516efb722f7d05e74fa46e9.tar.gz nextcloud-server-1acd42e10ce13d253516efb722f7d05e74fa46e9.zip |
Invert header if primary is bright and background disabled
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/theming/lib')
-rw-r--r-- | apps/theming/lib/Controller/UserThemeController.php | 12 | ||||
-rw-r--r-- | apps/theming/lib/Themes/CommonThemeTrait.php | 15 |
2 files changed, 17 insertions, 10 deletions
diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php index a227e72d998..6a58366c4f6 100644 --- a/apps/theming/lib/Controller/UserThemeController.php +++ b/apps/theming/lib/Controller/UserThemeController.php @@ -50,16 +50,14 @@ use OCP\PreConditionNotMetException; class UserThemeController extends OCSController { - protected string $userId; + protected ?string $userId = null; + private IConfig $config; private IUserSession $userSession; private ThemesService $themesService; private ThemingDefaults $themingDefaults; private BackgroundService $backgroundService; - /** - * Config constructor. - */ public function __construct(string $appName, IRequest $request, IConfig $config, @@ -73,7 +71,11 @@ class UserThemeController extends OCSController { $this->themesService = $themesService; $this->themingDefaults = $themingDefaults; $this->backgroundService = $backgroundService; - $this->userId = $userSession->getUser()->getUID(); + + $user = $userSession->getUser(); + if ($user !== null) { + $this->userId = $user->getUID(); + } } /** diff --git a/apps/theming/lib/Themes/CommonThemeTrait.php b/apps/theming/lib/Themes/CommonThemeTrait.php index 0305a95b3d5..17591c232bb 100644 --- a/apps/theming/lib/Themes/CommonThemeTrait.php +++ b/apps/theming/lib/Themes/CommonThemeTrait.php @@ -24,10 +24,10 @@ declare(strict_types=1); */ namespace OCA\Theming\Themes; -use OCA\Theming\AppInfo\Application; +use OCA\Theming\Util; use OCA\Theming\ImageManager; +use OCA\Theming\AppInfo\Application; use OCA\Theming\Service\BackgroundService; -use OCA\Theming\Util; trait CommonThemeTrait { public Util $util; @@ -82,9 +82,9 @@ trait CommonThemeTrait { * Generate admin theming background-related variables */ protected function generateGlobalBackgroundVariables(): array { - $user = $this->userSession->getUser(); $backgroundDeleted = $this->config->getAppValue(Application::APP_ID, 'backgroundMime', '') === 'backgroundColor'; $hasCustomLogoHeader = $this->util->isLogoThemed(); + $isDefaultPrimaryBright = $this->util->invertTextColor($this->defaultPrimaryColor); $variables = []; @@ -95,8 +95,10 @@ trait CommonThemeTrait { // If primary as background has been request or if we have a custom primary colour // let's not define the background image if ($backgroundDeleted) { - $variables['--color-background-plain'] = $this->themingDefaults->getColorPrimary(); + $variables['--color-background-plain'] = $this->defaultPrimaryColor; $variables['--image-background-plain'] = 'yes'; + // If no background image is set, we need to check against the shown primary colour + $variables['--background-image-invert-if-bright'] = $isDefaultPrimaryBright ? 'invert(100%)' : 'no'; } // Register image variables only if custom-defined @@ -125,12 +127,15 @@ trait CommonThemeTrait { && $this->appManager->isEnabledForUser(Application::APP_ID)) { $backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT); $currentVersion = (int)$this->config->getUserValue($user->getUID(), Application::APP_ID, 'userCacheBuster', '0'); + $isPrimaryBright = $this->util->invertTextColor($this->primaryColor); // The user removed the background if ($backgroundImage === BackgroundService::BACKGROUND_DISABLED) { return [ '--image-background' => 'no', - '--color-background-plain' => $this->themingDefaults->getColorPrimary(), + '--color-background-plain' => $this->primaryColor, + // If no background image is set, we need to check against the shown primary colour + '--background-image-invert-if-bright' => $isPrimaryBright ? 'invert(100%)' : 'no', ]; } |