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.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(android): an upgrade keeps push off, and a reconnect can't undo the switch
leepokaifb5fe288314e
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/AppStore.kt b/apps/android/app/src/main/kotlin/com/codync/android/AppStore.ktindex dc973886..b9a3c6e2 100644--- a/apps/android/app/src/main/kotlin/com/codync/android/AppStore.kt+++ b/apps/android/app/src/main/kotlin/com/codync/android/AppStore.kt@@ -24,6 +24,8 @@ class AppStore(application: Application) : AndroidViewModel(application) {private var contextJob = SupervisorJob(viewModelScope.coroutineContext[Job])internal var contextScope = CoroutineScope(contextJob + Dispatchers.Main.immediate)internal val transitions = Mutex()+ /** One change to the paired computer's saved copy at a time (`changeComputer`). */+ internal val computerChanges = Mutex()internal val screenTakeovers = Mutex()internal var cloud: CloudClient? = nullprivate var sessionJob: Job? = null@@ -57,6 +59,7 @@ class AppStore(application: Application) : AndroidViewModel(application) {init {viewModelScope.launch {+ withContext(Dispatchers.IO) { PushPreferences.splitSwitch(getApplication()) }transitions.withLock { loadContext(null) }NativeAccounts.observe(viewModelScope) { account ->mutableState.update { it.copy(account = account) }diff --git a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreAccount.kt b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreAccount.ktindex 2e511e94..45ffa31b 100644--- a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreAccount.kt+++ b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreAccount.kt@@ -166,12 +166,7 @@ fun AppStore.revokeAccess(computerId: String) = action("revoke") {}/** The computer's badge color, picked on this phone (an `AvatarPalette` id). */-fun AppStore.setColor(color: String) = action("color") {- val computer = state.value.computers.firstOrNull() ?: return@action- val changed = computer.copy(color = color)- withContext(Dispatchers.IO) { local.saveComputers(listOf(changed)) }- mutableState.update { it.copy(computers = listOf(changed)) }-}+fun AppStore.setColor(color: String) = action("color") { changeComputer { it.copy(color = color) } }/*** Remove: forgets the computer here. Approved through the account, its grant goes too (as on iOS), or itdiff --git a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreConnection.kt b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreConnection.ktindex 2ae7671f..4ef48447 100644--- a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreConnection.kt+++ b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreConnection.kt@@ -5,16 +5,25 @@ import java.io.IOExceptionimport com.codync.android.core.*import kotlinx.coroutines.*import kotlinx.coroutines.flow.*+import kotlinx.coroutines.sync.withLockimport kotlinx.serialization.json.*// Pairing, the encrypted link to the computer and the mirror's event stream.fun AppStore.setRoute(route: ConnectionRoute) = action("route") {- val computer = state.value.computers.firstOrNull() ?: return@action- val changed = computer.copy(route = route)+ changeComputer { it.copy(route = route) } ?: return@action+ reconnect().join()+}++/**+ * Changes the paired computer's latest copy, saved and then shown, one change at a time: a switch+ * flipped while a link's `hello` runs isn't undone by the copy that link saves.+ */+internal suspend fun AppStore.changeComputer(change: (Computer) -> Computer): Computer? = computerChanges.withLock {+ val changed = change(state.value.computers.firstOrNull() ?: return@withLock null)withContext(Dispatchers.IO) { local.saveComputers(listOf(changed)) }mutableState.update { it.copy(computers = listOf(changed)) }- reconnect().join()+ changed}/**@@ -110,17 +119,16 @@ fun AppStore.connect() {reconcileMailbox(active)}if (link is LinkState.Ready) {- // The latest saved copy: its color may have changed since this link opened.- val updated = HostClient.hello(active, state.value.computers.firstOrNull { it.id == target.id } ?: target)+ val fromHost = HostClient.hello(active, state.value.computers.firstOrNull { it.id == target.id } ?: target)val hello = active.call("hello").jsonObject+ // This phone's picks (color, route, push) may have changed during those calls.+ changeComputer { current -> if (current.id == fromHost.id) fromHost.keepingDevicePicks(current) else current }val dropped = withContext(Dispatchers.IO) {- local.saveComputers(listOf(updated))requireNotNull(database).setStamp(requireNotNull(hello["hostId"]?.jsonPrimitive?.content),BuildConfig.VERSION_NAME + "/" + hello["version"]?.jsonPrimitive?.content)}// Dropped chats page their earlier messages again.- mutableState.update { it.copy(computers = listOf(updated),- historyComplete = if (dropped) emptySet() else it.historyComplete) }+ mutableState.update { it.copy(historyComplete = if (dropped) emptySet() else it.historyComplete) }noteHello(hello)// The event catch-up is ordered by revision; bot revisions can// follow hundreds of historical entries. Load the current rosterdiff --git a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreNotifications.kt b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreNotifications.ktindex ad04fc0e..2a72bec6 100644--- a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreNotifications.kt+++ b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreNotifications.kt@@ -18,10 +18,7 @@ fun AppStore.syncPush() = action("push") {}/** Saved with the computer on this phone (iOS `AccountStore.setNotifications`). */fun AppStore.notifications(enabled: Boolean) = action("notificationSettings") {- val computer = state.value.computers.firstOrNull() ?: return@action- val changed = computer.copy(notifications = enabled)- withContext(Dispatchers.IO) { local.saveComputers(listOf(changed)) }- mutableState.update { it.copy(computers = listOf(changed)) }+ changeComputer { it.copy(notifications = enabled) } ?: return@actionAnalytics.capture(AnalyticsEvent.SettingChanged(PhoneSetting.Push, enabled))if (!enabled) NotificationDisplay.cancel(getApplication(), 1)syncPush(); PushDelivery.schedule(getApplication())diff --git a/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt b/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.ktindex 5aebcd3e..21876911 100644--- a/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt+++ b/apps/android/app/src/main/kotlin/com/codync/android/LocalStore.kt@@ -84,19 +84,31 @@ class LocalStore(context: Context, val contextId: String = "local") {check(directory.mkdirs()) { "Couldn't create new local storage." }}- private fun write(file: AtomicFile, bytes: ByteArray) {- val output = file.startWrite()- try { output.write(bytes); file.finishWrite(output) }- catch (error: Throwable) { file.failWrite(output); throw error }- }-companion object {+ private fun write(file: AtomicFile, bytes: ByteArray) {+ val output = file.startWrite()+ try { output.write(bytes); file.finishWrite(output) }+ catch (error: Throwable) { file.failWrite(output); throw error }+ }++ /** Every account's folder (signed out included), by its scope id. */+ private fun scopes(context: Context): List<File> =+ context.noBackupFilesDir.listFiles()?.filter { it.isDirectory && it.name.matches(Regex("[a-f0-9]{64}")) }.orEmpty()++ /** Push switched off on every account's saved computers (`PushPreferences.splitSwitch`). */+ fun pushOffEverywhere(context: Context) {+ val json = Json { ignoreUnknownKeys = true }+ for (file in scopes(context).map { AtomicFile(File(it, "computers.json")) }.filter { it.baseFile.exists() }) {+ val computers = json.decodeFromString<List<Computer>>(file.readFully().toString(Charsets.UTF_8))+ write(file, json.encodeToString(computers.map { it.copy(notifications = false) }).toByteArray())+ }+ }+fun referenceId(contextId: String): String = if (contextId == "local") "local" else MessageDigest.getInstance("SHA-256").digest(contextId.toByteArray()).joinToString("") { "%02x".format(it) }/** Reset includes inactive accounts and their wrapping keys, never host data. */fun eraseAll(context: Context) {- context.noBackupFilesDir.listFiles()?.filter { it.isDirectory && it.name.matches(Regex("[a-f0-9]{64}")) }- ?.forEach { check(it.deleteRecursively()) { "Couldn't erase local account data." } }+ scopes(context).forEach { check(it.deleteRecursively()) { "Couldn't erase local account data." } }val keys = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }keys.aliases().toList().filter { it.startsWith("codync.identity.") }.forEach(keys::deleteEntry)}diff --git a/apps/android/app/src/main/kotlin/com/codync/android/PushService.kt b/apps/android/app/src/main/kotlin/com/codync/android/PushService.ktindex 80741cf0..3394e4de 100644--- a/apps/android/app/src/main/kotlin/com/codync/android/PushService.kt+++ b/apps/android/app/src/main/kotlin/com/codync/android/PushService.kt@@ -35,6 +35,15 @@ object PushPreferences {fun retired(context: Context) = prefs(context).getBoolean("retired", false)fun retire(context: Context) = synchronized(this) { prefs(context).edit().putBoolean("retired", true).commit() }fun tasks(context: Context, enabled: Boolean) { prefs(context).edit().putBoolean("tasks", enabled).commit() }+ /** 2.28.0 had one push switch for every computer; switched off, it becomes each saved computer's own, once (iOS `splitPushSwitch`). */+ fun splitSwitch(context: Context) {+ synchronized(this) {+ val prefs = prefs(context)+ if (!prefs.contains("enabled")) return+ if (!prefs.getBoolean("enabled", true)) LocalStore.pushOffEverywhere(context)+ prefs.edit().remove("enabled").commit()+ }+ }fun reset(context: Context) {val token = fid(context)prefs(context).edit().clear().putString("fid", token).commit()@@ -110,6 +119,7 @@ object PushDelivery {suspend fun background(context: Context) = gate.withLock {if (!BuildConfig.PUSH_CONFIGURED) return@withLockif (PushPreferences.retired(context)) return@withLock+ withContext(Dispatchers.IO) { PushPreferences.splitSwitch(context) }val local = LocalStore(context, PushPreferences.activeUser(context) ?: "local")val computers = withContext(Dispatchers.IO) { local.computers() }val computer = computers.firstOrNull() ?: return@withLock@@ -163,6 +173,7 @@ class PushService : FirebaseMessagingService() {synchronized(PushPreferences) {try {if (PushPreferences.retired(context)) return+ PushPreferences.splitSwitch(context)val user = PushPreferences.activeUser(context)val scope = LocalStore.referenceId(user ?: "local")if (data["ctx"] != scope || data["kind"] !in setOf("alert", "task")) return