# Maintainer: Christoph Brandau <c.brandau91@googlemail.com>
#
# Local/in-tree PKGBUILD: builds straight from this working directory (no
# source download, no tauri-bundler/AppImage step) and installs the raw
# binary + desktop entry. Run `makepkg -si` from the repo root.

pkgname=gitty
pkgver=2026.7.20
pkgrel=1
pkgdesc="A lightweight, modern Git client built with Tauri"
arch=('x86_64')
url="https://git.cbsk-tech.de/Christoph/GitLite"
license=('MIT')
depends=('webkit2gtk-4.1' 'gtk3' 'git' 'hicolor-icon-theme')
makedepends=('rust' 'nodejs' 'npm')
options=('!lto')

source=()
sha256sums=()

# Keeps pkgver in sync with package.json (the release CI bumps that file).
pkgver() {
  cd "$startdir"
  node -p "require('./package.json').version"
}

build() {
  cd "$startdir"
  npm ci
  # Build through the Tauri CLI (not a raw `cargo build --release`): it enables
  # the `custom-protocol` cargo feature that makes the binary load the embedded
  # `dist/` assets instead of the Vite dev server URL (127.0.0.1:1420), and runs
  # `beforeBuildCommand` (`npm run build`) for us. `--no-bundle` skips deb/rpm/
  # appimage packaging (and with it linuxdeploy/FUSE) since pacman owns that here.
  npm run tauri -- build --no-bundle
}

package() {
  cd "$startdir"

  install -Dm755 "src-tauri/target/release/gitty" "$pkgdir/usr/bin/gitty"

  install -Dm644 "src-tauri/icons/32x32.png" \
    "$pkgdir/usr/share/icons/hicolor/32x32/apps/gitty.png"
  install -Dm644 "src-tauri/icons/128x128.png" \
    "$pkgdir/usr/share/icons/hicolor/128x128/apps/gitty.png"
  install -Dm644 "src-tauri/icons/128x128@2x.png" \
    "$pkgdir/usr/share/icons/hicolor/256x256@2/apps/gitty.png"
  install -Dm644 "src-tauri/icons/icon.png" \
    "$pkgdir/usr/share/icons/hicolor/512x512/apps/gitty.png"

  install -d "$pkgdir/usr/share/applications"
  cat > "$pkgdir/usr/share/applications/gitty.desktop" <<-EOF
	[Desktop Entry]
	Type=Application
	Name=Gitty
	Comment=$pkgdesc
	Exec=gitty
	Icon=gitty
	Terminal=false
	Categories=Development;RevisionControl;
	StartupWMClass=gitty
	EOF

  install -Dm644 "README.md" "$pkgdir/usr/share/doc/$pkgname/README.md"
}
