Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.5 KB
Raw Blame
import { useEffect, useState } from 'react'
import {
  appUpdateChecker,
  installedAppVersion,
  openAppUpdate,
  useAppUpdateState
} from '../app-update/app-update-runtime'
import { AppUpdateSettingsRows, type AppUpdateCheckRowStatus } from './app-update-settings-rows'

const CHECK_RESULT_VISIBLE_MS = 3000
const RELATIVE_TIME_TICK_MS = 60_000

export function SettingsAppUpdateSection() {
  const state = useAppUpdateState()
  const [result, setResult] = useState<'up-to-date' | 'failed' | null>(null)
  // Tick only when the relative label can age past just now.
  const [now, setNow] = useState(() => Date.now())

  useEffect(() => {
    const tick = setInterval(() => setNow(Date.now()), RELATIVE_TIME_TICK_MS)
    return () => clearInterval(tick)
  }, [])

  useEffect(() => {
    if (result === null) {
      return
    }
    const hide = setTimeout(() => setResult(null), CHECK_RESULT_VISIBLE_MS)
    return () => clearTimeout(hide)
  }, [result])

  const runCheck = () => {
    setResult(null)
    void appUpdateChecker.checkNow().then((outcome) => {
      setResult(outcome === 'available' ? null : outcome)
    })
  }

  const checkStatus: AppUpdateCheckRowStatus = state.checking ? 'checking' : (result ?? 'idle')
  return (
    <AppUpdateSettingsRows
      installedVersion={installedAppVersion}
      available={state.available}
      lastCheckedAt={state.lastCheckedAt}
      now={now}
      checkStatus={checkStatus}
      onUpdate={openAppUpdate}
      onCheck={runCheck}
    />
  )
}