#!/bin/bash
# Exit immediately on error, treat unset variables as errors, propagate pipe failures.
set -euo pipefail
# Load shared log/skip/warn/err helpers from the installer library.
source "$(dirname "${BASH_SOURCE[0]}")/../../lib/logging.sh"

# lamco-rdp-server is a native Wayland RDP server written in Rust that uses
# H.264 hardware encoding via VA-API.  It is AUR-only and builds from source,
# so cargo, clang, cmake, and nasm are pulled in automatically as makedepends.
log "Installing lamco-rdp-server (AUR)..."
# --answerdiff None / --answerclean All keep the build unattended without showing diffs.
yay -S --answerdiff None --answerclean All --noconfirm lamco-rdp-server

log "Enabling lamco-rdp-server as user service..."
# Register the service in the user's systemd session so it starts on login.
# --user targets the per-user manager (not the system manager); no sudo required.
# If no active D-Bus/systemd user session exists yet (e.g. during a fresh install
# before first login), the enable call will fail — the || clause warns the user
# and lets the script continue rather than aborting with set -e.
systemctl --user enable lamco-rdp-server.service 2>/dev/null \
    || warn "No user session active — run after login: systemctl --user enable lamco-rdp-server.service"

log "lamco-rdp-server enabled as a user service."
log "Start it with:  systemctl --user start lamco-rdp-server"
log "Or launch the GUI tray:  lamco-rdp-server-gui"
# RDP screen capture on Wayland requires an xdg-desktop-portal backend that matches
# the running compositor; without it the portal will refuse screen share requests.
warn "Install a matching xdg-desktop-portal for your compositor: xdg-desktop-portal-hyprland / -wlr / -gnome / -kde"
