Skip to content

Debloat your Android TV, install apps, browse and transfer files on it, all from your phone. Just 3 MB, no tracking, no root, no PC.

Tell users when a new release is out

jesse-agent-36228676ef074b9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a60c9d..615fd05 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ until this file has a section for its version.
- **New:** Allow or deny another device's connection request from your phone. [#36](../../pull/36)
- **New:** Make another launcher, like Projectivy, your home screen; Undo restores yours. [#37](../../pull/37)
- **New:** Use your own fork of the debloat lists, set in Settings. [#40](../../pull/40)
+- **New:** Hear when a new version is out; turn it off in Settings. [#43](../../pull/43)
## 0.1.0 — 2026-10-23
diff --git a/README.md b/README.md
index 61dd316..e67e126 100644
--- a/README.md
+++ b/README.md
@@ -66,7 +66,7 @@ Tellyscope needs a phone on Android 8.0 or newer, on the same Wi-Fi as the TV, a
## Is it safe?
-- **Small and private.** Under 3 MB. No ads, no tracking, no accounts. Its only internet request fetches the debloat lists from this project's GitHub, or from your own fork if you point it there; everything else stays on your Wi-Fi. Turning on Private DNS changes where the *TV* looks up addresses, not what the app sends.
+- **Small and private.** Under 3 MB. No ads, no tracking, no accounts. It makes two internet requests: one fetches the debloat lists from this project's GitHub, or from your own fork if you point it there; the other asks GitHub once a day whether a newer version is out, and you can turn it off in Settings. Everything else stays on your Wi-Fi. Turning on Private DNS changes where the *TV* looks up addresses, not what the app sends.
- **Reversible.** Apps that came with the TV are only ever disabled, never uninstalled, so nothing is deleted. Apps you installed yourself can also be uninstalled, after a confirm that says it can't be undone. Every change goes into History, all but Uninstall with an Undo, and **Restore everything** turns back on all it turned off.
- **Protected list.** Apps the TV needs to start, update, stay on Wi-Fi, show its home screen or take input can't be stopped or disabled. They sit in their own **Can't be changed** section under Apps. There is no override.
- **You see it first.** Debloat shows every app it will turn off, and the confirm names each one before anything runs.
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.kt
index d8a8dd0..e3b4b6d 100644
--- a/app/src/main/java/app/tellyscope/MainActivity.kt
+++ b/app/src/main/java/app/tellyscope/MainActivity.kt
@@ -24,6 +24,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
+import androidx.compose.ui.platform.LocalUriHandler
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
@@ -34,6 +35,7 @@ import androidx.lifecycle.viewmodel.viewModelFactory
import app.tellyscope.data.AdbDeviceSource
import app.tellyscope.data.AndroidPhoneStorage
import app.tellyscope.data.FakeDeviceSource
+import app.tellyscope.data.UpdateCheck
import app.tellyscope.ui.AdvancedScreen
import app.tellyscope.ui.Copy
import app.tellyscope.ui.DebloatScreen
@@ -46,9 +48,11 @@ import app.tellyscope.ui.RemoteScreen
import app.tellyscope.ui.ScanScreen
import app.tellyscope.ui.SettingsScreen
import app.tellyscope.ui.TellyscopeViewModel
+import app.tellyscope.ui.UpdateDialog
import app.tellyscope.ui.theme.TellyscopeTheme
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filterNotNull
+import java.io.File
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -71,6 +75,7 @@ class MainActivity : ComponentActivity() {
TellyscopeViewModel(
scenario?.let(::FakeDeviceSource) ?: AdbDeviceSource(applicationContext),
AndroidPhoneStorage(applicationContext),
+ updates = if (scenario != null) null else updateCheck(),
)
}
},
@@ -81,6 +86,13 @@ class MainActivity : ComponentActivity() {
}
}
+ private fun updateCheck(): UpdateCheck {
+ @Suppress("DEPRECATION") // the flags overload is API 33+
+ val version = packageManager.getPackageInfo(packageName, 0).versionName.orEmpty()
+ // Alpha builds install as app.tellyscope.alpha (app/build.gradle.kts).
+ return UpdateCheck(File(filesDir, "updates.properties"), version, alpha = packageName.endsWith(".alpha"))
+ }
+
/**
* Android 17 blocks LAN connections and mDNS for apps targeting 37 until the user grants
* ACCESS_LOCAL_NETWORK, so nothing scans until then. The view model is created inside
@@ -123,6 +135,7 @@ class MainActivity : ComponentActivity() {
@Composable
fun TellyscopeApp(vm: TellyscopeViewModel) {
val state by vm.state.collectAsStateWithLifecycle()
+ val browser = LocalUriHandler.current
val snackbar = remember { SnackbarHostState() }
var adding by rememberSaveable { mutableStateOf(false) }
var remote by rememberSaveable { mutableStateOf(false) }
@@ -136,6 +149,10 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
val saveFile = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("application/octet-stream"), vm::saveTo)
val saveScreenshot = rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("image/png"), vm::screenshotTo)
+ state.update?.let { u ->
+ UpdateDialog(u, onGet = { vm.updateLater(); runCatching { browser.openUri(u.url) } }, onLater = vm::updateLater, onSkip = vm::skipUpdate)
+ }
+
Snackbars(snackbar, vm.done, vm.notice, vm::doneShown, vm::noticeShown) { vm.undo(it.entry, it.deviceId) }
// A newly connected TV becomes the selection; leave the add flow then, not on tap.
@@ -170,7 +187,14 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {
AdvancedScreen(state, back = { advanced = false }, snackbar = snackbar)
} else if (settings) {
BackHandler { settings = false }
- SettingsScreen(state.listSource, onListSource = vm::setListSource, back = { settings = false }, snackbar = snackbar)
+ SettingsScreen(
+ state.listSource,
+ onListSource = vm::setListSource,
+ checkUpdates = state.checkUpdates,
+ onCheckUpdates = vm::setCheckUpdates,
+ back = { settings = false },
+ snackbar = snackbar,
+ )
} else if (debloat) {
// Its own back handler steps back from the review to the model before leaving.
DebloatScreen(
diff --git a/app/src/main/java/app/tellyscope/data/DeviceLists.kt b/app/src/main/java/app/tellyscope/data/DeviceLists.kt
index 7cb0e43..24d2926 100644
--- a/app/src/main/java/app/tellyscope/data/DeviceLists.kt
+++ b/app/src/main/java/app/tellyscope/data/DeviceLists.kt
@@ -295,7 +295,7 @@ fun sourceName(base: String): String {
private const val MAX_BYTES = 2 shl 20 // 2 MiB; the index is ~60 KB
/** Plain GET with short timeouts, so a slow network falls back to the cache rather than hanging. */
-private suspend fun download(url: String): ByteArray = withContext(Dispatchers.IO) {
+internal suspend fun download(url: String): ByteArray = withContext(Dispatchers.IO) {
val c = URL(url).openConnection() as HttpURLConnection
c.connectTimeout = 10_000
c.readTimeout = 10_000
diff --git a/app/src/main/java/app/tellyscope/data/UpdateCheck.kt b/app/src/main/java/app/tellyscope/data/UpdateCheck.kt
new file mode 100644
index 0000000..c69cdc0
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/data/UpdateCheck.kt
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.data
+
+import kotlinx.coroutines.CancellationException
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import org.json.JSONArray
+import java.io.File
+import java.util.Properties
+
+/** Where releases are published: the app's own GitHub repo. */
+const val RELEASES = "https://github.com/man15h/tellyscope/releases"
+private const val RELEASES_API = "https://api.github.com/repos/man15h/tellyscope/releases?per_page=20"
+
+private const val DAY_MS = 24 * 60 * 60 * 1000L
+
+/** A newer Tellyscope than the one running. */
+data class Update(val version: String, val notes: String, val url: String)
+
+/**
+ * Asks GitHub, at most once a day, whether a newer release is out. No auth and no download: it
+ * only reads the release list. Off switch, last check and a skipped version live in [file].
+ * Release builds look at full releases only; alpha builds at `-alpha` pre-releases too.
+ */
+class UpdateCheck(
+ private val file: File,
+ /** The running versionName, alpha suffix included. */
+ private val current: String,
+ private val alpha: Boolean,
+ private val clock: () -> Long = System::currentTimeMillis,
+ private val fetch: suspend (String) -> ByteArray = ::download,
+) {
+ @get:Synchronized @set:Synchronized
+ var enabled: Boolean
+ get() = props().getProperty("off") != "true"
+ set(on) = save { if (on) remove("off") else setProperty("off", "true") }
+
+ @Synchronized
+ fun skip(version: String) = save { setProperty("skip", version) }
+
+ /** The newest release past [current], unless it was skipped. Null when off, checked today, or on any failure. */
+ suspend fun check(): Update? = withContext(Dispatchers.IO) {
+ val p = props()
+ if (p.getProperty("off") == "true") return@withContext null
+ val last = p.getProperty("checked")?.toLongOrNull()
+ val now = clock()
+ if (last != null && now - last in 0 until DAY_MS) return@withContext null
+ val text = try {
+ fetch(RELEASES_API).decodeToString()
+ } catch (e: CancellationException) {
+ throw e
+ } catch (_: Exception) {
+ return@withContext null
+ }
+ save { setProperty("checked", now.toString()) }
+ newest(text, alpha)?.takeIf { compareVersions(it.version, current) > 0 && it.version != p.getProperty("skip") }
+ }
+
+ private fun props() = Properties().apply {
+ runCatching { file.takeIf { it.exists() }?.inputStream()?.use(::load) }
+ }
+
+ @Synchronized
+ private fun save(change: Properties.() -> Unit) {
+ val p = props().apply(change)
+ runCatching {
+ file.parentFile?.mkdirs()
+ file.outputStream().use { p.store(it, null) }
+ }
+ }
+}
+
+/** The newest release in a GitHub release list a build may move to; null when there is none or the list won't parse. */
+fun newest(json: String, alpha: Boolean): Update? = runCatching {
+ val list = JSONArray(json)
+ (0 until list.length()).map(list::getJSONObject)
+ .filter { !it.optBoolean("draft") }
+ .mapNotNull { r ->
+ val version = r.optString("tag_name").removePrefix("v")
+ val parsed = parseVersion(version) ?: return@mapNotNull null
+ // A release build never offers an alpha; an alpha build offers both.
+ if (parsed.alpha != null && !alpha) return@mapNotNull null
+ if (r.optBoolean("prerelease") && parsed.alpha == null) return@mapNotNull null
+ Update(version, r.optString("body").trim(), "$RELEASES/tag/v$version")
+ }
+ .maxWithOrNull { a, b -> compareVersions(a.version, b.version) }
+}.getOrNull()
+
+private class Version(val core: List<Int>, val alpha: Int?)
+
+/** `X.Y.Z` or `X.Y.Z-alpha.N`; anything else is not a Tellyscope version. */
+private fun parseVersion(v: String): Version? {
+ val m = Regex("""(\d+)\.(\d+)\.(\d+)(?:-alpha\.(\d+))?""").matchEntire(v) ?: return null
+ val n = m.groupValues.drop(1).map { it.toIntOrNull() }
+ if (n.take(3).any { it == null }) return null
+ return Version(n.take(3).map { it!! }, m.groups[4]?.let { it.value.toIntOrNull() ?: return null })
+}
+
+/** Like semver: `0.2.0-alpha.3` < `0.2.0` < `0.2.1-alpha.1`. An unparseable version sorts first. */
+fun compareVersions(a: String, b: String): Int {
+ val x = parseVersion(a)
+ val y = parseVersion(b)
+ if (x == null || y == null) return compareValues(x != null, y != null)
+ for (i in 0..2) x.core[i].compareTo(y.core[i]).takeIf { it != 0 }?.let { return it }
+ return when {
+ x.alpha == y.alpha -> 0
+ x.alpha == null -> 1
+ y.alpha == null -> -1
+ else -> x.alpha.compareTo(y.alpha)
+ }
+}
diff --git a/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt b/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt
index 2afeae0..28f06e0 100644
--- a/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt
+++ b/app/src/main/java/app/tellyscope/ui/SettingsScreen.kt
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.selection.toggleable
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.AlertDialog
@@ -24,6 +25,7 @@ import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
+import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
@@ -35,6 +37,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
/** App-wide choices, not tied to one TV. */
@@ -44,6 +47,9 @@ fun SettingsScreen(
/** The user's own debloat-list source; null for tellyscope-devices. */
listSource: String?,
onListSource: (String?) -> Unit,
+ /** Null hides the switch: this build doesn't check (screenshots). */
+ checkUpdates: Boolean?,
+ onCheckUpdates: (Boolean) -> Unit,
back: () -> Unit,
snackbar: SnackbarHostState = remember { SnackbarHostState() },
) {
@@ -76,6 +82,25 @@ fun SettingsScreen(
}
}
}
+ if (checkUpdates != null) item {
+ Card(colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)) {
+ Row(
+ Modifier.fillMaxWidth()
+ .toggleable(checkUpdates, role = Role.Switch, onValueChange = onCheckUpdates)
+ .padding(16.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ Column(Modifier.weight(1f)) {
+ Text("Check for updates", style = MaterialTheme.typography.titleSmall)
+ Text(
+ "Once a day, ask GitHub whether a newer Tellyscope is out. Nothing is downloaded.",
+ style = MaterialTheme.typography.bodyMedium,
+ )
+ }
+ Switch(checked = checkUpdates, onCheckedChange = null)
+ }
+ }
+ }
}
}
}
diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
index e9f25b1..0ccd060 100644
--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt
@@ -34,7 +34,10 @@ import app.tellyscope.data.Snapshot
import app.tellyscope.data.Suggestions
import app.tellyscope.data.TvSettings
import app.tellyscope.data.TvTweaks
+import app.tellyscope.data.Update
+import app.tellyscope.data.UpdateCheck
import kotlinx.coroutines.CancellationException
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
@@ -123,6 +126,10 @@ data class UiState(
val restarting: Map<String, Restart> = emptyMap(),
/** The user's own debloat-list source; null for tellyscope-devices. */
val listSource: String? = null,
+ /** The once-a-day look at GitHub for a newer release; null when this build has none (screenshots, tests). */
+ val checkUpdates: Boolean? = null,
+ /** A newer release to offer; cleared once the user answers. */
+ val update: Update? = null,
) {
val selected: Device? get() = devices.firstOrNull { it.id == selectedId }
}
@@ -151,6 +158,7 @@ class TellyscopeViewModel(
private val storage: PhoneStorage? = null,
private val allowTimeoutMs: Long = 60_000,
private val clock: () -> Long = System::currentTimeMillis,
+ private val updates: UpdateCheck? = null,
) : ViewModel() {
private val _state = MutableStateFlow(UiState(now = clock()))
@@ -196,6 +204,14 @@ class TellyscopeViewModel(
if (++tick % 3 == 0) refreshDevices()
}
}
+ updates?.let { u ->
+ viewModelScope.launch(Dispatchers.IO) {
+ _state.update { it.copy(checkUpdates = u.enabled) }
+ // Null on any failure: no offer looks the same as no newer release.
+ val found = u.check()
+ _state.update { it.copy(update = found) }
+ }
+ }
rescan()
}
@@ -764,6 +780,24 @@ class TellyscopeViewModel(
}
}
+ /** "Get it" or "Later": the offer goes away until tomorrow's check. */
+ fun updateLater() {
+ _state.update { it.copy(update = null) }
+ }
+
+ /** "Skip this version": never offered again; a later release still is. */
+ fun skipUpdate() {
+ val version = _state.value.update?.version ?: return
+ _state.update { it.copy(update = null) }
+ viewModelScope.launch(Dispatchers.IO) { updates?.skip(version) }
+ }
+
+ fun setCheckUpdates(on: Boolean) {
+ val u = updates ?: return
+ _state.update { it.copy(checkUpdates = on) }
+ viewModelScope.launch(Dispatchers.IO) { u.enabled = on }
+ }
+
/** Disables the ticked suggestions one by one, each recorded in History with its own undo. */
fun disableSuggested(packages: List<String>) {
val id = _state.value.selectedId ?: return
diff --git a/app/src/main/java/app/tellyscope/ui/UpdateDialog.kt b/app/src/main/java/app/tellyscope/ui/UpdateDialog.kt
new file mode 100644
index 0000000..550281b
--- /dev/null
+++ b/app/src/main/java/app/tellyscope/ui/UpdateDialog.kt
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope.ui
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.Button
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import app.tellyscope.data.Update
+
+/** A newer release is out. Get it opens its GitHub page; the app never downloads it itself. */
+@Composable
+fun UpdateDialog(update: Update, onGet: () -> Unit, onLater: () -> Unit, onSkip: () -> Unit) {
+ AlertDialog(
+ onDismissRequest = onLater,
+ title = { Text("Tellyscope ${update.version} is out") },
+ text = {
+ // Release notes are Markdown; shown as written rather than rendered.
+ Column(Modifier.heightIn(max = 320.dp).verticalScroll(rememberScrollState())) {
+ Text(update.notes.ifEmpty { "No release notes." }, style = MaterialTheme.typography.bodyMedium)
+ }
+ },
+ confirmButton = { Button(onClick = onGet) { Text("Get it") } },
+ dismissButton = {
+ Row {
+ TextButton(onClick = onSkip) { Text("Skip this version") }
+ TextButton(onClick = onLater) { Text("Later") }
+ }
+ },
+ )
+}
diff --git a/app/src/test/java/app/tellyscope/UpdateCheckTest.kt b/app/src/test/java/app/tellyscope/UpdateCheckTest.kt
new file mode 100644
index 0000000..81f6c0b
--- /dev/null
+++ b/app/src/test/java/app/tellyscope/UpdateCheckTest.kt
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-3.0-only
+
+package app.tellyscope
+
+import app.tellyscope.data.UpdateCheck
+import app.tellyscope.data.compareVersions
+import app.tellyscope.data.newest
+import kotlinx.coroutines.test.runTest
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertNull
+import org.junit.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import java.io.IOException
+
+/** org.json is Android's, so this runs under Robolectric. */
+@RunWith(RobolectricTestRunner::class)
+@Config(sdk = [35])
+class UpdateCheckTest {
+ @get:Rule val tmp = TemporaryFolder()
+
+ private val day = 24 * 60 * 60 * 1000L
+
+ private fun release(tag: String, pre: Boolean = tag.contains("-alpha"), notes: String = "Notes for $tag") =
+ """{"tag_name":"$tag","prerelease":$pre,"draft":false,"body":"$notes"}"""
+
+ private fun releases(vararg r: String) = "[" + r.joinToString(",") + "]"
+
+ @Test fun `alpha sorts before its release, which sorts before the next alpha`() {
+ assertTrue(compareVersions("0.2.0-alpha.3", "0.2.0") < 0)
+ assertTrue(compareVersions("0.2.0", "0.2.1-alpha.1") < 0)
+ assertTrue(compareVersions("0.2.0-alpha.3", "0.2.1-alpha.1") < 0)
+ assertTrue(compareVersions("0.2.0-alpha.2", "0.2.0-alpha.10") < 0)
+ assertTrue(compareVersions("0.10.0", "0.9.9") > 0)
+ assertEquals(0, compareVersions("0.2.0", "0.2.0"))
+ }
+
+ @Test fun `release builds see full releases only, alpha builds see alphas too`() {
+ val list = releases(release("v0.2.1-alpha.1"), release("v0.2.0"), release("v0.2.0-alpha.3"), release("v0.1.0"))
+ assertEquals("0.2.0", newest(list, alpha = false)?.version)
+ assertEquals("0.2.1-alpha.1", newest(list, alpha = true)?.version)
+ }
+
+ @Test fun `odd tags, drafts and pre-releases without an alpha tag are ignored`() {
+ val list = releases(
+ release("v9.0.0-beta"),
+ release("nightly"),
+ release("v3.0.0", pre = true),
+ """{"tag_name":"v4.0.0","prerelease":false,"draft":true,"body":""}""",
+ release("v0.2.0"),
+ )
+ assertEquals("0.2.0", newest(list, alpha = true)?.version)
+ assertNull(newest("not json", alpha = false))
+ }
+
+ @Test fun `offers a newer release with its notes and page`() = runTest {
+ val u = UpdateCheck(tmp.newFile(), "0.2.0-alpha.1", alpha = true, fetch = { releases(release("v0.2.0")).toByteArray() }).check()
+ assertEquals("0.2.0", u?.version)
+ assertEquals("Notes for v0.2.0", u?.notes)
+ assertTrue(u!!.url.endsWith("/tellyscope/releases/tag/v0.2.0"))
+ }
+
+ @Test fun `nothing when the running version is the newest`() = runTest {
+ val check = UpdateCheck(tmp.newFile(), "0.2.0", alpha = false, fetch = { releases(release("v0.2.0"), release("v0.1.0")).toByteArray() })
+ assertNull(check.check())
+ }
+
+ @Test fun `asks at most once a day`() = runTest {
+ var now = 1_000_000L
+ var calls = 0
+ val check = UpdateCheck(tmp.newFile(), "0.1.0", alpha = false, clock = { now }) { calls++; releases(release("v0.2.0")).toByteArray() }
+ assertEquals("0.2.0", check.check()?.version)
+ now += day - 1
+ assertNull(check.check())
+ assertEquals(1, calls)
+ now += 1
+ assertEquals("0.2.0", check.check()?.version)
+ assertEquals(2, calls)
+ }
+
+ @Test fun `a failed request is silent and tried again next time`() = runTest {
+ var fail = true
+ val check = UpdateCheck(tmp.newFile(), "0.1.0", alpha = false) {
+ if (fail) throw IOException("offline")
+ releases(release("v0.2.0")).toByteArray()
+ }
+ assertNull(check.check())
+ fail = false
+ assertEquals("0.2.0", check.check()?.version)
+ }
+
+ @Test fun `a skipped version stays skipped, a later one is offered`() = runTest {
+ val file = tmp.newFile()
+ var now = 0L
+ var latest = "v0.2.0"
+ val check = UpdateCheck(file, "0.1.0", alpha = false, clock = { now }) { releases(release(latest)).toByteArray() }
+ check.skip("0.2.0")
+ assertNull(check.check())
+ now += day
+ latest = "v0.2.1"
+ assertEquals("0.2.1", UpdateCheck(file, "0.1.0", alpha = false, clock = { now }) { releases(release(latest)).toByteArray() }.check()?.version)
+ }
+
+ @Test fun `on by default, and off means no request`() = runTest {
+ val file = tmp.newFile()
+ var calls = 0
+ val check = UpdateCheck(file, "0.1.0", alpha = false) { calls++; releases(release("v0.2.0")).toByteArray() }
+ assertTrue(check.enabled)
+ check.enabled = false
+ assertFalse(UpdateCheck(file, "0.1.0", alpha = false).enabled)
+ assertNull(check.check())
+ assertEquals(0, calls)
+ }
+}