@ -27,10 +27,11 @@ declare(strict_types=1);
namespace OC\Dashboard;
namespace OC\Dashboard;
use InvalidArgumentException;
use InvalidArgumentException;
use OCP\AppFramework\QueryException ;
use OCP\App\IAppManager ;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
use OCP\Dashboard\IWidget;
use OCP\IServerContainer;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Throwable;
use Throwable;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerInterface;
@ -42,11 +43,12 @@ class Manager implements IManager {
/** @var IWidget[] */
/** @var IWidget[] */
private $widgets = [];
private $widgets = [];
/** @var IServerContainer */
private ContainerInterface $serverContainer;
private $serverContain er;
private IAppManager $appManag er;
public function __construct(IServer Container $serverContainer) {
public function __construct(ContainerInterface $serverContainer, IAppManager $appManag er) {
$this->serverContainer = $serverContainer;
$this->serverContainer = $serverContainer;
$this->appManager = $appManager;
}
}
private function registerWidget(IWidget $widget): void {
private function registerWidget(IWidget $widget): void {
@ -57,17 +59,22 @@ class Manager implements IManager {
$this->widgets[$widget->getId()] = $widget;
$this->widgets[$widget->getId()] = $widget;
}
}
public function lazyRegisterWidget(string $widgetClass): void {
public function lazyRegisterWidget(string $widgetClass, string $appId ): void {
$this->lazyWidgets[] = $widgetClass;
$this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId] ;
}
}
public function loadLazyPanels(): void {
public function loadLazyPanels(): void {
$classes = $this->lazyWidgets;
$services = $this->lazyWidgets;
foreach ($classes as $class) {
foreach ($services as $service) {
/** @psalm-suppress InvalidCatch */
try {
try {
if (!$this->appManager->isEnabledForUser($service['appId'])) {
// all apps are registered, but some may not be enabled for the user
continue;
}
/** @var IWidget $widget */
/** @var IWidget $widget */
$widget = $this->serverContainer->query($class);
$widget = $this->serverContainer->get($service['class'] );
} catch (QueryException $e) {
} catch (ContainerExceptionInterface $e) {
/*
/*
* There is a circular dependency between the logger and the registry, so
* There is a circular dependency between the logger and the registry, so
* we can not inject it. Thus the static call.
* we can not inject it. Thus the static call.
@ -90,7 +97,7 @@ class Manager implements IManager {
*/
*/
\OC::$server->get(LoggerInterface::class)->critical(
\OC::$server->get(LoggerInterface::class)->critical(
'Could not register lazy dashboard widget: ' . $e->getMessage(),
'Could not register lazy dashboard widget: ' . $e->getMessage(),
['excepi ton' => $e]
['excepti on' => $e]
);
);
}
}
@ -111,7 +118,7 @@ class Manager implements IManager {
} catch (Throwable $e) {
} catch (Throwable $e) {
\OC::$server->get(LoggerInterface::class)->critical(
\OC::$server->get(LoggerInterface::class)->critical(
'Error during dashboard widget loading: ' . $e->getMessage(),
'Error during dashboard widget loading: ' . $e->getMessage(),
['excepi ton' => $e]
['excepti on' => $e]
);
);
}
}
}
}