Help in API design

I’m trying to maintain the dashboard app. Integrated in the app is an API, which provides a method, where other app can register their widgets to the dashboard.
But this api uses classes from the dashboard app. This leads to the problem, when the dashboard app is not installed, the apps which try to register a widget, fails.
This could possibly be solved by checking first, if the dashboard app is installed. But I thing, this is not a proper wa to this.
I currently see some posssibilities, how this can be done - but I don’t see how to do this in Nextcloud:

  1. The dashboard app scans every installed app and looks, if there is a special class or function which returns the widgets.
  2. The dashboard app sends out a signal to all apps, and every app which is listening to this signal registers its widget in the dashboard app.

Can someone give me some tipps how to solve this?

Thanks, Holger

It’s really easy to test if an app is installed, but I agree that it’s not nice to have to force each plugin to do so.

I would use your 2nd solution.
It’s similar to the way the server includes scripts from apps.

Thanks Oliver,

can you point me to an example, how this is done in the server? And would you prefer an hook or an event?
At which point should I emit the event or hook?

Sure, take a look at these results:

I would prefer an event, just like in the examples posted above

Event is a very good idea to do this.

I’m still struggling with the position where I emit the events.
I need at least two events, one before the dashboard is shown and one, on the config page where the user can select, which should be displayed on the dashboard.
I tried ti dispatch one event on the index method og the main template
$dispatcher = \OC::$server->getEventDispatcher(); $dispatcher->dispatch('Dashboard::addWidget', $data);

  • the application immediately hangs on that position
  • and there it might be too late anyway

As there in no documentation regarding events, I might have done it completely wrong…

Sorry for not replying so long, I was busy finishing my Nextcloud10 stuff and then was on vacation.

Do you have your branch on github, so I can check it out for testing? Basically the dispatch looks good, so I guess something might be wrong with your $data.

Btw for the event name it is recommended to use a namespace like name, so OCA\Dashboard\....