gallery/harnesses/ttimg/scripts/cargo-shim
Greg Pomerantz 16cd868f22 gtauri: pure-push watching only; one emit per burst; live swipe preview
Watch de-duplication (per the plan review): FileObserver (inotify,
push) and MediaStore ContentObserver (URI push) are the ONLY change
detectors. Removed: the 100 ms recv_timeout tick, the fast_dir_sig
mtime-diff watcher, collect_watched_dirs, changed_dirs, dir_sig,
rescan_subtrees, and the 5-minute full-rescan timer thread.
watch_files now blocks on the push channel; on Android each wake
coalesces ~50 ms so a burst of N file events becomes one payload
batch, one SQLite connection, and ONE grid emit (verified on the
emulator: 20-file copy = 1-2 emits, 20-file delete = 1 emit,
single add still lands in ~75-95 ms).

FileObserver rewritten: recursive registration (Pictures/DCIM tree,
cap 5000 dirs) and self-extending — a CREATE/MOVED_TO on a directory
spawns a new observer for it, so new albums are watched too.
tif/tiff added to the image filter.

Dead code removed (the Tauri port never wired them): scan::walk,
walk_dir_nostats, walk_dir_into, mtime_ns, decode_jpeg (full-size),
images::thumb_png, db::set_thumb, db::list_entries, db::count,
db::delete_by_media_id; Thumb shrunk to {rgb,width,height} (the
grid is uniform squares; the viewer uses full-res). Tests now
compile (tempfile dev-dependency was missing — the test module
never built) and were fixed to match the current API.

Viewer: live swipe preview — while a horizontal drag is in flight at
fit scale, the picture being swiped in renders on the page strip
(second <img>, its grid thumb, a ~1 ms mem hit) and tracks the
finger, so there is no blank side. On commit the primary image takes
over from exactly where the preview was; on snap-back the preview
slides back with the tween. Verified on the emulator (two images
visible mid-drag, clean slide home).

Not re-verified: 120 Hz jank (per instruction — measure once when
settled). Desktop paths untouched (deferred).
2026-11-03 12:49:30 -05:00

62 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# cargo shim: intercept `cargo tauri android android-studio-script` (the
# hidden subcommand the tauri gradle plugin's rustBuild task runs) and
# reproduce its effect with a PLAIN cargo build.
#
# Why: the cargo-tauri CLI (every subcommand that builds a Rust interface)
# starts an inotify debouncer on Cargo.toml. This host's per-user inotify
# WATCH quota (65536) is exhausted by the user's standalone syncthing
# (65,482 watches), so inotify_add_watch → ENOSPC and the CLI dies before
# doing anything. Plain cargo build uses no inotify.
#
# android-studio-script's output (verified on the tttest build): the lib .so
# placed at gen/android/app/src/main/jniLibs/<abi-dir>/lib<lib>.so.
set -euo pipefail
REAL_CARGO="$HOME/.cargo/bin/cargo"
PROJ=/mnt/Backup/prog/android/gallery/harnesses/ttimg
NDK="$HOME/android-sdk/ndk/27.0.12077973"
if [ "${1:-}" = "tauri" ] && [ "${2:-}" = "android" ] && [ "${3:-}" = "android-studio-script" ]; then
shift 3
release="" ; target="x86_64"
while [ $# -gt 0 ]; do
case "$1" in
--release) release=1 ;;
--target) shift; target="${1:-x86_64}" ;;
esac
shift
done
case "$target" in
x86_64) TRIPLE=x86_64-linux-android; ABI_DIR=x86_64; CLANG=x86_64-linux-android24-clang ;;
aarch64) TRIPLE=aarch64-linux-android; ABI_DIR=arm64-v8a; CLANG=aarch64-linux-android24-clang ;;
armv7) TRIPLE=armv7-linux-androideabi; ABI_DIR=armeabi-v7a; CLANG=armv7a-linux-androideabi24-clang ;;
i686) TRIPLE=i686-linux-android; ABI_DIR=x86; CLANG=i686-linux-android24-clang ;;
*) echo "shim: unknown target $target" >&2; exit 1 ;;
esac
prof="debug"; [ -n "$release" ] && prof="release"
echo "ttimg shim: cargo build $TRIPLE $prof (bypassing cargo-tauri)"
# env var names are CARGO_TARGET_<UPPER_TRIPLE>_... with HYPHENS → UNDERSCORES
UPPER=$(echo "$TRIPLE" | tr 'a-z-' 'A-Z_')
env \
"CARGO_TARGET_${UPPER}_LINKER=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/$CLANG" \
"CARGO_TARGET_${UPPER}_RUSTFLAGS=-Clink-arg=-landroid -Clink-arg=-llog -Clink-arg=-lOpenSLES" \
"$REAL_CARGO" build --package ttimg --manifest-path "$PROJ/Cargo.toml" \
--target "$TRIPLE" --features "tauri/custom-protocol" --lib --"$prof"
SO="$PROJ/target/$TRIPLE/$prof/libttimg_lib.so"
[ -f "$SO" ] || { echo "shim: $SO not produced" >&2; exit 1; }
DEST="$PROJ/gen/android/app/src/main/jniLibs/$ABI_DIR/libttimg_lib.so"
mkdir -p "$(dirname "$DEST")"
# /mnt/Backup's stat identity is unreliable here (cp still reports
# "same file"), so just break any link and copy fresh:
rm -f "$DEST"
cp "$SO" "$DEST"
echo "ttimg shim: .so -> jniLibs/$ABI_DIR"
exit 0
fi
exec "$REAL_CARGO" "$@"