From 759d6799bc1758498008494f4074b372f5259729 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 9 Jul 2020 19:55:15 +0200 Subject: Use IBootstrap for the app bootstrap Signed-off-by: Morris Jobke --- .../FilesLoadAdditionalScriptsListener.php | 69 ++++++++++++++++++++++ .../FilesSharingLoadAdditionalScriptsListener.php | 62 +++++++++++++++++++ lib/Listeners/LoadViewerListener.php | 40 +++++++++++++ .../RegisterDirectEditorEventListener.php | 47 +++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 lib/Listeners/FilesLoadAdditionalScriptsListener.php create mode 100644 lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php create mode 100644 lib/Listeners/LoadViewerListener.php create mode 100644 lib/Listeners/RegisterDirectEditorEventListener.php (limited to 'lib/Listeners') 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 @@ + + * + * @author Morris Jobke + * + * @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 . + * + */ + +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 @@ + + * + * @author Morris Jobke + * + * @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 . + * + */ + +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/lib/Listeners/LoadViewerListener.php b/lib/Listeners/LoadViewerListener.php new file mode 100644 index 000000000..291384afd --- /dev/null +++ b/lib/Listeners/LoadViewerListener.php @@ -0,0 +1,40 @@ + + * + * @author Morris Jobke + * + * @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 . + * + */ + +namespace OCA\Text\Listeners; + +use OCA\Viewer\Event\LoadViewer; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; + +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 @@ + + * + * @author Morris Jobke + * + * @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 . + * + */ + +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); + } +} -- cgit v1.2.3