Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Ongoing notification: post it only when its text changes

Claude4c966b8d0551
diff --git a/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt b/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt
index 2b2415df..beb65871 100644
--- a/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt
+++ b/android/app/src/main/kotlin/com/coucou/android/app/Notifications.kt
@@ -17,6 +17,7 @@ import com.coucou.android.core.ApprovalSheetPlan
import com.coucou.android.core.Glance
import com.coucou.android.core.GlanceTone
import com.coucou.android.core.OverlayPolicy
+import com.coucou.android.core.OngoingGate
import com.coucou.android.core.SafeText
import com.coucou.android.core.ToolLabels
import com.coucou.android.link.ApprovalRequest
@@ -82,7 +83,12 @@ class Notifications(private val context: Context) {
* when expanded, one line per agent ("Claude Code: Working"). Only states, never a command or a path. On a locked
* screen it shows the plain "Connected" line, like the other notifications of the app.
*/
- fun ongoing(model: AppModel?): Notification = ongoing(model?.glance())
+ fun ongoing(model: AppModel?): Notification {
+ val g = model?.glance()
+ ongoingGate.forget()
+ ongoingGate.shouldPost(g) // what the service posts is now the last notification
+ return ongoing(g)
+ }
private fun ongoing(g: Glance?): Notification {
val title = g?.headline ?: context.getString(R.string.status_connecting)
@@ -109,8 +115,11 @@ class Notifications(private val context: Context) {
return b.build()
}
+ /** Only posted again when what it shows changes ([OngoingGate]); the service's own first post counts as the last one. */
+ private val ongoingGate = OngoingGate()
+
fun updateOngoing(model: AppModel, g: Glance = model.glance()) {
- if (model.mode == Mode.PAIRED) runCatching { nm.notify(ONGOING_ID, ongoing(g)) }
+ if (model.mode == Mode.PAIRED && ongoingGate.shouldPost(g)) runCatching { nm.notify(ONGOING_ID, ongoing(g)) }
}
fun showApproval(r: ApprovalRequest, agentName: String, alert: OverlayPolicy.ApprovalAlert = OverlayPolicy.ApprovalAlert.HEADS_UP) {
diff --git a/android/app/src/main/kotlin/com/coucou/android/core/OngoingGate.kt b/android/app/src/main/kotlin/com/coucou/android/core/OngoingGate.kt
new file mode 100644
index 00000000..83a547d3
--- /dev/null
+++ b/android/app/src/main/kotlin/com/coucou/android/core/OngoingGate.kt
@@ -0,0 +1,31 @@
+package com.coucou.android.core
+
+/**
+ * Decides when the ongoing notification is posted again. Every push to the surfaces comes here, but the notification shows only a
+ * title, a detail, one line per agent, its accent colour and (on a locked screen) whether the link is up: a push that changes none of
+ * those is dropped, so the shade is not redrawn for nothing. Pure, so the rule is a unit test.
+ */
+class OngoingGate {
+ /** What the notification would show. */
+ data class Key(val title: String, val detail: String, val lines: List<String>, val argb: Int, val connected: Boolean)
+
+ private var last: Key? = null
+
+ /** The key for a glance (null: nothing known yet, the notification says "connecting"). */
+ fun keyOf(g: Glance?): Key =
+ if (g == null) Key("", "", emptyList(), GlanceTone.CALM.argb, false)
+ else Key(g.headline, g.detail, g.lines.map { "${it.agent}: ${it.text}" }, g.tone.argb, g.connected)
+
+ /** True the first time and whenever the notification would look different; false for a push that changes nothing. */
+ @Synchronized
+ fun shouldPost(g: Glance?): Boolean {
+ val k = keyOf(g)
+ if (k == last) return false
+ last = k
+ return true
+ }
+
+ /** The notification was removed or rebuilt elsewhere (the service started again): the next push posts. */
+ @Synchronized
+ fun forget() { last = null }
+}
diff --git a/android/app/src/test/kotlin/com/coucou/android/OngoingGateTest.kt b/android/app/src/test/kotlin/com/coucou/android/OngoingGateTest.kt
new file mode 100644
index 00000000..29aaa73b
--- /dev/null
+++ b/android/app/src/test/kotlin/com/coucou/android/OngoingGateTest.kt
@@ -0,0 +1,57 @@
+package com.coucou.android
+
+import com.coucou.android.core.Glance
+import com.coucou.android.core.GlanceLine
+import com.coucou.android.core.GlanceTone
+import com.coucou.android.core.OngoingGate
+import com.coucou.android.mochi.BotState
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class OngoingGateTest {
+ private fun glance(head: String = "1 agent working", detail: String = "Claude Code", waiting: Int = 0, tone: GlanceTone = GlanceTone.BUSY, state: BotState = BotState.WORKING) =
+ Glance(head, detail, tone, true, listOf(GlanceLine("Claude Code", "Working", state)), waiting)
+
+ @Test fun theFirstPushPosts() = assertTrue(OngoingGate().shouldPost(glance()))
+
+ @Test fun thePushThatLooksTheSameIsDropped() {
+ val gate = OngoingGate()
+ assertTrue(gate.shouldPost(glance()))
+ assertFalse(gate.shouldPost(glance()))
+ assertFalse(gate.shouldPost(glance().copy(waiting = 0)))
+ }
+
+ @Test fun aChangeInTextOrColourPostsAgain() {
+ val gate = OngoingGate()
+ gate.shouldPost(glance())
+ assertTrue(gate.shouldPost(glance(head = "All done")))
+ assertTrue(gate.shouldPost(glance(head = "All done", detail = "2 finished")))
+ assertTrue(gate.shouldPost(glance(head = "All done", detail = "2 finished", tone = GlanceTone.OK)))
+ assertTrue(gate.shouldPost(glance(head = "All done", detail = "2 finished", tone = GlanceTone.OK).copy(lines = listOf(GlanceLine("Codex", "Done", BotState.FINISHED)))))
+ assertTrue(gate.shouldPost(glance(head = "All done", detail = "2 finished", tone = GlanceTone.OK).copy(connected = false)))
+ }
+
+ @Test fun somethingThatIsNotOnTheNotificationDoesNotRepostIt() {
+ val gate = OngoingGate()
+ gate.shouldPost(glance(waiting = 0))
+ // The count of waiting requests is not shown in the ongoing notification's text: the same text, the same notification.
+ assertFalse(gate.shouldPost(glance(waiting = 3)))
+ // The state of a line is not shown either, only its words.
+ assertFalse(gate.shouldPost(glance(state = BotState.THINKING)))
+ }
+
+ @Test fun forgetMakesTheNextPushPost() {
+ val gate = OngoingGate()
+ gate.shouldPost(glance())
+ gate.forget()
+ assertTrue(gate.shouldPost(glance()))
+ }
+
+ @Test fun noGlanceYetIsOneKeyToo() {
+ val gate = OngoingGate()
+ assertTrue(gate.shouldPost(null))
+ assertFalse(gate.shouldPost(null))
+ assertTrue(gate.shouldPost(glance()))
+ }
+}