diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 9cae642af4db0cc43b9c7581300056f0a9c70679..6c7966501180a739dbe699c52493ff607a898214 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -4,17 +4,28 @@ declare(strict_types=1); namespace OCA\MultiOffice\AppInfo; +use OCA\MultiOffice\Listener; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; -class Application extends App { +class Application extends App implements IBootstrap +{ + const APP_ID = "multioffice"; - public function __construct() { - parent::__construct('multioffice'); - $eventDispatcher = \OC::$server->getEventDispatcher(); - $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() { - script('multioffice', 'script'); - style('multioffice', 'style'); - }); + public function __construct() + { + parent::__construct(self::APP_ID); } + public function register(IRegistrationContext $context): void + { + $context->registerEventListener(BeforeTemplateRenderedEvent::class, Listener::class); + } + + public function boot(IBootContext $context): void + { + } } diff --git a/lib/Listener.php b/lib/Listener.php new file mode 100644 index 0000000000000000000000000000000000000000..041c9c6eaab540bd91da31d1c7b6d27d742b3702 --- /dev/null +++ b/lib/Listener.php @@ -0,0 +1,22 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later + +namespace OCA\MultiOffice; + +use OCA\MultiOffice\AppInfo\Application; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class Listener implements IEventListener +{ + public function handle(Event $event): void + { + if ($event instanceof BeforeTemplateRenderedEvent) { + Util::addStyle(Application::APP_ID, "style"); + Util::addScript(Application::APP_ID, "script"); + } + } +}