3232use OCA \Theming \IconBuilder ;
3333use OCA \Theming \ImageManager ;
3434use OCA \Theming \ThemingDefaults ;
35+ use OCP \App \IAppManager ;
3536use OCP \AppFramework \Controller ;
3637use OCP \AppFramework \Http ;
3738use OCP \AppFramework \Http \DataDisplayResponse ;
3839use OCP \AppFramework \Http \FileDisplayResponse ;
40+ use OCP \AppFramework \Http \JSONResponse ;
3941use OCP \AppFramework \Http \NotFoundResponse ;
4042use OCP \AppFramework \Http \Response ;
4143use OCP \Files \NotFoundException ;
@@ -50,31 +52,25 @@ class IconController extends Controller {
5052 private $ imageManager ;
5153 /** @var FileAccessHelper */
5254 private $ fileAccessHelper ;
55+ /** @var IAppManager */
56+ private $ appManager ;
5357
54- /**
55- * IconController constructor.
56- *
57- * @param string $appName
58- * @param IRequest $request
59- * @param ThemingDefaults $themingDefaults
60- * @param IconBuilder $iconBuilder
61- * @param ImageManager $imageManager
62- * @param FileAccessHelper $fileAccessHelper
63- */
6458 public function __construct (
6559 $ appName ,
6660 IRequest $ request ,
6761 ThemingDefaults $ themingDefaults ,
6862 IconBuilder $ iconBuilder ,
6963 ImageManager $ imageManager ,
70- FileAccessHelper $ fileAccessHelper
64+ FileAccessHelper $ fileAccessHelper ,
65+ IAppManager $ appManager
7166 ) {
7267 parent ::__construct ($ appName , $ request );
7368
7469 $ this ->themingDefaults = $ themingDefaults ;
7570 $ this ->iconBuilder = $ iconBuilder ;
7671 $ this ->imageManager = $ imageManager ;
7772 $ this ->fileAccessHelper = $ fileAccessHelper ;
73+ $ this ->appManager = $ appManager ;
7874 }
7975
8076 /**
@@ -92,6 +88,11 @@ public function __construct(
9288 * 404: Themed icon not found
9389 */
9490 public function getThemedIcon (string $ app , string $ image ): Response {
91+ if ($ app !== 'core ' && !$ this ->appManager ->isEnabledForUser ($ app )) {
92+ $ app = 'core ' ;
93+ $ image = 'favicon.png ' ;
94+ }
95+
9596 $ color = $ this ->themingDefaults ->getColorPrimary ();
9697 try {
9798 $ iconFileName = $ this ->imageManager ->getCachedImage ('icon- ' . $ app . '- ' . $ color . str_replace ('/ ' , '_ ' , $ image ));
@@ -121,6 +122,10 @@ public function getThemedIcon(string $app, string $image): Response {
121122 * 404: Favicon not found
122123 */
123124 public function getFavicon (string $ app = 'core ' ): Response {
125+ if ($ app !== 'core ' && !$ this ->appManager ->isEnabledForUser ($ app )) {
126+ $ app = 'core ' ;
127+ }
128+
124129 $ response = null ;
125130 $ iconFile = null ;
126131 try {
@@ -163,6 +168,10 @@ public function getFavicon(string $app = 'core'): Response {
163168 * 404: Touch icon not found
164169 */
165170 public function getTouchIcon (string $ app = 'core ' ): Response {
171+ if ($ app !== 'core ' && !$ this ->appManager ->isEnabledForUser ($ app )) {
172+ $ app = 'core ' ;
173+ }
174+
166175 $ response = null ;
167176 try {
168177 $ iconFile = $ this ->imageManager ->getImage ('favicon ' );
0 commit comments