feat(core,app,android,ios): look at shares again on their own, and say when they were last looked at

No client crawled a share unless someone pressed Refresh, so a new
episode stayed out of the library until then, and nothing said how stale
the library was.

Catalog schema v11 adds share_crawls: when each share's last crawl
finished and was attempted, how many files it stored and how many were
new, and why the last attempt failed. A failure keeps the last good
crawl's numbers.

Every client now crawls, quietly, any share not looked at for six hours:
the desktop at launch and every half hour while open, the phones at
launch and on their existing catch-up timer. A quiet crawl says only
news ("anime: 3 new files") and leaves failures on the share's row
rather than in a toast.

Share rows on all three show "120 files - crawled 2 h ago", or the last
failure until a crawl succeeds.
This commit is contained in:
nvrl committed 2026-10-12 22:22:25 +02:00
1 parent a306d02cf1
commit 5807493a4a
13 files changed
+552 -75

No files matched your search

@@ -297,7 +297,9 @@ class AppViewModel(context: Context, private val workManager: WorkManager) : Vie
}
}
reloadNow()
if (failed.isNotEmpty()) {
// A catch-up is the app's doing, not the viewer's: a failure goes on
// the share's row rather than in their face, and only news is said.
if (failed.isNotEmpty() && announce) {
mutableState.update { it.copy(message = failed.joinToString("\n")) }
return
}
@@ -305,13 +307,19 @@ class AppViewModel(context: Context, private val workManager: WorkManager) : Vie
if (announce) {
val added = (mutableState.value.titles.map { it.key }.toSet() - before).size
mutableState.update { it.copy(message = if (added == 1) "1 title added" else "$added titles added") }
} else {
val files = mutableState.value.shares.filter { it.id in ids }.sumOf { it.crawlAdded ?: 0uL }
if (files > 0uL) {
mutableState.update { it.copy(message = if (files == 1uL) "1 new file" else "$files new files") }
}
}
}
/**
* Crawl shares the catalog has nothing of: brought by a sync that ran in
* [io.narl.protonstream.sync.WatchSyncWorker], or an add whose crawl never
* finished.
* Crawl shares due a look: ones the catalog has nothing of — brought by a
* sync that ran in [io.narl.protonstream.sync.WatchSyncWorker], or an add
* whose crawl never finished — and ones not crawled for six hours, so new
* episodes turn up without a pull to refresh.
*/
fun catchUp() {
if (catchingUp) return
@@ -30,6 +30,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.window.DialogProperties
@@ -167,6 +168,25 @@ internal fun SharesScreen(
* Three differently styled controls beside the name squeezed it into a column
* a word wide; one icon leaves the row its width.
*/
/** "120 files · crawled 2 h ago", or that it has not been yet. */
internal fun crawlLine(share: ShareRecord, now: Long = System.currentTimeMillis() / 1_000): String {
val at = share.crawledAt ?: return "Not crawled yet"
val files = share.crawlFiles?.toLong()?.let { if (it == 1L) "1 file" else "$it files" }
return listOfNotNull(files, "crawled ${ago(at, now)}").joinToString(" · ")
}
/** "just now", "5 min ago", "3 h ago", "2 days ago" — the desktop's `ui::ago`. */
internal fun ago(at: Long, now: Long): String {
val seconds = (now - at).coerceAtLeast(0)
return when {
seconds < 60 -> "just now"
seconds < 3_600 -> "${seconds / 60} min ago"
seconds < 86_400 -> "${seconds / 3_600} h ago"
seconds < 172_800 -> "1 day ago"
else -> "${seconds / 86_400} days ago"
}
}
@Composable
private fun ShareRow(
share: ShareRecord,
@@ -178,13 +198,27 @@ private fun ShareRow(
ListItem(
headlineContent = { Text(share.name, fontWeight = FontWeight.SemiBold) },
supportingContent = {
Text(
when {
share.fromAccount -> "Folder of your Drive"
share.hasCustomPassword -> "Link and custom password, stored securely"
else -> "Public link"
},
)
Column {
Text(
when {
share.fromAccount -> "Folder of your Drive"
share.hasCustomPassword -> "Link and custom password"
else -> "Public link"
},
)
Text(crawlLine(share), style = MaterialTheme.typography.bodySmall)
// Until a crawl succeeds: a link revoked upstream otherwise
// just stops growing.
share.crawlError?.let {
Text(
"Last crawl failed: $it",
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
}
}
},
leadingContent = {
Icon(
@@ -309,9 +309,17 @@ class ScreenshotTest {
},
shelves = listOf(ShelfRecord("From MAPPA", listOf("oshi-no-ko", "bleach", "akira"))),
),
// Crawled relative to the clock, so the row reads "2 h ago" on
// whatever day the test runs.
shares = listOf(
ShareRecord("anime", "anime", true),
ShareRecord("films", "films", false),
ShareRecord(
"anime",
"anime",
true,
crawledAt = System.currentTimeMillis() / 1_000 - 2 * 3_600,
crawlFiles = 120uL,
),
ShareRecord("films", "films", false, crawlError = "the link was revoked or has expired"),
),
storage = StorageUsageRecord(6_400_000_000uL, 3uL, 0uL, 1_100_000_000uL),
)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 54 KiB