From a37b6c7e5fe1d55d877c502987a7dfbeee2ed7b3 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 7 Feb 2024 12:44:28 +0100 Subject: [PATCH] fix!: Remove deprecated `RegisterWidgetEvent` Signed-off-by: Ferdinand Thiessen --- .../lib/Controller/DashboardController.php | 3 - .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../lib/AppInfo/Application.php | 12 +--- .../BeforeTemplateRenderedListener.php | 55 +++++++++++++++++ lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - lib/public/Dashboard/RegisterWidgetEvent.php | 61 ------------------- 8 files changed, 60 insertions(+), 75 deletions(-) create mode 100644 apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php delete mode 100644 lib/public/Dashboard/RegisterWidgetEvent.php diff --git a/apps/dashboard/lib/Controller/DashboardController.php b/apps/dashboard/lib/Controller/DashboardController.php index a2605e69f4c..1c7b98dc3ea 100644 --- a/apps/dashboard/lib/Controller/DashboardController.php +++ b/apps/dashboard/lib/Controller/DashboardController.php @@ -38,7 +38,6 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\Dashboard\IManager; use OCP\Dashboard\IWidget; -use OCP\Dashboard\RegisterWidgetEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IL10N; @@ -89,8 +88,6 @@ class DashboardController extends Controller { \OCP\Util::addStyle('dashboard', 'dashboard'); \OCP\Util::addScript('dashboard', 'main', 'theming'); - $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager)); - $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); $widgets = array_map(function (IWidget $widget) { diff --git a/apps/weather_status/composer/composer/autoload_classmap.php b/apps/weather_status/composer/composer/autoload_classmap.php index 00626b48042..0a76e820a0a 100644 --- a/apps/weather_status/composer/composer/autoload_classmap.php +++ b/apps/weather_status/composer/composer/autoload_classmap.php @@ -10,6 +10,7 @@ return array( 'OCA\\WeatherStatus\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', 'OCA\\WeatherStatus\\Capabilities' => $baseDir . '/../lib/Capabilities.php', 'OCA\\WeatherStatus\\Controller\\WeatherStatusController' => $baseDir . '/../lib/Controller/WeatherStatusController.php', + 'OCA\\WeatherStatus\\Listeners\\BeforeTemplateRenderedListener' => $baseDir . '/../lib/Listeners/BeforeTemplateRenderedListener.php', 'OCA\\WeatherStatus\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php', 'OCA\\WeatherStatus\\Service\\WeatherStatusService' => $baseDir . '/../lib/Service/WeatherStatusService.php', ); diff --git a/apps/weather_status/composer/composer/autoload_static.php b/apps/weather_status/composer/composer/autoload_static.php index 1891eb468e2..c9c58f836a8 100644 --- a/apps/weather_status/composer/composer/autoload_static.php +++ b/apps/weather_status/composer/composer/autoload_static.php @@ -25,6 +25,7 @@ class ComposerStaticInitWeatherStatus 'OCA\\WeatherStatus\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', 'OCA\\WeatherStatus\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php', 'OCA\\WeatherStatus\\Controller\\WeatherStatusController' => __DIR__ . '/..' . '/../lib/Controller/WeatherStatusController.php', + 'OCA\\WeatherStatus\\Listeners\\BeforeTemplateRenderedListener' => __DIR__ . '/..' . '/../lib/Listeners/BeforeTemplateRenderedListener.php', 'OCA\\WeatherStatus\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php', 'OCA\\WeatherStatus\\Service\\WeatherStatusService' => __DIR__ . '/..' . '/../lib/Service/WeatherStatusService.php', ); diff --git a/apps/weather_status/lib/AppInfo/Application.php b/apps/weather_status/lib/AppInfo/Application.php index e69215148e0..19cfd643a7e 100644 --- a/apps/weather_status/lib/AppInfo/Application.php +++ b/apps/weather_status/lib/AppInfo/Application.php @@ -26,14 +26,12 @@ declare(strict_types=1); namespace OCA\WeatherStatus\AppInfo; use OCA\WeatherStatus\Capabilities; +use OCA\WeatherStatus\Listeners\BeforeTemplateRenderedListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; -use OCP\Dashboard\RegisterWidgetEvent; -use OCP\EventDispatcher\Event; -use OCP\EventDispatcher\IEventDispatcher; -use OCP\Util; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; /** * Class Application @@ -52,11 +50,6 @@ class Application extends App implements IBootstrap { */ public function __construct(array $urlParams = []) { parent::__construct(self::APP_ID, $urlParams); - - $dispatcher = $this->getContainer()->query(IEventDispatcher::class); - $dispatcher->addListener(RegisterWidgetEvent::class, function (Event $e) { - Util::addScript(self::APP_ID, 'weather-status'); - }); } /** @@ -65,6 +58,7 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { // Register OCS Capabilities $context->registerCapability(Capabilities::class); + $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); } public function boot(IBootContext $context): void { diff --git a/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php b/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php new file mode 100644 index 00000000000..5b08661337b --- /dev/null +++ b/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php @@ -0,0 +1,55 @@ + + * + * @author Ferdinand Thiessen + * + * @license AGPL-3.0-or-later + * + * 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\WeatherStatus\Listeners; + +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +/** + * @template-implements IEventListener + */ +class BeforeTemplateRenderedListener implements IEventListener { + + /** + * Inject our status widget script when the dashboard is loaded + * We need to do it like this because there is currently no PHP API for registering "status widgets" + */ + public function handle(Event $event): void { + if (!($event instanceof BeforeTemplateRenderedEvent)) { + return; + } + + // Only handle the dashboard + if ($event->getResponse()->getApp() !== 'dashboard') { + return; + } + + Util::addScript('weather_status', 'weather-status'); + } +} diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 90ab0c8e207..65c00e53bcd 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -248,7 +248,6 @@ return array( 'OCP\\Dashboard\\Model\\WidgetItem' => $baseDir . '/lib/public/Dashboard/Model/WidgetItem.php', 'OCP\\Dashboard\\Model\\WidgetItems' => $baseDir . '/lib/public/Dashboard/Model/WidgetItems.php', 'OCP\\Dashboard\\Model\\WidgetOptions' => $baseDir . '/lib/public/Dashboard/Model/WidgetOptions.php', - 'OCP\\Dashboard\\RegisterWidgetEvent' => $baseDir . '/lib/public/Dashboard/RegisterWidgetEvent.php', 'OCP\\DataCollector\\AbstractDataCollector' => $baseDir . '/lib/public/DataCollector/AbstractDataCollector.php', 'OCP\\DataCollector\\IDataCollector' => $baseDir . '/lib/public/DataCollector/IDataCollector.php', 'OCP\\Defaults' => $baseDir . '/lib/public/Defaults.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 983a1081621..814245a79b8 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -281,7 +281,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Dashboard\\Model\\WidgetItem' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetItem.php', 'OCP\\Dashboard\\Model\\WidgetItems' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetItems.php', 'OCP\\Dashboard\\Model\\WidgetOptions' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetOptions.php', - 'OCP\\Dashboard\\RegisterWidgetEvent' => __DIR__ . '/../../..' . '/lib/public/Dashboard/RegisterWidgetEvent.php', 'OCP\\DataCollector\\AbstractDataCollector' => __DIR__ . '/../../..' . '/lib/public/DataCollector/AbstractDataCollector.php', 'OCP\\DataCollector\\IDataCollector' => __DIR__ . '/../../..' . '/lib/public/DataCollector/IDataCollector.php', 'OCP\\Defaults' => __DIR__ . '/../../..' . '/lib/public/Defaults.php', diff --git a/lib/public/Dashboard/RegisterWidgetEvent.php b/lib/public/Dashboard/RegisterWidgetEvent.php deleted file mode 100644 index f0bf049571a..00000000000 --- a/lib/public/Dashboard/RegisterWidgetEvent.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * @author Julius Härtl - * - * @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 OCP\Dashboard; - -use OCP\EventDispatcher\Event; - -/** - * Class RegisterPanelEvent - * - * This event is dispatched to allow apps supporting older Nextcloud versions to - * still register their dashboard panels so that they are only constructed when - * they are needed. Deprecated right away so we can drop it again after 19 is EOL - * and backward compatible apps can use OCP\AppFramework\Bootstrap\IBootstrap - * - * @since 20.0.0 - * @deprecated 20.0.0 - */ -class RegisterWidgetEvent extends Event { - private $manager; - - /** - * @param IManager $manager - * @since 20.0.0 - */ - public function __construct(IManager $manager) { - parent::__construct(); - - $this->manager = $manager; - } - - /** - * @param string $panelClass - * @since 20.0.0 - */ - public function registerWidget(string $panelClass) { - $this->manager->lazyRegisterWidget($panelClass); - } -}