Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(android): a dropped connection no longer closes the app

leepokaie5b121bec111
diff --git a/apps/android/WhatsNew.md b/apps/android/WhatsNew.md
index 39918e87..0355d0df 100644
--- a/apps/android/WhatsNew.md
+++ b/apps/android/WhatsNew.md
@@ -7,13 +7,15 @@ released version's section; a version without one gets the PRs' "What's New: And
else a generic "Bug fixes and improvements" line. Delete old sections.
-->
-## 2.38.0
+## 2.38.1
### zh-Hant
+- 修正與電腦的連線中斷時,app 可能閃退的問題。
- 介面新增巴西葡萄牙文:可在設定選擇「Português (Brasil)」,或跟隨系統的葡萄牙文語言。
- 新增俄文介面:在設定選擇「Русский」,或跟隨系統的俄文語言。
- 用 QR Code 配對時,如果電腦當下沒能加入你的帳號(例如手機連不上 Codync 雲端,或電腦的雲端關著),下次連上時會自動補上。
### en-US
+- Fixed a crash when the connection to your computer dropped.
- Choose Português (Brasil) in Settings, or follow your Portuguese system language.
- Choose Русский in Settings, or follow your Russian system language.
- A computer you pair with a QR code that couldn't join your account at the time (the phone couldn't reach the Codync cloud, or the computer's cloud was off, say) joins it the next time it connects.
diff --git a/apps/android/core/src/main/kotlin/com/codync/android/core/EncryptedChannel.kt b/apps/android/core/src/main/kotlin/com/codync/android/core/EncryptedChannel.kt
index bcbb85cb..d7af8b10 100644
--- a/apps/android/core/src/main/kotlin/com/codync/android/core/EncryptedChannel.kt
+++ b/apps/android/core/src/main/kotlin/com/codync/android/core/EncryptedChannel.kt
@@ -328,8 +328,8 @@ class EncryptedChannel internal constructor(
}
private fun dropPending(error: Throwable) {
- calls.keys.toList().forEach { calls.remove(it)?.completeExceptionally(error) }
- streams.keys.toList().forEach { streams.remove(it)?.events?.close(error) }
+ calls.drain { it.completeExceptionally(error) }
+ streams.drain { it.events.close(error) }
}
private fun fail(error: Throwable) {
@@ -346,10 +346,19 @@ class EncryptedChannel internal constructor(
if (mutableState.value !is LinkState.Failed) mutableState.value = LinkState.Failed("Connection closed.")
firstState.cancel()
dropPending(IOException("Connection closed."))
- mailboxCalls.keys.toList().forEach { mailboxCalls.remove(it)?.completeExceptionally(IOException("Relay connection closed.")) }
+ mailboxCalls.drain { it.completeExceptionally(IOException("Relay connection closed.")) }
socket.close()
scope.cancel()
}
}
+/**
+ * Removes every entry while other threads may remove some too (a reply, an unsubscribe): it walks the live key view,
+ * never a snapshot. `keys.toList()` throws NoSuchElementException when an entry goes meanwhile, which ended the app
+ * on a dropped connection.
+ */
+private inline fun <K : Any, V : Any> ConcurrentHashMap<K, V>.drain(action: (V) -> Unit) {
+ for (key in keys) remove(key)?.let(action)
+}
+
internal fun JsonObject.text(key: String): String? = this[key]?.takeUnless { it == JsonNull }?.jsonPrimitive?.content