Skip to content

Commit 8de89b2

Browse files
committed
fix(theming): Apply same logic on capabilities for primary color like on themes
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 64ccc1e commit 8de89b2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

apps/theming/lib/Capabilities.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator
9494
*/
9595
public function getCapabilities() {
9696
$color = $this->theming->getDefaultColorPrimary();
97-
$colorText = $this->theming->getDefaultTextColorPrimary();
97+
// Same as in DefaultTheme
98+
if ($color === BackgroundService::DEFAULT_COLOR) {
99+
$color = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
100+
}
101+
$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';
98102

99103
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
100104
$backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $color !== '#0082c9');
@@ -108,7 +112,10 @@ public function getCapabilities() {
108112
* @see \OCA\Theming\Themes\CommonThemeTrait::generateUserBackgroundVariables()
109113
*/
110114
$color = $this->theming->getColorPrimary();
111-
$colorText = $this->theming->getTextColorPrimary();
115+
if ($color === BackgroundService::DEFAULT_COLOR) {
116+
$color = BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
117+
}
118+
$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';
112119

113120
$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
114121
if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {

apps/theming/tests/CapabilitiesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $l
174174
$this->theming->expects($this->exactly(3))
175175
->method('getLogo')
176176
->willReturn($logo);
177-
$this->theming->expects($this->once())
178-
->method('getDefaultTextColorPrimary')
179-
->willReturn($textColor);
180177

181178
$util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class));
182179
$this->util->expects($this->exactly(3))
@@ -186,6 +183,9 @@ public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $l
186183
return $util->elementColor($color, $brightBackground);
187184
});
188185

186+
$this->util->expects($this->any())
187+
->method('invertTextColor')
188+
->willReturnCallback(fn () => $textColor === '#000000');
189189
$this->util->expects($this->once())
190190
->method('isBackgroundThemed')
191191
->willReturn($backgroundThemed);

0 commit comments

Comments
 (0)