From 816d189422c5dd182e171359609fc763aaaed64b Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Sat, 16 Nov 2024 03:25:50 +0100 Subject: [PATCH] Load frontend js on files pages --- lib/AppInfo/Application.php | 3 ++ lib/Listener/LoadAdditionalScripts.php | 55 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/Listener/LoadAdditionalScripts.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 7522f9a..16d2c32 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -11,8 +11,10 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\IUserSession; use OCA\DAV\Events\SabrePluginAddEvent; +use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\OrganizationFolders\Listener\SabrePluginAddListener; +use OCA\OrganizationFolders\Listener\LoadAdditionalScripts; use OCA\OrganizationFolders\Security\AuthorizationService; use OCA\OrganizationFolders\Security\ResourceVoter; @@ -24,6 +26,7 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + $context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class); $context->registerEventListener(SabrePluginAddEvent::class, SabrePluginAddListener::class); $context->registerService(AuthorizationService::class, function (ContainerInterface $c) { diff --git a/lib/Listener/LoadAdditionalScripts.php b/lib/Listener/LoadAdditionalScripts.php new file mode 100644 index 0000000..5577f01 --- /dev/null +++ b/lib/Listener/LoadAdditionalScripts.php @@ -0,0 +1,55 @@ + + * + * @author Christoph Wurst + * @author John Molakvoæ + * @author Roeland Jago Douma + * @author Jonathan Treffler + * + * @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\OrganizationFolders\Listener; + +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\AppFramework\Services\IInitialState; +use OCP\App\IAppManager; +use OCP\Util; + +use OCA\OrganizationFolders\AppInfo\Application; + +class LoadAdditionalScripts implements IEventListener { + public function __construct( + private IAppManager $appManager, + private IInitialState $initialState, + ) {} + + public function handle(Event $event): void { + if (!($event instanceof LoadAdditionalScriptsEvent)) { + return; + } + + Util::addScript(Application::APP_ID, 'organization_folders-main', 'files'); + + $this->initialState->provideInitialState('snapshot_integration_active', $this->appManager->isEnabledForUser("groupfolder_filesystem_snapshots")); + } +} \ No newline at end of file