diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index d0f9c282f5..2411fcc720 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -15,10 +15,9 @@ use OCA\Libresign\Events\SendSignNotificationEvent; use OCA\Libresign\Events\SignedEvent; use OCA\Libresign\Events\SignRequestCanceledEvent; -use OCA\Libresign\Files\TemplateLoader as FilesTemplateLoader; +use OCA\Libresign\Files\TemplateLoader; use OCA\Libresign\Listener\BeforeNodeDeletedListener; use OCA\Libresign\Listener\LoadAdditionalListener; -use OCA\Libresign\Listener\LoadSidebarListener; use OCA\Libresign\Listener\MailNotifyListener; use OCA\Libresign\Listener\NotificationListener; use OCA\Libresign\Listener\SignedCallbackListener; @@ -31,7 +30,6 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\CacheEntryRemovedEvent; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\User\Events\UserDeletedEvent; @@ -48,12 +46,6 @@ public function __construct() { #[\Override] public function boot(IBootContext $context): void { - $server = $context->getServerContainer(); - - /** @var IEventDispatcher $dispatcher */ - $dispatcher = $server->get(IEventDispatcher::class); - - FilesTemplateLoader::register($dispatcher); } #[\Override] @@ -64,7 +56,7 @@ public function register(IRegistrationContext $context): void { $context->registerNotifierService(Notifier::class); - $context->registerEventListener(LoadSidebar::class, LoadSidebarListener::class); + $context->registerEventListener(LoadSidebar::class, TemplateLoader::class); $context->registerEventListener(BeforeNodeDeletedEvent::class, BeforeNodeDeletedListener::class); $context->registerEventListener(CacheEntryRemovedEvent::class, BeforeNodeDeletedListener::class); $context->registerEventListener(SignedEvent::class, SignedCallbackListener::class); diff --git a/lib/Files/TemplateLoader.php b/lib/Files/TemplateLoader.php index 3868b0e5a2..b95e1e5db9 100644 --- a/lib/Files/TemplateLoader.php +++ b/lib/Files/TemplateLoader.php @@ -15,13 +15,14 @@ use OCA\Libresign\Helper\ValidateHelper; use OCA\Libresign\Service\AccountService; use OCA\Libresign\Service\IdentifyMethodService; +use OCP\App\IAppManager; use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use OCP\IAppConfig; use OCP\IRequest; use OCP\IUserSession; +use OCP\Util; /** * @template-implements IEventListener @@ -36,18 +37,20 @@ public function __construct( private IdentifyMethodService $identifyMethodService, private CertificateEngineFactory $certificateEngineFactory, private IAppConfig $appConfig, + private IAppManager $appManager, ) { } - public static function register(IEventDispatcher $dispatcher): void { - $dispatcher->addServiceListener(LoadSidebar::class, self::class); - } - #[\Override] public function handle(Event $event): void { if (!($event instanceof LoadSidebar)) { return; } + + if (!$this->appManager->isEnabledForUser('libresign')) { + return; + } + $this->initialState->provideInitialState( 'certificate_ok', $this->certificateEngineFactory->getEngine()->isSetupOk() @@ -69,5 +72,8 @@ public function handle(Event $event): void { } catch (LibresignException) { $this->initialState->provideInitialState('can_request_sign', false); } + + Util::addScript(Application::APP_ID, 'libresign-tab'); + Util::addStyle(Application::APP_ID, 'icons'); } } diff --git a/lib/Listener/LoadSidebarListener.php b/lib/Listener/LoadSidebarListener.php deleted file mode 100644 index 0432258315..0000000000 --- a/lib/Listener/LoadSidebarListener.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ -class LoadSidebarListener implements IEventListener { - public function __construct( - private IAppManager $appManager, - ) { - } - #[\Override] - public function handle(Event $event): void { - if (!($event instanceof LoadSidebar)) { - return; - } - - if (!$this->appManager->isEnabledForUser('libresign')) { - return; - } - - Util::addScript(Application::APP_ID, 'libresign-tab'); - Util::addStyle(Application::APP_ID, 'icons'); - } -} diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 6dcef9f899..7876bec980 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -3,7 +3,6 @@ - @@ -61,9 +60,6 @@ - - - @@ -86,17 +82,7 @@ - - - - - - - - - - - +