2727 */
2828namespace OCA \Theming ;
2929
30+ use Exception ;
31+ use OCA \Theming \AppInfo \Application ;
32+ use OCA \Theming \Service \BackgroundService ;
3033use OCP \Capabilities \IPublicCapability ;
3134use OCP \IConfig ;
3235use OCP \IURLGenerator ;
36+ use OCP \IUser ;
37+ use OCP \IUserSession ;
3338
3439/**
3540 * Class Capabilities
@@ -50,17 +55,20 @@ class Capabilities implements IPublicCapability {
5055 /** @var IConfig */
5156 protected $ config ;
5257
58+ protected IUserSession $ userSession ;
59+
5360 /**
5461 * @param ThemingDefaults $theming
5562 * @param Util $util
5663 * @param IURLGenerator $url
5764 * @param IConfig $config
5865 */
59- public function __construct (ThemingDefaults $ theming , Util $ util , IURLGenerator $ url , IConfig $ config ) {
66+ public function __construct (ThemingDefaults $ theming , Util $ util , IURLGenerator $ url , IConfig $ config, IUserSession $ userSession ) {
6067 $ this ->theming = $ theming ;
6168 $ this ->util = $ util ;
6269 $ this ->url = $ url ;
6370 $ this ->config = $ config ;
71+ $ this ->userSession = $ userSession ;
6472 }
6573
6674 /**
@@ -86,23 +94,44 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator
8694 * }
8795 */
8896 public function getCapabilities () {
97+ $ color = $ this ->theming ->getDefaultColorPrimary ();
98+ $ colorText = $ this ->theming ->getDefaultTextColorPrimary ();
99+
89100 $ backgroundLogo = $ this ->config ->getAppValue ('theming ' , 'backgroundMime ' , '' );
90- $ color = $ this ->theming ->getColorPrimary ();
101+ $ backgroundPlain = $ backgroundLogo === 'backgroundColor ' || ($ backgroundLogo === '' && $ color !== '#0082c9 ' );
102+ $ background = $ backgroundPlain ? $ color : $ this ->url ->getAbsoluteURL ($ this ->theming ->getBackground ());
103+
104+ $ user = $ this ->userSession ->getUser ();
105+ if ($ user instanceof IUser) {
106+ $ color = $ this ->theming ->getColorPrimary ();
107+ $ colorText = $ this ->theming ->getTextColorPrimary ();
108+
109+ $ backgroundImage = $ this ->config ->getUserValue ($ user ->getUID (), Application::APP_ID , 'background_image ' , BackgroundService::BACKGROUND_DEFAULT );
110+ if ($ backgroundImage === BackgroundService::BACKGROUND_CUSTOM ) {
111+ $ backgroundPlain = false ;
112+ $ background = $ this ->url ->linkToRouteAbsolute ('theming.userTheme.getBackground ' );
113+ } else if (isset (BackgroundService::SHIPPED_BACKGROUNDS [$ backgroundImage ])) {
114+ $ backgroundPlain = false ;
115+ $ background = $ this ->url ->linkTo (Application::APP_ID , "img/background/ $ backgroundImage " );
116+ } else if ($ backgroundImage !== BackgroundService::BACKGROUND_DEFAULT ) {
117+ $ backgroundPlain = true ;
118+ $ background = $ color ;
119+ }
120+ }
121+
91122 return [
92123 'theming ' => [
93124 'name ' => $ this ->theming ->getName (),
94125 'url ' => $ this ->theming ->getBaseUrl (),
95126 'slogan ' => $ this ->theming ->getSlogan (),
96127 'color ' => $ color ,
97- 'color-text ' => $ this -> theming -> getTextColorPrimary () ,
128+ 'color-text ' => $ colorText ,
98129 'color-element ' => $ this ->util ->elementColor ($ color ),
99130 'color-element-bright ' => $ this ->util ->elementColor ($ color ),
100131 'color-element-dark ' => $ this ->util ->elementColor ($ color , false ),
101132 'logo ' => $ this ->url ->getAbsoluteURL ($ this ->theming ->getLogo ()),
102- 'background ' => $ backgroundLogo === 'backgroundColor ' || ($ backgroundLogo === '' && $ this ->theming ->getColorPrimary () !== '#0082c9 ' ) ?
103- $ this ->theming ->getColorPrimary () :
104- $ this ->url ->getAbsoluteURL ($ this ->theming ->getBackground ()),
105- 'background-plain ' => $ backgroundLogo === 'backgroundColor ' || ($ backgroundLogo === '' && $ this ->theming ->getColorPrimary () !== '#0082c9 ' ),
133+ 'background ' => $ background ,
134+ 'background-plain ' => $ backgroundPlain ,
106135 'background-default ' => !$ this ->util ->isBackgroundThemed (),
107136 'logoheader ' => $ this ->url ->getAbsoluteURL ($ this ->theming ->getLogo ()),
108137 'favicon ' => $ this ->url ->getAbsoluteURL ($ this ->theming ->getLogo ()),
0 commit comments