# Maintainer: FunnelFix <linda@sayhellotolinda.com>

# Slap Notes publishes a plain Electron tree rather than an AppImage, so this
# repackages the vendor tarball as-is. .omarchy/upstream.sh rewrites the version
# and checksum below from the release feed the app updates itself from.

pkgname=slap-notes-bin
_appname=slap-notes
pkgver=0.2.3
pkgrel=1
pkgdesc="Local-first block notes with a wiki-link graph and a built-in AI research agent"
arch=('x86_64')
url="https://slapnotes.com"
license=('LicenseRef-proprietary')
depends=(
  'alsa-lib'
  'at-spi2-core'
  'cairo'
  'dbus'
  'expat'
  'gcc-libs'
  'glib2'
  'glibc'
  'gtk3'
  'hicolor-icon-theme'
  'libcups'
  'libdrm'
  # Both are opened by name at runtime rather than linked, so nothing else in
  # this list pulls them in: libnotify carries desktop notifications and
  # libsecret backs Electron's encrypted storage.
  'libnotify'
  'libsecret'
  'libx11'
  'libxcb'
  'libxcomposite'
  'libxdamage'
  'libxext'
  'libxfixes'
  'libxkbcommon'
  'libxrandr'
  'mesa'
  'nspr'
  'nss'
  'pango'
  'systemd-libs'
  'xdg-utils'
)
provides=("${_appname}=${pkgver}")
conflicts=("${_appname}")
# Electron ships prebuilt binaries: stripping them breaks the bundle.
options=('!strip' '!debug')
install="${pkgname}.install"
_tarball="${_appname}-${pkgver}-linux-x64.tar.zst"
source=("${_appname}-launcher.sh")
source_x86_64=("${pkgname}-${pkgver}.tar.zst::https://github.com/Onefailatatime/slap-notes/releases/download/${pkgver}/${_tarball}")
sha256sums=('9d208c06717906b74c41874bdd3fdba0f0dc5b31d239ae00d19472e6eab2ea29')
sha256sums_x86_64=('56cb7606f41051ba10d088ed8e1ae85a17b20692f4b45c0c6a6e6cec6669a5e2')

package() {
  cd "${srcdir}/${_appname}-${pkgver}"

  install -dm755 "${pkgdir}/opt/${_appname}"
  cp -a app/. "${pkgdir}/opt/${_appname}/"
  chmod -R a+rX "${pkgdir}/opt/${_appname}"

  install -Dm755 "${srcdir}/${_appname}-launcher.sh" "${pkgdir}/usr/bin/${_appname}"

  # Upstream's entry points straight into /opt, which would step around the
  # launcher and hand every desktop-started window to XWayland.
  sed -e "s|^Exec=.*|Exec=${_appname} %U|" "${_appname}.desktop" \
    > "${srcdir}/${_appname}.desktop.arch"
  install -Dm644 "${srcdir}/${_appname}.desktop.arch" \
    "${pkgdir}/usr/share/applications/${_appname}.desktop"

  local size
  for size in 16 32 48 64 128 256 512 1024; do
    install -Dm644 "icons/${size}.png" \
      "${pkgdir}/usr/share/icons/hicolor/${size}x${size}/apps/${_appname}.png"
  done

  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
