From 731dc2c7b214ee2a5fac0369253dcf71ae849906 Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:27 +0530 Subject: [PATCH 1/7] Phone: keep a notifications list on the phone --- .../app/src/main/java/dev/zendr/companion/Api.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mobile/android/app/src/main/java/dev/zendr/companion/Api.kt b/mobile/android/app/src/main/java/dev/zendr/companion/Api.kt index af459fc..23933da 100644 --- a/mobile/android/app/src/main/java/dev/zendr/companion/Api.kt +++ b/mobile/android/app/src/main/java/dev/zendr/companion/Api.kt @@ -114,6 +114,16 @@ class Store(context: Context) { get() = prefs.getLong("updateCheckedAt", 0L) set(v) = prefs.edit().putLong("updateCheckedAt", v).apply() + /** The notifications list, newest first (see [Feed]). */ + var notesJson: String + get() = prefs.getString("notes", null) ?: "[]" + set(v) = prefs.edit().putString("notes", v).apply() + + /** The newest version already in the notifications list. */ + var notedVersion: String? + get() = prefs.getString("notedVersion", null) + set(v) = prefs.edit().putString("notedVersion", v).apply() + /** A version you chose to skip: no popup for it. */ var skipVersion: String? get() = prefs.getString("skipVersion", null) From f8543c7f0af01d06ece5f10f36191c7a17530f85 Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:28 +0530 Subject: [PATCH 2/7] Phone: note when an agent needs you or finishes, once, whoever sees it first --- .../src/main/java/dev/zendr/companion/Feed.kt | 124 ++++++++++++++++++ .../test/java/dev/zendr/companion/FeedTest.kt | 39 ++++++ 2 files changed, 163 insertions(+) create mode 100644 mobile/android/app/src/main/java/dev/zendr/companion/Feed.kt create mode 100644 mobile/android/app/src/test/java/dev/zendr/companion/FeedTest.kt diff --git a/mobile/android/app/src/main/java/dev/zendr/companion/Feed.kt b/mobile/android/app/src/main/java/dev/zendr/companion/Feed.kt new file mode 100644 index 0000000..9bf4815 --- /dev/null +++ b/mobile/android/app/src/main/java/dev/zendr/companion/Feed.kt @@ -0,0 +1,124 @@ +package dev.zendr.companion + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.setValue +import org.json.JSONArray +import org.json.JSONObject + +/** + * One thing that happened: an agent started needing you ("blocked"), one finished ("done"), or a + * new version of the app came out ("update"). + */ +data class Note( + val id: Long, + val at: Long, + val kind: String, + val title: String, + val text: String, + val computer: String? = null, + val terminal: String? = null, + val app: String? = null, + /** The session's own name, for opening it. */ + val session: String? = null, + val read: Boolean = false, +) { + fun toJson(): JSONObject = JSONObject() + .put("id", id).put("at", at).put("kind", kind).put("title", title).put("text", text) + .put("computer", computer).put("terminal", terminal).put("app", app).put("session", session).put("read", read) + + companion object { + fun fromJson(j: JSONObject) = Note( + id = j.optLong("id"), + at = j.optLong("at"), + kind = j.optString("kind"), + title = j.optString("title"), + text = j.optString("text"), + computer = j.optString("computer").takeIf { it.isNotEmpty() && it != "null" }, + terminal = j.optString("terminal").takeIf { it.isNotEmpty() && it != "null" }, + app = j.optString("app").takeIf { it.isNotEmpty() && it != "null" }, + session = j.optString("session").takeIf { it.isNotEmpty() && it != "null" }, + read = j.optBoolean("read"), + ) + } +} + +/** + * The notifications list: everything the app saw happen, whether it saw it in the open app or in + * Alert me's watch. Kept on the phone, newest first, the last [MOST]. + */ +object Feed { + const val MOST = 100 + + /** Bumps whenever the list changes, so the bell and the list redraw. */ + var version by mutableIntStateOf(0) + private set + + // computer id + terminal -> the status last seen, shared by the app's screens and the watch, + // so one change is noted once. + private val last = HashMap() + private val known = HashSet() + + /** What a change of status is worth noting as, if anything. */ + fun change(before: String?, now: String?): String? = when { + before == now -> null + now == "blocked" -> "blocked" + now == "done" && before == "working" -> "done" + else -> null + } + + /** Notes what changed on [c] since it was last looked at (the first look only learns). */ + @Synchronized + fun observe(store: Store, c: Computer, spaces: List) { + val first = known.add(c.id) + val now = System.currentTimeMillis() + val fresh = mutableListOf() + for (s in spaces.flatMap { it.sessions }) { + val key = "${c.id}/${s.terminal}" + val before = last[key] + last[key] = s.status + if (first) continue + when (change(before, s.status)) { + "blocked" -> fresh += Note(now + fresh.size, now, "blocked", "${s.title} needs you", "On ${c.name}", c.id, s.terminal, s.app, s.title) + "done" -> fresh += Note(now + fresh.size, now, "done", "${s.title} finished", "On ${c.name}", c.id, s.terminal, s.app, s.title) + } + } + if (fresh.isNotEmpty()) save(store, fresh + list(store)) + } + + /** A new version, noted once. */ + @Synchronized + fun noteUpdate(store: Store, r: Release) { + if (store.notedVersion == r.version) return + store.notedVersion = r.version + val now = System.currentTimeMillis() + val text = Updates.summary(r.notes).lineSequence().firstOrNull { it.isNotBlank() } ?: "Tap to see what's new." + save(store, listOf(Note(now, now, "update", "Zendr ${r.version} is out", text)) + list(store)) + } + + fun list(store: Store): List = parse(store.notesJson) + + fun unread(store: Store) = list(store).count { !it.read } + + @Synchronized + fun markRead(store: Store, id: Long? = null) = + save(store, list(store).map { if (id == null || it.id == id) it.copy(read = true) else it }) + + @Synchronized + fun remove(store: Store, id: Long) = save(store, list(store).filterNot { it.id == id }) + + @Synchronized + fun clear(store: Store) = save(store, emptyList()) + + fun parse(raw: String): List = runCatching { + val a = JSONArray(raw) + (0 until a.length()).map { Note.fromJson(a.getJSONObject(it)) } + }.getOrDefault(emptyList()) + + fun encode(notes: List): String = JSONArray(notes.take(MOST).map { it.toJson() }).toString() + + private fun save(store: Store, notes: List) { + store.notesJson = encode(notes) + version++ + } +} diff --git a/mobile/android/app/src/test/java/dev/zendr/companion/FeedTest.kt b/mobile/android/app/src/test/java/dev/zendr/companion/FeedTest.kt new file mode 100644 index 0000000..bdd3d15 --- /dev/null +++ b/mobile/android/app/src/test/java/dev/zendr/companion/FeedTest.kt @@ -0,0 +1,39 @@ +package dev.zendr.companion + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test + +class FeedTest { + @Test fun notesWhenAnAgentStartsNeedingYouOrFinishesWork() { + assertEquals("blocked", Feed.change("working", "blocked")) + assertEquals("blocked", Feed.change(null, "blocked")) + assertEquals("done", Feed.change("working", "done")) + } + + @Test fun staysQuietOtherwise() { + assertNull(Feed.change("blocked", "blocked")) + assertNull(Feed.change("idle", "done")) + assertNull(Feed.change("blocked", "working")) + assertNull(Feed.change("done", "idle")) + assertNull(Feed.change(null, null)) + } + + @Test fun keepsEachNoteThroughStorage() { + val n = Note(7, 1000, "blocked", "Codex needs you", "On TEST-PC", "c1", "t2", "codex", "Codex", read = true) + assertEquals(listOf(n), Feed.parse(Feed.encode(listOf(n)))) + val update = Note(8, 2000, "update", "Zendr 0.3.0 is out", "Steadier") + assertEquals(listOf(update), Feed.parse(Feed.encode(listOf(update)))) + } + + @Test fun keepsTheNewestHundred() { + val many = (1..150L).map { Note(it, it, "done", "n$it", "") } + val kept = Feed.parse(Feed.encode(many)) + assertEquals(Feed.MOST, kept.size) + assertEquals(1L, kept.first().id) + } + + @Test fun aBrokenListReadsAsEmpty() { + assertEquals(emptyList(), Feed.parse("not json")) + } +} From 5c20929acf5e524907b6633543e284b0425c98e5 Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:29 +0530 Subject: [PATCH 3/7] Phone: note a new version in the notifications list --- .../android/app/src/main/java/dev/zendr/companion/Updates.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mobile/android/app/src/main/java/dev/zendr/companion/Updates.kt b/mobile/android/app/src/main/java/dev/zendr/companion/Updates.kt index 9762e2c..496d0b3 100644 --- a/mobile/android/app/src/main/java/dev/zendr/companion/Updates.kt +++ b/mobile/android/app/src/main/java/dev/zendr/companion/Updates.kt @@ -129,7 +129,10 @@ object Updates { val r = fetch() store.updateCheckedAt = System.currentTimeMillis() latest = r - if (newer(r.version, installed(context)) && (manual || r.version != store.skipVersion)) offer = r + if (newer(r.version, installed(context))) { + Feed.noteUpdate(store, r) + if (manual || r.version != store.skipVersion) offer = r + } } catch (e: Exception) { error = if (e is IOException && e.message?.startsWith("GitHub") == true) e.message else "Couldn't reach GitHub. Check your internet connection." From 1e7daa4dcbf9396a5beccff9ecd177d55759a379 Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:29 +0530 Subject: [PATCH 4/7] Phone: a notifications screen and a bell with what's new --- .../zendr/companion/NotificationsScreen.kt | 249 ++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 mobile/android/app/src/main/java/dev/zendr/companion/NotificationsScreen.kt diff --git a/mobile/android/app/src/main/java/dev/zendr/companion/NotificationsScreen.kt b/mobile/android/app/src/main/java/dev/zendr/companion/NotificationsScreen.kt new file mode 100644 index 0000000..b95aaf9 --- /dev/null +++ b/mobile/android/app/src/main/java/dev/zendr/companion/NotificationsScreen.kt @@ -0,0 +1,249 @@ +package dev.zendr.companion + +import android.Manifest +import android.os.Build +import android.text.format.DateUtils +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.filled.MoreVert +import androidx.compose.material.icons.filled.Notifications +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Badge +import androidx.compose.material3.BadgedBox +import androidx.compose.material3.Button +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.material3.SwipeToDismissBox +import androidx.compose.material3.SwipeToDismissBoxValue +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.rememberSwipeToDismissBoxState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import java.util.Calendar + +/** The bell in the bar, with how many you haven't seen. */ +@Composable +fun BellButton(store: Store, onClick: () -> Unit) { + val unread = remember(Feed.version) { Feed.unread(store) } + IconButton(onClick = onClick) { + BadgedBox(badge = { if (unread > 0) Badge { Text(if (unread > 99) "99+" else "$unread") } }) { + Icon(Icons.Default.Notifications, if (unread > 0) "Notifications, $unread new" else "Notifications") + } + } +} + +/** Everything that happened: agents that needed you or finished, and new versions. */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun NotificationsScreen(store: Store, onBack: () -> Unit, onOpen: (Note) -> Unit) { + val context = LocalContext.current + val notes = remember(Feed.version) { Feed.list(store) } + var menu by remember { mutableStateOf(false) } + var confirmClear by remember { mutableStateOf(false) } + var alerts by remember { mutableStateOf(store.alerts) } + val notifyPermission = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { } + // New ones keep their dot while you look; leaving marks them all seen. + DisposableEffect(Unit) { onDispose { Feed.markRead(store) } } + + Scaffold(topBar = { + TopAppBar( + title = { Text("Notifications") }, + navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back") } }, + actions = { + if (notes.isNotEmpty()) { + IconButton(onClick = { menu = true }) { Icon(Icons.Default.MoreVert, "More") } + DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) { + DropdownMenuItem(text = { Text("Mark all as read") }, onClick = { menu = false; Feed.markRead(store) }) + DropdownMenuItem(text = { Text("Clear all") }, onClick = { menu = false; confirmClear = true }) + } + } + }, + ) + }) { pad -> + if (notes.isEmpty()) { + Column( + Modifier.fillMaxSize().padding(pad).padding(32.dp), + horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, + ) { + val green = MaterialTheme.colorScheme.primary + Box( + Modifier.size(132.dp).background(Brush.radialGradient(listOf(green.copy(alpha = 0.22f), green.copy(alpha = 0f))), CircleShape), + contentAlignment = Alignment.Center, + ) { + Box(Modifier.size(76.dp).background(MaterialTheme.colorScheme.secondaryContainer, CircleShape), contentAlignment = Alignment.Center) { + Icon(Icons.Default.Notifications, null, tint = MaterialTheme.colorScheme.onSecondaryContainer, modifier = Modifier.size(36.dp)) + } + } + Spacer(Modifier.height(18.dp)) + Text("All caught up", fontSize = 22.sp, fontWeight = FontWeight.SemiBold) + Spacer(Modifier.height(8.dp)) + Text( + "When an agent needs you or finishes, or a new Zendr is out, you'll find it here.", + textAlign = TextAlign.Center, fontSize = 15.sp, lineHeight = 21.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + if (!alerts) { + Spacer(Modifier.height(20.dp)) + Text( + "Turn on Alert me to catch them while the app is closed too.", + textAlign = TextAlign.Center, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Spacer(Modifier.height(10.dp)) + Button(onClick = { + alerts = true + store.alerts = true + if (Build.VERSION.SDK_INT >= 33) notifyPermission.launch(Manifest.permission.POST_NOTIFICATIONS) + WatchService.start(context) + }) { Text("Turn on Alert me") } + } + } + } else { + LazyColumn( + Modifier.fillMaxSize().padding(pad), + contentPadding = PaddingValues(start = 12.dp, end = 12.dp, bottom = 24.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + notes.groupBy { day(it.at) }.forEach { (label, group) -> + item(key = "day-$label") { + Text( + label, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(start = 4.dp, top = 10.dp, bottom = 2.dp), + ) + } + items(group, key = { it.id }) { n -> NoteRow(store, n, onOpen) } + } + item { + Text( + "Swipe one away to remove it.", fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth().padding(top = 12.dp), + ) + } + } + } + } + + if (confirmClear) { + AlertDialog( + onDismissRequest = { confirmClear = false }, + title = { Text("Clear all notifications?") }, + text = { Text("They're only on this phone. Your sessions aren't touched.") }, + confirmButton = { TextButton(onClick = { Feed.clear(store); confirmClear = false }) { Text("Clear") } }, + dismissButton = { TextButton(onClick = { confirmClear = false }) { Text("Cancel") } }, + ) + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +private fun NoteRow(store: Store, n: Note, onOpen: (Note) -> Unit) { + val swipe = rememberSwipeToDismissBoxState(confirmValueChange = { + if (it != SwipeToDismissBoxValue.Settled) Feed.remove(store, n.id) + it != SwipeToDismissBoxValue.Settled + }) + SwipeToDismissBox( + swipe, + backgroundContent = { + if (swipe.dismissDirection != SwipeToDismissBoxValue.Settled) Box( + Modifier.fillMaxSize().background(Red.copy(alpha = 0.16f), RoundedCornerShape(16.dp)).padding(horizontal = 20.dp), + contentAlignment = if (swipe.dismissDirection == SwipeToDismissBoxValue.EndToStart) Alignment.CenterEnd else Alignment.CenterStart, + ) { Icon(Icons.Default.Delete, "Remove", tint = Red) } + }, + ) { + val accent = when (n.kind) { + "blocked" -> Red + "done" -> Green + else -> MaterialTheme.colorScheme.primary + } + Surface( + onClick = { Feed.markRead(store, n.id); onOpen(n) }, + shape = RoundedCornerShape(16.dp), + color = MaterialTheme.colorScheme.surfaceContainer.let { if (n.read) it else accent.copy(alpha = 0.10f).compositeOver(it) }, + modifier = Modifier.fillMaxWidth(), + ) { + Row(Modifier.padding(14.dp), verticalAlignment = Alignment.CenterVertically) { + if (n.kind == "update") { + Box(Modifier.size(40.dp).background(MaterialTheme.colorScheme.secondaryContainer, RoundedCornerShape(11.dp)), contentAlignment = Alignment.Center) { + ZendrLogo(30.dp) + } + } else { + AppBadge(n.app) + } + Spacer(Modifier.width(12.dp)) + Column(Modifier.weight(1f)) { + Row(verticalAlignment = Alignment.CenterVertically) { + Text( + n.title, fontSize = 15.sp, fontWeight = if (n.read) FontWeight.Medium else FontWeight.SemiBold, + maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false), + ) + if (!n.read) { + Spacer(Modifier.width(6.dp)) + Box(Modifier.size(8.dp).background(accent, CircleShape)) + } + } + Text(n.text, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis) + } + Spacer(Modifier.width(8.dp)) + Text(ago(n.at), fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant) + } + } + } +} + +private fun ago(at: Long): String { + val now = System.currentTimeMillis() + return if (now - at < DateUtils.MINUTE_IN_MILLIS) "Just now" + else DateUtils.getRelativeTimeSpanString(at, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString() +} + +/** Today, Yesterday or Earlier. */ +private fun day(at: Long): String { + val start = Calendar.getInstance().apply { + set(Calendar.HOUR_OF_DAY, 0); set(Calendar.MINUTE, 0); set(Calendar.SECOND, 0); set(Calendar.MILLISECOND, 0) + }.timeInMillis + return when { + at >= start -> "Today" + at >= start - DateUtils.DAY_IN_MILLIS -> "Yesterday" + else -> "Earlier" + } +} From bd7f2de2d7c2d95e6de475d853ca1bf80a14358e Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:30 +0530 Subject: [PATCH 5/7] Phone: Alert me fills the list and says when a new version is out --- .../java/dev/zendr/companion/WatchService.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mobile/android/app/src/main/java/dev/zendr/companion/WatchService.kt b/mobile/android/app/src/main/java/dev/zendr/companion/WatchService.kt index baa19e1..cf82481 100644 --- a/mobile/android/app/src/main/java/dev/zendr/companion/WatchService.kt +++ b/mobile/android/app/src/main/java/dev/zendr/companion/WatchService.kt @@ -72,6 +72,7 @@ class WatchService : Service() { } for (c in store.computers()) { val spaces = runCatching { Api.state(store, c) }.getOrNull() ?: continue + Feed.observe(store, c, spaces) for (s in spaces.flatMap { it.sessions }) { val key = "${c.id}/${s.terminal}" val before = seen[key] @@ -84,6 +85,10 @@ class WatchService : Service() { } } first = false + // A new version: noted in the list and, once, as a notification. + val noted = store.notedVersion + Updates.checkNow(this, store) + Updates.latest?.takeIf { store.notedVersion != noted && it.version == store.notedVersion }?.let { update(it) } delay(20_000) } } @@ -112,6 +117,24 @@ class WatchService : Service() { NotificationManagerCompat.from(this).notify(id, n) } + private fun update(r: Release) { + if (Build.VERSION.SDK_INT >= 33 && + ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED + ) return + val open = Intent(this, MainActivity::class.java) + .putExtra(MainActivity.EXTRA_UPDATE, true) + .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + val pending = PendingIntent.getActivity(this, ID_UPDATE, open, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) + val n = NotificationCompat.Builder(this, CHANNEL_UPDATES) + .setSmallIcon(R.drawable.ic_notify) + .setContentTitle("Zendr ${r.version} is out") + .setContentText("Tap to see what's new and download it.") + .setContentIntent(pending) + .setAutoCancel(true) + .build() + NotificationManagerCompat.from(this).notify(ID_UPDATE, n) + } + override fun onDestroy() { scope.cancel() super.onDestroy() @@ -120,13 +143,16 @@ class WatchService : Service() { companion object { private const val CHANNEL_WATCH = "watch" private const val CHANNEL_ALERTS = "alerts" + private const val CHANNEL_UPDATES = "updates" private const val ID_WATCH = 1 + private const val ID_UPDATE = 2 fun channels(context: Context) { if (Build.VERSION.SDK_INT < 26) return val nm = context.getSystemService(NotificationManager::class.java) nm.createNotificationChannel(NotificationChannel(CHANNEL_WATCH, "Watching", NotificationManager.IMPORTANCE_MIN)) nm.createNotificationChannel(NotificationChannel(CHANNEL_ALERTS, "Agents that need you", NotificationManager.IMPORTANCE_HIGH)) + nm.createNotificationChannel(NotificationChannel(CHANNEL_UPDATES, "New versions", NotificationManager.IMPORTANCE_DEFAULT)) } fun start(context: Context) = ContextCompat.startForegroundService(context, Intent(context, WatchService::class.java)) From eff3a7abec8227410b160e911cb5994d54623063 Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:30 +0530 Subject: [PATCH 6/7] Phone: the bell on the main screens; notes open their session or the update --- .../java/dev/zendr/companion/MainActivity.kt | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/mobile/android/app/src/main/java/dev/zendr/companion/MainActivity.kt b/mobile/android/app/src/main/java/dev/zendr/companion/MainActivity.kt index fdd02ec..59db031 100644 --- a/mobile/android/app/src/main/java/dev/zendr/companion/MainActivity.kt +++ b/mobile/android/app/src/main/java/dev/zendr/companion/MainActivity.kt @@ -91,11 +91,13 @@ sealed class Screen { val status: String? = null, ) : Screen() data class About(val from: Screen) : Screen() + data class Notifications(val from: Screen) : Screen() } class MainActivity : ComponentActivity() { private var screen by mutableStateOf(Screen.Home) private var pendingLink by mutableStateOf(null) + private var pendingUpdate by mutableStateOf(false) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -128,6 +130,7 @@ class MainActivity : ComponentActivity() { private fun handle(intent: Intent?) { intent ?: return intent.data?.toString()?.takeIf { it.startsWith("zendr://") }?.let { pendingLink = it; screen = Screen.Pair } + if (intent.getBooleanExtra(EXTRA_UPDATE, false)) pendingUpdate = true val c = intent.getStringExtra(EXTRA_COMPUTER) val t = intent.getStringExtra(EXTRA_TERMINAL) if (c != null && t != null) { @@ -139,15 +142,16 @@ class MainActivity : ComponentActivity() { private fun App() { val store = remember { Store(this) } val about = { screen = Screen.About(screen) } + val bell = { screen = Screen.Notifications(screen) } when (val s = screen) { - Screen.Home -> HomeScreen(store, onOpen = { screen = Screen.Sessions(it.id) }, onAdd = { screen = Screen.Pair }, onAbout = about) + Screen.Home -> HomeScreen(store, onOpen = { screen = Screen.Sessions(it.id) }, onAdd = { screen = Screen.Pair }, onAbout = about, onBell = bell) Screen.Pair -> { BackHandler { screen = Screen.Home } PairScreen(store, pendingLink, onDone = { pendingLink = null; screen = if (it != null) Screen.Sessions(it.id) else Screen.Home }) } is Screen.Sessions -> { BackHandler { screen = Screen.Home } - SessionsScreen(store, s.computer, onBack = { screen = Screen.Home }, onAbout = about, onOpen = { + SessionsScreen(store, s.computer, onBack = { screen = Screen.Home }, onAbout = about, onBell = bell, onOpen = { screen = Screen.Terminal(s.computer, it.terminal, it.title, it.app, it.status) }) } @@ -159,6 +163,25 @@ class MainActivity : ComponentActivity() { BackHandler { screen = s.from } AboutScreen(store, onBack = { screen = s.from }) } + is Screen.Notifications -> { + BackHandler { screen = s.from } + NotificationsScreen(store, onBack = { screen = s.from }, onOpen = { n -> + val c = store.computers().firstOrNull { it.id == n.computer } + when { + n.kind == "update" -> Updates.latest?.let { Updates.offer = it } ?: run { pendingUpdate = true } + c != null && n.terminal != null -> screen = Screen.Terminal(c.id, n.terminal, n.session ?: "Session", n.app) + c != null -> screen = Screen.Sessions(c.id) + } + }) + } + } + + // From the "new version" notification: look now, and offer it. + LaunchedEffect(pendingUpdate) { + if (pendingUpdate) { + pendingUpdate = false + Updates.check(this@MainActivity, store, manual = true) + } } // A new version: offered in a popup when the app opens, and every few hours while it's open. @@ -186,6 +209,7 @@ class MainActivity : ComponentActivity() { const val EXTRA_TITLE = "title" const val EXTRA_APP = "app" const val EXTRA_STATUS = "status" + const val EXTRA_UPDATE = "update" // What enableEdgeToEdge() puts behind three-button navigation. private val LIGHT_SCRIM = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF) @@ -210,7 +234,7 @@ private fun summarize(spaces: List): String { @OptIn(ExperimentalMaterial3Api::class) @Composable -fun HomeScreen(store: Store, onOpen: (Computer) -> Unit, onAdd: () -> Unit, onAbout: () -> Unit) { +fun HomeScreen(store: Store, onOpen: (Computer) -> Unit, onAdd: () -> Unit, onAbout: () -> Unit, onBell: () -> Unit) { val context = LocalContext.current var computers by remember { mutableStateOf(store.computers()) } var summary by remember { mutableStateOf>>(emptyMap()) } @@ -223,7 +247,8 @@ fun HomeScreen(store: Store, onOpen: (Computer) -> Unit, onAdd: () -> Unit, onAb lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { while (true) { summary = computers.associate { c -> - c.id to runCatching { summarize(Api.state(store, c)) to true }.getOrElse { "Offline: ${it.message}" to false } + c.id to runCatching { Api.state(store, c).also { Feed.observe(store, c, it) }.let(::summarize) to true } + .getOrElse { "Offline: ${it.message}" to false } } delay(5000) } @@ -234,7 +259,10 @@ fun HomeScreen(store: Store, onOpen: (Computer) -> Unit, onAdd: () -> Unit, onAb topBar = { ZendrTopBar( navigationIcon = { ThemeButton(store) }, - actions = { IconButton(onClick = onAbout) { Icon(Icons.Default.Info, "About") } }, + actions = { + BellButton(store, onBell) + IconButton(onClick = onAbout) { Icon(Icons.Default.Info, "About") } + }, ) }, floatingActionButton = { @@ -393,7 +421,7 @@ private enum class Filter(val label: String) { All("All"), Need("Needs you"), Wo @OptIn(ExperimentalMaterial3Api::class) @Composable -fun SessionsScreen(store: Store, computerId: String, onBack: () -> Unit, onAbout: () -> Unit, onOpen: (Session) -> Unit) { +fun SessionsScreen(store: Store, computerId: String, onBack: () -> Unit, onAbout: () -> Unit, onBell: () -> Unit, onOpen: (Session) -> Unit) { val scope = rememberCoroutineScope() val computer = store.computers().firstOrNull { it.id == computerId } var spaces by remember { mutableStateOf?>(null) } @@ -406,7 +434,7 @@ fun SessionsScreen(store: Store, computerId: String, onBack: () -> Unit, onAbout suspend fun load() { val c = store.computers().firstOrNull { it.id == computerId } ?: return runCatching { Api.state(store, c) } - .onSuccess { spaces = it; error = null } + .onSuccess { spaces = it; error = null; Feed.observe(store, c, it) } .onFailure { error = it.message } } @@ -436,7 +464,10 @@ fun SessionsScreen(store: Store, computerId: String, onBack: () -> Unit, onAbout Scaffold(topBar = { ZendrTopBar( navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back") } }, - actions = { IconButton(onClick = onAbout) { Icon(Icons.Default.Info, "About") } }, + actions = { + BellButton(store, onBell) + IconButton(onClick = onAbout) { Icon(Icons.Default.Info, "About") } + }, ) }) { pad -> PullToRefreshBox( From 14a478d11b7014ce3c845ea8df786d3f3f3f67f2 Mon Sep 17 00:00:00 2001 From: Ruchira Edirisinghe Date: Sat, 28 Nov 2026 20:49:40 +0530 Subject: [PATCH 7/7] README: the phone's notifications list --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index da856c3..e92c780 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,7 @@ The **Zendr app for Android** shows every session on your computers, says which - **When an agent asks a question** (allow this command? 1. Yes 2. No), its choices are buttons. - **The key bar** has **Esc**, **Tab**, the arrows, **Enter** and **Ctrl+C**. Send with an empty box presses Enter. - **At a shell prompt**, the same command suggestions as on your computer show as you type. Tap one, or press → or Tab on a keyboard. +- **The bell** at the top keeps a list of what happened: agents that needed you or finished, and new versions. A dot marks the ones you haven't seen. Tap one to open that session, swipe it away to remove it. - **Light or dark**: the moon and sun at the top left switch it, and **About** (ⓘ) can also follow your phone's setting. - **New versions** pop up by themselves with what's new and a **Download** button. **About** shows your version, checks for updates and links to the source, the releases and the issue tracker.