Unify offline detection + offline playlist UX (NetworkStatusController) #86

Merged
bvandeusen merged 8 commits from dev into main 2026-06-05 13:27:36 -04:00
Showing only changes of commit c33ef18a50 - Show all commits
@@ -26,6 +26,19 @@ class OfflineGatedDataSource(
) : DataSource {
override fun open(dataSpec: DataSpec): Long {
gateOnHealth()
return try {
val opened = delegate.open(dataSpec)
health.reportSuccess() // bytes flowing from the server == reachable
opened
} catch (e: IOException) {
health.reportFailure() // real network read failed → arbitrate via /healthz
throw e
}
}
/** Fast-fail before touching the network when the server can't be reached. */
private fun gateOnHealth() {
when (health.state.value) {
ServerHealth.Offline -> throw OfflineException(
"Track not in the on-device cache and the device is offline.",
@@ -36,14 +49,6 @@ class OfflineGatedDataSource(
// Unstable is non-gating: still try the network. Healthy too.
ServerHealth.Unstable, ServerHealth.Healthy -> Unit
}
return try {
val opened = delegate.open(dataSpec)
health.reportSuccess() // bytes flowing from the server == reachable
opened
} catch (e: IOException) {
health.reportFailure() // real network read failed → arbitrate via /healthz
throw e
}
}
override fun close() = delegate.close()