# Maintainer: David Heinemeier Hansson <david@hey.com>

pkgname=hermes-desktop
pkgver=2026.8.31
pkgrel=1
pkgdesc='Installer and launcher for the self-updating Hermes desktop'
arch=('x86_64')
url='https://github.com/NousResearch/hermes-agent'
license=('MIT')

# Hermes builds its desktop under the user's runtime so both the app and CLI
# can update it. The compiler and Electron libraries must survive installation.
depends=(
  'alsa-lib' 'at-spi2-core' 'bash' 'cairo' 'curl' 'dbus' 'expat' 'gcc'
  'gdk-pixbuf2' 'git' 'glib2' 'glibc' 'gtk3' 'hicolor-icon-theme' 'libcups'
  'libdrm' 'libglvnd' 'libnotify' 'libsecret' 'libx11' 'libxcb' 'libxcomposite'
  'libxdamage' 'libxext' 'libxfixes' 'libxkbcommon' 'libxrandr' 'make' 'mesa'
  'nodejs' 'npm' 'nspr' 'nss' 'pango' 'python' 'systemd-libs' 'util-linux'
  'xdg-terminal-exec' 'xdg-utils'
)
makedepends=('imagemagick')

# Snapshot the bootstrap installer, including upstream's Linux sandbox fixes.
# Only installation uses it; updates belong to the native runtime on main.
_commit=245e48008fa814b3251f50755eb656bd9fb86cb1
source=("install-${_commit}.sh::https://raw.githubusercontent.com/NousResearch/hermes-agent/${_commit}/scripts/install.sh"
        "LICENSE-${_commit}::https://raw.githubusercontent.com/NousResearch/hermes-agent/${_commit}/LICENSE"
        'hermes-desktop.sh'
        'hermes-desktop.desktop'
        'hermes-desktop.png')
sha256sums=('5854b15670b51a8daae8f59ddfa917062de9f74be261eb73b4b8d719710f8968'
            '821556e6336796450ab852d375117b48a4887e71d255794fd6318d99982a5ab6'
            '85834b56348529413bbc248282d3a1769a2276a016affe9eafb7dd8773d9e12f'
            'c37d4cfa4801eccbd769fddaebb2115d54faa49a5b7bc0f305f563e3cefd9bd8'
            'd60d164e24fdcf6532133b8ea43c77a201e4b9e9dbc396187b58d51d8590ef52')

package() {
  install -Dm644 "${srcdir}/install-${_commit}.sh" "${pkgdir}/usr/share/${pkgname}/install.sh"
  install -Dm644 "${srcdir}/LICENSE-${_commit}" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm755 "${srcdir}/hermes-desktop.sh" "${pkgdir}/usr/bin/${pkgname}"

  # Native registration uses hermes.desktop but omits URI handling. Keep the
  # original handler ID hidden, and let the native entry replace the visible one.
  install -Dm644 "${srcdir}/hermes-desktop.desktop" "${pkgdir}/usr/share/applications/hermes-desktop.desktop"
  printf 'NoDisplay=true\n' >>"${pkgdir}/usr/share/applications/hermes-desktop.desktop"
  sed '/^MimeType=/d' "${srcdir}/hermes-desktop.desktop" >"${pkgdir}/usr/share/applications/hermes.desktop"
  install -Dm644 "${srcdir}/hermes-desktop.png" "${pkgdir}/usr/share/icons/hicolor/1024x1024/apps/${pkgname}.png"
  local size
  for size in 512 256 128 64 48; do
    magick "${srcdir}/hermes-desktop.png" -resize "${size}x${size}" "${srcdir}/icon-${size}.png"
    install -Dm644 "${srcdir}/icon-${size}.png" "${pkgdir}/usr/share/icons/hicolor/${size}x${size}/apps/${pkgname}.png"
  done
}
