# Everything this package does at runtime is one systemd unit: it publishes the
# menu entries the hardware justifies. There is nothing to watch, nothing to
# re-apply after an upgrade, and no package-manager hook.
#
# What older versions wrote into other packages' desktop files is left alone.
# Those files are owned by those packages, so each edit goes away when its own
# package is next upgraded; until then the affected applications offer the entry
# twice, once in English without an icon (owner, 2026-08-19).

post_install() {
  systemctl enable render-menu-options.service
  systemctl start render-menu-options.service
}

post_upgrade() {
  # The path units and hooks earlier versions installed are gone from the
  # package, so anything still enabled points at a file that no longer exists.
  for unit in render-menu-options.path render-menu-options-flatpak.path; do
    systemctl stop "$unit" >/dev/null 2>&1 || true
    rm -f "/etc/systemd/system/multi-user.target.wants/$unit" \
          "/etc/systemd/system/default.target.wants/$unit"
  done
  rm -f /etc/systemd/user/default.target.wants/render-menu-options-user.path \
        /etc/systemd/user/default.target.wants/render-menu-options-user.service
  systemctl daemon-reload >/dev/null 2>&1 || true

  post_install
}

pre_remove() {
  # The unit outlives the files it was built from otherwise: systemd keeps it
  # loaded and enabled, and the symlink in multi-user.target.wants points at a
  # unit file pacman is about to delete.
  systemctl disable --now render-menu-options.service
}

post_remove() {
  rm -f /usr/share/plasma/kickeractions/render-menu-options.desktop
  systemctl daemon-reload
}
