Compare commits
4
Commits
b8ac68b363
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79a43b9ab3 | ||
|
|
f99a68532f | ||
|
|
7d58013aa1 | ||
|
|
97fda5a3df |
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user