diff options
-rw-r--r-- | lib/AppInfo/Application.php | 86 | ||||
-rw-r--r-- | lib/Listeners/FilesLoadAdditionalScriptsListener.php | 69 | ||||
-rw-r--r-- | lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php | 62 | ||||
-rw-r--r-- | lib/Listeners/LoadViewerListener.php (renamed from appinfo/app.php) | 21 | ||||
-rw-r--r-- | lib/Listeners/RegisterDirectEditorEventListener.php | 47 |
5 files changed, 212 insertions, 73 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 70876a593..10292e292 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -24,85 +24,33 @@ declare(strict_types=1); namespace OCA\Text\AppInfo; -use OCA\Text\DirectEditing\TextDirectEditor; +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Text\Listeners\FilesLoadAdditionalScriptsListener; +use OCA\Text\Listeners\FilesSharingLoadAdditionalScriptsListener; +use OCA\Text\Listeners\LoadViewerListener; +use OCA\Text\Listeners\RegisterDirectEditorEventListener; use OCA\Viewer\Event\LoadViewer; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\DirectEditing\RegisterDirectEditorEvent; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\IInitialStateService; - -class Application extends App { - +class Application extends App implements IBootstrap { const APP_NAME = 'text'; - /** @var IInitialStateService */ - private $initialStateService; - /** - * @var \OCP\IUserSession - */ - private $userSession; - /** - * @var \OCP\IConfig - */ - private $config; - - - /** - * Application constructor. - * - * @param array $params - * @throws \OCP\AppFramework\QueryException - */ public function __construct(array $params = []) { parent::__construct(self::APP_NAME, $params); + } - $container = $this->getContainer(); - $server = $container->getServer(); - /** @var IEventDispatcher $eventDispatcher */ - $eventDispatcher = $server->query(IEventDispatcher::class); - $this->initialStateService = $server->query(IInitialStateService::class); - $this->userSession = $server->getUserSession(); - $this->config = $this->getContainer()->getServer()->getConfig(); - - $eventDispatcher->addListener(RegisterDirectEditorEvent::class, function (RegisterDirectEditorEvent $event) use ($container) { - $editor = $container->query(TextDirectEditor::class); - $event->register($editor); - }); - - $eventDispatcher->addListener(LoadViewer::class, function () { - \OCP\Util::addScript('text', 'viewer'); - \OCP\Util::addStyle('text', 'icons'); - }); - - if ($this->userSession->isLoggedIn()) { - $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () { - \OCP\Util::addScript('text', 'files'); - \OCP\Util::addStyle('text', 'icons'); - - $this->initialStateService->provideInitialState( - self::APP_NAME, - 'workspace_available', - $this->config->getAppValue(self::APP_NAME, 'workspace_available', '1') === '1' - ); - $this->initialStateService->provideInitialState( - self::APP_NAME, - 'workspace_enabled', - $this->config->getUserValue($this->userSession->getUser()->getUID(), self::APP_NAME, 'workspace_enabled', '1') === '1' - ); - }); - } - - $eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () { - \OCP\Util::addScript('text', 'public'); - \OCP\Util::addStyle('text', 'icons'); - $this->initialStateService->provideInitialState( - self::APP_NAME, - 'workspace_available', - $this->config->getAppValue(self::APP_NAME, 'workspace_available', '1') === '1' - ); - }); + public function register(IRegistrationContext $context): void { + $context->registerEventListener(RegisterDirectEditorEvent::class, RegisterDirectEditorEventListener::class); + $context->registerEventListener(LoadViewer::class, LoadViewerListener::class); + $context->registerEventListener('OCA\Files_Sharing::loadAdditionalScripts', FilesSharingLoadAdditionalScriptsListener::class); + $context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class); } + public function boot(IBootContext $context): void { + } } diff --git a/lib/Listeners/FilesLoadAdditionalScriptsListener.php b/lib/Listeners/FilesLoadAdditionalScriptsListener.php new file mode 100644 index 000000000..c49c6f88e --- /dev/null +++ b/lib/Listeners/FilesLoadAdditionalScriptsListener.php @@ -0,0 +1,69 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> + * + * @author Morris Jobke <hey@morrisjobke.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Text\Listeners; + +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Text\AppInfo\Application; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; +use OCP\IInitialStateService; +use OCP\IUserSession; + +class FilesLoadAdditionalScriptsListener implements IEventListener { + /** @var IConfig */ + protected $config; + /** @var IInitialStateService */ + protected $initialStateService; + /** @var IUserSession */ + protected $userSession; + + public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) { + $this->config = $config; + $this->initialStateService = $initialStateService; + $this->userSession = $userSession; + } + + public function handle(Event $event): void { + if (!$event instanceof LoadAdditionalScriptsEvent) { + return; + } + + \OCP\Util::addScript('text', 'files'); + \OCP\Util::addStyle('text', 'icons'); + + $this->initialStateService->provideInitialState( + Application::APP_NAME, + 'workspace_available', + $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1' + ); + $this->initialStateService->provideInitialState( + Application::APP_NAME, + 'workspace_enabled', + $this->config->getUserValue($this->userSession->getUser()->getUID(), Application::APP_NAME, 'workspace_enabled', '1') === '1' + ); + } +} diff --git a/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php new file mode 100644 index 000000000..bf097ddb4 --- /dev/null +++ b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php @@ -0,0 +1,62 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> + * + * @author Morris Jobke <hey@morrisjobke.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Text\Listeners; + +use OCA\Text\AppInfo\Application; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; +use OCP\IInitialStateService; +use OCP\IUserSession; + +class FilesSharingLoadAdditionalScriptsListener implements IEventListener { + /** @var IConfig */ + protected $config; + /** @var IInitialStateService */ + protected $initialStateService; + /** @var IUserSession */ + protected $userSession; + + public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) { + $this->config = $config; + $this->initialStateService = $initialStateService; + $this->userSession = $userSession; + } + + public function handle(Event $event): void { + if (!$this->userSession->isLoggedIn()) { + return; + } + \OCP\Util::addScript('text', 'public'); + \OCP\Util::addStyle('text', 'icons'); + + $this->initialStateService->provideInitialState( + Application::APP_NAME, + 'workspace_available', + $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1' + ); + } +} diff --git a/appinfo/app.php b/lib/Listeners/LoadViewerListener.php index d52ea44fb..291384afd 100644 --- a/appinfo/app.php +++ b/lib/Listeners/LoadViewerListener.php @@ -1,9 +1,10 @@ <?php + declare(strict_types=1); /** - * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> + * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> * - * @author Julius Härtl <jus@bitgrid.net> + * @author Morris Jobke <hey@morrisjobke.de> * * @license GNU AGPL version 3 or any later version * @@ -22,6 +23,18 @@ declare(strict_types=1); * */ -namespace OCA\Text\AppInfo; +namespace OCA\Text\Listeners; + +use OCA\Viewer\Event\LoadViewer; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; -$app = \OC::$server->query(Application::class); +class LoadViewerListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof LoadViewer) { + return; + } + \OCP\Util::addScript('text', 'viewer'); + \OCP\Util::addStyle('text', 'icons'); + } +} diff --git a/lib/Listeners/RegisterDirectEditorEventListener.php b/lib/Listeners/RegisterDirectEditorEventListener.php new file mode 100644 index 000000000..77770d991 --- /dev/null +++ b/lib/Listeners/RegisterDirectEditorEventListener.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de> + * + * @author Morris Jobke <hey@morrisjobke.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Text\Listeners; + +use OCA\Text\DirectEditing\TextDirectEditor; +use OCP\DirectEditing\RegisterDirectEditorEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +class RegisterDirectEditorEventListener implements IEventListener { + /** @var TextDirectEditor */ + protected $editor; + + public function __construct(TextDirectEditor $editor) { + $this->editor = $editor; + } + + public function handle(Event $event): void { + if (!$event instanceof RegisterDirectEditorEvent) { + return; + } + $event->register($this->editor); + } +} |