# Maintainer: goll <adrian.goll+aur[at]gmail>
# Contributor: George Woodall <georgewoodall82@gmail.com>
pkgname=bambustudio-bin
pkgver=02.08.02.61
pkgrel=1
pkgdesc="PC Software for BambuLab's 3D printers"
arch=("x86_64")
url="https://github.com/bambulab/BambuStudio"
license=('AGPL-3.0-only')
conflicts=('bambustudio' 'bambustudio-git')
depends=('cairo' 'dbus' 'fontconfig' 'gcc-libs' 'glib2' 'glibc'
         'gst-libav' 'gst-plugins-base-libs' 'gstreamer' 'gtk3' 'libglvnd'
         'libx11' 'mesa' 'pango' 'wayland' 'webkit2gtk-4.1')
makedepends=('7zip')
options=('!strip' '!debug')
# The upstream watch updates the timestamp together with pkgver.
_build=20260820225108
source=("bambustudio-${pkgver}.AppImage::https://github.com/bambulab/BambuStudio/releases/download/v${pkgver}/BambuStudio_ubuntu24.04-v${pkgver}-${_build}.AppImage"
        "BambuStudio.desktop"
        "bambu-studio")
noextract=("bambustudio-${pkgver}.AppImage")
sha256sums=(
    'd501b103fac5424513ec0e8d6bc145fb30719de2c7d94d7320d723740c81a7fd'
    'f10718a8b201cad64800746fe8167ccc032c545d05f7ad8caa99eb5fb975f2a1'
    'a3a5c8f6a8b287e42b93957e9602621923c766e0b6a3f10c14eca10b023b15f2'
)

prepare() {
    # Read the embedded SquashFS without executing or modifying the AppImage.
    rm -rf "$srcdir/squashfs-root"
    7z x "$srcdir/bambustudio-${pkgver}.AppImage" -o"$srcdir/squashfs-root" >/dev/null
}

package() {
    cd "$srcdir/squashfs-root"
    install -Dm755 AppRun "$pkgdir/opt/$pkgname/AppRun"
    cp -a bin resources "$pkgdir/opt/$pkgname/"

    local icon size
    for icon in usr/share/icons/hicolor/*/apps/BambuStudio.png; do
        size="${icon#usr/share/icons/hicolor/}"
        install -Dm644 "$icon" "$pkgdir/usr/share/icons/hicolor/$size"
    done

    install -Dm755 "$srcdir/bambu-studio" "$pkgdir/usr/bin/bambu-studio"
    install -Dm644 "$srcdir/BambuStudio.desktop" \
        "$pkgdir/usr/share/applications/BambuStudio.desktop"
}
