   @doc ~S"""
   Reload all plugin data. Normally called from the inotify watcher
   """
-  def reload_plugins(pid) do
-    Agent.update(pid, fn _ -> load_plugins() end)
-    plugins = Agent.get pid, &(&1)
-    Logger.info("Reloaded plugin registry #{inspect pid}, got #{Enum.count plugins}")
+  def reload_plugins do
+    GenServer.cast(Serverboards.Plugin.Registry, {:reload})
+  end
+
+  def active_plugins do
+    GenServer.call(Serverboards.Plugin.Registry, {:get_active})
+  end
+
+  def all_plugins do
+    GenServer.call(Serverboards.Plugin.Registry, {:get_all})
   end
 
   @doc ~S"""


  def list(registry) do
    Logger.warn("No permission checking for list of plugins. FIXME.")
    plugins = Agent.get registry, &(&1)
    Enum.reduce(plugins, %{}, fn plugin, acc ->
      components = Enum.reduce(plugin.components, %{}, fn component, acc ->
        Map.put(acc, component.id, %{
          id: component.id,

    list(Serverboards.Plugin.Registry)
  end


  ## server impl, jsut stores state
  def init([]) do
    Serverboards.Plugin.Monitor.start_link

    GenServer.cast(self, {:reload})
    {:ok, %{ active: [], all: []}}
  end

  def decorate_plugin(p) do
    Logger.debug("#{inspect p}")
    p
  end

  def handle_cast({:reload}, _status) do
    all_plugins = load_plugins
      |> Enum.map(&decorate_plugin/1)

    {:noreply, %{
      all: all_plugins,
      active: all_plugins
      }}
  end

  def handle_call({:get_all}, _from, state) do
    {:reply, state.all, state}
  end
  def handle_call({:get_active}, _from, state) do
    {:reply, state.active, state}
  end

end
