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(apps): keep the Codync row honest on every computer and bring it to the desktop

leepokai854c92517ba2
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreHostUpdate.kt b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreHostUpdate.kt
index 9210aed4..e122941e 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/AppStoreHostUpdate.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/AppStoreHostUpdate.kt
@@ -55,30 +55,36 @@ private fun howToUpdate(os: String?) = when (os) {
* sentences, each its own phrase to translate.
*/
internal data class HostVersionLine(val version: String, val detail: List<String>, val warns: Boolean = false,
- val action: String? = null, val updating: Boolean = false)
+ val accessory: Accessory? = null) {
+ /** What the row ends with: a spinner while the computer updates, or the button that asks it to. */
+ sealed interface Accessory {
+ data object Updating : Accessory
+ data class Button(val title: String) : Accessory
+ }
+}
/** `latest` is the latest release the computer found (null while it doesn't know: then no verdict). */
internal fun hostVersionLine(version: String, latest: String?, mismatch: VersionMismatch?, canUpdate: Boolean,
update: HostUpdate?, host: String, os: String?, now: Long): HostVersionLine {
- if (update.updating(now)) return HostVersionLine(version, listOf(updatingText(host)), updating = true)
+ if (update.updating(now)) return HostVersionLine(version, listOf(updatingText(host)), accessory = HostVersionLine.Accessory.Updating)
val minimum = (mismatch as? VersionMismatch.UpdateHost)?.minimum
val available = latest?.takeIf { AppVersion.isBelow(version, it) }
- val due = minimum?.let { "This app needs $it or newer." } ?: available?.let { "$it available" }
+ val due = minimum?.let { "This app needs $it or newer." } ?: available?.let { "Version $it is available." }
?: return HostVersionLine(version, if (latest == null) emptyList() else listOf("Up to date"))
if (!canUpdate) return HostVersionLine(version, listOf(due, howToUpdate(os)), warns = minimum != null)
+ val tryAgain = HostVersionLine.Accessory.Button("Try again")
return when (update) {
- is HostUpdate.Failed -> HostVersionLine(version, listOf(update.message), warns = true, action = "Try again")
- is HostUpdate.Requested -> HostVersionLine(version, listOf(notUpdatedText(host)), warns = true, action = "Try again")
- null -> HostVersionLine(version, listOf(due), warns = minimum != null, action = "Update")
+ is HostUpdate.Failed -> HostVersionLine(version, listOf(update.message), warns = true, accessory = tryAgain)
+ is HostUpdate.Requested -> HostVersionLine(version, listOf(notUpdatedText(host)), warns = true, accessory = tryAgain)
+ null -> HostVersionLine(version, listOf(due), warns = minimum != null, accessory = HostVersionLine.Accessory.Button("Update"))
}
}
-/** This computer's Codync row; null until its `hello` arrives. */
+/** This computer's Codync row at `now`; null until its `hello` arrives. */
internal fun AppState.hostVersionLine(now: Long): HostVersionLine? {
val hello = hello ?: return null
val version = hello.text("version") ?: return null
- val host = hello.text("name") ?: computers.firstOrNull()?.name ?: "your computer"
- return hostVersionLine(version, hello.text("latestVersion"), mismatch, canUpdateHost, hostUpdate, host, hello.text("os"), now)
+ return hostVersionLine(version, hello.text("latestVersion"), mismatch, canUpdateHost, hostUpdate, hostName, hello.text("os"), now)
}
/** Asks a computer that's behind to install the latest release (the update card's Update now). */
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/ComputersView.kt b/apps/android/app/src/main/kotlin/com/codync/android/ComputersView.kt
index 9a5bb4ce..7fed8cdf 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/ComputersView.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/ComputersView.kt
@@ -112,8 +112,8 @@ private class ComputerActions(val extensions: () -> Unit, val screen: () -> Unit
/**
* The paired computer as the rows of its card: its connection and whether it's in the account, then
* Extensions, Voice chat (its keys live on the computer), Screen, whether it sends push alerts here
- * (the only computer this phone pairs, so the switch is the phone's), how it's reached and, for a stale
- * pairing, Remove (iOS `ComputerRows`).
+ * (the only computer this phone pairs, so the switch is the phone's), how it's reached, the Codync it runs
+ * (and its update) and, for a stale pairing, Remove (iOS `ComputerRows`).
*/
private fun CardRows.computerRows(state: AppState, store: AppStore, inAccount: Boolean, actions: ComputerActions) {
row { ComputerSummary(state, inAccount, actions) }
@@ -128,9 +128,7 @@ private fun CardRows.computerRows(state: AppState, store: AppStore, inAccount: B
}
}
row { ConnectionRow(state.computers.first(), store) }
- if (state.connection is LinkState.Ready) state.hostVersionLine(System.currentTimeMillis())?.let { line ->
- row { CodyncVersionRow(line, store::requestHostUpdate) }
- }
+ if (state.connection is LinkState.Ready && state.hello != null) row { CodyncVersionRow(state, store::requestHostUpdate) }
if (state.isStale && !inAccount) row { RowLabel("Remove", "trash", Palette.danger, modifier = Modifier.plainButton(action = actions.remove)) }
}
@@ -166,9 +164,9 @@ private fun CardRows.computerRows(state: AppState, store: AppStore, inAccount: B
}
}
-/** How this phone reaches the computer: the short name on the row, the whole route in the menu. */
/** The Codync the computer runs, and its update when one is due (iOS `CodyncVersionRow`). */
-@Composable private fun CodyncVersionRow(line: HostVersionLine, update: () -> Unit) {
+@Composable private fun CodyncVersionRow(state: AppState, update: () -> Unit) {
+ val line = state.hostVersionLine(rememberHostUpdateNow(state.hostUpdate)) ?: return
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Box(Modifier.width(26.dp), contentAlignment = Alignment.Center) { Symbol("arrow.down.circle", size = 20.dp, tint = Palette.text) }
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
@@ -179,11 +177,15 @@ private fun CardRows.computerRows(state: AppState, store: AppStore, inAccount: B
if (line.detail.isNotEmpty()) Text(line.detail.map { tr(it) }.joinToString(" "), style = Type.footnote,
color = if (line.warns) Palette.warning else Palette.secondary)
}
- if (line.updating) Spinner(16.dp)
- line.action?.let { PrimaryButton(it, action = update) }
+ when (val accessory = line.accessory) {
+ HostVersionLine.Accessory.Updating -> Spinner(16.dp)
+ is HostVersionLine.Accessory.Button -> PrimaryButton(accessory.title, action = update)
+ null -> {}
+ }
}
}
+/** How this phone reaches the computer: the short name on the row, the whole route in the menu. */
@Composable private fun ConnectionRow(computer: Computer, store: AppStore) {
DropdownMenu({ ConnectionRoute.entries.map { route -> MenuItem(routeTitle(route, computer.cloud), icon = route.icon, selected = route == computer.route) { store.setRoute(route) } } },
Modifier.fillMaxWidth(), label = "Connection") {
diff --git a/apps/android/app/src/main/kotlin/com/codync/android/UpdateNeededCard.kt b/apps/android/app/src/main/kotlin/com/codync/android/UpdateNeededCard.kt
index 6680c8cd..5d7a29d9 100644
--- a/apps/android/app/src/main/kotlin/com/codync/android/UpdateNeededCard.kt
+++ b/apps/android/app/src/main/kotlin/com/codync/android/UpdateNeededCard.kt
@@ -31,16 +31,21 @@ internal val AppState.mismatch: VersionMismatch? get() {
?: if (unreadable && host != null && AppVersion.isBelow(BuildConfig.VERSION_NAME, host)) VersionMismatch.UpdateApp(host) else null
}
-/** Says which side has to update, shown instead of the composer and above the computer's bots. */
-@Composable internal fun UpdateNeededCard(state: AppState, mismatch: VersionMismatch, requestUpdate: () -> Unit, modifier: Modifier = Modifier) {
- val host = state.hello?.text("name") ?: state.computers.firstOrNull()?.name ?: "your computer"
- // A requested update that never finishes offers the button again once its wait is over.
+/** The time to judge `update` by, read again when a requested update's wait is over, so one that never finished is offered again. */
+@Composable internal fun rememberHostUpdateNow(update: HostUpdate?): Long {
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
- LaunchedEffect(state.hostUpdate) {
- val requested = state.hostUpdate as? HostUpdate.Requested ?: return@LaunchedEffect
+ LaunchedEffect(update) {
+ val requested = update as? HostUpdate.Requested ?: return@LaunchedEffect
delay(requested.at + HOST_UPDATE_WAIT_MS - System.currentTimeMillis())
now = System.currentTimeMillis()
}
+ return maxOf(now, System.currentTimeMillis())
+}
+
+/** Says which side has to update, shown instead of the composer and above the computer's bots. */
+@Composable internal fun UpdateNeededCard(state: AppState, mismatch: VersionMismatch, requestUpdate: () -> Unit, modifier: Modifier = Modifier) {
+ val host = state.hello?.text("name") ?: state.computers.firstOrNull()?.name ?: "your computer"
+ val now = rememberHostUpdateNow(state.hostUpdate)
Row(modifier.fillMaxWidth().clip(RoundedRectangle(16.dp)).background(Palette.surface).padding(14.dp),
verticalAlignment = Alignment.Top, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Symbol("arrow.down.circle", size = 22.dp, tint = Palette.warning)
@@ -53,8 +58,7 @@ internal val AppState.mismatch: VersionMismatch? get() {
is VersionMismatch.UpdateApp -> Text("${state.hello?.text("version")?.let { "$host runs Codync $it and" } ?: host} needs this app to be " +
"${mismatch.minimum} or newer. Your chats are safe on the computer.", style = Type.footnote, color = Palette.secondary)
is VersionMismatch.UpdateHost -> {
- val notice = hostUpdateNotice(host, mismatch, state.hello?.text("os"), state.canUpdateHost, state.hostUpdate,
- maxOf(now, System.currentTimeMillis()))
+ val notice = hostUpdateNotice(host, mismatch, state.hello?.text("os"), state.canUpdateHost, state.hostUpdate, now)
Text(notice.detail, style = Type.footnote, color = Palette.secondary)
if (notice.offersUpdate) PrimaryButton("Update now", Modifier.padding(top = 4.dp), action = requestUpdate)
}
diff --git a/apps/android/app/src/test/kotlin/com/codync/android/HostUpdateNoticeTest.kt b/apps/android/app/src/test/kotlin/com/codync/android/HostUpdateNoticeTest.kt
index 4e6e774d..b29519aa 100644
--- a/apps/android/app/src/test/kotlin/com/codync/android/HostUpdateNoticeTest.kt
+++ b/apps/android/app/src/test/kotlin/com/codync/android/HostUpdateNoticeTest.kt
@@ -1,6 +1,8 @@
package com.codync.android
import com.codync.android.core.VersionMismatch
+import kotlinx.serialization.json.buildJsonObject
+import kotlinx.serialization.json.put
import org.junit.Assert.*
import org.junit.Test
@@ -34,22 +36,34 @@ class HostUpdateNoticeTest {
// The Codync row on the computer's card in Computer management (iOS `HostVersionLine`).
private fun line(latest: String?, mismatch: VersionMismatch? = null, canUpdate: Boolean = true, update: HostUpdate? = null) =
hostVersionLine("2.28.0", latest, mismatch, canUpdate, update, "Mini", "macos", now)
+ private val update = HostVersionLine.Accessory.Button("Update")
+ private val tryAgain = HostVersionLine.Accessory.Button("Try again")
@Test fun theCodyncRowOffersANewerReleaseOrSaysItsCurrent() {
assertEquals(HostVersionLine("2.28.0", listOf("Up to date")), line("2.28.0"))
assertEquals(listOf("Up to date"), line("2.27.0").detail)
// A computer that doesn't know the latest release makes no claim.
assertEquals(HostVersionLine("2.28.0", emptyList()), line(null))
- assertEquals(HostVersionLine("2.28.0", listOf("2.29.0 available"), action = "Update"), line("2.29.0"))
- assertEquals(HostVersionLine("2.28.0", listOf("2.29.0 available", "Open Codync on that Mac and choose Check for Updates.")),
+ assertEquals(HostVersionLine("2.28.0", listOf("Version 2.29.0 is available."), accessory = update), line("2.29.0"))
+ assertEquals(HostVersionLine("2.28.0", listOf("Version 2.29.0 is available.", "Open Codync on that Mac and choose Check for Updates.")),
line("2.29.0", canUpdate = false))
- assertEquals(HostVersionLine("2.28.0", listOf("Updating Codync on Mini. This takes a few minutes."), updating = true),
+ assertEquals(HostVersionLine("2.28.0", listOf("Updating Codync on Mini. This takes a few minutes."), accessory = HostVersionLine.Accessory.Updating),
line("2.29.0", update = HostUpdate.Requested(now)))
}
@Test fun aComputerTooOldOrAnUpdateThatDidntTakeIsAProblem() {
- assertEquals(HostVersionLine("2.28.0", listOf("This app needs 2.26.0 or newer."), warns = true, action = "Update"), line(null, behind))
+ assertEquals(HostVersionLine("2.28.0", listOf("This app needs 2.26.0 or newer."), warns = true, accessory = update), line(null, behind))
val busy = "A bot is working on this computer. Update it once the bot is done."
- assertEquals(HostVersionLine("2.28.0", listOf(busy), warns = true, action = "Try again"), line("2.29.0", update = HostUpdate.Failed(busy)))
+ assertEquals(HostVersionLine("2.28.0", listOf(busy), warns = true, accessory = tryAgain), line("2.29.0", update = HostUpdate.Failed(busy)))
+ // Asked, but the computer never came back updated.
+ assertEquals(HostVersionLine("2.28.0", listOf("Mini didn't finish updating. Try again, or update Codync on that computer."), warns = true,
+ accessory = tryAgain), line("2.29.0", update = HostUpdate.Requested(now - HOST_UPDATE_WAIT_MS)))
+ }
+
+ @Test fun theCodyncRowComparesWithTheLatestReleaseTheComputerFound() {
+ val state = AppState().copy(hello = buildJsonObject {
+ put("name", "Mini"); put("version", "2.28.0"); put("latestVersion", "2.30.0"); put("canUpdate", true)
+ })
+ assertEquals(HostVersionLine("2.28.0", listOf("Version 2.30.0 is available."), accessory = update), state.hostVersionLine(now))
}
}
diff --git a/apps/desktop/src/renderer/lib/host-update.test.ts b/apps/desktop/src/renderer/lib/host-update.test.ts
index 8fd63ed5..46ebf69f 100644
--- a/apps/desktop/src/renderer/lib/host-update.test.ts
+++ b/apps/desktop/src/renderer/lib/host-update.test.ts
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
-import { HOST_UPDATE_WAIT, offerHostUpdate } from './host-update.ts'
+import { HOST_UPDATE_WAIT, hostVersionLine, offerHostUpdate, type HostUpdateOffer } from './host-update.ts'
test('an update asked from here runs for a while, then is offered again', () => {
const requested = { kind: 'requested', at: 1_000_000 } as const
@@ -14,3 +14,26 @@ test('a refused update is offered again with why; a computer that cannot update
assert.deepEqual(offerHostUpdate(failed, true), { kind: 'available', last: failed })
assert.deepEqual(offerHostUpdate(null, false), { kind: 'unavailable' })
})
+
+test('the Codync row offers a newer release, says it is current, or makes no claim', () => {
+ const line = (latest: string | null, offer: HostUpdateOffer) => hostVersionLine('2.28.0', latest, null, offer, 'Mac', 'macos')
+ const available = { kind: 'available', last: null } as const
+ assert.deepEqual(line('2.28.0', available), { version: '2.28.0', detail: ['Up to date'], warns: false, accessory: null })
+ assert.deepEqual(line(null, available).detail, [])
+ assert.deepEqual(line('2.29.0', available),
+ { version: '2.28.0', detail: ['Version 2.29.0 is available.'], warns: false, accessory: { kind: 'button', title: 'Update' } })
+ assert.deepEqual(line('2.29.0', { kind: 'unavailable' }).detail,
+ ['Version 2.29.0 is available.', 'Open Codync on that Mac and choose Check for Updates.'])
+ assert.deepEqual(line('2.29.0', { kind: 'updating' }).accessory, { kind: 'updating' })
+})
+
+test('a computer too old for this app, or an update that did not take, is a problem', () => {
+ const behind = { kind: 'updateHost', version: '2.20.0', minimum: '2.26.0' } as const
+ assert.deepEqual(hostVersionLine('2.20.0', null, behind, { kind: 'available', last: null }, 'Mac', 'linux'),
+ { version: '2.20.0', detail: ['This app needs 2.26.0 or newer.'], warns: true, accessory: { kind: 'button', title: 'Update' } })
+ const stalled = hostVersionLine('2.28.0', '2.29.0', null, { kind: 'available', last: { kind: 'requested', at: 0 } }, 'Mac', 'macos')
+ assert.deepEqual(stalled, {
+ version: '2.28.0', detail: ["Mac didn't finish updating. Try again, or update Codync on that computer."], warns: true,
+ accessory: { kind: 'button', title: 'Try again' },
+ })
+})
diff --git a/apps/desktop/src/renderer/lib/host-update.ts b/apps/desktop/src/renderer/lib/host-update.ts
index 7e4dde7d..efd141c7 100644
--- a/apps/desktop/src/renderer/lib/host-update.ts
+++ b/apps/desktop/src/renderer/lib/host-update.ts
@@ -1,3 +1,5 @@
+import { isBelow, type VersionMismatch } from '../../shared/compat.ts'
+
/** An update this app asked of a computer that's behind it (`installHostUpdate`). */
export type HostUpdate = { kind: 'requested'; at: number } | { kind: 'failed'; message: string }
@@ -16,3 +18,59 @@ export function offerHostUpdate(update: HostUpdate | null, canUpdate: boolean, n
if (update?.kind === 'requested' && now - update.at < HOST_UPDATE_WAIT) return { kind: 'updating' }
return canUpdate ? { kind: 'available', last: update } : { kind: 'unavailable' }
}
+
+/** The words every client uses for a version mismatch (iOS, the TUI and this app). */
+export const updateNeededText = {
+ title(m: VersionMismatch, host: string) {
+ return m.kind === 'updateApp' ? 'Update this app' : `Update Codync on ${host}`
+ },
+ detail(m: VersionMismatch, host: string, hostVersion: string | null | undefined, os: string | null | undefined, instructions = true) {
+ if (m.kind === 'updateApp') {
+ const runs = hostVersion ? `${host} runs Codync ${hostVersion} and` : host
+ return `${runs} needs this app to be ${m.minimum} or newer. Your chats are safe on the computer.`
+ }
+ const needs = `${host} runs Codync ${m.version}; this app needs ${m.minimum} or newer.`
+ return instructions ? `${needs} ${updateNeededText.how(os)}` : needs
+ },
+ /** How to update Codync on a computer this app can't update. */
+ how(os: string | null | undefined) {
+ return os === 'macos' ? 'Open Codync on that Mac and choose Check for Updates.'
+ : os === 'linux' ? 'Run codync-host update there.'
+ : 'Update Codync on that computer.'
+ },
+ /** A computer updating at this app's request. */
+ updating(host: string) {
+ return `Updating Codync on ${host}. This takes a few minutes.`
+ },
+ /** Why the last update asked of the computer didn't take. */
+ notUpdated(last: HostUpdate, host: string) {
+ return last.kind === 'failed' ? last.message : `${host} didn't finish updating. Try again, or update Codync on that computer.`
+ },
+}
+
+/**
+ * The Codync row on a computer's card in Settings > Computers (iOS `HostVersionLine`): the version it
+ * runs, and an update when one is due, a newer release or a version too old for this app. `detail` is
+ * sentences, each its own phrase to translate; `accessory` is a spinner while the computer updates, or
+ * the button that asks it to.
+ */
+export interface HostVersionLine {
+ version: string
+ detail: string[]
+ warns: boolean
+ accessory: { kind: 'updating' } | { kind: 'button'; title: string } | null
+}
+
+/** `latest` is the latest release the computer found (null while it doesn't know: then no verdict). */
+export function hostVersionLine(version: string, latest: string | null | undefined, mismatch: VersionMismatch | null,
+ offer: HostUpdateOffer, host: string, os: string | null | undefined): HostVersionLine {
+ const line = (detail: string[], warns = false, accessory: HostVersionLine['accessory'] = null) => ({ version, detail, warns, accessory })
+ if (offer.kind === 'updating') return line([updateNeededText.updating(host)], false, { kind: 'updating' })
+ const minimum = mismatch?.kind === 'updateHost' ? mismatch.minimum : null
+ const available = latest && isBelow(version, latest) ? latest : null
+ const due = minimum ? `This app needs ${minimum} or newer.` : available ? `Version ${available} is available.` : null
+ if (!due) return line(latest ? ['Up to date'] : [])
+ if (offer.kind === 'unavailable') return line([due, updateNeededText.how(os)], minimum !== null)
+ if (offer.last) return line([updateNeededText.notUpdated(offer.last, host)], true, { kind: 'button', title: 'Try again' })
+ return line([due], minimum !== null, { kind: 'button', title: 'Update' })
+}
diff --git a/apps/desktop/src/renderer/store/bot-mirror.ts b/apps/desktop/src/renderer/store/bot-mirror.ts
index 76ac0765..38536d93 100644
--- a/apps/desktop/src/renderer/store/bot-mirror.ts
+++ b/apps/desktop/src/renderer/store/bot-mirror.ts
@@ -11,7 +11,7 @@ import {
} from '@shared/models'
import type { HostClient, HostRoute, HostTransport } from '../client/host-client'
import { rosterOrder } from '../lib/computer-roster'
-import { offerHostUpdate, type HostUpdate, type HostUpdateOffer } from '../lib/host-update'
+import { HOST_UPDATE_WAIT, hostVersionLine, offerHostUpdate, type HostUpdate, type HostUpdateOffer, type HostVersionLine } from '../lib/host-update'
import { Observable } from '../lib/observable'
import { ComposerDrafts } from '@shared/composer-drafts'
import { canLoadHistory } from '@shared/mirror-window'
@@ -111,6 +111,18 @@ export class BotMirror extends Observable {
return offerHostUpdate(this.hostUpdate, this.hello?.canUpdate === true)
}
+ /** This computer's Codync row at `now` (Settings > Computers); null until its `hello` arrives. */
+ hostVersionLine(now = Date.now()): HostVersionLine | null {
+ if (!this.hello) return null
+ return hostVersionLine(this.hello.version, this.hello.latestVersion, this.mismatch,
+ offerHostUpdate(this.hostUpdate, this.hello.canUpdate === true, now), this.hostName, this.hello.os)
+ }
+
+ /** When an update asked from here stops reading as under way; null when none was asked. */
+ get hostUpdateWaitEnds(): number | null {
+ return this.hostUpdate?.kind === 'requested' ? this.hostUpdate.at + HOST_UPDATE_WAIT : null
+ }
+
/** Roster order: the lead, then pinned bots, then where the user dragged them, then most recent activity. */
get roster(): Bot[] {
return [...this.bots.values()].filter((b) => !b.hidden).sort(rosterOrder)
diff --git a/apps/desktop/src/renderer/views/UpdateNeededCard.tsx b/apps/desktop/src/renderer/views/UpdateNeededCard.tsx
index f0974e9e..d2fb8945 100644
--- a/apps/desktop/src/renderer/views/UpdateNeededCard.tsx
+++ b/apps/desktop/src/renderer/views/UpdateNeededCard.tsx
@@ -1,39 +1,11 @@
-import type { VersionMismatch } from '@shared/compat'
import { Button } from '../components/Controls'
import { Icon } from '../components/Icon'
import { HStack, VStack } from '../components/Stack'
import { Text } from '../components/Text'
-import type { HostUpdate } from '../lib/host-update'
+import { updateNeededText } from '../lib/host-update'
import { useApp, useStore } from '../store/context'
import { UpdateButton, useUpdates } from './UpdateButton'
-/** The words every client uses for a version mismatch (iOS, the TUI and this app). */
-export const updateNeededText = {
- title(m: VersionMismatch, host: string) {
- return m.kind === 'updateApp' ? 'Update this app' : `Update Codync on ${host}`
- },
- detail(m: VersionMismatch, host: string, hostVersion: string | null | undefined, os: string | null | undefined, instructions = true) {
- if (m.kind === 'updateApp') {
- const runs = hostVersion ? `${host} runs Codync ${hostVersion} and` : host
- return `${runs} needs this app to be ${m.minimum} or newer. Your chats are safe on the computer.`
- }
- const how =
- os === 'macos' ? 'Open Codync on that Mac and choose Check for Updates.'
- : os === 'linux' ? 'Run codync-host update there.'
- : 'Update Codync on that computer.'
- const needs = `${host} runs Codync ${m.version}; this app needs ${m.minimum} or newer.`
- return instructions ? `${needs} ${how}` : needs
- },
- /** A computer updating at this app's request. */
- updating(host: string) {
- return `Updating Codync on ${host}. This takes a few minutes.`
- },
- /** Why the last update asked of the computer didn't take. */
- notUpdated(last: HostUpdate, host: string) {
- return last.kind === 'failed' ? last.message : `${host} didn't finish updating. Try again, or update Codync on that computer.`
- },
-}
-
/**
* Says which side has to update before this app and a computer can work together, and offers
* the update where this app can start it. Shown instead of the composer and above the bots.
diff --git a/apps/desktop/src/renderer/views/settings/ComputersView.tsx b/apps/desktop/src/renderer/views/settings/ComputersView.tsx
index 3efc082f..520bcbb1 100644
--- a/apps/desktop/src/renderer/views/settings/ComputersView.tsx
+++ b/apps/desktop/src/renderer/views/settings/ComputersView.tsx
@@ -1,7 +1,7 @@
-import { useCallback, useState } from 'react'
+import { useCallback, useEffect, useState } from 'react'
import type { AccountApproval, PairingInfo } from '@shared/models'
import { newSSHProfile, type SSHProfile } from '@shared/ssh'
-import { Button, CardSection, IconButton, Reveal, Switch } from '../../components/Controls'
+import { Button, CardSection, IconButton, Reveal, Spinner, Switch } from '../../components/Controls'
import { Icon } from '../../components/Icon'
import { Dialog, ModalHeader, Sheet, useDismiss } from '../../components/Overlay'
import { HStack, Spacer, VStack } from '../../components/Stack'
@@ -96,7 +96,7 @@ export function ComputersView() {
const isMacLabel = thisMac === 'this Mac' ? 'This Mac' : 'This computer'
-/** This computer or an SSH computer: relay, account membership, pairing and authorized devices. */
+/** This computer or an SSH computer: relay, account membership, the Codync it runs, pairing and authorized devices. */
function ManagedComputerCard({ store, ssh: overSSH }: { store: BotStore; ssh: boolean }) {
const tr = useTr()
const app = useApp()
@@ -217,6 +217,10 @@ function ManagedComputerCard({ store, ssh: overSSH }: { store: BotStore; ssh: bo
</Switch>,
]
: []),
+ // On macOS and Windows this computer's Codync is this app: its version and update are on the Updates page.
+ online && store.hello && !(store === app.local && window.codync.platform !== 'linux')
+ ? <CodyncVersionRow key="codync" store={store} />
+ : null,
]}
</CardSection>
@@ -249,6 +253,35 @@ function ManagedComputerCard({ store, ssh: overSSH }: { store: BotStore; ssh: bo
)
}
+/** The Codync a computer runs, and its update when one is due (iOS `CodyncVersionRow`). */
+function CodyncVersionRow({ store }: { store: BotStore }) {
+ const tr = useTr()
+ // Moved on when an update asked from here runs out of time, so one that never finished is offered again.
+ const [now, setNow] = useState(Date.now)
+ const ends = store.hostUpdateWaitEnds
+ useEffect(() => {
+ if (ends === null) return
+ const timer = setTimeout(() => setNow(Date.now()), Math.max(0, ends - Date.now()))
+ return () => clearTimeout(timer)
+ }, [ends])
+ const line = store.hostVersionLine(Math.max(now, Date.now()))
+ if (!line) return null
+ return (
+ <div className="settings-row settings-appear">
+ <Icon name="arrow.down.circle" size={13} color="var(--secondary)" />
+ <VStack grow className="settings-stack">
+ <Text>Codync <Text tone="secondary" tabular>{line.version}</Text></Text>
+ {line.detail.length > 0 ? (
+ <Text size="caption" tone={line.warns ? 'attention' : 'secondary'}>{line.detail.map((sentence) => tr(sentence)).join(' ')}</Text>
+ ) : null}
+ </VStack>
+ {line.accessory?.kind === 'updating' ? <Spinner />
+ : line.accessory ? <Button onClick={() => store.requestHostUpdate()}>{line.accessory.title}</Button>
+ : null}
+ </div>
+ )
+}
+
/** An account computer this app isn't authorized on, or one it uses under an earlier identity (`olderCopy`). */
function AccountComputerRow({ computer, olderCopy, onRemove }: { computer: CloudComputer; olderCopy: boolean; onRemove: () => void }) {
const tr = useTr()
diff --git a/apps/desktop/src/shared/models.ts b/apps/desktop/src/shared/models.ts
index d334e149..a5d71f42 100644
--- a/apps/desktop/src/shared/models.ts
+++ b/apps/desktop/src/shared/models.ts
@@ -469,6 +469,8 @@ export interface Hello {
minApp?: string
/** `installHostUpdate` can update this computer (absent before hosts could be updated from a client). */
canUpdate?: boolean
+ /** The latest release the computer found; null while unknown (development builds, Homebrew, Windows; absent from older hosts). */
+ latestVersion?: string | null
cloud?: string | null
/** Product analytics on this computer: on unless its owner turned it off. */
analytics?: boolean
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/de.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/de.json
index ca9db6c2..9749a940 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/de.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/de.json
@@ -1244,7 +1244,7 @@
"Search models": "Modelle suchen",
"No results": "Keine Ergebnisse",
"Up to date": "Aktuell",
- "{version} available": "{version} verfügbar",
+ "Version {version} is available.": "Version {version} ist verfügbar.",
"This app needs {version} or newer.": "Diese App benötigt {version} oder neuer.",
"Update": "Aktualisieren",
"Updating Codync on {name}. This takes a few minutes.": "Codync auf {name} wird aktualisiert. Das dauert ein paar Minuten.",
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/es.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/es.json
index c4e24d01..dfec0c44 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/es.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/es.json
@@ -1244,7 +1244,7 @@
"Search models": "Buscar modelos",
"No results": "Sin resultados",
"Up to date": "Actualizado",
- "{version} available": "{version} disponible",
+ "Version {version} is available.": "La versión {version} está disponible.",
"This app needs {version} or newer.": "Esta app necesita {version} o una versión más reciente.",
"Update": "Actualizar",
"Updating Codync on {name}. This takes a few minutes.": "Actualizando Codync en {name}. Tarda unos minutos.",
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/fr.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/fr.json
index 0d60e08a..7b05edff 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/fr.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/fr.json
@@ -1244,7 +1244,7 @@
"Search models": "Rechercher des modèles",
"No results": "Aucun résultat",
"Up to date": "À jour",
- "{version} available": "{version} disponible",
+ "Version {version} is available.": "La version {version} est disponible.",
"This app needs {version} or newer.": "Cette app nécessite {version} ou une version plus récente.",
"Update": "Mettre à jour",
"Updating Codync on {name}. This takes a few minutes.": "Mise à jour de Codync sur {name}. Cela prend quelques minutes.",
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ja.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ja.json
index 15ec8741..b0038091 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ja.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ja.json
@@ -1244,7 +1244,7 @@
"Search models": "モデルを検索",
"No results": "結果がありません",
"Up to date": "最新です",
- "{version} available": "{version} が利用可能",
+ "Version {version} is available.": "バージョン {version} が利用可能です。",
"This app needs {version} or newer.": "このアプリには {version} 以降が必要です。",
"Update": "アップデート",
"Updating Codync on {name}. This takes a few minutes.": "{name} の Codync をアップデート中です。数分かかります。",
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ko.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ko.json
index 148f60bc..0c8e3b8a 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ko.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/ko.json
@@ -1244,7 +1244,7 @@
"Search models": "모델 검색",
"No results": "결과 없음",
"Up to date": "최신 버전",
- "{version} available": "{version} 사용 가능",
+ "Version {version} is available.": "{version} 버전을 사용할 수 있습니다.",
"This app needs {version} or newer.": "이 앱에는 {version} 이상이 필요합니다.",
"Update": "업데이트",
"Updating Codync on {name}. This takes a few minutes.": "{name}에서 Codync를 업데이트하는 중입니다. 몇 분 정도 걸립니다.",
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hans.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hans.json
index 05b71d0c..e87380a2 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hans.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hans.json
@@ -1244,7 +1244,7 @@
"Search models": "搜索模型",
"No results": "没有结果",
"Up to date": "已是最新版本",
- "{version} available": "有新版本 {version}",
+ "Version {version} is available.": "有新版本 {version}。",
"This app needs {version} or newer.": "这个 App 需要 {version} 或更高版本。",
"Update": "更新",
"Updating Codync on {name}. This takes a few minutes.": "正在更新 {name} 上的 Codync,需要几分钟。",
diff --git a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hant.json b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hant.json
index d03f89a5..02a49691 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hant.json
+++ b/apps/ios/Kit/Sources/CodyncKit/Resources/Languages/zh-Hant.json
@@ -1244,7 +1244,7 @@
"Search models": "搜尋模型",
"No results": "沒有結果",
"Up to date": "已是最新版本",
- "{version} available": "有新版 {version}",
+ "Version {version} is available.": "有新版 {version}。",
"This app needs {version} or newer.": "這個 App 需要 {version} 或更新的版本。",
"Update": "更新",
"Updating Codync on {name}. This takes a few minutes.": "正在更新 {name} 上的 Codync,需要幾分鐘。",
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+HostUpdate.swift b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+HostUpdate.swift
index b1c55db5..a9d13d92 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+HostUpdate.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/BotStore+HostUpdate.swift
@@ -21,40 +21,53 @@ public enum HostUpdateOffer: Equatable, Sendable {
/// The Codync row on a computer's card in Computer management: the version it runs, and an update
/// when one is due (a newer release, or a version too old for this app).
public struct HostVersionLine: Equatable, Sendable {
+ /// What the row ends with: a spinner while the computer updates, or the button that asks it to.
+ public enum Accessory: Equatable, Sendable {
+ case updating
+ case button(String)
+ }
+
public var version: String
/// Sentences, each its own phrase to translate.
public var detail: [String]
/// The detail is a problem: the computer is too old for this app, or its update didn't take.
public var warns = false
- /// The button that asks the computer to update; nil when this phone can't, or it's updating.
- public var action: String?
- public var updating = false
+ /// Nil when there's nothing to update, or this phone can't update it.
+ public var accessory: Accessory?
/// `latest` is the latest release the computer found (nil while it doesn't know: then no verdict).
public static func make(version: String, latest: String?, mismatch: VersionMismatch?, offer: HostUpdateOffer,
host: String, os: String?) -> HostVersionLine {
- if offer == .updating { return HostVersionLine(version: version, detail: [UpdateNeededText.updating(host: host)], updating: true) }
let minimum: String? = if case let .updateHost(_, minimum) = mismatch { minimum } else { nil }
let available = latest.flatMap { AppVersion.isBelow(version, $0) ? $0 : nil }
- let due = minimum.map { "This app needs \($0) or newer." } ?? available.map { "\($0) available" }
- guard let due else { return HostVersionLine(version: version, detail: latest == nil ? [] : ["Up to date"]) }
- switch offer {
- case let .available(last?):
- return HostVersionLine(version: version, detail: [UpdateNeededText.notUpdated(last, host: host)], warns: true, action: "Try again")
- case .available(nil):
- return HostVersionLine(version: version, detail: [due], warns: minimum != nil, action: "Update")
- case .unavailable, .updating:
+ let due = minimum.map { "This app needs \($0) or newer." } ?? available.map { "Version \($0) is available." }
+ switch (offer, due) {
+ case (.updating, _):
+ return HostVersionLine(version: version, detail: [UpdateNeededText.updating(host: host)], accessory: .updating)
+ case (_, nil):
+ return HostVersionLine(version: version, detail: latest == nil ? [] : ["Up to date"])
+ case let (.available(last?), _?):
+ return HostVersionLine(version: version, detail: [UpdateNeededText.notUpdated(last, host: host)], warns: true,
+ accessory: .button("Try again"))
+ case let (.available(nil), due?):
+ return HostVersionLine(version: version, detail: [due], warns: minimum != nil, accessory: .button("Update"))
+ case let (.unavailable, due?):
return HostVersionLine(version: version, detail: [due, UpdateNeededText.how(os: os)], warns: minimum != nil)
}
}
}
extension BotStore {
- /// This computer's Codync row; nil until its `hello` arrives.
- public var hostVersionLine: HostVersionLine? {
+ /// This computer's Codync row at `now`; nil until its `hello` arrives.
+ public func hostVersionLine(now: Date = .now) -> HostVersionLine? {
guard let hello else { return nil }
return .make(version: hello.version, latest: hello.latestVersion, mismatch: mismatch,
- offer: hostUpdateOffer(), host: hostName, os: hello.os)
+ offer: hostUpdateOffer(now: now), host: hostName, os: hello.os)
+ }
+
+ /// When an update asked from here stops reading as under way; nil when none was asked.
+ public var hostUpdateWaitEnds: Date? {
+ if case let .requested(at) = hostUpdate { at + Self.hostUpdateWait } else { nil }
}
/// How long an update may take before the notice offers it again.
diff --git a/apps/ios/Kit/Tests/CodyncUITests/HostUpdateTests.swift b/apps/ios/Kit/Tests/CodyncUITests/HostUpdateTests.swift
index 85df6b09..056196e1 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/HostUpdateTests.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/HostUpdateTests.swift
@@ -50,21 +50,46 @@ import Testing
#expect(line("2.27.0", .available(last: nil)).detail == ["Up to date"])
// A computer that doesn't know the latest release makes no claim.
#expect(line(nil, .available(last: nil)) == HostVersionLine(version: "2.28.0", detail: []))
- #expect(line("2.29.0", .available(last: nil)) == HostVersionLine(version: "2.28.0", detail: ["2.29.0 available"], action: "Update"))
+ #expect(line("2.29.0", .available(last: nil))
+ == HostVersionLine(version: "2.28.0", detail: ["Version 2.29.0 is available."], accessory: .button("Update")))
// Not from here: it says how, on that computer.
- #expect(line("2.29.0", .unavailable).detail == ["2.29.0 available", "Open Codync on that Mac and choose Check for Updates."])
- #expect(line("2.29.0", .unavailable).action == nil)
- #expect(line("2.29.0", .updating) == HostVersionLine(version: "2.28.0", detail: ["Updating Codync on Mac. This takes a few minutes."],
- updating: true))
+ #expect(line("2.29.0", .unavailable)
+ == HostVersionLine(version: "2.28.0", detail: ["Version 2.29.0 is available.", "Open Codync on that Mac and choose Check for Updates."]))
+ #expect(line("2.29.0", .updating)
+ == HostVersionLine(version: "2.28.0", detail: ["Updating Codync on Mac. This takes a few minutes."], accessory: .updating))
}
@Test func aComputerTooOldOrAnUpdateThatDidntTakeIsAProblem() {
let behind = VersionMismatch.updateHost(version: "2.20.0", minimum: "2.26.0")
let old = HostVersionLine.make(version: "2.20.0", latest: nil, mismatch: behind, offer: .available(last: nil), host: "Mac", os: "linux")
- #expect(old == HostVersionLine(version: "2.20.0", detail: ["This app needs 2.26.0 or newer."], warns: true, action: "Update"))
+ #expect(old == HostVersionLine(version: "2.20.0", detail: ["This app needs 2.26.0 or newer."], warns: true, accessory: .button("Update")))
let manual = HostVersionLine.make(version: "2.20.0", latest: "2.29.0", mismatch: behind, offer: .unavailable, host: "Mac", os: "linux")
#expect(manual.detail == ["This app needs 2.26.0 or newer.", "Run codync-host update there."] && manual.warns)
let failed = HostVersionLine.make(version: "2.28.0", latest: "2.29.0", mismatch: nil,
offer: .available(last: .failed("A bot is working on this computer.")), host: "Mac", os: "macos")
- #expect(failed == HostVersionLine(version: "2.28.0", detail: ["A bot is working on this computer."], warns: true, action: "Try again"))
+ #expect(failed == HostVersionLine(version: "2.28.0", detail: ["A bot is working on this computer."], warns: true,
+ accessory: .button("Try again")))
+ // Asked, but the computer never came back updated.
+ let stalled = HostVersionLine.make(version: "2.28.0", latest: "2.29.0", mismatch: nil,
+ offer: .available(last: .requested(at: .now)), host: "Mac", os: "macos")
+ #expect(stalled == HostVersionLine(version: "2.28.0", detail: ["Mac didn't finish updating. Try again, or update Codync on that computer."],
+ warns: true, accessory: .button("Try again")))
+}
+
+@MainActor @Test func theCodyncRowComparesWithTheLatestReleaseTheComputerFound() async throws {
+ let (storage, suite) = context()
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ let fake = FakeRemote(.ready(.relay))
+ await fake.setHello(helloJSON(version: "2.28.0", canUpdate: true, latestVersion: "2.30.0"))
+ let store = BotStore(computer: randomComputer("Mac"), storage: storage, appVersion: VersionMismatch.minHost) { _ in fake }
+ defer { store.retire() }
+ store.setActive(true)
+ #expect(await until { store.hello != nil })
+ #expect(store.hostVersionLine()
+ == HostVersionLine(version: "2.28.0", detail: ["Version 2.30.0 is available."], accessory: .button("Update")))
+ // Asked, the row shows it under way until the wait is over, then offers it again.
+ store.requestHostUpdate()
+ #expect(store.hostVersionLine()?.accessory == .updating)
+ let ends = try #require(store.hostUpdateWaitEnds)
+ #expect(store.hostVersionLine(now: ends)?.accessory == .button("Try again"))
}
diff --git a/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift b/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift
index d5756a7d..747053d4 100644
--- a/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift
+++ b/apps/ios/Kit/Tests/CodyncUITests/StoreTests.swift
@@ -638,9 +638,11 @@ extension FakeRemote {
// MARK: - Version compatibility (docs/reference/compatibility.md)
-func helloJSON(version: String, minApp: String? = nil, backends: String = "[]", canUpdate: Bool = false) -> String {
+func helloJSON(version: String, minApp: String? = nil, backends: String = "[]", canUpdate: Bool = false,
+ latestVersion: String? = nil) -> String {
let min = minApp.map { #","minApp":"\#($0)""# } ?? ""
- return #"{"hostId":"h1","name":"Mac","version":"\#(version)"\#(min),"os":"macos","backends":\#(backends),"rev":0,"canUpdate":\#(canUpdate)}"#
+ let latest = latestVersion.map { #","latestVersion":"\#($0)""# } ?? ""
+ return #"{"hostId":"h1","name":"Mac","version":"\#(version)"\#(min)\#(latest),"os":"macos","backends":\#(backends),"rev":0,"canUpdate":\#(canUpdate)}"#
}
@MainActor @Test func hostNeedingANewerAppStopsSyncAndAsksForTheUpdate() async throws {
diff --git a/apps/ios/Views/ComputersView.swift b/apps/ios/Views/ComputersView.swift
index b2f9ca95..7cf6752e 100644
--- a/apps/ios/Views/ComputersView.swift
+++ b/apps/ios/Views/ComputersView.swift
@@ -141,7 +141,7 @@ struct ComputersView: View {
/// A computer this iPhone can use, as the rows of its card: its connection and whether it's in the account,
/// then Extensions, Voice chat (its keys live on the computer), Screen, whether it sends push alerts here,
-/// how it's reached and, for a stale pairing, Remove.
+/// how it's reached, the Codync it runs (and its update) and, for a stale pairing, Remove.
private struct ComputerRows: View {
let store: BotStore
let inAccount: CloudComputer?
@@ -174,8 +174,8 @@ private struct ComputerRows: View {
}
.toggleStyle(.codync)
connection
- if store.connection == .online, let line = store.hostVersionLine {
- CodyncVersionRow(line: line, update: store.requestHostUpdate)
+ if store.connection == .online, store.hello != nil {
+ CodyncVersionRow(store: store)
}
if accounts.isStale(store.computer.id), inAccount == nil {
Button(action: remove) { RowLabel("Remove", systemImage: "trash", tint: Palette.danger) }
@@ -278,32 +278,41 @@ private struct ComputerRows: View {
/// The Codync a computer runs, and its update when one is due (`HostVersionLine`).
private struct CodyncVersionRow: View {
- let line: HostVersionLine
- let update: () -> Void
+ let store: BotStore
+ /// Moved on when an update asked from here runs out of time, so one that never finished is offered again.
+ @State private var now = Date.now
var body: some View {
- HStack(spacing: 12) {
- Image(systemName: "arrow.down.circle").font(.system(size: 17)).frame(width: 26)
- VStack(alignment: .leading, spacing: 3) {
- HStack(spacing: 8) {
- Text(verbatim: "Codync")
- Text(verbatim: line.version).foregroundStyle(Palette.secondary).monospacedDigit()
+ if let line = store.hostVersionLine(now: max(now, .now)) {
+ HStack(spacing: 12) {
+ Image(systemName: "arrow.down.circle").font(.system(size: 17)).frame(width: 26)
+ VStack(alignment: .leading, spacing: 3) {
+ HStack(spacing: 8) {
+ Text(verbatim: "Codync")
+ Text(verbatim: line.version).foregroundStyle(Palette.secondary).monospacedDigit()
+ }
+ if !line.detail.isEmpty {
+ Text(line.detail.map { L10n.tr($0) }.joined(separator: " "))
+ .font(.footnote)
+ .foregroundStyle(line.warns ? Palette.warning : Palette.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
}
- if !line.detail.isEmpty {
- Text(line.detail.map { L10n.tr($0) }.joined(separator: " "))
- .font(.footnote)
- .foregroundStyle(line.warns ? Palette.warning : Palette.secondary)
- .fixedSize(horizontal: false, vertical: true)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ switch line.accessory {
+ case .updating: Spinner(size: 16)
+ case let .button(title): Button(L10n.tr(title), action: store.requestHostUpdate).buttonStyle(.primary)
+ case nil: EmptyView()
}
}
- .frame(maxWidth: .infinity, alignment: .leading)
- if line.updating { Spinner(size: 16) }
- if let action = line.action {
- Button(L10n.tr(action), action: update).buttonStyle(.primary)
+ .foregroundStyle(Palette.text)
+ .animation(Motion.layout, value: line)
+ .task(id: store.hostUpdateWaitEnds) {
+ guard let ends = store.hostUpdateWaitEnds else { return }
+ try? await Task.sleep(for: .seconds(ends.timeIntervalSinceNow))
+ now = .now
}
}
- .foregroundStyle(Palette.text)
- .animation(Motion.layout, value: line)
}
}
diff --git a/docs/design/ui-conventions.md b/docs/design/ui-conventions.md
index 0bb66aa0..555675a7 100644
--- a/docs/design/ui-conventions.md
+++ b/docs/design/ui-conventions.md
@@ -48,7 +48,7 @@ Usage row shows no number; it opens Settings' Usage page with the same per-provi
## Account menu and Settings (desktop)
-The chat window's account menu copies Grok Bot's: Usage, Get Codync for mobile, Support, Settings, then the signed-in account and Sign out. Everything else is a page of **Settings**, laid out like ChatGPT's desktop settings (references in `reference/chatgpt-settings-*.png`): a sidebar of pages under small group labels (Personal: General, Voice chat, Usage; This Mac, or This computer on Linux: Computers, Updates) and a large page title over the page's sections. Manage computers and approval badges lead to the Computers page. The phone apps' Settings tab (iPhone and Android), to the right of State in the same bar, holds only what belongs to the phone itself: appearance, language, thinking details, notification permission, usage analytics and Start over. Anything that belongs to one computer lives in Computer management, the sheet Manage computers and links open: one card per computer with its name and status, then Extensions, Voice chat (its keys live on that computer), Screen, Push notifications (whether that computer alerts this phone), Connection and Codync as rows (Connection shows the route's short name, its menu the whole route; Codync shows the version the computer runs, whether it's up to date, and **Update** when a newer release is out or this app needs one), then Hidden bots, and Pair a computer in a card of its own. Source: `apps/desktop/src/renderer/views/settings/SettingsView.tsx`, account menu in `apps/desktop/src/renderer/views/PanelMenus.tsx`.
+The chat window's account menu copies Grok Bot's: Usage, Get Codync for mobile, Support, Settings, then the signed-in account and Sign out. Everything else is a page of **Settings**, laid out like ChatGPT's desktop settings (references in `reference/chatgpt-settings-*.png`): a sidebar of pages under small group labels (Personal: General, Voice chat, Usage; This Mac, or This computer on Linux: Computers, Updates) and a large page title over the page's sections. Manage computers and approval badges lead to the Computers page. The phone apps' Settings tab (iPhone and Android), to the right of State in the same bar, holds only what belongs to the phone itself: appearance, language, thinking details, notification permission, usage analytics and Start over. Anything that belongs to one computer lives in Computer management, the sheet Manage computers and links open: one card per computer with its name and status, then Extensions, Voice chat (its keys live on that computer), Screen, Push notifications (whether that computer alerts this phone), Connection and Codync as rows (Connection shows the route's short name, its menu the whole route; Codync shows the version the computer runs, whether it's up to date, and **Update** when a newer release is out or this app needs one), then Hidden bots, and Pair a computer in a card of its own. The desktop's Computers page shows the same Codync row on each SSH computer's card, and on this computer's on Linux (on macOS and Windows this computer's Codync is the app, on the Updates page). Source: `apps/desktop/src/renderer/views/settings/SettingsView.tsx`, account menu in `apps/desktop/src/renderer/views/PanelMenus.tsx`.
## iPhone and desktop code
diff --git a/docs/guides/updates.md b/docs/guides/updates.md
index 33c38ccd..9610d3ac 100644
--- a/docs/guides/updates.md
+++ b/docs/guides/updates.md
@@ -188,12 +188,15 @@ The API operations `hostUpdateStatus`, `checkHostUpdate` and `setHostAutomaticUp
require a local connection, including an SSH tunnel.
`installHostUpdate` is also open to paired devices: it's what a client's **Update now**
-calls when a computer is too old for it, and what **Update** on the computer's Codync row in
-the phones' Computer management calls. That row compares `hello.version` with
-`hello.latestVersion`, the latest release `update::release_watch` looks up at start and every
-6 hours whatever installed the host (release builds only; null until a lookup succeeds, and on
-Windows, which has no host update manifests), so it says *Up to date*, *2.29.0 available*, or
-nothing when the computer doesn't know. `hello.canUpdate` says whether it can work there:
+calls when a computer is too old for it, and what **Update** on the computer's Codync row
+calls: in the phones' Computer management, and in the desktop's Settings > Computers for SSH
+computers (and this computer on Linux; on macOS and Windows this computer's Codync is the app,
+on its Updates page). That row compares `hello.version` with `hello.latestVersion`, the latest
+release `update::release_watch` looks up at start and every 6 hours (a failed lookup is tried
+again after 1, 5, 25, then every 30 minutes), and `checkHostUpdate` records too. It's null on
+development builds, until a lookup succeeds, on Windows (no host update manifests), and on a
+Homebrew host, which `brew` updates; then the row shows only the version. Otherwise it says
+*Up to date* or *Version 2.29.0 is available.* `hello.canUpdate` says whether it can work there:
a release host the installed service runs, or one the desktop app bundles while that app is
open (it polls `/health?app=true` every 5 seconds; `canUpdate` needs a poll in the last 15).
Both cases are decided in one place, `update::route`. A standalone host schedules the
diff --git a/docs/reference/compatibility.md b/docs/reference/compatibility.md
index 095f6dfe..5f2f41e4 100644
--- a/docs/reference/compatibility.md
+++ b/docs/reference/compatibility.md
@@ -32,7 +32,7 @@ reason to lock someone out.
|---|---|---|
| Notice | `UpdateNeededCard` above the computer's bots and in place of the composer; status reads *Needs update* | *needs update* in the status line, with the reason |
| Update this app | iPhone: App Store page. Desktop: electron-updater check (`apps/desktop/src/main/updates.ts`). Android: text only | Text only |
-| Update the host | Desktop on macOS and Windows, its own computer: the bundled host is reinstalled (**Update now**). Any computer whose `hello` has `canUpdate` (the Linux desktop's own too): **Update now** calls `installHostUpdate` ([updates](../guides/updates.md#standalone-hosts-on-linux-and-macos)), and the notice reads *Updating Codync on …* until the host comes back newer, or for 10 minutes; then it offers the update again with why. Otherwise: instructions for that computer. The phones also offer it, and any newer release (`hello.latestVersion`), on the Codync row of the computer's card in Computer management | `^k` → Check for updates |
+| Update the host | Desktop on macOS and Windows, its own computer: the bundled host is reinstalled (**Update now**). Any computer whose `hello` has `canUpdate` (the Linux desktop's own too): **Update now** calls `installHostUpdate` ([updates](../guides/updates.md#standalone-hosts-on-linux-and-macos)), and the notice reads *Updating Codync on …* until the host comes back newer, or for 10 minutes; then it offers the update again with why. Otherwise: instructions for that computer. The phones also offer it, and any newer release (`hello.latestVersion`), on the Codync row of the computer's card in Computer management; the desktop on SSH computers' cards in Settings > Computers | `^k` → Check for updates |
| Sync while mismatched | Stopped; `hello` is asked again every 30 s (5 s while an update asked from here runs) and on every reconnect | Continues; sending is blocked |
Drafts are kept while sending is blocked. A host update restarts the host, so the reconnect
diff --git a/host/src/api/host.rs b/host/src/api/host.rs
index a686469d..2ada0277 100644
--- a/host/src/api/host.rs
+++ b/host/src/api/host.rs
@@ -69,7 +69,7 @@ pub(super) async fn call(hub: &Arc<Hub>, caller: &Caller, method: &str, b: Value
// Whether `installHostUpdate` can update this computer, from here or a phone.
"canUpdate": tokio::task::spawn_blocking(crate::update::installable).await?,
// The latest release, so a phone can say whether this computer is current (null: unknown).
- "latestVersion": crate::update::latest_version(),
+ "latestVersion": tokio::task::spawn_blocking(crate::update::latest_version).await?,
"os": std::env::consts::OS,
"device": tokio::task::spawn_blocking(crate::service::device).await?,
"home": dirs::home_dir().map(|p| p.to_string_lossy().into_owned()),
diff --git a/host/src/update/mod.rs b/host/src/update/mod.rs
index b8f57705..2d9238b2 100644
--- a/host/src/update/mod.rs
+++ b/host/src/update/mod.rs
@@ -95,27 +95,46 @@ fn route(executable: &Path) -> Result<Route> {
Ok(Route::App)
}
-/// The latest release `release_watch` found, whatever installed this host.
+/// The latest release a lookup found, whatever installed this host (`latest_version`).
static LATEST: Mutex<Option<String>> = Mutex::new(None);
+fn note_latest(version: &str) {
+ *LATEST.locked() = Some(version.to_owned());
+}
+
/// The latest release for this platform (`hello.latestVersion`), so a phone can say whether this computer is
-/// current and offer the update; None until a lookup succeeds, and always on development builds.
+/// current and offer the update. None until a lookup succeeds and on development builds; also on a host
+/// Homebrew owns, which `brew` updates.
pub fn latest_version() -> Option<String> {
- LATEST.locked().clone()
+ let homebrew = service::current_exe().is_ok_and(|exe| install::method(&exe) == install::Method::Homebrew);
+ LATEST.locked().clone().filter(|_| !homebrew)
}
-/// Looks up the latest release at start and every 6 hours, for `latest_version`. Release builds only:
-/// a development host never offers a release.
+/// Looks up the latest release at start and every 6 hours, for `latest_version`; a failed lookup (offline
+/// at login, GitHub unreachable) is tried again sooner, from a minute up to every 30 minutes. Release builds
+/// on platforms with releases only: a development host never offers one.
pub async fn release_watch() {
- if crate::environment::Environment::current() != crate::environment::Environment::Main {
+ if crate::environment::Environment::current() != crate::environment::Environment::Main
+ || release::platform().is_err()
+ {
return;
}
+ let mut retry = Duration::from_mins(1);
loop {
- match release::latest().await {
- Ok(release) => *LATEST.locked() = Some(release.version),
- Err(error) => tracing::debug!(error = format!("{error:#}"), "latest release lookup failed"),
- }
- tokio::time::sleep(Duration::from_hours(6)).await;
+ let wait = match release::latest().await {
+ Ok(release) => {
+ note_latest(&release.version);
+ retry = Duration::from_mins(1);
+ Duration::from_hours(6)
+ }
+ Err(error) => {
+ tracing::debug!(error = format!("{error:#}"), "latest release lookup failed");
+ let wait = retry;
+ retry = (retry * 5).min(Duration::from_mins(30));
+ wait
+ }
+ };
+ tokio::time::sleep(wait).await;
}
}
@@ -212,6 +231,7 @@ pub async fn check() -> Result<Value> {
state.checked_at = Some(crate::store::now_ms());
match release::latest().await {
Ok(release) => {
+ note_latest(&release.version);
let available = (semver::Version::parse(&release.version)?
> semver::Version::parse(env!("CARGO_PKG_VERSION"))?)
.then_some(release.version);
diff --git a/web/content/docs/updates.mdx b/web/content/docs/updates.mdx
index 66b8b251..6ae961fb 100644
--- a/web/content/docs/updates.mdx
+++ b/web/content/docs/updates.mdx
@@ -45,9 +45,13 @@ codync-host update --auto off # turn automatic updates off (on to turn them bac
A manual update won't interrupt a bot that's working unless you add `--force`; interrupted bots pick up their sessions again. In the terminal UI, press `^k` and choose **Check for updates**.
-## Update a computer from your phone
+## A computer's version and its update
-On the iPhone or Android, tap the connection status at the top of the Bots tab (such as **1 connected**), choose **Manage computers**, and look at **Codync** at the bottom of the computer's card. It shows the version that computer runs, and says **Up to date** or which newer version is available. Tap **Update** to have the computer download it and restart into it, usually within a few minutes; the row says it's updating until the computer is back. It's the same update as **Update now** on the notice [below](#when-the-phone-and-computer-versions-dont-match), with the same rules: a computer doesn't update while a bot is working on it, and a Mac or Windows computer updates this way while the Codync app is open on it. When the computer can't be updated from your phone, the row says how to do it there.
+On the iPhone, tap the connection status at the top of the Bots tab (such as **1 connected**), choose **Manage computers**, and look at **Codync** at the bottom of the computer's card. It shows the version that computer runs, and says **Up to date** or which newer version is available. Tap **Update** to have the computer download it and restart into it, usually within a few minutes; the row says it's updating until the computer is back. It's the same update as **Update now** on the notice [below](#when-the-phone-and-computer-versions-dont-match), with the same rules: a computer doesn't update while a bot is working on it, and a Mac or Windows computer updates this way while the Codync app is open on it. When the computer can't be updated from your phone, the row says how to do it there.
+
+A Windows computer shows only its version there, with **Update** only when this app needs a newer Codync; otherwise it updates with its desktop app. A host installed with Homebrew also shows only its version: update it with `brew` ([above](#the-host-on-its-own)).
+
+**Desktop:** **Settings → Computers** shows the same **Codync** row on the card of each computer you reach over SSH, and on Linux on this computer's card too. On macOS and Windows this computer's Codync is the desktop app itself, updated from **Settings → Updates**.
## The iPhone app