Add service icons

This commit is contained in:
Harshad Sharma 2024-05-16 21:40:38 +05:30
parent e950e9fc60
commit 80a8efd582
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,25 @@
defmodule Freedive.Api.Service.Icons do
def icon_for_service(name) do
case name do
"automountd" -> "hard-drive"
"autounmountd" -> "hard-drive"
"caddy" -> "globe"
"cron" -> "clock"
"dbus" -> "bus"
"devd" -> "usb"
"ip6addrctl" -> "network"
"lockd" -> "lock"
"moused" -> "mouse"
"ntpd" -> "clock"
"pf" -> "shield"
"pflog" -> "newspaper"
"powerd" -> "utility-pole"
"sddm" -> "user"
"sshd" -> "lock"
"statd" -> "braces"
"syslogd" -> "newspaper"
"tailscaled" -> "shield"
_ -> "puzzle"
end
end
end

View file

@ -5,6 +5,7 @@ defmodule Freedive.Api.Service do
use GenServer
require Logger
import Freedive.Api.Service.Cli
import Freedive.Api.Service.Icons
def start_link(opts) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
@ -24,6 +25,11 @@ defmodule Freedive.Api.Service do
@impl true
def handle_continue(_opts, state) do
{:ok, services} = list_services()
services = services
|> Enum.map(fn {name, service} ->
{name, Map.put(service, :icon, icon_for_service(name))}
end)
|> Enum.into(%{}, &{&1[:name], &1})
state = %{state | services: services}
{:noreply, state}
end