#!/usr/bin/env bash
# Local Linux build of Zakuro Desktop (Ubuntu 24.04 / Debian 12): zc sidecar for
# the host arch, Tauri binary and .deb (tray, .desktop file; autostart is
# written by the app on first run, ~/.config/autostart/).
#
# Build deps (once):
#   sudo apt-get install -y build-essential curl pkg-config libssl-dev \
#     libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev libxdo-dev
#
#   desktop/scripts/build-linux.sh   # -> desktop/build/*.deb
#   SKIP_SIDECAR=1 / ZC_BIN=…        # as in build-sidecar.sh
set -euo pipefail

here="$(cd "$(dirname "$0")" && pwd)"
desk="$(cd "$here/.." && pwd)"

t0=$(date +%s)
[[ "${SKIP_SIDECAR:-0}" == 1 ]] || "$here/build-sidecar.sh"
t1=$(date +%s)
cd "$desk"
[[ -d node_modules ]] || npm ci
npx tauri build --bundles deb
t2=$(date +%s)

mkdir -p "$desk/build"
cp src-tauri/target/release/bundle/deb/*.deb "$desk/build/"
ls -l "$desk/build/"*.deb
echo "timings: sidecar $((t1 - t0))s, tauri $((t2 - t1))s, total $((t2 - t0))s"
