mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-07 07:08:25 +00:00
* feat(cursor): show the cursor.com sync in the apps, with an off switch status --format menubar-json gains an additive cursorSync block (enabled, state, lastSuccessAt, and a fixed errorCode/error on failure), read from the sync sidecar, the config and the Cursor app's login. It never syncs, never makes a request and never carries the token, the account hash or server text. It is absent when Cursor is not signed in and has never synced, and it is attached after the snapshot and per-device payloads. With the Cursor provider selected, the desktop overview, the macOS menu bar and the Windows tray show one line under the total: "Synced from cursor.com 12 min ago", or the error in a muted warning colour. A "Sync Cursor usage from cursor.com" switch writes config cursorSync: Settings > Providers > Cursor on the desktop, the Cursor settings pane on macOS and Windows. Desktop and mac strings are in all six locales; the tray stays English until its localization lands. * fix(cursor): guard config writes, show the env override in the switches The tray's shared config writer now refuses to write over a config.json that does not parse or is not an object (it used to replace it with an empty map plus the one key), which also protects the currency, budget and Claude config directory writers. The desktop writer rejects null and array configs the same way. With CODEBURN_CURSOR_SYNC=0 set, the desktop, mac and tray switches show "Turned off by CODEBURN_CURSOR_SYNC=0" and are disabled. A failed mac save now says so under the switch. The tray hero note uses the warning ink and maps errorCode to its own messages.
32 lines
1.5 KiB
TypeScript
32 lines
1.5 KiB
TypeScript
import { localeTag, t } from '../i18n'
|
|
import type { CursorSyncStatus } from '../lib/types'
|
|
|
|
const ERROR_KEYS: Record<string, string> = {
|
|
login: 'plans.cursorSync.login',
|
|
network: 'plans.cursorSync.network',
|
|
export: 'plans.cursorSync.export',
|
|
}
|
|
|
|
function ago(ms: number): string {
|
|
const minutes = Math.floor(ms / 60_000)
|
|
const rtf = new Intl.RelativeTimeFormat(localeTag(), { numeric: 'auto' })
|
|
if (minutes < 60) return rtf.format(-minutes, 'minute')
|
|
if (minutes < 24 * 60) return rtf.format(-Math.floor(minutes / 60), 'hour')
|
|
return rtf.format(-Math.floor(minutes / (24 * 60)), 'day')
|
|
}
|
|
|
|
/** The one line the apps show for the sync; null when it is off. */
|
|
export function cursorSyncLine(status: CursorSyncStatus, now = Date.now()): { text: string; warn: boolean } | null {
|
|
if (status.state === 'off') return null
|
|
if (status.errorCode) return { text: t(ERROR_KEYS[status.errorCode] ?? ERROR_KEYS.export!), warn: true }
|
|
const at = status.lastSuccessAt ? Date.parse(status.lastSuccessAt) : NaN
|
|
if (!Number.isFinite(at)) return { text: t('plans.cursorSync.notYet'), warn: false }
|
|
const elapsed = Math.max(0, now - at)
|
|
return { text: elapsed < 60_000 ? t('plans.cursorSync.justNow') : t('plans.cursorSync.synced', { ago: ago(elapsed) }), warn: false }
|
|
}
|
|
|
|
export function CursorSyncLine({ status }: { status?: CursorSyncStatus }) {
|
|
const line = status ? cursorSyncLine(status) : null
|
|
if (!line) return null
|
|
return <p className={line.warn ? 'cursor-sync-line warn' : 'cursor-sync-line'}>{line.text}</p>
|
|
}
|