# Maintainer: Ryan Hughes <ryan@omarchy.org>
# The main-branch build of omasnap. Pinned by the upstream watch in
# .omarchy/package.json (bin/sync-upstream): every main tip becomes a commit
# pin here, versioned <last tag>.r<commits since>.g<sha> so it sorts above the
# tagged release it follows and below the next one.

pkgname=omasnap-git
pkgver=1.21.0.r76.g614cdf5
pkgrel=1
_commit=614cdf55b42a43c1dcee2c85cd01e4764a52bdae
pkgdesc="Native Wayland screenshot and annotation overlay for Hyprland (main branch)"
arch=('x86_64' 'aarch64')
url="https://github.com/omacom/omasnap"
license=('MIT' 'OFL-1.1')
depends=(
  'hyprland'
  'layer-shell-qt'
  'qt6-base'
  'tesseract'
  'tesseract-data-eng'
  'wayland'
  'wl-clipboard'
)
makedepends=(
  'cmake'
  'git'
  'ninja'
  'pkgconf'
  'wayland-protocols'
)
provides=('omasnap')
conflicts=('omasnap')
options=('!debug')

source=("omasnap::git+$url.git#commit=${_commit}")
sha256sums=('952539c68a81ac373c0f2d5fc084106d3419ee3e5ec2d544d02b510a3f416484')

build() {
  cmake -S omasnap -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr
  cmake --build build --parallel
}

check() {
  # The smoke suite fsyncs its working documents under /tmp. On the CI
  # droplets the build leaves about a gigabyte of dirty pages, and the
  # flush that starts a few seconds into the suite makes those fsyncs stall
  # long enough to overrun the suite's 5-second settle windows. Flush first.
  local runtime_dir status started
  started=$(date +%s%N); sync
  echo "flushed dirty pages in $(( ($(date +%s%N) - started) / 1000000 )) ms"
  runtime_dir=$(mktemp -d /dev/shm/omasnap-runtime.XXXXXX)
  if QT_QPA_PLATFORM=offscreen QT_FORCE_STDERR_LOGGING=1 \
    XDG_RUNTIME_DIR="$runtime_dir" \
    ./build/omasnap-smoke "$srcdir/omasnap-smoke-output"; then
    status=0
  else
    status=$?
    echo "omasnap-smoke exited with status $status" >&2
  fi
  rm -r -- "$runtime_dir"
  return "$status"
}

package() {
  cmake --install build --prefix "$pkgdir/usr"
  install -Dm644 omasnap/README.md \
    "$pkgdir/usr/share/doc/omasnap/README.md"
  install -Dm644 omasnap/LICENSE \
    "$pkgdir/usr/share/licenses/omasnap/LICENSE"
}
