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(desktop): show progress while refreshing computers

leepokaidefc66534e79
diff --git a/apps/desktop/src/renderer/lib/refresh.test.ts b/apps/desktop/src/renderer/lib/refresh.test.ts
new file mode 100644
index 00000000..a4816c00
--- /dev/null
+++ b/apps/desktop/src/renderer/lib/refresh.test.ts
@@ -0,0 +1,107 @@
+import assert from 'node:assert/strict'
+import ts from 'typescript'
+import { existsSync, readFileSync } from 'node:fs'
+import { registerHooks } from 'node:module'
+import { test } from 'node:test'
+import type { BotStore } from '../store/bot-store'
+import type { HostTransport } from '../client/host-client'
+
+registerHooks({ resolve(specifier, context, nextResolve) {
+ if (specifier.startsWith('@shared/')) return nextResolve(new URL(`../../shared/${specifier.slice(8)}.ts`, import.meta.url).href, context)
+ if (specifier.startsWith('.') && context.parentURL && !/\.[a-z]+$/.test(specifier)) {
+ const url = new URL(`${specifier}.ts`, context.parentURL)
+ if (existsSync(url)) return nextResolve(url.href, context)
+ }
+ return nextResolve(specifier, context)
+}, load(url, context, nextLoad) {
+ if (url.endsWith('.ts')) return { format: 'module', shortCircuit: true, source: ts.transpileModule(readFileSync(new URL(url), 'utf8'), { compilerOptions: { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext } }).outputText }
+ return nextLoad(url, context)
+} })
+
+const storage = new Map<string, string>()
+Object.assign(globalThis, {
+ localStorage: { getItem: (key: string) => storage.get(key) ?? null, setItem: (key: string, value: string) => storage.set(key, value), removeItem: (key: string) => storage.delete(key) },
+ window: { addEventListener() {}, codync: { appVersion: '2.29.0' } },
+})
+const { AppModel } = await import('../store/app-model.ts')
+const { BotSync } = await import('../store/bot-sync.ts')
+
+function deferred() {
+ let resolve!: () => void
+ const promise = new Promise<void>((r) => { resolve = r })
+ return { promise, resolve }
+}
+
+test('refresh is visible immediately, ignores repeat shortcuts, and waits for computers and cloud', async () => {
+ const app = new AppModel(false)
+ const computer = deferred()
+ const cloud = deferred()
+ let calls = 0
+ app.stores.set('test', { refreshStream: () => { calls++; return computer.promise } } as unknown as BotStore)
+ app.cloud.refresh = async () => { await cloud.promise; return true }
+ const refreshing = app.refresh()
+ assert.equal(app.refreshing, true)
+ await app.refresh()
+ assert.equal(calls, 1)
+ computer.resolve()
+ await new Promise((r) => setTimeout(r, 650))
+ assert.equal(app.refreshing, true)
+ cloud.resolve()
+ await refreshing
+ assert.equal(app.refreshing, false)
+})
+
+test('a failed refresh clears loading, reports the failure and can be retried', async () => {
+ const app = new AppModel(false)
+ app.stores.set('test', { refreshStream: () => Promise.reject(new Error('Offline')) } as unknown as BotStore)
+ await app.refresh()
+ assert.equal(app.refreshing, false)
+ assert.equal(app.lastError, 'Offline')
+ app.stores.clear()
+ app.clearErrors()
+ await app.refresh()
+ assert.equal(app.refreshing, false)
+ assert.equal(app.lastError, null)
+})
+
+function sync(transport: HostTransport) {
+ return new BotSync({ id: 'test', name: 'Test', signKey: '', urls: [] }, false, () => transport)
+}
+
+test('an already-online computer stays refreshing until the replacement stream answers', async () => {
+ let receive!: (line: string) => void
+ const ready = deferred()
+ const store = sync({
+ call: async () => ({ version: '2.29.0', name: 'Test', backends: [] }),
+ stream: (_path, onData) => { receive = onData; ready.resolve(); return () => {} },
+ })
+ store.connection = { kind: 'online' }
+ let completed = false
+ const refresh = store.refreshStream().then(() => { completed = true })
+ await ready.promise
+ assert.equal(completed, false)
+ receive(JSON.stringify({ type: 'usage', usage: { providers: [] } }))
+ await refresh
+ assert.equal(completed, true)
+ store.retire()
+})
+
+test('a host failure and a removed computer both release the refresh waiter', async () => {
+ const failing = sync({ call: async () => { throw new Error('Unavailable') }, stream: () => () => {} })
+ await assert.rejects(failing.refreshStream(), /Unavailable/)
+ failing.retire()
+ const removed = sync({ call: () => new Promise(() => {}), stream: () => () => {} })
+ const refresh = removed.refreshStream()
+ removed.retire()
+ await refresh
+})
+
+test('an unresponsive host cannot leave manual refresh spinning forever', async (t) => {
+ t.mock.timers.enable({ apis: ['setTimeout'] })
+ const store = sync({ call: () => new Promise(() => {}), stream: () => () => {} })
+ const refresh = store.refreshStream()
+ const rejected = assert.rejects(refresh, /Connection timed out/)
+ t.mock.timers.tick(20_000)
+ await rejected
+ store.retire()
+})
diff --git a/apps/desktop/src/renderer/store/app-model.ts b/apps/desktop/src/renderer/store/app-model.ts
index df20173a..24d80d76 100644
--- a/apps/desktop/src/renderer/store/app-model.ts
+++ b/apps/desktop/src/renderer/store/app-model.ts
@@ -46,6 +46,7 @@ export class AppModel extends Observable {
computers: Computer[] = []
stores = new Map<string, BotStore>()
selection: BotRef | null = null
+ refreshing = false
lastError: string | null = null
/** Codync Screen waits for the user to allow it in System Settings → Login Items. */
screenNeedsApproval = false
@@ -141,9 +142,23 @@ export class AppModel extends Observable {
}
/** ⌘R, as the iPhone's pull to refresh: reconnect every computer and reload the account's computers. */
- refresh() {
- for (const store of this.stores.values()) store.restartStream()
- void this.cloud.refresh()
+ async refresh() {
+ if (this.refreshing) return
+ this.refreshing = true
+ this.changed()
+ try {
+ // Keep even a local refresh visible long enough to acknowledge the shortcut.
+ const results = await Promise.allSettled([
+ new Promise((resolve) => setTimeout(resolve, 600)),
+ ...[...this.stores.values()].map((store) => store.refreshStream()),
+ this.cloud.refresh(),
+ ])
+ const failure = results.find((result) => result.status === 'rejected')
+ if (failure?.status === 'rejected') this.setError(String(failure.reason instanceof Error ? failure.reason.message : failure.reason))
+ } finally {
+ this.refreshing = false
+ this.changed()
+ }
}
store(id: string) {
diff --git a/apps/desktop/src/renderer/store/bot-sync.ts b/apps/desktop/src/renderer/store/bot-sync.ts
index 31c2c8d9..dbc26721 100644
--- a/apps/desktop/src/renderer/store/bot-sync.ts
+++ b/apps/desktop/src/renderer/store/bot-sync.ts
@@ -5,6 +5,7 @@ import { BotMirror, type Connection } from './bot-mirror'
import { Artifacts } from './artifacts'
import type { CallCue } from '@shared/calls'
+const REFRESH_TIMEOUT = 20_000
const DROP_GRACE = 5000
const INITIAL_GRACE = 1000
const ACTION_PATIENCE = 20_000
@@ -35,6 +36,7 @@ export class BotSync extends BotMirror {
readonly callCues = new Map<string, (cue: CallCue) => void>()
/** The newest cue each call heard (`CallCue.seq`), kept across engine switches: a replayed one isn't said again. */
private readonly heardCues = new Map<string, number>()
+ private finishRefresh: ((error?: Error) => void) | null = null
private heldDrop: Connection | null = null
private dropTimer: ReturnType<typeof setTimeout> | null = null
private closeEvents: (() => void) | null = null
@@ -72,7 +74,23 @@ export class BotSync extends BotMirror {
this.runEvents(this.client)
}
+ /** Manual refresh waits for the new stream to answer, independently of the online grace period. */
+ refreshStream(): Promise<void> {
+ if (this.retired) return Promise.resolve()
+ this.restartStream()
+ return new Promise((resolve, reject) => {
+ const timer = setTimeout(() => this.finishRefresh?.(new Error('Connection timed out')), REFRESH_TIMEOUT)
+ this.finishRefresh = (error) => {
+ clearTimeout(timer)
+ this.finishRefresh = null
+ if (error) reject(error)
+ else resolve()
+ }
+ })
+ }
+
private stopTransport() {
+ this.finishRefresh?.()
this.eventsLoop++
this.closeEvents?.()
this.closeEvents = null
@@ -123,6 +141,7 @@ export class BotSync extends BotMirror {
await this.refreshHello(client)
if (!alive()) return
if (this.mismatch) {
+ this.finishRefresh?.()
this.setConnection({ kind: 'online' })
await sleep(this.hostUpdateOffer.kind === 'updating' ? UPDATE_RECHECK : MISMATCH_RECHECK)
return void attempt()
@@ -148,6 +167,7 @@ export class BotSync extends BotMirror {
this.setConnection({ kind: 'online' })
backoff = 1000
this.apply(event)
+ this.finishRefresh?.()
},
(error) => (error ? reject(error) : resolve()),
)
@@ -155,6 +175,7 @@ export class BotSync extends BotMirror {
} catch (error) {
if (!alive()) return
const message = error instanceof Error ? error.message : String(error)
+ this.finishRefresh?.(new Error(message))
this.setConnection({ kind: 'offline', message })
if (error instanceof HostError && error.status === 401) return
}
diff --git a/apps/desktop/src/renderer/views/ChatWindow.tsx b/apps/desktop/src/renderer/views/ChatWindow.tsx
index c3bd444b..604cfbc9 100644
--- a/apps/desktop/src/renderer/views/ChatWindow.tsx
+++ b/apps/desktop/src/renderer/views/ChatWindow.tsx
@@ -33,6 +33,7 @@ import { ComputerAccessView } from './computer-access/ComputerAccessView'
import { HostStateView } from './HostStateView'
import { StartupRecovery } from './StartupRecovery'
export { EmptyState } from './HostStateView'
+import { RefreshIndicator } from './RefreshIndicator'
import { StarPrompt } from './StarPrompt'
import { OpenVoiceSettings } from './call/CallView'
import { AccountPanelLayer, DesktopActionMenu, ProfileAvatar } from './PanelMenus'
@@ -90,7 +91,7 @@ export function ChatWindow() {
return
}
case 'refresh':
- return app.refresh()
+ return void app.refresh()
case 'setRemoteScreen':
void app.setRemoteScreen(c.on)
return
@@ -115,6 +116,7 @@ export function ChatWindow() {
return (
<div className="chat-window">
<Summaries />
+ <RefreshIndicator />
{onboarded ? (
accessSetup === null ? (
<ComputerAccessView onContinue={(ready) => finishAccess(ready, true)} />
diff --git a/apps/desktop/src/renderer/views/RefreshIndicator.tsx b/apps/desktop/src/renderer/views/RefreshIndicator.tsx
new file mode 100644
index 00000000..395b0d76
--- /dev/null
+++ b/apps/desktop/src/renderer/views/RefreshIndicator.tsx
@@ -0,0 +1,23 @@
+import { Spinner } from '../components/Controls'
+import { usePresence } from '../components/Overlay'
+import { HStack } from '../components/Stack'
+import { Text } from '../components/Text'
+import { useTr } from '../lib/use-language'
+import { useApp } from '../store/context'
+import './refresh-indicator.css'
+
+/** Window-wide feedback also stays visible when the sidebar is collapsed. */
+export function RefreshIndicator() {
+ const app = useApp()
+ const tr = useTr()
+ const { mounted, shown } = usePresence(app.refreshing, 120)
+ if (!mounted) return null
+ return (
+ <div className={`refresh-indicator ${shown ? 'shown' : ''}`} role="status" aria-live="polite">
+ <HStack gap={8}>
+ <Spinner size={14} />
+ <Text size="callout">{tr('Loading…')}</Text>
+ </HStack>
+ </div>
+ )
+}
diff --git a/apps/desktop/src/renderer/views/refresh-indicator.css b/apps/desktop/src/renderer/views/refresh-indicator.css
new file mode 100644
index 00000000..e734551a
--- /dev/null
+++ b/apps/desktop/src/renderer/views/refresh-indicator.css
@@ -0,0 +1,21 @@
+.refresh-indicator {
+ position: absolute;
+ top: 48px;
+ left: 50%;
+ z-index: 1500;
+ pointer-events: none;
+ padding: 10px 16px;
+ border-radius: 999px;
+ background: var(--surface);
+ box-shadow: var(--shadow-m);
+ opacity: 0;
+ transform: translate(-50%, -4px);
+ transition: opacity var(--fade), transform var(--fade);
+}
+.refresh-indicator.shown {
+ opacity: 1;
+ transform: translate(-50%, 0);
+}
+@media (prefers-reduced-motion: reduce) {
+ .refresh-indicator { transition: none; }
+}
diff --git a/web/content/docs/getting-started.mdx b/web/content/docs/getting-started.mdx
index df113549..0f19ff26 100644
--- a/web/content/docs/getting-started.mdx
+++ b/web/content/docs/getting-started.mdx
@@ -43,6 +43,8 @@ You can also install the host with Homebrew (`brew install leepokai/codync/codyn
The app first asks about an account. Signing in with Apple or Google is optional. Choose **Continue on this Mac** (or **Continue on this computer**) to go on without one. It then offers **Computer access**, which bots need only to use the screen; choose **Set up later** to skip it. See [Computer use](/docs/computer-use).
+Press **⌘R** on macOS or **Ctrl+R** on Windows and Linux to refresh your computers. A small spinning “Loading…” indicator appears while Codync reconnects and updates the computer list. Repeated presses wait for the current refresh to finish.
+
## Running only the host
For a computer without the desktop app, such as a headless Mac or a server, install the host on its own: