#!/sbin/openrc-run
# Bananarchy cover display daemon. Only active on flip devices; the
# lid-profile file is written by scripts/apply-bananarchy-overlay.sh.

description="Nokia 2720 Flip external cover display"
# The recovered native bananarchy-coverd busy-loops at 100% CPU on the
# spidev backend (gpio110/DC is owned by panel-mipi-dbi-spi) and paints
# nothing. Keep that binary installed for the future spi-mux work, but run
# the compiled idle IPC server in the default runlevel. No Python runs here.
command="/usr/bin/bananarchy-cover-idle"
command_args="--config /etc/bananarchy/cover-display.conf"
command_background="yes"
pidfile="/run/bananarchy/cover-display.pid"
output_log="/run/bananarchy/cover-display.log"
error_log="/run/bananarchy/cover-display.log"

depend() {
  need udev
  after udev-settle
}

start_pre() {
  mkdir -p /run/bananarchy
  chmod 0755 /run/bananarchy
}

start() {
  if [ "$(cat /usr/share/bananarchy/lid-profile 2>/dev/null)" != "flip" ]; then
    ebegin "Skipping cover display (not a flip device)"
    eend 0
    return 0
  fi
  default_start
  # Seed the compact network/battery indicators once at boot; later changes
  # arrive from the NetworkManager dispatcher (bananarchy-cover-event.sh).
  /usr/bin/bananarchy-cover-event.sh network >/dev/null 2>&1 &
}
