27
27
*/
28
28
namespace OCA \Theming ;
29
29
30
+ use Exception ;
31
+ use OCA \Theming \AppInfo \Application ;
32
+ use OCA \Theming \Service \BackgroundService ;
30
33
use OCP \Capabilities \IPublicCapability ;
31
34
use OCP \IConfig ;
32
35
use OCP \IURLGenerator ;
36
+ use OCP \IUser ;
37
+ use OCP \IUserSession ;
33
38
34
39
/**
35
40
* Class Capabilities
@@ -50,17 +55,20 @@ class Capabilities implements IPublicCapability {
50
55
/** @var IConfig */
51
56
protected $ config ;
52
57
58
+ protected IUserSession $ userSession ;
59
+
53
60
/**
54
61
* @param ThemingDefaults $theming
55
62
* @param Util $util
56
63
* @param IURLGenerator $url
57
64
* @param IConfig $config
58
65
*/
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 ) {
60
67
$ this ->theming = $ theming ;
61
68
$ this ->util = $ util ;
62
69
$ this ->url = $ url ;
63
70
$ this ->config = $ config ;
71
+ $ this ->userSession = $ userSession ;
64
72
}
65
73
66
74
/**
@@ -86,23 +94,44 @@ public function __construct(ThemingDefaults $theming, Util $util, IURLGenerator
86
94
* }
87
95
*/
88
96
public function getCapabilities () {
97
+ $ color = $ this ->theming ->getDefaultColorPrimary ();
98
+ $ colorText = $ this ->theming ->getDefaultTextColorPrimary ();
99
+
89
100
$ 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
+
91
122
return [
92
123
'theming ' => [
93
124
'name ' => $ this ->theming ->getName (),
94
125
'url ' => $ this ->theming ->getBaseUrl (),
95
126
'slogan ' => $ this ->theming ->getSlogan (),
96
127
'color ' => $ color ,
97
- 'color-text ' => $ this -> theming -> getTextColorPrimary () ,
128
+ 'color-text ' => $ colorText ,
98
129
'color-element ' => $ this ->util ->elementColor ($ color ),
99
130
'color-element-bright ' => $ this ->util ->elementColor ($ color ),
100
131
'color-element-dark ' => $ this ->util ->elementColor ($ color , false ),
101
132
'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 ,
106
135
'background-default ' => !$ this ->util ->isBackgroundThemed (),
107
136
'logoheader ' => $ this ->url ->getAbsoluteURL ($ this ->theming ->getLogo ()),
108
137
'favicon ' => $ this ->url ->getAbsoluteURL ($ this ->theming ->getLogo ()),
0 commit comments