# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=rustfs-launcher
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.0.4
pkgrel=1
pkgdesc="A simple launcher for RustFS (mingw-w64)"
arch=('any')
mingw_arch=('clang64' 'clangarm64')
url='https://rustfs.com/'
msys2_repository_url='https://github.com/rustfs/launcher'
#license=('spdx:Apache-2.0')
depends=(
  "${MINGW_PACKAGE_PREFIX}-rustfs"
  "${MINGW_PACKAGE_PREFIX}-webview2-loader"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-binaryen"
  "${MINGW_PACKAGE_PREFIX}-cargo-tauri"
  "${MINGW_PACKAGE_PREFIX}-jq"
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-trunk"
  "${MINGW_PACKAGE_PREFIX}-wasm-bindgen"
)
source=("${msys2_repository_url}/archive/v${pkgver}/launcher-${pkgver}.tar.gz"
        '0001-launcher-0.0.4-system-candidate.patch')
sha256sums=('003dd8a243ceee4c3edabb48fcea19fe21a6980951fadfca173d0b0c1ab92abf'
            'e66b9267bde7dc875c6bdca48563a5c2dc2c9764e1a9207c6c6b929b733d760a')

prepare() {
  cd "${srcdir}/launcher-${pkgver}"

  patch -p1 -i "${srcdir}"/0001-launcher-0.0.4-system-candidate.patch

  local _conf=src-tauri/tauri.conf.json
  echo $(jq '.build.beforeBuildCommand |= "trunk build --release"' $_conf) > $_conf
  echo $(jq 'del(.bundle.resources)' $_conf) > $_conf

  cargo fetch --target "${RUST_CHOST}"
}

build() {
  cd "${srcdir}/launcher-${pkgver}"

  cargo tauri build --no-bundle
}

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

  install -Dm755 "target/release/${_realname}.exe" -t "${pkgdir}${MINGW_PREFIX}/bin/"

  #install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
