Skip to content

Commit d2f2f62

Browse files
fixup! fix: generate favourite icon without imagick svg support
Signed-off-by: SebastianKrupinski <[email protected]>
1 parent 69057a5 commit d2f2f62

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

apps/theming/lib/Controller/IconController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public function getFavicon(string $app = 'core'): Response {
9797

9898
$response = null;
9999
$iconFile = null;
100-
// retrieve instance favorite icon
100+
// retrieve instance favicon
101101
try {
102102
$iconFile = $this->imageManager->getImage('favicon', false);
103103
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
104104
} catch (NotFoundException $e) {
105105
}
106-
// retrieve or generate app specific favorite icon
106+
// retrieve or generate app specific favicon
107107
if (($this->imageManager->canConvert('PNG') || $this->imageManager->canConvert('SVG')) && $this->imageManager->canConvert('ICO')) {
108108
$color = $this->themingDefaults->getColorPrimary();
109109
try {
@@ -117,7 +117,7 @@ public function getFavicon(string $app = 'core'): Response {
117117
}
118118
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => 'image/x-icon']);
119119
}
120-
// fallback to core favorite icon
120+
// fallback to core favicon
121121
if ($response === null) {
122122
$fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png';
123123
$response = new DataDisplayResponse($this->fileAccessHelper->file_get_contents($fallbackLogo), Http::STATUS_OK, ['Content-Type' => 'image/png']);
@@ -145,7 +145,7 @@ public function getTouchIcon(string $app = 'core'): Response {
145145
}
146146

147147
$response = null;
148-
// retrieve instance favorite icon
148+
// retrieve instance favicon
149149
try {
150150
$iconFile = $this->imageManager->getImage('favicon');
151151
$response = new FileDisplayResponse($iconFile, Http::STATUS_OK, ['Content-Type' => $iconFile->getMimeType()]);

apps/theming/lib/IconBuilder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,23 @@ public function renderAppIcon($app, $size) {
114114
if ($appIconContent === false || $appIconContent === '') {
115115
return false;
116116
}
117-
118-
$appIconFile = null;
119-
$appIconIsSvg = ($mime === 'image/svg+xml' || substr($appIconContent, 0, 4) === '<svg');
120-
121-
// if source image is svg but svg not supported, abort
117+
118+
$appIconIsSvg = ($mime === 'image/svg+xml' || str_starts_with($appIconContent, '<svg') || str_starts_with($appIconContent, '<?xml'));
119+
// if source image is svg but svg not supported, abort.
120+
// source images are both user and developer set, and there is guarantees that mime and extension match actual contents type
122121
if ($appIconIsSvg && !$supportSvg) {
123122
return false;
124123
}
125124

125+
// construct original image object
126126
try {
127-
// construct original image object
128127
$appIconFile = new Imagick();
129128
$appIconFile->setBackgroundColor(new ImagickPixel('transparent'));
130129

131130
if ($appIconIsSvg) {
132131
// handle SVG images
133132
// ensure proper XML declaration
134-
if (substr($appIconContent, 0, 5) !== '<?xml') {
133+
if (str_starts_with($appIconContent, '<?xml')) {
135134
$svg = '<?xml version="1.0"?>' . $appIconContent;
136135
} else {
137136
$svg = $appIconContent;

apps/theming/lib/ImageManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function shouldReplaceIcons() {
391391
*
392392
* @return bool
393393
*/
394-
public function canConvert(string $format = 'SVG'): bool {
394+
public function canConvert(string $format): bool {
395395
$cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl());
396396
if ($value = $cache->get('convert-' . $format)) {
397397
return (bool)$value;

apps/theming/lib/Util.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,24 +211,16 @@ public function getAppIcon($app, $useSvg = true) {
211211
try {
212212
// find app specific icon
213213
$appPath = $this->appManager->getAppPath($app);
214-
if ($useSvg) {
215-
$icon = $appPath . '/img/' . $app . '.svg';
216-
if (file_exists($icon)) {
217-
return $icon;
218-
}
219-
$icon = $appPath . '/img/app.svg';
220-
if (file_exists($icon)) {
221-
return $icon;
222-
}
223-
} else {
224-
$icon = $appPath . '/img/' . $app . '.png';
225-
if (file_exists($icon)) {
226-
return $icon;
227-
}
228-
$icon = $appPath . '/img/app.png';
229-
if (file_exists($icon)) {
230-
return $icon;
231-
}
214+
$extension = ($useSvg ? '.svg' : '.png');
215+
216+
$icon = $appPath . '/img/' . $app . $extension;
217+
if (file_exists($icon)) {
218+
return $icon;
219+
}
220+
221+
$icon = $appPath . '/img/app' . $extension;
222+
if (file_exists($icon)) {
223+
return $icon;
232224
}
233225
} catch (AppPathNotFoundException $e) {
234226
}
@@ -242,11 +234,9 @@ public function getAppIcon($app, $useSvg = true) {
242234
}
243235
// fallback to core logo
244236
if ($useSvg) {
245-
$icon = \OC::$SERVERROOT . '/core/img/logo/logo.svg';
246-
return $icon;
237+
return \OC::$SERVERROOT . '/core/img/logo/logo.svg';
247238
} else {
248-
$icon = \OC::$SERVERROOT . '/core/img/logo/logo.png';
249-
return $icon;
239+
return \OC::$SERVERROOT . '/core/img/logo/logo.png';
250240
}
251241
}
252242

0 commit comments

Comments
 (0)