Compare commits

...
6 Commits
Author SHA1 Message Date
nick 79a43b9ab3 docs: README for v0.2.1 (stats cache, sticky library controls, scan confirmations)
dev / Build debug APK (push) Successful in 14s
2026-09-21 19:07:48 +12:00
nick f99a68532f chore: release v0.2.1 (versionCode 4) with changelog section
dev / Build debug APK (push) Successful in 39s
release / Build & attach release APK (push) Successful in 1m3s
2026-09-21 19:00:19 +12:00
nick 7d58013aa1 feat: sticky library control strip on Library screen with scan confirmations 2026-09-21 19:00:19 +12:00
nick 97fda5a3df feat: cache last-good stats snapshot per server for instant Stats open 2026-09-21 19:00:19 +12:00
nick b8ac68b363 ci: use a Trafero-specific persistent CI keystore path
dev / Build debug APK (push) Successful in 15s
release / Build & attach release APK (push) Successful in 25s
The runner cache already held a release.jks minted by another project with a different store password, so packageRelease failed with "keystore password was incorrect". Mint and reuse trafero-release.jks instead.
2026-09-21 18:02:14 +12:00
nick ef12660b6a ci: Gitea Actions dev + release workflows adapted from incido process
dev / Build debug APK (push) Successful in 4m49s
release / Build & attach release APK (push) Failing after 2m3s
dev.yml builds assembleDebug on push/PR; release.yml publishes tag v*.*.* (or workflow_dispatch(tag)) with notes from PREVIOUS_HISTORY.md and both APKs + changes.md asset via the local-network API host. Android SDK install made idempotent per-package so the runner picks up platforms;android-35 + build-tools;35.0.0 even though it only cached android-34 before.
2026-09-21 17:52:12 +12:00
12 changed files with 518 additions and 73 deletions

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
name: dev
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
name: Build debug APK
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
run: |
git clone https://git.trevena.info/nick/trafero.git repo
cd repo
- name: Set up JDK 17
run: |
WORKDIR=/var/lib/gitea-runner/work
if [ ! -d "$WORKDIR/jdk" ]; then
wget -q 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz' -O /tmp/jdk.tar.gz
mkdir -p "$WORKDIR/jdk"
tar -xzf /tmp/jdk.tar.gz -C "$WORKDIR/jdk" --strip-components=1
rm /tmp/jdk.tar.gz
fi
echo "JAVA_HOME=$WORKDIR/jdk" >> $GITHUB_ENV
echo "PATH=$WORKDIR/jdk/bin:$PATH" >> $GITHUB_ENV
- name: Set up Android SDK
run: |
WORKDIR=/var/lib/gitea-runner/work
SDK=$WORKDIR/android-sdk
if [ ! -d "$SDK/cmdline-tools/latest" ]; then
mkdir -p "$SDK"
wget -q 'https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip' -O /tmp/cmdline-tools.zip
unzip -q /tmp/cmdline-tools.zip -d /tmp/cmdline-tools-extract
mkdir -p "$SDK/cmdline-tools"
mv /tmp/cmdline-tools-extract/cmdline-tools "$SDK/cmdline-tools/latest"
rm -rf /tmp/cmdline-tools.zip /tmp/cmdline-tools-extract
fi
# Install per-package (idempotent): a runner that only cached
# android-34 from other projects must still gain android-35.
# sdkmanager no-ops packages that are already present.
yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null 2>&1 || true
"$SDK/cmdline-tools/latest/bin/sdkmanager" --install \
"platform-tools" \
"platforms;android-35" \
"build-tools;35.0.0"
[ -d "$SDK/platforms/android-35" ] || { echo "ERROR: platforms;android-35 did not install"; exit 1; }
[ -d "$SDK/build-tools/35.0.0" ] || { echo "ERROR: build-tools;35.0.0 did not install"; exit 1; }
echo "ANDROID_HOME=$SDK" >> $GITHUB_ENV
echo "ANDROID_SDK_ROOT=$SDK" >> $GITHUB_ENV
echo "PATH=$SDK/cmdline-tools/latest/bin:$SDK/platform-tools:$PATH" >> $GITHUB_ENV
- name: Build
timeout-minutes: 25
run: |
cd repo
chmod +x gradlew
export JAVA_HOME=/var/lib/gitea-runner/work/jdk
export ANDROID_HOME=/var/lib/gitea-runner/work/android-sdk
export PATH=$JAVA_HOME/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH
./gradlew assembleDebug --no-daemon
+245
View File
@@ -0,0 +1,245 @@
name: release
on:
push:
tags:
- 'v*.*.*'
# Retry path: a tag push pins the workflow file to that tag's commit, so a
# re-run of a red release run replays the OLD workflow even after main is
# fixed (that is exactly how run 78 kept failing post-fix). Dispatching
# against main runs main's current workflow against any already-published
# tag, so a release can be re-published without moving a tag.
workflow_dispatch:
inputs:
tag:
description: 'Existing tag to rebuild and re-publish, e.g. v0.3.8.1'
required: true
type: string
jobs:
build-release:
name: Build & attach release APK
runs-on: ubuntu-latest
timeout-minutes: 30
env:
# The tag this run publishes: the tag itself on a push, or the typed
# input on a manual retry (where github.ref_name is just the branch).
RELEASE_TAG: ${{ github.event.inputs.tag || github.ref_name }}
steps:
- name: Checkout
run: |
git clone --depth=1 https://git.trevena.info/nick/trafero.git repo
cd repo
# Targeted shallow fetch of the exact tag: the clone above is shallow
# off the default branch, so --tags alone may not carry the tag's
# commit when the run is dispatched from main instead of pushed.
git fetch --depth=1 origin tag "$RELEASE_TAG" || true
git fetch --tags origin
git checkout "$RELEASE_TAG"
- name: Set up JDK 17
run: |
WORKDIR=/var/lib/gitea-runner/work
if [ ! -d "$WORKDIR/jdk" ]; then
wget -q 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz' -O /tmp/jdk.tar.gz
mkdir -p "$WORKDIR/jdk"
tar -xzf /tmp/jdk.tar.gz -C "$WORKDIR/jdk" --strip-components=1
rm /tmp/jdk.tar.gz
fi
echo "JAVA_HOME=$WORKDIR/jdk" >> $GITHUB_ENV
echo "PATH=$WORKDIR/jdk/bin:$PATH" >> $GITHUB_ENV
- name: Set up Android SDK
run: |
WORKDIR=/var/lib/gitea-runner/work
SDK=$WORKDIR/android-sdk
if [ ! -d "$SDK/cmdline-tools/latest" ]; then
mkdir -p "$SDK"
wget -q 'https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip' -O /tmp/cmdline-tools.zip
unzip -q /tmp/cmdline-tools.zip -d /tmp/cmdline-tools-extract
mkdir -p "$SDK/cmdline-tools"
mv /tmp/cmdline-tools-extract/cmdline-tools "$SDK/cmdline-tools/latest"
rm -rf /tmp/cmdline-tools.zip /tmp/cmdline-tools-extract
fi
# Install per-package (idempotent): a runner that only cached
# android-34 from other projects must still gain android-35.
# sdkmanager no-ops packages that are already present.
yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null 2>&1 || true
"$SDK/cmdline-tools/latest/bin/sdkmanager" --install \
"platform-tools" \
"platforms;android-35" \
"build-tools;35.0.0"
[ -d "$SDK/platforms/android-35" ] || { echo "ERROR: platforms;android-35 did not install"; exit 1; }
[ -d "$SDK/build-tools/35.0.0" ] || { echo "ERROR: build-tools;35.0.0 did not install"; exit 1; }
echo "ANDROID_HOME=$SDK" >> $GITHUB_ENV
echo "ANDROID_SDK_ROOT=$SDK" >> $GITHUB_ENV
echo "PATH=$SDK/cmdline-tools/latest/bin:$SDK/platform-tools:$PATH" >> $GITHUB_ENV
- name: Build debug + release APKs
timeout-minutes: 25
run: |
cd repo
git checkout "$RELEASE_TAG"
# Persistent signing keystore: minted ONCE in the runner's
# cache dir (which survives across runs, same place the JDK
# and SDK live) and copied into the checkout. Trafero uses its
# OWN file (trafero-release.jks) - the shared release.jks there
# was minted by another project with a different password.
# Every release is therefore signed with the SAME key, so
# users can upgrade in place instead of hitting a signature
# conflict. A runner-host rebuild would mint a fresh key - the
# only scenario that breaks one upgrade.
mkdir -p keystore
if [ ! -f /var/lib/gitea-runner/work/trafero-release.jks ]; then
echo "Minting new persistent CI keystore"
keytool -genkey -noprompt -v \
-keystore /var/lib/gitea-runner/work/trafero-release.jks \
-keyalg RSA -keysize 2048 -validity 10000 \
-alias trafero \
-storepass trafero_dev_keystore \
-keypass trafero_dev_keystore \
-dname "CN=Trafero CI, OU=Local, O=Trafero, L=Local, ST=Local, C=NZ"
else
echo "Reusing persistent CI keystore from runner cache"
fi
cp /var/lib/gitea-runner/work/trafero-release.jks keystore/release.jks
export JAVA_HOME=/var/lib/gitea-runner/work/jdk
export ANDROID_HOME=/var/lib/gitea-runner/work/android-sdk
export PATH=$JAVA_HOME/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH
chmod +x ./gradlew
./gradlew --stop 2>/dev/null || true
./gradlew assembleDebug assembleRelease --no-daemon --stacktrace 2>&1 | tee /tmp/build.log
BUILD_STATUS=${PIPESTATUS[0]}
echo "Gradle exit status: $BUILD_STATUS"
if [ $BUILD_STATUS -ne 0 ]; then
echo "Build failed"
tail -100 /tmp/build.log
exit 1
fi
ls -la app/build/outputs/apk/debug/ app/build/outputs/apk/release/
- name: Create release + attach both APKs
env:
GH_TOKEN: ${{ secrets.TOKEN }}
run: |
set -e
cd repo
TAG="$RELEASE_TAG"
VERSION="${TAG#v}"
API="http://192.168.8.17:3000/api/v1/repos/nick/trafero"
APK_DEBUG="Trafero-$VERSION-debug.apk"
APK_RELEASE="Trafero-$VERSION-release.apk"
echo "Tag: $TAG Version: $VERSION"
# User-facing release notes: harvest this version's section from
# PREVIOUS_HISTORY.md (see the file header for the convention).
# Used as the release description and uploaded beside the APKs.
NOTES_FILE="/tmp/Trafero-$VERSION-changes.md"
if python3 scripts/ci/release-notes.py "$VERSION" --out "$NOTES_FILE"; then
HAS_NOTES=1
echo "--- Release notes preview (v$VERSION) ---"
head -12 "$NOTES_FILE"
echo "---"
else
HAS_NOTES=0
echo "No PREVIOUS_HISTORY.md section for v$VERSION - falling back to the default description."
fi
echo "--- Check for existing release ---"
RELEASE_ID=$(curl -s "$API/releases/tags/$TAG" \
-H "Authorization: token $GH_TOKEN" \
| python3 -c "import sys,json; print(json.load(sys.stdin).get('id','') or '')")
if [ -z "$RELEASE_ID" ]; then
echo "--- Create release ---"
REL_TAG="$TAG" REL_NOTES_FILE="$NOTES_FILE" python3 -c "import json,os; nf=os.environ.get('REL_NOTES_FILE',''); body=(open(nf,encoding='utf-8').read() if nf and os.path.exists(nf) else 'Release '+os.environ['REL_TAG']); print(json.dumps({'tag_name':os.environ['REL_TAG'],'name':os.environ['REL_TAG'],'body':body,'draft':False,'prerelease':False}))" \
> /tmp/release_payload.json
RELEASE_ID=$(curl -s -X POST "$API/releases" \
-H "Authorization: token $GH_TOKEN" \
-H "Content-Type: application/json" \
-d @/tmp/release_payload.json \
| python3 -c "import sys,json; print(json.load(sys.stdin).get('id','') or '')")
else
echo "--- Reusing existing release $RELEASE_ID ---"
# Refresh the description even on a rerun, so backfills and
# retried asset uploads always match PREVIOUS_HISTORY.md.
if [ "$HAS_NOTES" = "1" ]; then
echo "--- Patching release description from PREVIOUS_HISTORY.md ---"
REL_NOTES_FILE="$NOTES_FILE" python3 -c "import json,os; print(json.dumps({'body': open(os.environ['REL_NOTES_FILE'],encoding='utf-8').read()}))" \
> /tmp/body_patch.json
curl -s -X PATCH "$API/releases/$RELEASE_ID" \
-H "Authorization: token $GH_TOKEN" \
-H "Content-Type: application/json" \
-d @/tmp/body_patch.json > /dev/null
fi
fi
echo "Release ID: $RELEASE_ID"
if [ -z "$RELEASE_ID" ]; then echo "ERROR: no release ID"; exit 1; fi
echo "aW1wb3J0IHN5cywganNvbiwgdXJsbGliLnJlcXVlc3QKYXBpID0gc3lzLmFyZ3ZbMV0KcmVsZWFzZV9pZCA9IHN5cy5hcmd2WzJdCmFwayA9IHN5cy5hcmd2WzNdCnRva2VuID0gc3lzLmFyZ3ZbNF0KcmVxID0gdXJsbGliLnJlcXVlc3QuUmVxdWVzdCgKICAgIGYie2FwaX0vcmVsZWFzZXMve3JlbGVhc2VfaWR9L2Fzc2V0cyIsCiAgICBoZWFkZXJzPXsiQXV0aG9yaXphdGlvbiI6IGYidG9rZW4ge3Rva2VufSJ9CikKcmVzcCA9IHVybGxpYi5yZXF1ZXN0LnVybG9wZW4ocmVxKQpmb3IgYSBpbiBqc29uLmxvYWRzKHJlc3AucmVhZCgpKToKICAgIGlmIGFbIm5hbWUiXSA9PSBhcGs6CiAgICAgICAgZGVsZXRlX3JlcSA9IHVybGxpYi5yZXF1ZXN0LlJlcXVlc3QoCiAgICAgICAgICAgIGYie2FwaX0vcmVsZWFzZXMve3JlbGVhc2VfaWR9L2Fzc2V0cy97YVsnaWQnXX0iLAogICAgICAgICAgICBtZXRob2Q9IkRFTEVURSIsCiAgICAgICAgICAgIGhlYWRlcnM9eyJBdXRob3JpemF0aW9uIjogZiJ0b2tlbiB7dG9rZW59In0KICAgICAgICApCiAgICAgICAgdXJsbGliLnJlcXVlc3QudXJsb3BlbihkZWxldGVfcmVxKQogICAgICAgIHByaW50KGYiRGVsZXRlZCB7YVsnaWQnXX0iLCBmbHVzaD1UcnVlKQo=" | base64 -d > /tmp/delete_asset.py
# Upload one asset with retries, then verify server-side.
# Cloudflare sits in front of the origin and returns
# "error code: 524" (origin timeout, ~100s) on large/slow
# uploads — the file frequently lands on the origin anyway,
# so success is decided by listing the release's assets
# rather than trusting the upload response body (which may
# be a non-JSON Cloudflare error page).
upload_asset() {
local apk_name="$1" apk_path="$2"
local attempt
for attempt in 1 2 3 4 5; do
echo "--- Uploading $apk_name (attempt $attempt/5) ---"
ls -la "$apk_path"
UPLOAD=$(curl -s -f -X POST "$API/releases/$RELEASE_ID/assets?name=$apk_name" \
-H "Authorization: token $GH_TOKEN" \
-F "attachment=@$apk_path" \
--max-time 600 --retry 2 --retry-all-errors --retry-delay 15 || true)
echo "Upload response: ${UPLOAD:0:200}"
if curl -s "$API/releases/$RELEASE_ID" \
-H "Authorization: token $GH_TOKEN" \
| python3 -c "import sys,json; d=json.load(sys.stdin); sys.exit(0 if any(a['name']=='$apk_name' for a in d['assets']) else 1)"; then
echo "Verified: $apk_name is attached to the release."
return 0
fi
echo "Asset not on the server yet — retrying in 15s..."
sleep 15
done
echo "ERROR: $apk_name failed to attach after 5 attempts."
return 1
}
for APK in "$APK_DEBUG" "$APK_RELEASE"; do
if echo "$APK" | grep -q "debug"; then
APK_PATH="app/build/outputs/apk/debug/app-debug.apk"
else
APK_PATH="app/build/outputs/apk/release/app-release.apk"
fi
if [ ! -f "$APK_PATH" ]; then
echo "ERROR: APK not found: $APK_PATH"
exit 1
fi
echo "--- Deleting stale assets for $APK ---"
python3 /tmp/delete_asset.py "$API" "$RELEASE_ID" "$APK" "$GH_TOKEN"
upload_asset "$APK" "$APK_PATH" || exit 1
done
# Ship the changelog beside the binaries: people skimming the
# downloads get the notes for exactly this version as a file,
# generated from PREVIOUS_HISTORY.md at the top of this run.
if [ "$HAS_NOTES" = "1" ]; then
NOTES_ASSET="Trafero-$VERSION-changes.md"
echo "--- Deleting stale asset for $NOTES_ASSET ---"
python3 /tmp/delete_asset.py "$API" "$RELEASE_ID" "$NOTES_ASSET" "$GH_TOKEN"
# Upload $NOTES_FILE directly: it already IS /tmp/<asset name>, so
# copying it onto itself made cp fail with exit 1 and killed the
# whole step (set -e) after the APKs had uploaded fine.
upload_asset "$NOTES_ASSET" "$NOTES_FILE" || exit 1
fi
echo "--- Final release state ---"
curl -s "$API/releases/$RELEASE_ID" -H "Authorization: token $GH_TOKEN" | python3 -c "import sys,json; d=json.load(sys.stdin); print('Release ' + d['tag_name'] + ' has ' + str(len(d['assets'])) + ' assets')"
+6
View File
@@ -8,6 +8,12 @@ Current downloads ship **with their own notes**: every release on the [Releases
---
## v0.2.1 — 2026-09-21
- **Stats open instantly.** Trafero now caches the last-good stats snapshot per server; opening the Stats tab shows the previous numbers immediately (with a small "Cached - updated …" hint) while a fresh poll refreshes everything in the background. It also means a cold start on a flaky link keeps showing the last known data behind the reconnecting chip instead of a blank screen.
- **Library controls moved to the Library screen.** The watch-folder toggle and Scan new / Full scan buttons (previously buried under More → Settings → Libraries) now sit in a compact sticky strip at the top of the Library screen, above the search box — always visible while the file list scrolls. Settings keeps the Processing toggles and server management.
- **Scan confirmations.** "Scan new" now asks for confirmation ("may take some time"), and "Full scan" shows an explicit warning that it wipes the database and re-queues the entire library for health checks and transcoding — with a one-tap "Scan new" fallback in the same dialog.
## v0.2.0 — 2026-09-21
> **⚠️ Reinstall required for phone installs of the debug build.** This is the first Trafero release built and signed by CI. Release APKs are signed with the persistent CI keystore, which is a **different signing key** from locally-built debug APKs (such as the v0.1.1 debug install most testers have). Android refuses to install over a different signature — uninstall the old app first, then install either APK from this release. From v0.2.0 onwards, debug↔release stay separate apps but release→release upgrades are normal in-place updates.
+10 -11
View File
@@ -2,7 +2,7 @@
Native Android (Kotlin / Jetpack Compose / Material 3) client for the Tdarr server v2.2x+ /api/v2 JSON API.
**Current release:** v0.2.0 — full release notes ship on its entry on the
**Current release:** v0.2.1 — full release notes ship on its entry on the
[Releases page](https://git.trevena.info/nick/Trafero/releases).
> **Installing a release APK over a debug build?** They are signed with
@@ -20,22 +20,21 @@ Release builds need the local dev keystore — see [`keystore/README.md`](keysto
## Install & test
adb install -r app/build/outputs/apk/debug/app-debug.apk
## Features (v0.2.0)
## Features (v0.2.1)
- Connection wizard: custom URL (scheme/port normalization, default :8265), auth mode None / API key (x-api-key) / username+password (bearer token), self-signed TLS toggle, live test probe, multi-server switcher.
- Jobs: running workers (progress/fps/ETA, cancel), staged queue (approve/reject), history (file filter), error stacks (table1/2/3).
- Library: search + per-library filter + sort, paged file cards, detail bottom sheet (streams from ffprobe, plugin output, re-check).
- Library: sticky control strip pinned above the search (per-library watch toggle, scan new / full scan), search + per-library filter + sort, paged file cards, detail bottom sheet (streams from ffprobe, plugin output, re-check). Scan buttons confirm first; full scan warns explicitly (wipes DB + re-queues everything) and offers the safe scan-for-new-files fallback.
- Nodes: pause/resume, worker limit +/-, kill worker, queue depths.
- Stats: server info, CPU/mem, totals, space saved, transcode/health donuts, codec mix.
- Stats: server info, CPU/mem, totals, space saved, transcode/health donuts, codec mix; opens instantly from a cached per-server snapshot while refreshing in the background.
- Logs: server log with filter + follow.
- Settings: pause-all-nodes & ignore-schedules, libraries (watch toggle, scan new / full scan), server CRUD.
- Settings: pause-all-nodes & ignore-schedules, server CRUD.
- Flows: read-only flow-plugin catalog (inputs/filters/actions/variables/outputs).
- Polling interval picker (Off/5s/15s/30s/1m/5m) in app bar; Material You dynamic color, dark & light.
## v0.2.0 changes (slow-connection resilience)
- Per-server **timeout** field and **"Slow connection"** mode (doubles all timeouts) in the server editor; defaults 20 s connect / 90 s read.
- Read-style/polling calls auto-retry twice (2 s / 5 s backoff) on network failures only — user-triggered mutations are never repeated.
- Screens keep their last good data on transient failures and show a slim **"reconnecting…"** chip; full error banners are reserved for no-data, auth, or server errors. After 3 consecutive poll failures a screen backs off to a 60 s cadence.
- OkHttp keep-alive pool is evicted on app resume so stale NAT/LAN sockets can't cause phantom timeouts.
## v0.2.1 changes
- **Instant Stats.** The last-good stats snapshot is cached per server; the Stats tab opens with the previous numbers immediately (small "Cached - updated …" hint) and refreshes in the background — no more blank screen while the first poll runs, and cold starts on flaky links keep showing last-known data behind the reconnecting chip.
- **Library controls on the Library screen.** Watch-folder toggles and Scan new / Full scan moved out of More → Settings into a compact sticky strip pinned above the library search; the file list scrolls beneath it.
- **Scan confirmations.** Scan new asks before running; Full scan shows a destructive-action warning (wipes the database, re-queues the library for health checks + transcoding) with a one-tap Scan-new fallback.
## Earlier changes
Full history lives in [`PREVIOUS_HISTORY.md`](PREVIOUS_HISTORY.md); each release on the Releases page carries its own notes plus a `Trafero-<version>-changes.md` asset.
@@ -45,7 +44,7 @@ Full history lives in [`PREVIOUS_HISTORY.md`](PREVIOUS_HISTORY.md); each release
- Flow editing, node/server restart, updater and disk-delete actions intentionally not exposed (agreed scope / safety).
## Architecture
Single :app module. data/api/TdarrClient (OkHttp, {data:{...}} envelope, TraferoApiException kinds: AUTH/NETWORK/SERVER/LEGACY), data/repo/TraferoRepo (typed parsing), DataStore server profiles, manual DI (AppContainer), Compose screens under ui/screens/*, pollLoop() helper for per-screen refresh.
Single :app module. data/api/TdarrClient (OkHttp, {data:{...}} envelope, TraferoApiException kinds: AUTH/NETWORK/SERVER/LEGACY), data/repo/TraferoRepo (typed parsing), DataStore server profiles + per-server stats snapshots, manual DI (AppContainer), Compose screens under ui/screens/*, pollLoop() helper for per-screen refresh.
## Reference
OpenAPI 2.0 spec of the target API vendored at app/src/main/assets/api-docs-v2.json (served live by any Tdarr server at /api/v2/public/api-docs/json).
+2 -2
View File
@@ -13,8 +13,8 @@ android {
applicationId = "com.trafero.app"
minSdk = 26
targetSdk = 35
versionCode = 3
versionName = "0.2.0"
versionCode = 4
versionName = "0.2.1"
}
signingConfigs {
@@ -21,6 +21,7 @@ data class ServerProfile(
val slowConnection: Boolean = false
)
@Serializable
data class ServerStatus(
val version: String,
val buildDate: String,
@@ -95,8 +96,10 @@ data class StagedRow(
val status: String
)
@Serializable
data class PieStatBucket(val name: String, val value: Int)
@Serializable
data class PieStats(
val totalFiles: Int,
val totalTranscodeCount: Int,
@@ -107,6 +110,7 @@ data class PieStats(
val videoCodecs: List<PieStatBucket>
)
@Serializable
data class ResStats(
val cpuPerc: Double,
val memUsedGB: Double,
@@ -114,6 +118,15 @@ data class ResStats(
val heapUsedMB: Double
)
/** Last-good stats snapshot persisted so the Stats screen opens instantly. */
@Serializable
data class StatsSnapshot(
val savedAtMs: Long,
val status: ServerStatus? = null,
val res: ResStats? = null,
val pies: PieStats? = null
)
data class FlowPluginInfo(
val id: String,
val name: String,
@@ -5,8 +5,10 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.trafero.app.data.model.ServerProfile
import com.trafero.app.data.model.StatsSnapshot
import com.trafero.app.util.TraferoJson
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.serialization.builtins.ListSerializer
@@ -45,6 +47,7 @@ class ServerStore(private val context: Context) {
val updated = book.profiles.filterNot { it.id == id }
prefs[keyServers] = TraferoJson.encodeToString(ListSerializer(ServerProfile.serializer()), updated)
if (prefs[keyActive] == id) prefs[keyActive] = updated.firstOrNull()?.id ?: ""
prefs.remove(statsKey(id))
}
}
@@ -52,6 +55,29 @@ class ServerStore(private val context: Context) {
context.traferoDataStore.edit { prefs -> prefs[keyActive] = id }
}
// ---- last-good stats snapshot (per server) ----
private fun statsKey(serverId: String) = stringPreferencesKey("stats_$serverId")
suspend fun saveStatsSnapshot(serverId: String, snapshot: StatsSnapshot) {
context.traferoDataStore.edit { prefs ->
prefs[statsKey(serverId)] =
TraferoJson.encodeToString(StatsSnapshot.serializer(), snapshot)
}
}
suspend fun loadStatsSnapshot(serverId: String): StatsSnapshot? {
val json = context.traferoDataStore.data.first()[statsKey(serverId)]
if (json.isNullOrBlank()) return null
return runCatching {
TraferoJson.decodeFromString(StatsSnapshot.serializer(), json)
}.getOrNull()
}
suspend fun removeStatsSnapshot(serverId: String) {
context.traferoDataStore.edit { prefs -> prefs.remove(statsKey(serverId)) }
}
private fun decodeBook(serversJson: String?, activeId: String?): ServerBook {
val list = if (serversJson.isNullOrBlank()) emptyList() else
runCatching {
@@ -55,6 +55,7 @@ val LocalServerCtx = compositionLocalOf<ServerCtx> { ServerCtx() }
data class ServerCtx(
val refreshMs: Long = 15_000L,
val serverId: String = "",
val onError: (String) -> Unit = {}
)
@@ -92,7 +93,7 @@ fun AppRoot(container: AppContainer) {
var refreshMs by remember { mutableStateOf(15_000L) }
CompositionLocalProvider(
LocalRepo provides repo,
LocalServerCtx provides ServerCtx(refreshMs = refreshMs)
LocalServerCtx provides ServerCtx(refreshMs = refreshMs, serverId = active.id)
) {
MainScaffold(container, state.profiles, active, refreshMs) { refreshMs = it }
}
@@ -165,7 +166,7 @@ private fun MainScaffold(
composable("jobs") { JobsScreen(nav) }
composable("library") { LibraryScreen(nav) }
composable("nodes") { NodesScreen() }
composable("stats") { StatsScreen() }
composable("stats") { StatsScreen(container) }
composable("more") { MoreScreen(nav) }
composable("logs") { LogsScreen() }
composable("settings") { SettingsScreen(container) }
@@ -1,5 +1,6 @@
package com.trafero.app.ui.screens.library
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@@ -12,6 +13,9 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.DropdownMenu
@@ -19,6 +23,7 @@ import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.MaterialTheme
@@ -31,6 +36,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
@@ -81,6 +87,22 @@ fun LibraryScreen(nav: NavController) {
var sortMenu by remember { mutableStateOf(false) }
val pageSize = 30
val scope = rememberCoroutineScope()
var pendingScan by remember { mutableStateOf<Pair<LibInfo, String>?>(null) }
fun launchScan(lib: LibInfo, mode: String) {
scope.launch {
runCatching { repo.scanLibrary(lib.id, lib.folder, mode) }
.onSuccess {
error = if (mode == "scanFresh") "Full scan queued: " + lib.name
else "Scan (new files) queued: " + lib.name
}
.onFailure { error = TraferoRepo.describeError(it) }
}
}
fun refreshLibs() {
scope.launch { runCatching { repo.libraries() }.onSuccess { libs = it } }
}
LaunchedEffect(Unit) { runCatching { repo.libraries() }.onSuccess { libs = it } }
@@ -98,7 +120,25 @@ fun LibraryScreen(nav: NavController) {
}
Column(Modifier.fillMaxSize()) {
Row(Modifier.padding(horizontal = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
// Sticky library control strip: watch toggle + scans for every library,
// capped to ~3 rows (internal scroll) so the file list stays usable.
if (libs.isNotEmpty()) {
Column(
Modifier.fillMaxWidth()
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.45f))
.heightIn(max = 150.dp)
.verticalScroll(rememberScrollState())
.padding(horizontal = 12.dp, vertical = 2.dp)
) {
libs.forEach { lib ->
LibControlRow(lib, repo,
onScan = { l, mode -> pendingScan = l to mode }) { msg ->
if (msg != null) error = msg else refreshLibs()
}
}
}
}
Row(Modifier.padding(horizontal = 12.dp, vertical = 6.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedTextField(value = query, onValueChange = { query = it }, singleLine = true,
label = { Text("Search files") }, modifier = Modifier.weight(1f))
}
@@ -142,6 +182,74 @@ fun LibraryScreen(nav: NavController) {
FileDetailSheet(repo, row) { msg -> error = msg; selected = null }
}
}
// Scan confirmations: full scan is destructive (wipes + re-queues everything),
// so it warns explicitly and offers the safe scan-for-new-files alternative.
pendingScan?.let { (lib, mode) ->
AlertDialog(
onDismissRequest = { pendingScan = null },
title = { Text(if (mode == "scanFresh") "Full scan warning" else "Scan for new files?") },
text = {
Text(if (mode == "scanFresh")
"A full scan of \"" + lib.name + "\" will wipe the database and rescan the entire library, then re-queue everything for health checks and transcoding. In most circumstances, scanning for new files is recommended. Are you sure?"
else "Scanning \"" + lib.name + "\" for new files may take some time. Are you sure?")
},
confirmButton = {
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
if (mode == "scanFresh") {
TextButton(onClick = {
pendingScan = null
launchScan(lib, "scanFindNew")
}) { Text("Scan new") }
}
TextButton(onClick = {
pendingScan = null
launchScan(lib, mode)
}) { Text("Proceed") }
}
},
dismissButton = {
TextButton(onClick = { pendingScan = null }) { Text("Cancel") }
}
)
}
}
@Composable
private fun LibControlRow(
lib: LibInfo,
repo: TraferoRepo,
onScan: (LibInfo, String) -> Unit,
onResult: (String?) -> Unit
) {
val scope = rememberCoroutineScope()
Row(
Modifier.fillMaxWidth().padding(vertical = 1.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(lib.name, Modifier.weight(1f).padding(end = 6.dp), maxLines = 1,
overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.SemiBold)
Text("Watch", style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant)
Switch(
checked = lib.folderWatching,
onCheckedChange = { on ->
scope.launch {
runCatching { repo.toggleFolderWatch(lib.id, lib.folder, on) }
.onSuccess { onResult(null) }
.onFailure { onResult(TraferoRepo.describeError(it)) }
}
},
modifier = Modifier.scale(0.7f)
)
TextButton(onClick = { onScan(lib, "scanFindNew") }) {
Text("Scan new", style = MaterialTheme.typography.labelMedium)
}
TextButton(onClick = { onScan(lib, "scanFresh") }) {
Text("Full scan", style = MaterialTheme.typography.labelMedium)
}
}
}
@Composable
@@ -1,7 +1,6 @@
package com.trafero.app.ui.screens.settings
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@@ -28,9 +27,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.trafero.app.data.model.LibInfo
import com.trafero.app.data.model.ServerProfile
import com.trafero.app.data.repo.TraferoRepo
import com.trafero.app.di.AppContainer
@@ -51,7 +48,6 @@ fun SettingsScreen(container: AppContainer) {
val book by container.serverStore.book.collectAsState(initial = com.trafero.app.data.store.ServerBook())
var error by remember { mutableStateOf<String?>(null) }
var settings by remember { mutableStateOf<com.trafero.app.data.model.GlobalSettings?>(null) }
var libs by remember { mutableStateOf<List<LibInfo>>(emptyList()) }
var editing by remember { mutableStateOf<ServerProfile?>(null) }
var addingNew by remember { mutableStateOf(false) }
var confirmDelete by remember { mutableStateOf<ServerProfile?>(null) }
@@ -59,8 +55,8 @@ fun SettingsScreen(container: AppContainer) {
val poll = rememberPollState()
pollLoop(ctx.refreshMs, listOf<Any?>("settings"), poll) {
if (repo != null) {
runCatching { repo.globalSettings() to repo.libraries() }
.onSuccess { (g, l) -> settings = g; libs = l; error = null; poll.success() }
runCatching { repo.globalSettings() }
.onSuccess { g -> settings = g; error = null; poll.success() }
.onFailure { poll.failure(it, hasData = settings != null)?.let { msg -> error = msg } }
}
}
@@ -91,14 +87,6 @@ fun SettingsScreen(container: AppContainer) {
}
}
if (libs.isNotEmpty()) {
SectionCard("Libraries") {
libs.forEach { lib ->
LibRow(lib, repo) { msg -> if (msg != null) error = msg }
}
}
}
SectionCard("Servers") {
book.profiles.forEach { p ->
Card(Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
@@ -153,40 +141,3 @@ private fun ToggleRow(label: String, checked: Boolean, onChange: (Boolean) -> Un
}
}
@Composable
private fun LibRow(lib: LibInfo, repo: TraferoRepo?, onResult: (String?) -> Unit) {
val scope = rememberCoroutineScope()
Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Column(Modifier.weight(1f)) {
Text(lib.name, fontWeight = FontWeight.SemiBold)
Text(lib.folder, maxLines = 1, overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant)
}
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Watch", style = MaterialTheme.typography.labelSmall)
Switch(checked = lib.folderWatching, onCheckedChange = { on ->
scope.launch {
runCatching { repo?.toggleFolderWatch(lib.id, lib.folder, on) }
.onFailure { onResult(TraferoRepo.describeError(it)) }
}
})
}
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedButton(onClick = {
scope.launch {
runCatching { repo?.scanLibrary(lib.id, lib.folder, "scanFindNew") }
.onFailure { onResult(TraferoRepo.describeError(it)) }
}
}) { Text("Scan new") }
OutlinedButton(onClick = {
scope.launch {
runCatching { repo?.scanLibrary(lib.id, lib.folder, "scanFresh") }
.onFailure { onResult(TraferoRepo.describeError(it)) }
}
}) { Text("Full scan") }
}
}
}
@@ -14,6 +14,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -25,7 +26,9 @@ import androidx.compose.ui.unit.dp
import com.trafero.app.data.model.PieStats
import com.trafero.app.data.model.ResStats
import com.trafero.app.data.model.ServerStatus
import com.trafero.app.data.model.StatsSnapshot
import com.trafero.app.data.repo.TraferoRepo
import com.trafero.app.di.AppContainer
import com.trafero.app.ui.LocalRepo
import com.trafero.app.ui.LocalServerCtx
import com.trafero.app.ui.common.ChartPalette
@@ -40,23 +43,48 @@ import com.trafero.app.ui.common.pollLoop
import com.trafero.app.ui.common.rememberPollState
@Composable
fun StatsScreen() {
fun StatsScreen(container: AppContainer) {
val repo = LocalRepo.current ?: return
val ctx = LocalServerCtx.current
var status by remember { mutableStateOf<ServerStatus?>(null) }
var pies by remember { mutableStateOf<PieStats?>(null) }
var res by remember { mutableStateOf<ResStats?>(null) }
var error by remember { mutableStateOf<String?>(null) }
var updatedAt by remember { mutableStateOf(0L) }
var live by remember { mutableStateOf(false) }
val poll = rememberPollState()
pollLoop(ctx.refreshMs, listOf<Any?>("stats"), poll) {
// Seed from the last-good snapshot on open (per server) so the screen
// renders immediately while the first poll refreshes in the background.
LaunchedEffect(ctx.serverId) {
status = null; pies = null; res = null; error = null; live = false; updatedAt = 0L
val snap = container.serverStore.loadStatsSnapshot(ctx.serverId) ?: return@LaunchedEffect
if (status == null && pies == null && res == null) { // don't clobber a faster live poll
status = snap.status; pies = snap.pies; res = snap.res
updatedAt = snap.savedAtMs
}
}
pollLoop(ctx.refreshMs, listOf<Any?>("stats", ctx.serverId), poll) {
runCatching {
Triple(repo.status(), repo.pies(), repo.resStats())
}.onSuccess { (s, p, r) -> status = s; pies = p; res = r; error = null; poll.success() }
}.onSuccess { (s, p, r) ->
status = s; pies = p; res = r; error = null; live = true; poll.success()
updatedAt = System.currentTimeMillis()
val snap = StatsSnapshot(updatedAt, s, r, p)
runCatching { container.serverStore.saveStatsSnapshot(ctx.serverId, snap) }
}
.onFailure { poll.failure(it, hasData = status != null)?.let { msg -> error = msg } }
}
Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
error?.let { ErrorBanner(it) }
if (poll.reconnecting) ReconnectChip()
if (!live && updatedAt > 0 && status != null) {
Text("Cached - updated " + Fmt.timeAgo(updatedAt),
Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 2.dp),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.outline)
}
status?.let { s ->
SectionCard("Server") {
Text("Tdarr " + s.version + " (" + s.serverEngine + ")", fontWeight = FontWeight.SemiBold)
+5 -3
View File
@@ -25,9 +25,11 @@ before publishing anywhere real.
## CI (Gitea Actions)
`release.yml` mints one persistent keystore on the runner at
`/var/lib/gitea-runner/work/release.jks` (same parameters as above) and
copies it to `keystore/release.jks` for every build, so all CI release
APKs share one signing key and users can upgrade in place.
`/var/lib/gitea-runner/work/trafero-release.jks` (same parameters as
above, except `CN=Trafero CI`) and copies it to `keystore/release.jks`
for every build, so all CI release APKs share one signing key and users
can upgrade in place. The file is project-specific (`trafero-` prefix)
because the runner cache directory is shared between repositories.
**Important:** locally-built (and debug) APKs have a *different*
signature from CI release APKs — installing a CI release build over a