From 09a8573a4d4bce42a7c4aac96d7d9b1071832162 Mon Sep 17 00:00:00 2001 From: falghamdi125 <152446244+falghamdi125@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:12:38 +0300 Subject: [PATCH] fix(flow_notifications): Improve app loading by checking if notifications app is not installed and enabled when registering the app Signed-off-by: Faisal Alghamdi --- README.md | 2 ++ appinfo/info.xml | 2 ++ lib/Listener/RegisterOperationsListener.php | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index b13df92..a0b62fe 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ ### 🔔 Receive notifications ![](screenshots/notification.png) +💡 To use the `Flow Notifications` app, ensure that the [Notifications](https://github.com/nextcloud/notifications) app is installed and enabled. The `Notifications` app provides the necessary APIs for the `Flow Notifications` app to work correctly. + ## 🏗 Development setup 1. ☁ Clone this app into the `apps` folder of your Nextcloud: `git clone https://github.com/nextcloud/flow_notifications.git` diff --git a/appinfo/info.xml b/appinfo/info.xml index 66e6dee..84b1cbf 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -8,6 +8,8 @@ Users are empowered to configure a "Send a notification" Flow in their personal settings. They can choose between the events being triggered, and other conditions like filetypes, assigned tags, time ranges and more. They can specify an inscription so that when the notification appears they will have context. +To use the `Flow Notifications` app, ensure that the `Notifications` app is installed and enabled. The `Notifications` app provides the necessary APIs for the `Flow Notifications` app to work correctly. + ![Notification Flow Configuration](https://raw.githubusercontent.com/nextcloud/flow_notifications/master/screenshots/configuration.png) When an event happens where all conditions are apply, the user will receive a regular Nextcloud notification. diff --git a/lib/Listener/RegisterOperationsListener.php b/lib/Listener/RegisterOperationsListener.php index 1c9cb3e..c47f6e8 100644 --- a/lib/Listener/RegisterOperationsListener.php +++ b/lib/Listener/RegisterOperationsListener.php @@ -27,10 +27,12 @@ use OCA\FlowNotifications\AppInfo\Application; use OCA\FlowNotifications\Flow\Operation; +use OCP\App\IAppManager; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Util; use OCP\WorkflowEngine\Events\RegisterOperationsEvent; +use Psr\Log\LoggerInterface; /** * @template-implements IEventListener @@ -38,12 +40,17 @@ class RegisterOperationsListener implements IEventListener { public function __construct( protected readonly Operation $operation + protected IAppManager $appManager, + private readonly LoggerInterface $logger, ) { } public function handle(Event $event): void { if (!$event instanceof RegisterOperationsEvent) { return; + } elseif (!$this->appManager->isEnabledForUser('notifications')) { + $this->logger->error('Failed to register `flow_notifications` app. This could happen due to the `notifications` app isn\'t installed or enabled.', ['app' => 'flow_notifications']); + return; } $event->registerOperation($this->operation);