# Template file for 'voiced'
#
# Canonical Void Linux package definition, to be built with xbps-src from a
# void-packages checkout:
#
#   mkdir -p void-packages/srcpkgs/voiced
#   cp packaging/void/template packaging/void/INSTALL packaging/void/REMOVE \
#       void-packages/srcpkgs/voiced/
#   cd void-packages && ./xbps-src pkg voiced
#
# Notes:
#  * `distfiles` points at a tagged archive of the (private) source repository.
#    Private repositories require credentials, so either publish a release
#    tarball, mirror it, or drop the sources into the xbps-src masterdir.
#  * `checksum=SKIP` avoids pinning a hash that cannot be computed here; replace
#    it with the real sha256 once the tarball is published.
#  * INSTALL and REMOVE (next to this file) are xbps action scripts that run
#    `fc-cache -f /usr/share/fonts/voiced` after install and removal. xbps-src
#    picks them up automatically from srcpkgs/voiced/INSTALL and
#    srcpkgs/voiced/REMOVE and packs them into the package; the template does
#    not install them. Copy them next to the template (see the commands above).
#    The stock x11-fonts trigger enabled by font_dirs does not run fc-cache
#    unless mkfontdir and mkfontscale are installed, hence these scripts.
#  * xbps-src builds without network access: vendor the crates (`cargo vendor`
#    in src-tauri/ plus a .cargo/config.toml pointing at vendor/) and pre-populate
#    the npm cache in the source archive or masterdir before building.
#  * No openssl-devel: the ERPNext client uses rustls (ring); reqwest and zip are
#    pure Rust and need no extra system libraries.
#
pkgname=voiced
version=1.1.0
revision=1
archs="x86_64*"
hostmakedepends="rust nodejs pkg-config"
makedepends="libwebkit2gtk41-devel libsoup3-devel gtk+3-devel librsvg-devel"
depends="libwebkit2gtk41>=2.50 fontconfig xdg-utils hicolor-icon-theme desktop-file-utils"
short_desc="Offline invoicing app by Bongbetic"
maintainer="Xavier Karma <xavier@bongbetic.com>"
license="Apache-2.0"
homepage="https://git.bongbetic.com/xavierk/Voiced"
distfiles="https://git.bongbetic.com/xavierk/Voiced/archive/v${version}.tar.gz"
checksum=SKIP
compression="zstd"
# Fonts install under a voiced/ subdirectory so they never conflict with the
# files of Void's own font-ibm-plex-ttf and noto-fonts-ttf packages.
font_dirs="/usr/share/fonts/voiced"

do_build() {
    # Not --omit=optional: that also drops rollup's and esbuild's native binaries (they are
    # optional dependencies), so vite fails; and tsc in `npm run build` type-checks the
    # @napi-rs/canvas test helpers, so that package must be installed too.
    npm ci --no-audit --no-fund
    npm run build
    cd src-tauri
    # `custom-protocol` embeds the frontend for production; without it the app
    # expects a dev server on localhost:1420.
    cargo build --release --features custom-protocol
}

do_install() {
    vbin "${wrksrc}/src-tauri/target/release/voiced"
    vinstall "${wrksrc}/packaging/void/voiced.desktop" 644 usr/share/applications
    for size in 32 64 128; do
        vinstall "${wrksrc}/src-tauri/icons/${size}x${size}.png" 644 \
            "usr/share/icons/hicolor/${size}x${size}/apps" voiced.png
    done
    vinstall "${wrksrc}/src-tauri/icons/128x128@2x.png" 644 \
        usr/share/icons/hicolor/256x256/apps voiced.png
    vinstall "${wrksrc}/src-tauri/icons/icon.png" 644 \
        usr/share/icons/hicolor/512x512/apps voiced.png
    vdoc "${wrksrc}/README.md"

    # Bundled fonts: one subdirectory per family, plus its OFL text.
    # manifest.json and any other non-font file are deliberately skipped.
    for dir in "${wrksrc}"/public/fonts/*/; do
        family="$(basename "${dir}")"
        for ttf in "${dir}"*.ttf; do
            vinstall "${ttf}" 644 "usr/share/fonts/voiced/${family}"
        done
        vlicense "${dir}OFL.txt" "${family}-OFL.txt"
    done
}
