diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-03-06 11:13:29 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2024-03-07 22:40:31 +0100 |
commit | 876e2d6198040553cdf0b184fb585b3b63048a7d (patch) | |
tree | bccdffb7f66222df0f5261c26a38c845a640abe7 /lib/private | |
parent | 26728846b40bb1819ad4de507f397b944d15877b (diff) | |
download | nextcloud-server-876e2d6198040553cdf0b184fb585b3b63048a7d.tar.gz nextcloud-server-876e2d6198040553cdf0b184fb585b3b63048a7d.zip |
feat(AppManager): Provide `getAppIcon` function
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/App/AppManager.php | 16 | ||||
-rw-r--r-- | lib/private/NavigationManager.php | 12 | ||||
-rw-r--r-- | lib/private/Server.php | 3 |
3 files changed, 25 insertions, 6 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 5eeb7ef1fbd..5dec4e7ccde 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -56,6 +56,7 @@ use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; use OCP\IGroupManager; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; use OCP\Settings\IManager as ISettingsManager; @@ -104,9 +105,24 @@ class AppManager implements IAppManager { private ICacheFactory $memCacheFactory, private IEventDispatcher $dispatcher, private LoggerInterface $logger, + private IURLGenerator $urlGenerator, ) { } + public function getAppIcon(string $appId): ?string { + $possibleIcons = [$appId . '.svg', 'app.svg', $appId . '-dark.svg', 'app-dark.svg']; + $icon = null; + foreach ($possibleIcons as $iconName) { + try { + $icon = $this->urlGenerator->imagePath($appId, $iconName); + break; + } catch (\RuntimeException $e) { + // ignore + } + } + return $icon; + } + /** * @return string[] $appId => $enabled */ diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 17573d9db86..cac52ab5c9f 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -372,16 +372,18 @@ class NavigationManager implements INavigationManager { $order = $nav['order'] ?? 100; $type = $nav['type']; $route = !empty($nav['route']) ? $this->urlGenerator->linkToRoute($nav['route']) : ''; - $icon = $nav['icon'] ?? 'app.svg'; - foreach ([$icon, "$app.svg"] as $i) { + $icon = $nav['icon'] ?? null; + if ($icon !== null) { try { - $icon = $this->urlGenerator->imagePath($app, $i); - break; + $icon = $this->urlGenerator->imagePath($app, $icon); } catch (\RuntimeException $ex) { - // no icon? - ignore it then + // ignore } } if ($icon === null) { + $icon = $this->appManager->getAppIcon($app); + } + if ($icon === null) { $icon = $this->urlGenerator->imagePath('core', 'default-app-icon'); } diff --git a/lib/private/Server.php b/lib/private/Server.php index 385d654b951..2732b6486f2 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -893,7 +893,8 @@ class Server extends ServerContainer implements IServerContainer { $c->get(IGroupManager::class), $c->get(ICacheFactory::class), $c->get(IEventDispatcher::class), - $c->get(LoggerInterface::class) + $c->get(LoggerInterface::class), + $c->get(IURLGenerator::class), ); }); /** @deprecated 19.0.0 */ |