# Maintainer: Joey Yakimowich-Payne <jyapayne@pm.me>
#
# BlueRune, from the newest commit of its repository. Build it from this directory with
# `makepkg -si`; docs/after-install.md and docs/setup.md say what to do after installing. The release package,
# built from a tagged version and published to the BlueRune package repository, is
# bluerune/PKGBUILD; both install what package-files.sh lists.

pkgname=bluerune-git
_pkgname=bluerune
pkgver=0.0.1.r0.g0000000
pkgrel=1
pkgdesc='Fast, animated desktop shell for Hyprland: bar, launcher, notifications, overview, Settings, and a calculator, image viewer and system monitor'
arch=('x86_64' 'aarch64')
url='https://git.joeypayne.com/jyapayne/bluerune'
# bluerune-docs links poppler (GPL): that binary is distributed under GPL-3.0-or-later terms.
# bluerune-media links libmpv (GPL): that binary is distributed under GPL-2.0-or-later terms.
# The Gabarito font (dist/fonts/gabarito) is under the SIL Open Font License 1.1.
license=('Apache-2.0 OR MIT' 'GPL-3.0-or-later' 'GPL-2.0-or-later' 'OFL-1.1')
depends=(
  # The compositor it is a shell for, and the programs it configures rather than replaces.
  'hyprland>=0.57'
  'hypridle'
  'hyprlock'
  # The BlueRune session: uwsm starts Hyprland and binds the session's services to it.
  'uwsm'
  # Portals (dist/portals/bluerune-portals.conf): sharing and screenshots from Hyprland's, the
  # file chooser BlueRune's own (xdg-desktop-portal-bluerune, in this package) with GTK's as
  # its fallback, and the light or dark preference apps follow from GTK's.
  'xdg-desktop-portal'
  'xdg-desktop-portal-hyprland'
  'xdg-desktop-portal-gtk'
  # Services the bar, quick settings and Settings read and change.
  'power-profiles-daemon'
  'networkmanager'
  'bluez'
  'upower'
  'accountsservice'
  'udisks2'
  'polkit'
  'dbus'
  'systemd'
  # Sound: `wpctl` and `pactl` against PipeWire. `pw-dump` and `pw-cli`: which app a screen
  # is shared with, and stopping it from the bar.
  'pipewire'
  'pipewire-pulse'
  'wireplumber'
  'libpulse'
  # Copying to the clipboard, the screen's brightness, theme archives, GTK settings.
  'wl-clipboard'
  'brightnessctl'
  'libarchive'
  'glib2'
  # bluerune-setup compares each file it would change with what is there, and shows how.
  'diffutils'
  # The Store (bluerune-store): Arch's packages through PackageKit (its polkit prompts, no root
  # code of ours), the catalog that lists them (archlinux-appstream-data), and Flathub through
  # Flatpak, whose apps' permissions Settings shows too.
  'packagekit'
  'archlinux-appstream-data'
  'flatpak'
  # The fonts every app is given (Settings > Fonts): Inter for the interface (BlueRune's own
  # text has it built in; other apps need it installed), JetBrains Mono Nerd Font for code
  # and terminals, and the Nerd Font symbols after either.
  'inter-font'
  'ttf-jetbrains-mono-nerd'
  'ttf-nerd-fonts-symbols'
  # The shell's own symbols (Material Symbols Rounded).
  'ttf-material-symbols-variable'
  # The camera (bluerune-camera): GStreamer, which it links, and the plugins it films,
  # converts, encodes and saves with: PipeWire's and V4L2's cameras, VP8, Opus, WebM and MP4.
  'gstreamer'
  'gst-plugins-base-libs'
  'gst-plugins-base'
  'gst-plugins-good'
  'gst-plugin-pipewire'
  # Documents (bluerune-docs): poppler draws PDFs; cairo and Pango typeset ePub books and comics.
  'poppler-glib'
  'cairo'
  'pango'
  # Snapshots (bluerune-snapshots): snapperd lists, compares, takes and deletes Snapper's
  # snapshots; btrfs-progs is what Snapper drives on Btrfs.
  'snapper'
  'btrfs-progs'
  # What the binaries link to.
  'glibc'
  'libgcc'
  'libxkbcommon'
  'vulkan-icd-loader'
  'wayland'
  # Media (bluerune-media): libmpv plays, drawing on the GPU through Mesa's EGL and GBM;
  # ffmpeg takes the seek bar's thumbnails.
  'mpv'
  'mesa'
  'libglvnd'
  'ffmpeg'
)
makedepends=('cargo' 'git')
# makepkg's LTO compiles ring's C and assembly (behind Media's cover downloads) into bitcode
# that Rust's linker can't resolve, so the build doesn't link with it on.
options=('!lto')
# The helper's tests run its libinput Lua plugins under Lua 5.4; Media's play media ffmpeg
# makes, on a private session bus.
checkdepends=('lua54' 'ffmpeg' 'dbus')
optdepends=(
  'cliphist: clipboard history in the launcher'
  'wtype: type a picked emoji into the window (emoji.type)'
  "hyprpolkitagent: password prompts for apps when BlueRune's own agent (Settings > Lock and privacy > Password prompts for apps) is off"
  'sddm: the BlueRune login screen theme'
  "greetd: BlueRune's own login screen (bluerune-greeter), chosen on Settings > Login screen"
  'grim: screenshots through the portal (apps that ask to take one)'
  'tesseract: copy text out of a screen region'
  'tesseract-data-eng: English for text recognition'
  'wf-recorder: record the screen or a region'
  'satty: edit a screenshot'
  'swappy: edit a screenshot'
  'ddcutil: brightness of external monitors'
  'fcitx5: input methods'
  'orca: screen reader'
  'cups: the Printers page, and printing from Documents'
  'djvulibre: DjVu documents in Documents'
  'libgxps: XPS documents in Documents'
  'snap-pac: snapshots before and after each pacman transaction, to compare and undo in Snapshots'
  'limine-snapper-sync: boot into a snapshot from the boot menu and keep it (Snapshots explains how)'
  'firewalld: the Firewall page'
  'bolt: the Thunderbolt page'
  'colord: color profiles of displays'
  'fprintd: fingerprint sign-in'
  'bluez-obex: send and receive files over Bluetooth'
  'wayvnc: the Remote desktop page'
  'gnome-online-accounts: the Online accounts page'
  'modemmanager: mobile broadband'
  'fwupd: firmware updates'
  'pacman-contrib: count updates without touching the system database (checkupdates)'
  'libcanberra: event sounds'
  'xorg-xrdb: font DPI for X11 apps'
  'rsync: the backups on the Storage page'
  'gphoto2: cameras on the Storage page'
  "gst-plugins-bad: the camera's videos encoded on the graphics card (VA-API H.264 and VP9)"
  "gst-plugins-ugly: the camera's MP4 videos without a graphics card encoder (x264)"
  "ffmpegthumbnailer: pictures of the camera's older videos in its strip of shots"
  "sound-theme-freedesktop: the camera's shutter sound"
  'exfatprogs: Disks makes, checks and resizes exFAT filesystems'
  'ntfsprogs: Disks makes, checks and resizes NTFS filesystems'
  'xfsprogs: Disks makes, checks and grows XFS filesystems'
  'dosfstools: Disks makes and checks FAT filesystems'
  'btrfs-progs: Disks makes Btrfs filesystems, and its health check reads their errors and scrubs'
  'smartmontools: the health check reads SSD wear where UDisks2 does not'
  'snapper: Clean up offers to remove old snapshots, and the health check sees their limits'
  'yt-dlp: Media plays links from video sites'
  'freerdp: Remote Desktop opens .rdp files and connects to the computers they name'
)
# With its version, so what needs a newer bluerune (an extension's bluerune>0.3.3) takes it.
provides=("$_pkgname=$pkgver")
conflicts=("$_pkgname")
install=bluerune.install
backup=('etc/pam.d/bluerune' 'etc/mpv/mpv.conf' 'etc/xdg/fastfetch/config.jsonc')
source=("$_pkgname::git+$url.git")
sha256sums=('SKIP')

pkgver() {
  cd "$_pkgname"
  local version
  version=$(sed -n '/^\[workspace\.package\]/,/^\[/s/^version = "\(.*\)"/\1/p' Cargo.toml)
  printf '%s.r%s.g%s' "$version" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
}

prepare() {
  cd "$_pkgname"
  export RUSTUP_TOOLCHAIN=stable
  cargo fetch --locked --target "$(rustc --print host-tuple)"
}

build() {
  cd "$_pkgname"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo build --frozen --release --workspace --bins
}

check() {
  cd "$_pkgname"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  # The crates with no display or session to need: the shell's state, theme and settings
  # model, and the privileged helper.
  cargo test --frozen --release -p bluerune-core -p bluerune-helper
}

package() {
  cd "$_pkgname"
  bash dist/arch/package-files.sh "$pkgdir" "$pkgname"
}
