Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions apps/theming/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

use OCA\Theming\AppInfo\Application;
use OCA\Theming\Service\BackgroundService;
use OCA\Theming\Service\ThemesService;
use OCP\Capabilities\IPublicCapability;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IAppConfig;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
Expand All @@ -21,18 +23,14 @@
*/
class Capabilities implements IPublicCapability {

/**
* @param ThemingDefaults $theming
* @param Util $util
* @param IURLGenerator $url
* @param IConfig $config
*/
public function __construct(
protected ThemingDefaults $theming,
protected Util $util,
protected IURLGenerator $url,
protected IConfig $config,
protected IAppConfig $appConfig,
protected IUserConfig $userConfig,
protected IUserSession $userSession,
protected ThemesService $themesService,
) {
}

Expand All @@ -44,6 +42,8 @@ public function __construct(
* name: string,
* productName: string,
* url: string,
* imprintUrl: string,
* privacyUrl: string,
* slogan: string,
* color: string,
* color-text: string,
Expand All @@ -57,14 +57,21 @@ public function __construct(
* background-default: bool,
* logoheader: string,
* favicon: string,
* primaryColor: string,
* backgroundColor: string,
* defaultPrimaryColor: string,
* defaultBackgroundColor: string,
* inverted: bool,
* cacheBuster: string,
* enabledThemes: list<string>,
* },
* }
*/
public function getCapabilities() {
$color = $this->theming->getDefaultColorPrimary();
$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';

$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
$backgroundLogo = $this->appConfig->getValueString('theming', 'backgroundMime', '');
$backgroundColor = $this->theming->getColorBackground();
$backgroundText = $this->theming->getTextColorBackground();
$backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $backgroundColor !== BackgroundService::DEFAULT_COLOR);
Expand All @@ -80,7 +87,7 @@ public function getCapabilities() {
$color = $this->theming->getColorPrimary();
$colorText = $this->theming->getTextColorPrimary();

$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
$backgroundImage = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {
$backgroundPlain = false;
$background = $this->url->linkToRouteAbsolute('theming.userTheme.getBackground');
Expand All @@ -98,6 +105,8 @@ public function getCapabilities() {
'name' => $this->theming->getName(),
'productName' => $this->theming->getProductName(),
'url' => $this->theming->getBaseUrl(),
'imprintUrl' => $this->theming->getImprintUrl(),
'privacyUrl' => $this->theming->getPrivacyUrl(),
'slogan' => $this->theming->getSlogan(),
'color' => $color,
'color-text' => $colorText,
Expand All @@ -111,6 +120,13 @@ public function getCapabilities() {
'background-default' => !$this->util->isBackgroundThemed(),
'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),
'primaryColor' => $color,
'backgroundColor' => $backgroundColor,
'defaultPrimaryColor' => $this->theming->getDefaultColorPrimary(),
'defaultBackgroundColor' => $this->theming->getDefaultColorBackground(),
'inverted' => $this->util->invertTextColor($color),
'cacheBuster' => $this->util->getCacheBuster(),
'enabledThemes' => $this->themesService->getEnabledThemes(),
],
];
}
Expand Down
7 changes: 3 additions & 4 deletions apps/theming/lib/Service/JSDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;

/**
* @deprecated since Nextcloud 34 — all properties are now exposed via Capabilities
*/
class JSDataService implements \JsonSerializable {

public function __construct(
Expand Down Expand Up @@ -40,10 +43,6 @@ public function jsonSerialize(): array {

'cacheBuster' => $this->util->getCacheBuster(),
'enabledThemes' => $this->themesService->getEnabledThemes(),

// deprecated use primaryColor
'color' => $this->themingDefaults->getColorPrimary(),
'' => 'color is deprecated since Nextcloud 29, use primaryColor instead'
];
}
}
5 changes: 3 additions & 2 deletions apps/theming/lib/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public function isEnabled(ITheme $theme): bool {
/**
* Get the list of all enabled themes IDs for the current user.
*
* @return string[]
* @return list<string>
*/
public function getEnabledThemes(): array {
public function getEnabledThemes() {
$enforcedTheme = $this->config->getSystemValueString('enforce_theme', '');
$user = $this->userSession->getUser();
if ($user === null) {
Expand All @@ -163,6 +163,7 @@ public function getEnabledThemes(): array {
return [];
}

/** @var list<string> */
$enabledThemes = json_decode($this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled-themes', '["default"]'));
if ($enforcedTheme !== '') {
return array_merge([$enforcedTheme], $enabledThemes);
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getEntity() {
return strip_tags($this->appConfig->getAppValueString(ConfigLexicon::INSTANCE_NAME, $this->entity));
}

public function getProductName() {
public function getProductName(): string {
return strip_tags($this->appConfig->getAppValueString(ConfigLexicon::PRODUCT_NAME, $this->productName));
}

Expand Down
41 changes: 40 additions & 1 deletion apps/theming/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"name",
"productName",
"url",
"imprintUrl",
"privacyUrl",
"slogan",
"color",
"color-text",
Expand All @@ -93,7 +95,14 @@
"background-plain",
"background-default",
"logoheader",
"favicon"
"favicon",
"primaryColor",
"backgroundColor",
"defaultPrimaryColor",
"defaultBackgroundColor",
"inverted",
"cacheBuster",
"enabledThemes"
],
"properties": {
"name": {
Expand All @@ -105,6 +114,12 @@
"url": {
"type": "string"
},
"imprintUrl": {
"type": "string"
},
"privacyUrl": {
"type": "string"
},
"slogan": {
"type": "string"
},
Expand Down Expand Up @@ -143,6 +158,30 @@
},
"favicon": {
"type": "string"
},
"primaryColor": {
"type": "string"
},
"backgroundColor": {
"type": "string"
},
"defaultPrimaryColor": {
"type": "string"
},
"defaultBackgroundColor": {
"type": "string"
},
"inverted": {
"type": "boolean"
},
"cacheBuster": {
"type": "string"
},
"enabledThemes": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Expand Down
Loading
Loading