# Maintainer: Matheus França <matheus-catarino@hotmail.com>
pkgname=qidistudio-appimage
_pkgname=QIDIStudio
pkgver=2.04.01.10
pkgrel=1
pkgdesc="PC Software for QIDI 3D printers"
arch=('x86_64')
url="https://github.com/QIDITECH/QIDIStudio"
license=('AGPL-3.0')
options=('!strip' '!debug')
provides=('qidistudio')
conflicts=('qidistudio' 'qidistudio-git' 'qidistudio-bin')
source=("${_pkgname}_${pkgver}_Ubuntu24.AppImage::https://github.com/QIDITECH/QIDIStudio/releases/download/v${pkgver}/QIDIStudio_v0${pkgver}_Ubuntu24.AppImage")
sha256sums=('40dbdbf9a188bff1f19b5d27d2280cb889e61cd96d178f0e4a7af83c0d2042ef')

package() {
  cd "$srcdir"

  chmod +x "${_pkgname}_${pkgver}_Ubuntu24.AppImage"
  install -Dm755 "${_pkgname}_${pkgver}_Ubuntu24.AppImage" "$pkgdir/usr/bin/qidistudio"

  ./"${_pkgname}_${pkgver}_Ubuntu24.AppImage" --appimage-extract &>/dev/null

  if [ -f "squashfs-root/QIDIStudio.png" ]; then
    install -Dm644 "squashfs-root/QIDIStudio.png" "$pkgdir/usr/share/pixmaps/QIDIStudio.png"
  else
    msg2 "Warning: Could not automatically find an icon file (QIDIStudio.png) within the AppImage."
    msg2 "         Desktop entry icon might be missing."
  fi

  if [ -f "squashfs-root/QIDIStudio.desktop" ]; then
    sed -i 's|Exec=AppRun|Exec=/usr/bin/qidistudio|' "squashfs-root/QIDIStudio.desktop"
    install -Dm644 "squashfs-root/QIDIStudio.desktop" "$pkgdir/usr/share/applications/QIDIStudio.desktop"
  else
    msg2 "Fail: Could not automatically find desktop file (QIDIStudio.desktop) within the AppImage."
    exit 1
  fi
}