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.
Keep history across restarts; add Restore everything
jesse-agent-232d77e819de496
diff --git a/app/src/main/java/app/tellyscope/MainActivity.kt b/app/src/main/java/app/tellyscope/MainActivity.ktindex 5018cc5..2c869d2 100644--- a/app/src/main/java/app/tellyscope/MainActivity.kt+++ b/app/src/main/java/app/tellyscope/MainActivity.kt@@ -112,7 +112,7 @@ class MainActivity : ComponentActivity() {fun TellyscopeApp(vm: TellyscopeViewModel) {val state by vm.state.collectAsStateWithLifecycle()val done by vm.done.collectAsStateWithLifecycle()- val error by vm.error.collectAsStateWithLifecycle()+ val notice by vm.notice.collectAsStateWithLifecycle()val snackbar = remember { SnackbarHostState() }var adding by rememberSaveable { mutableStateOf(false) }@@ -127,9 +127,9 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {if (result == SnackbarResult.ActionPerformed) vm.undo(entry)}- LaunchedEffect(error) {- val message = error ?: return@LaunchedEffect- vm.errorShown()+ LaunchedEffect(notice) {+ val message = notice ?: return@LaunchedEffect+ vm.noticeShown()snackbar.showSnackbar(message, duration = SnackbarDuration.Long)}@@ -163,6 +163,7 @@ fun TellyscopeApp(vm: TellyscopeViewModel) {undo = vm::undo,reconnect = { state.selectedId?.let(vm::reconnect) },forget = vm::forget,+ restoreAll = vm::restoreAll,),)}diff --git a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.ktindex a1851d0..899f831 100644--- a/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/AdbDeviceSource.kt@@ -51,7 +51,7 @@ class AdbDeviceSource(context: Context) : DeviceSource {private val watchers = ConcurrentHashMap<String, Job>()/** Wireless debugging advertises pairing and connect on different ports. */private val pairingPorts = ConcurrentHashMap<String, Int>()- private var historyId = 0L+ private val book = HistoryBook(File(appContext.filesDir, "history.tsv"))init {Connector.init(File(appContext.filesDir, "adbkey.pem"))@@ -247,24 +247,37 @@ class AdbDeviceSource(context: Context) : DeviceSource {)}- override suspend fun act(deviceId: String, action: Action, packageName: String): HistoryEntry {- val r = Actions(session(deviceId)).run(AdbAction.valueOf(action.name.uppercase()), packageName)+ override suspend fun act(deviceId: String, action: Action, packageName: String, undoing: Long?): HistoryEntry {+ val shell = session(deviceId)+ // Before the first change on a TV, note what was already off: Restore must leave those alone.+ if (!book.hasBaseline(deviceId)) book.setBaseline(deviceId, disabledPackages(deviceId))+ val r = Actions(shell).run(AdbAction.valueOf(action.name.uppercase()), packageName)return when (r) {- is ActionResult.Done -> HistoryEntry(- id = ++historyId,+ is ActionResult.Done -> book.record(deviceId = deviceId,at = System.currentTimeMillis(),action = action,packageName = packageName,label = humanise(packageName),undo = r.undo?.let { Action.valueOf(it.name.lowercase().replaceFirstChar(Char::uppercase)) },- undoneAt = null,+ undoing = undoing,)is ActionResult.Refused -> throw IllegalStateException(reasonText(r.reason))is ActionResult.Failed -> throw IllegalStateException(r.output.ifEmpty { "the TV refused" })}}+ override suspend fun history(deviceId: String): List<HistoryEntry> = book.entries(deviceId)++ override suspend fun restoreAll(deviceId: String): List<HistoryEntry> {+ // Only what is still off now: the user may have turned some back on from the TV itself.+ val off = disabledPackages(deviceId)+ return book.restorable(deviceId).filter { it in off }.map { act(deviceId, Action.Enable, it) }+ }++ private suspend fun disabledPackages(deviceId: String) =+ Parsers.packages(session(deviceId).shell("pm list packages -d").output).map { it.name }.toSet()+private fun session(deviceId: String) =links[deviceId]?.session ?: throw IllegalStateException("$deviceId is offline")diff --git a/app/src/main/java/app/tellyscope/data/DeviceSource.kt b/app/src/main/java/app/tellyscope/data/DeviceSource.ktindex 9a13817..dab7099 100644--- a/app/src/main/java/app/tellyscope/data/DeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/DeviceSource.kt@@ -36,6 +36,15 @@ interface DeviceSource {suspend fun network(deviceId: String): NetworkInfo- /** Runs an action. Never uninstalls: there is no uninstall in [Action] on purpose. */- suspend fun act(deviceId: String, action: Action, packageName: String): HistoryEntry+ /**+ * Runs an action and records it. Never uninstalls: there is no uninstall in [Action] on+ * purpose. [undoing] is the history entry this reverses, which gets marked undone.+ */+ suspend fun act(deviceId: String, action: Action, packageName: String, undoing: Long? = null): HistoryEntry++ /** Everything Tellyscope changed on this TV, newest first. Survives app restarts. */+ suspend fun history(deviceId: String): List<HistoryEntry>++ /** Turns back on every app Tellyscope disabled, and nothing that was off before. */+ suspend fun restoreAll(deviceId: String): List<HistoryEntry>}diff --git a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.ktindex 76695da..e8658e7 100644--- a/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt+++ b/app/src/main/java/app/tellyscope/data/FakeDeviceSource.kt@@ -41,7 +41,7 @@ class FakeDeviceSource()private val apps = mutableMapOf<String, MutableList<AppInfo>>()- private var nextHistoryId = 1L+ private val book = HistoryBook()override fun scan(): Flow<ScanEvent> = flow {val subnet = "192.168.1.0/24"@@ -162,9 +162,10 @@ class FakeDeviceSource(),)- override suspend fun act(deviceId: String, action: Action, packageName: String): HistoryEntry {+ override suspend fun act(deviceId: String, action: Action, packageName: String, undoing: Long?): HistoryEntry {delay(400)val list = appsFor(deviceId)+ if (!book.hasBaseline(deviceId)) book.setBaseline(deviceId, list.filter { !it.enabled }.map { it.packageName }.toSet())val i = list.indexOfFirst { it.packageName == packageName }val app = list[i]when (action) {@@ -178,7 +179,14 @@ class FakeDeviceSource(Action.Enable -> Action.DisableAction.Open -> null}- return HistoryEntry(nextHistoryId++, deviceId, clock(), action, packageName, app.label, undo, null)+ return book.record(deviceId, clock(), action, packageName, app.label, undo, undoing)+ }++ override suspend fun history(deviceId: String): List<HistoryEntry> = book.entries(deviceId)++ override suspend fun restoreAll(deviceId: String): List<HistoryEntry> {+ val off = appsFor(deviceId).filter { !it.enabled }.map { it.packageName }.toSet()+ return book.restorable(deviceId).filter { it in off }.map { act(deviceId, Action.Enable, it) }}private companion object {diff --git a/app/src/main/java/app/tellyscope/data/HistoryBook.kt b/app/src/main/java/app/tellyscope/data/HistoryBook.ktnew file mode 100644index 0000000..3894e80--- /dev/null+++ b/app/src/main/java/app/tellyscope/data/HistoryBook.kt@@ -0,0 +1,119 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope.data++import java.io.File++/**+ * Every change Tellyscope made, per TV, plus the TV's disabled-apps list from before the first+ * one. Kept in a tab-separated file so undo and "Restore everything" survive an app restart;+ * with no file (screenshots, the fake source) it lives in memory only.+ */+class HistoryBook(private val file: File? = null) {+ private val entries = mutableListOf<HistoryEntry>()+ private val baselines = mutableMapOf<String, Set<String>>()++ init {+ file?.takeIf { it.exists() }?.readLines()?.forEach(::parse)+ }++ /** Newest first. */+ @Synchronized+ fun entries(deviceId: String): List<HistoryEntry> = entries.filter { it.deviceId == deviceId }.sortedByDescending { it.id }++ @Synchronized+ fun hasBaseline(deviceId: String) = deviceId in baselines++ /** What was already disabled before Tellyscope changed anything; written once per TV. */+ @Synchronized+ fun setBaseline(deviceId: String, disabled: Set<String>) {+ if (deviceId in baselines) return+ baselines[deviceId] = disabled+ save()+ }++ @Synchronized+ fun record(+ deviceId: String,+ at: Long,+ action: Action,+ packageName: String,+ label: String,+ undo: Action?,+ undoing: Long? = null,+ ): HistoryEntry {+ if (undoing != null) {+ val i = entries.indexOfFirst { it.id == undoing }+ if (i >= 0) entries[i] = entries[i].copy(undoneAt = at)+ }+ val entry = HistoryEntry((entries.maxOfOrNull { it.id } ?: 0) + 1, deviceId, at, action, packageName, label, undo, null)+ entries += entry+ save()+ return entry+ }++ /**+ * Apps Tellyscope left disabled on this TV: the last disable/enable it ran was a disable, and+ * the app wasn't already off before Tellyscope's first change. Restore turns on only these.+ */+ @Synchronized+ fun restorable(deviceId: String): List<String> {+ val before = baselines[deviceId].orEmpty()+ return leftDisabled(entries.filter { it.deviceId == deviceId }).filter { it !in before }+ }++ companion object {+ /** Packages whose last disable/enable in [history] was a disable. */+ fun leftDisabled(history: List<HistoryEntry>): List<String> =+ history.filter { it.action == Action.Disable || it.action == Action.Enable }+ .sortedBy { it.id }+ .associate { it.packageName to it.action }+ .filterValues { it == Action.Disable }+ .keys.sorted()+ }++ private fun save() {+ val f = file ?: return+ f.parentFile?.mkdirs()+ val lines = baselines.map { (id, pkgs) -> listOf(VERSION, "b", id, pkgs.sorted().joinToString(",")) } ++ entries.map { e ->+ listOf(+ VERSION, "e", e.deviceId, e.id.toString(), e.at.toString(), e.action.name, e.packageName,+ clean(e.label), e.undo?.name.orEmpty(), e.undoneAt?.toString().orEmpty(),+ )+ }+ val tmp = File(f.path + ".tmp")+ tmp.writeText(lines.joinToString("") { it.joinToString("\t") + "\n" })+ if (!tmp.renameTo(f)) {+ f.delete()+ tmp.renameTo(f)+ }+ }++ /** A damaged line costs that line only. */+ private fun parse(line: String) {+ val f = line.split('\t')+ if (f.size < 4 || f[0] != VERSION) return+ when (f[1]) {+ "b" -> baselines[f[2]] = f[3].split(',').filter { it.isNotEmpty() }.toSet()+ "e" -> if (f.size == 10) {+ entries += HistoryEntry(+ id = f[3].toLongOrNull() ?: return,+ deviceId = f[2],+ at = f[4].toLongOrNull() ?: return,+ action = action(f[5]) ?: return,+ packageName = f[6],+ label = f[7],+ undo = action(f[8]),+ undoneAt = f[9].toLongOrNull(),+ )+ }+ }+ }++ private fun action(s: String) = Action.entries.firstOrNull { it.name == s }++ private fun clean(s: String) = s.replace(Regex("[\\t\\r\\n]"), " ")+}++private const val VERSION = "v1"diff --git a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt b/app/src/main/java/app/tellyscope/ui/DeviceScreen.ktindex 9ad55f7..919fdc8 100644--- a/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt+++ b/app/src/main/java/app/tellyscope/ui/DeviceScreen.kt@@ -71,6 +71,7 @@ import app.tellyscope.data.Actionimport app.tellyscope.data.AppInfoimport app.tellyscope.data.Deviceimport app.tellyscope.data.DeviceState+import app.tellyscope.data.HistoryBookimport app.tellyscope.data.HistoryEntryimport app.tellyscope.data.NetworkInfoimport app.tellyscope.data.Proc@@ -89,6 +90,7 @@ data class DeviceActions(val undo: (HistoryEntry) -> Unit = {},val reconnect: () -> Unit = {},val forget: (String) -> Unit = {},+ val restoreAll: () -> Unit = {},)@OptIn(ExperimentalMaterial3Api::class)@@ -184,7 +186,7 @@ fun DeviceScreen(ui.network?.let { NetworkBlock(it, q) }}section("history", "History", ui.history.size) {- HistoryList(ui.history, state.now, actions.undo)+ HistoryList(ui.history, state.now, actions.undo, restoring = ui.busy == RESTORING, onRestoreAll = actions.restoreAll)}}}@@ -243,6 +245,23 @@ private fun DevicePicker(state: UiState, actions: DeviceActions) {}}+/** Restore only touches what Tellyscope turned off; the dialog says so before anything runs. */+@Composable+fun RestoreDialog(count: Int, onRestore: () -> Unit, onDismiss: () -> Unit) {+ AlertDialog(+ onDismissRequest = onDismiss,+ title = { Text("Turn $count ${if (count == 1) "app" else "apps"} back on?") },+ text = {+ Text(+ "Turns back on every app Tellyscope disabled on this TV. " ++ "Apps that were already off before Tellyscope's first change stay off.",+ )+ },+ confirmButton = { Button(onClick = onRestore) { Text("Turn back on") } },+ dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },+ )+}+private fun name(d: Device) = d.hit.hostname ?: d.model ?: d.hit.ip/** Forgetting only touches this phone; the TV keeps its own list of allowed computers. */@@ -552,7 +571,21 @@ private fun KeyValue(k: String, v: String) {}@Composable-private fun HistoryList(history: List<HistoryEntry>, now: Long, onUndo: (HistoryEntry) -> Unit) {+private fun HistoryList(+ history: List<HistoryEntry>,+ now: Long,+ onUndo: (HistoryEntry) -> Unit,+ restoring: Boolean = false,+ onRestoreAll: () -> Unit = {},+) {+ var confirming by rememberSaveable { mutableStateOf(false) }+ val off = HistoryBook.leftDisabled(history).size+ if (confirming) RestoreDialog(off, onRestore = { confirming = false; onRestoreAll() }, onDismiss = { confirming = false })+ if (off > 0) {+ OutlinedButton(onClick = { confirming = true }, enabled = !restoring) {+ Text(if (restoring) "Turning apps back on…" else "Restore everything ($off)")+ }+ }if (history.isEmpty()) {Text("Nothing changed yet. Anything you stop, disable or turn on shows up here, with a way to undo it.",diff --git a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.ktindex 4fc8dd8..847a0a9 100644--- a/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt+++ b/app/src/main/java/app/tellyscope/ui/TellyscopeViewModel.kt@@ -65,6 +65,9 @@ data class UiState(val selected: Device? get() = devices.firstOrNull { it.id == selectedId }}+/** [DeviceUi.busy] value while "Restore everything" runs. */+const val RESTORING = "restore"+class TellyscopeViewModel(private val source: DeviceSource,private val allowTimeoutMs: Long = 60_000,@@ -78,9 +81,9 @@ class TellyscopeViewModel(private val _done = MutableStateFlow<HistoryEntry?>(null)val done: StateFlow<HistoryEntry?> = _done.asStateFlow()- /** One-shot failures for the snackbar: the TV refused, or went away mid-action. */- private val _error = MutableStateFlow<String?>(null)- val error: StateFlow<String?> = _error.asStateFlow()+ /** One-shot snackbar lines: the TV refused, went away mid-action, or a restore finished. */+ private val _notice = MutableStateFlow<String?>(null)+ val notice: StateFlow<String?> = _notice.asStateFlow()private var scanJob: Job? = nullprivate var liveJob: Job? = null@@ -194,6 +197,11 @@ class TellyscopeViewModel(mediumJob?.cancel()_state.update { it.copy(selectedId = id, device = DeviceUi(), query = "") }val device = _state.value.selected ?: return+ // History lives on the phone, so it shows (and undo is offered) even while the TV is off.+ viewModelScope.launch {+ val history = source.history(device.id)+ _state.update { if (it.selectedId == device.id) it.copy(device = it.device.copy(history = history)) else it }+ }if (device.state != DeviceState.Online) returnliveJob = viewModelScope.launch {source.live(id!!).collect { snap -> _state.update { it.copy(device = it.device.copy(snapshot = snap)) } }@@ -269,19 +277,17 @@ class TellyscopeViewModel(viewModelScope.launch {// The source throws with the user-facing reason when the TV refuses.val (entry, apps) = try {- source.act(id, action, pkg) to source.apps(id)+ source.act(id, action, pkg, undoing) to source.apps(id)} catch (e: CancellationException) {throw e} catch (e: Exception) {// Anything else (a dropped socket) still must not crash the app._state.update { it.copy(device = it.device.copy(busy = null)) }- _error.value = e.message?.replaceFirstChar(Char::uppercase) ?: "That didn't work."+ _notice.value = e.message?.replaceFirstChar(Char::uppercase) ?: "That didn't work."return@launch}- _state.update { s ->- val history = s.device.history.map { if (it.id == undoing) it.copy(undoneAt = entry.at) else it }- s.copy(device = s.device.copy(apps = apps, busy = null, history = listOf(entry) + history))- }+ val history = source.history(id)+ _state.update { s -> s.copy(device = s.device.copy(apps = apps, busy = null, history = history)) }if (undoing == null) _done.value = entry}}@@ -290,8 +296,29 @@ class TellyscopeViewModel(_done.value = null}- fun errorShown() {- _error.value = null+ fun noticeShown() {+ _notice.value = null+ }++ /** Turns back on everything Tellyscope disabled on the selected TV. */+ fun restoreAll() {+ val id = _state.value.selectedId ?: return+ _state.update { it.copy(device = it.device.copy(busy = RESTORING)) }+ viewModelScope.launch {+ _notice.value = try {+ val n = source.restoreAll(id).size+ if (n == 0) "Nothing to turn back on." else "Turned $n ${if (n == 1) "app" else "apps"} back on."+ } catch (e: CancellationException) {+ throw e+ } catch (e: Exception) {+ e.message?.replaceFirstChar(Char::uppercase) ?: "That didn't work."+ }+ val apps = runCatching { source.apps(id) }.getOrNull()+ val history = source.history(id)+ _state.update { s ->+ s.copy(device = s.device.copy(apps = apps ?: s.device.apps, busy = null, history = history))+ }+ }}private fun setRow(ip: String, row: RowState) =diff --git a/app/src/test/java/app/tellyscope/HistoryBookTest.kt b/app/src/test/java/app/tellyscope/HistoryBookTest.ktnew file mode 100644index 0000000..b5a3a0e--- /dev/null+++ b/app/src/test/java/app/tellyscope/HistoryBookTest.kt@@ -0,0 +1,89 @@+// SPDX-License-Identifier: GPL-3.0-only++package app.tellyscope++import app.tellyscope.data.Action+import app.tellyscope.data.FakeDeviceSource+import app.tellyscope.data.HistoryBook+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++class HistoryBookTest {+ @get:Rule val tmp = TemporaryFolder()++ private val tv = "tv-1"++ @Test fun historyAndUndoSurviveARestart() {+ val file = tmp.root.resolve("history.tsv")+ val before = HistoryBook(file)+ before.setBaseline(tv, setOf("com.old.off"))+ val disabled = before.record(tv, 1_000, Action.Disable, "com.netflix.ninja", "Netflix", undo = Action.Enable)++ // Next launch: same file, new book. The entry is there and can still be undone.+ val after = HistoryBook(file)+ assertEquals(listOf(disabled), after.entries(tv))+ assertTrue(after.hasBaseline(tv))+ after.record(tv, 2_000, Action.Enable, "com.netflix.ninja", "Netflix", undo = Action.Disable, undoing = disabled.id)++ val again = HistoryBook(file).entries(tv)+ assertEquals(2, again.size)+ assertEquals(2_000L, again.single { it.id == disabled.id }.undoneAt)+ assertNull(again.first().undoneAt)+ assertTrue(again.first().id > disabled.id)+ }++ @Test fun baselineIsWrittenOnlyOnce() {+ val book = HistoryBook(tmp.root.resolve("history.tsv"))+ book.setBaseline(tv, setOf("com.old.off"))+ book.setBaseline(tv, emptySet())+ book.record(tv, 1, Action.Disable, "com.old.off", "Old", Action.Enable)+ assertEquals(emptyList<String>(), book.restorable(tv))+ }++ @Test fun restoreSkipsWhatWasOffBeforeAndWhatWasTurnedBackOn() {+ val book = HistoryBook()+ book.setBaseline(tv, setOf("com.old.off"))+ book.record(tv, 1, Action.Disable, "com.netflix.ninja", "Netflix", Action.Enable)+ book.record(tv, 2, Action.Disable, "org.jellyfin.androidtv", "Jellyfin", Action.Enable)+ book.record(tv, 3, Action.Enable, "org.jellyfin.androidtv", "Jellyfin", Action.Disable)+ book.record(tv, 4, Action.Disable, "com.old.off", "Old", Action.Enable)+ book.record(tv, 5, Action.Stop, "com.google.android.youtube.tv", "YouTube", Action.Open)+ book.record("other-tv", 6, Action.Disable, "com.xgimi.ota", "XGIMI Updates", Action.Enable)+ assertEquals(listOf("com.netflix.ninja"), book.restorable(tv))+ }++ @Test fun damagedLinesCostOnlyThemselves() {+ val file = tmp.root.resolve("history.tsv")+ HistoryBook(file).record(tv, 1, Action.Disable, "com.netflix.ninja", "Net\tflix", Action.Enable)+ file.appendText("v1\te\ttv-1\tnot-a-number\n")+ file.appendText("v2\te\ttv-1\t9\t9\tDisable\tx\tx\t\t\n")+ val entries = HistoryBook(file).entries(tv)+ assertEquals(1, entries.size)+ assertEquals("Net flix", entries.single().label)+ }++ @Test fun restoreAllTurnsOnOnlyWhatTellyscopeDisabled() = runTest {+ // The fake TV starts with TV Recommendations already disabled.+ val source = FakeDeviceSource()+ val id = "tv"+ source.act(id, Action.Disable, "com.netflix.ninja")+ source.act(id, Action.Disable, "org.jellyfin.androidtv")+ source.act(id, Action.Enable, "com.google.android.tvrecommendations")+ source.act(id, Action.Disable, "com.google.android.tvrecommendations")++ val restored = source.restoreAll(id)++ assertEquals(setOf("com.netflix.ninja", "org.jellyfin.androidtv"), restored.map { it.packageName }.toSet())+ val apps = source.apps(id).associateBy { it.packageName }+ assertTrue(apps.getValue("com.netflix.ninja").enabled)+ assertTrue(apps.getValue("org.jellyfin.androidtv").enabled)+ assertFalse(apps.getValue("com.google.android.tvrecommendations").enabled)+ assertEquals(emptyList<String>(), source.restoreAll(id).map { it.packageName })+ }+}diff --git a/app/src/test/java/app/tellyscope/ScreenshotTest.kt b/app/src/test/java/app/tellyscope/ScreenshotTest.ktindex 7a900d1..1f58a69 100644--- a/app/src/test/java/app/tellyscope/ScreenshotTest.kt+++ b/app/src/test/java/app/tellyscope/ScreenshotTest.kt@@ -4,7 +4,10 @@ package app.tellyscopeimport androidx.compose.runtime.Composableimport androidx.compose.ui.test.junit4.v2.createComposeRule+import androidx.compose.ui.test.onNodeWithTextimport androidx.compose.ui.test.onRoot+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performScrollToimport app.tellyscope.data.Actionimport app.tellyscope.data.Deviceimport app.tellyscope.data.DeviceState@@ -17,6 +20,7 @@ import app.tellyscope.ui.DeviceActionsimport app.tellyscope.ui.DeviceScreenimport app.tellyscope.ui.DeviceUiimport app.tellyscope.ui.ForgetDialog+import app.tellyscope.ui.RestoreDialogimport app.tellyscope.ui.PermissionScreenimport app.tellyscope.ui.RowStateimport app.tellyscope.ui.ScanScreen@@ -53,12 +57,14 @@ class ScreenshotTest {private val chromecast = ScanHit("192.168.1.57", 37211, ScanKind.Wireless, "chromecast", "Google")private val unknown = ScanHit("192.168.1.88", 5555, ScanKind.Classic, null, null)- private fun shot(name: String, dark: Boolean = false, content: @Composable () -> Unit) {+ private fun shot(name: String, dark: Boolean = false, before: () -> Unit = {}, content: @Composable () -> Unit) {// Expressive indicators animate forever, so the clock never idles on its own:// drive it by hand and capture a fixed frame.compose.mainClock.autoAdvance = falsecompose.setContent { TellyscopeTheme(dark = dark, dynamic = false) { content() } }compose.mainClock.advanceTimeBy(1_000)+ before()+ compose.mainClock.advanceTimeBy(1_000)compose.onRoot().captureRoboImage("build/outputs/roborazzi/${name}${if (dark) "_dark" else ""}.png")}@@ -134,7 +140,12 @@ class ScreenshotTest {HistoryEntry(2, xgimi.ip, now - 40_000, Action.Disable, "com.xgimi.ota", "XGIMI Updates", Action.Enable, null),HistoryEntry(1, xgimi.ip, now - 5 * 60_000, Action.Stop, "com.netflix.ninja", "Netflix", Action.Open, now - 4 * 60_000),)- shot("07_device_history") { DeviceScreen(deviceState { copy(history = history) }, DeviceActions()) }+ val openHistory = {+ compose.onNodeWithText("Apps").performClick() // fold the long list away+ compose.onNodeWithText("History").performScrollTo().performClick()+ Unit+ }+ shot("07_device_history", before = openHistory) { DeviceScreen(deviceState { copy(history = history) }, DeviceActions()) }}@Test fun permission() = shot("08_permission") { PermissionScreen(denied = false, canAsk = true, {}, {}) }@@ -155,4 +166,6 @@ class ScreenshotTest {DeviceScreen(base.copy(devices = base.devices.dropLast(1) + off, selectedId = off.id, device = DeviceUi()), DeviceActions())}}++ @Test fun restore() = shot("11_restore") { RestoreDialog(2, {}, {}) }}