# Maintainer: mollusk <jitty+lc1iz0dc@protonmail.com>
#
# Local versioned package, built from the local git repo on `main`.
# For a tagged release, switch the source fragment to `#tag=v0.1.0`.

pkgname=pixelpass
pkgver=0.1.0
pkgrel=1
pkgdesc='P2P screen sharing over iroh — no port forwarding, no signup'
arch=('x86_64')
url='file:///home/mollusk/git/butter/pixelpass'
license=('MIT' 'Apache-2.0' 'OFL-1.1')
depends=(
  'gstreamer'          # gst-launch-1.0 / gst-inspect-1.0
  'gst-plugins-base'   # videoscale (quality-preset downscale)
  'gst-plugins-good'   # ximagesrc (X11 capture) + pulsesrc
  'gst-plugins-bad'    # h264parse, mpegtsmux, aacparse
  'gst-libav'          # avenc_aac (audio encode)
  'gst-plugin-va'      # vah264enc (default hardware H.264 encoder)
  'libpulse'           # pactl (audio routing / device control)
  'hicolor-icon-theme' # owns the scalable icon dir
  'libglvnd'           # libGL for the egui (glow) GUI
  'libxkbcommon'       # GUI keyboard handling (winit)
  'wayland'            # GUI Wayland backend libs
)
optdepends=(
  'mpv: recommended stream viewer (the GUI launches mpv)'
  'vlc: alternative stream viewer'
  'gst-plugins-ugly: software x264 encoding for `pixelpass --no-hwencode`'
  'gst-plugin-pipewire: screen capture on Wayland sessions'
  'xorg-xwininfo: share a single window on X11 (`pixelpass --window`)'
)
makedepends=('cargo' 'git')
options=('!lto')
_branch='main'
source=("$pkgname::git+file:///home/mollusk/git/butter/pixelpass#branch=$_branch")
sha256sums=('SKIP')

prepare() {
  cd "$srcdir/$pkgname"
  export RUSTUP_TOOLCHAIN=stable
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "$srcdir/$pkgname"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  # --features gui so the .desktop launcher (pixelpass --gui) works.
  cargo build --frozen --release --features gui
}

package() {
  cd "$srcdir/$pkgname"
  install -Dm0755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm0644 assets/pixelpass.desktop \
    "$pkgdir/usr/share/applications/$pkgname.desktop"
  install -Dm0644 assets/pixelpass.svg \
    "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"
  install -Dm0644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm0644 LICENSE-MIT "$pkgdir/usr/share/licenses/$pkgname/LICENSE-MIT"
  install -Dm0644 LICENSE-APACHE "$pkgdir/usr/share/licenses/$pkgname/LICENSE-APACHE"
  install -Dm0644 assets/NotoSans-OFL.txt \
    "$pkgdir/usr/share/licenses/$pkgname/NotoSans-OFL.txt"
}
