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.

2.5 KB
Raw Blame
import { useEffect, useState } from 'react'
import { Text, View } from 'react-native'
import type { MobileWebShellUpdateFailure } from '../mobile-web-shell/mobile-web-shell-update-failure'
import { processGenerationStore } from '../mobile-web-shell/process-generation-store'
import { loadHosts } from '../transport/host-store'
import { formatUpdateFailure } from './mobile-web-shell-update-failure-copy'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
import { troubleshootScreenStyles as styles } from './troubleshoot-screen-styles'
import { useMobileTranslation } from '../i18n/use-mobile-translation'

type Line = { readonly hostId: string; readonly text: string }

// Ignore orphaned records from hosts no longer paired; they have no host name to display.
export function updateFailureLines(
  failures: readonly MobileWebShellUpdateFailure[],
  hosts: readonly { id: string; name: string }[],
  now: number
): Line[] {
  return hosts.flatMap((host) => {
    const newest = failures.findLast((failure) => failure.hostId === host.id)
    return newest === undefined
      ? []
      : [{ hostId: host.id, text: formatUpdateFailure(newest, host.name, now) }]
  })
}

// Release console output never reaches logcat; this row is the only update-failure evidence visible there. Mount only in shell-capable builds.
export function MobileWebShellUpdateFailureRow() {
  useMobileColorScheme()
  const t = useMobileTranslation()
  const [lines, setLines] = useState<readonly Line[]>([])

  useEffect(() => {
    let stale = false
    void Promise.all([processGenerationStore().readUpdateFailures(), loadHosts()])
      .then(([failures, hosts]) => {
        if (!stale) {
          setLines(updateFailureLines(failures, hosts, Date.now()))
        }
      })
      // Evidence, not a feature: an unreadable log or host list shows nothing rather than an error.
      .catch(() => undefined)
    return () => {
      stale = true
    }
  }, [t])

  if (lines.length === 0) {
    return null
  }
  return (
    <View testID="mobile-web-shell-update-failures">
      <Text style={styles.sectionHeading}>
        {t('diagnostics.mobileWebShellUpdateFailureRow.title', 'Workspace updates')}
      </Text>
      <View style={styles.section}>
        <View style={styles.accordionBody}>
          {lines.map((line) => (
            <Text
              key={line.hostId}
              style={styles.stepText}
              testID="mobile-web-shell-update-failure"
            >
              {line.text}
            </Text>
          ))}
        </View>
      </View>
    </View>
  )
}