# Maintainer: Devpotion <jake@devpotion.com>
pkgname=maylyn-bin
pkgver=0.32.5
pkgrel=1
pkgdesc="Local-first AI assistant (desktop app)"
arch=('x86_64')
url="https://maylyn.cloud"
license=('MIT')
provides=('maylyn')
conflicts=('maylyn')
# The payload is a self-contained AppImage, not a binary this PKGBUILD
# compiles — stripping/splitting debug info out of it is meaningless and
# makepkg otherwise tries anyway, generating a pointless multi-hundred-MB
# maylyn-bin-debug package.
options=('!strip' '!debug')
depends=(
  'webkit2gtk-4.1'
  'gtk3'
  'gst-plugins-base'
  'gst-plugins-good'
  'libayatana-appindicator'
  'fuse2'
  'hicolor-icon-theme'
)
optdepends=(
  'pipewire-pulse: audio capture via PipeWire'
  'pulseaudio: audio capture via PulseAudio'
)
# The AppImage is self-hosted, not pulled from GitHub Releases — the repo is
# private, so GitHub's own asset URLs 404 for anyone who isn't a collaborator.
# website/get/ mirrors every signed release asset alongside checksums.sha256,
# which is where this sha256sum comes from; bump both together on release.
source=("Maylyn_${pkgver}_amd64.AppImage::https://app.maylyn.cloud/get/Maylyn_${pkgver}_amd64.AppImage")
sha256sums=('3d515806187e6fe1ae202c091fe39cb729ef5f0faecad5f770d02dae78698ab8')

package() {
  chmod +x "Maylyn_${pkgver}_amd64.AppImage"
  install -Dm755 "Maylyn_${pkgver}_amd64.AppImage" "${pkgdir}/opt/${pkgname%-bin}/maylyn.AppImage"

  install -d "${pkgdir}/usr/bin"
  cat > "${pkgdir}/usr/bin/maylyn-desktop" <<EOF
#!/bin/sh
exec /opt/maylyn/maylyn.AppImage "\$@"
EOF
  chmod 755 "${pkgdir}/usr/bin/maylyn-desktop"

  # Extract just the desktop entry + icons rather than shipping the whole
  # AppImage payload twice — the AppImage itself is the one copy of the app;
  # this only pulls out the bits a system integration needs on the shelf.
  ./"Maylyn_${pkgver}_amd64.AppImage" --appimage-extract >/dev/null
  install -Dm644 squashfs-root/usr/share/applications/Maylyn.desktop \
    "${pkgdir}/usr/share/applications/maylyn.desktop"
  sed -i 's/^Exec=.*/Exec=maylyn-desktop/' "${pkgdir}/usr/share/applications/maylyn.desktop"
  sed -i 's/^Icon=.*/Icon=maylyn/' "${pkgdir}/usr/share/applications/maylyn.desktop"

  for size in 32x32 128x128 256x256@2; do
    src="squashfs-root/usr/share/icons/hicolor/${size}/apps/maylyn-desktop.png"
    [ -f "$src" ] || continue
    install -Dm644 "$src" "${pkgdir}/usr/share/icons/hicolor/${size}/apps/maylyn.png"
  done
}
