pkgname=hyprshell-slim
# x-release-please-start-version
pkgver=4.10.4
# x-release-please-end
pkgrel=1
pkgdesc="A modern GTK4-based window switcher and application launcher for Hyprland (lightweight version)"
arch=('x86_64' 'aarch64')
conflicts=('hyprshell')
provides=('hyprshell')
url="https://github.com/h3rmt/hyprshell/"
license=("MIT")
makedepends=('cargo')
depends=('hyprland' 'gtk4-layer-shell' 'gtk4' 'libadwaita' 'zstd')
source=("hyprshell-$pkgver.tar.gz::https://static.crates.io/crates/hyprshell/hyprshell-$pkgver.crate")

prepare() {
    export RUSTUP_TOOLCHAIN=stable
    cd "hyprshell-$pkgver"
    cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target
    cd "hyprshell-$pkgver"
    cargo build --frozen --release --no-default-features --features=slim
}

package() {
    install -Dm755 "hyprshell-$pkgver/target/release/hyprshell"             "$pkgdir/usr/bin/hyprshell"
    install -Dm644 "hyprshell-$pkgver/LICENSE"                              "$pkgdir/usr/share/licenses/hyprshell/LICENSE"
    install -Dm644 "hyprshell-$pkgver/README.md"                            "$pkgdir/usr/share/doc/hyprshell/README.md"
    install -Dm644 "hyprshell-$pkgver/docs/CONFIGURE.md"                    "$pkgdir/usr/share/doc/hyprshell/CONFIGURE.md"
    install -Dm644 "hyprshell-$pkgver/docs/DEBUG.md"                        "$pkgdir/usr/share/doc/hyprshell/DEBUG.md"
    install -Dm644 "hyprshell-$pkgver/packaging/hyprshell.service"          "$pkgdir/usr/lib/systemd/user/hyprshell.service"
    install -Dm644 "hyprshell-$pkgver/packaging/hyprshell-settings.png"     "$pkgdir/usr/share/pixmaps/hyprshell.png"
    install -Dm644 "hyprshell-$pkgver/packaging/hyprshell-settings.desktop" "$pkgdir/usr/share/applications/hyprshell-settings.desktop"

    mkdir "$pkgdir/usr/share/hyprshell"
    tar -xvf "hyprshell-$pkgver/packaging/usr-share.tar" -C "$pkgdir/usr/share/hyprshell" | tee >(wc -l | xargs -I {} echo "Extracted {} files to $pkgdir/usr/share/hyprshell") > /dev/null

    "$pkgdir/usr/bin/hyprshell" completions bash -p  "$pkgdir/usr/share/bash-completion/completions"
    "$pkgdir/usr/bin/hyprshell" completions fish -p  "$pkgdir/usr/share/fish/vendor_completions.d"
    "$pkgdir/usr/bin/hyprshell" completions zsh -p   "$pkgdir/usr/share/zsh/site-functions"
}
