diff --git a/src/main/ipc/preflight.ts b/src/main/ipc/preflight.ts new file mode 100644 index 000000000..5f7e1aae3 --- /dev/null +++ b/src/main/ipc/preflight.ts @@ -0,0 +1,63 @@ +import { ipcMain } from 'electron' +import { execFile } from 'child_process' +import { promisify } from 'util' + +const execFileAsync = promisify(execFile) + +export type PreflightStatus = { + git: { installed: boolean } + gh: { installed: boolean; authenticated: boolean } +} + +// Why: cache the result so repeated Landing mounts don't re-spawn processes. +// The check only runs once per app session — relaunch to re-check. +let cached: PreflightStatus | null = null + +async function isCommandAvailable(command: string): Promise { + try { + await execFileAsync(command, ['--version']) + return true + } catch { + return false + } +} + +async function isGhAuthenticated(): Promise { + try { + const { stdout } = await execFileAsync('gh', ['auth', 'status'], { + encoding: 'utf-8' + }) + return stdout.includes('Logged in') + } catch (error) { + // gh auth status writes to stderr and exits 1 when not authenticated, + // but also writes "Logged in" to stderr when authenticated on older versions. + const stderr = (error as { stderr?: string }).stderr ?? '' + return stderr.includes('Logged in') + } +} + +async function runPreflightCheck(): Promise { + if (cached) { + return cached + } + + const [gitInstalled, ghInstalled] = await Promise.all([ + isCommandAvailable('git'), + isCommandAvailable('gh') + ]) + + const ghAuthenticated = ghInstalled ? await isGhAuthenticated() : false + + cached = { + git: { installed: gitInstalled }, + gh: { installed: ghInstalled, authenticated: ghAuthenticated } + } + + return cached +} + +export function registerPreflightHandlers(): void { + ipcMain.handle('preflight:check', async (): Promise => { + return runPreflightCheck() + }) +} diff --git a/src/main/ipc/register-core-handlers.test.ts b/src/main/ipc/register-core-handlers.test.ts index 06d845024..39cfe3ae4 100644 --- a/src/main/ipc/register-core-handlers.test.ts +++ b/src/main/ipc/register-core-handlers.test.ts @@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const { registerCliHandlersMock, + registerPreflightHandlersMock, registerGitHubHandlersMock, registerSettingsHandlersMock, registerShellHandlersMock, @@ -13,6 +14,7 @@ const { registerUpdaterHandlersMock } = vi.hoisted(() => ({ registerCliHandlersMock: vi.fn(), + registerPreflightHandlersMock: vi.fn(), registerGitHubHandlersMock: vi.fn(), registerSettingsHandlersMock: vi.fn(), registerShellHandlersMock: vi.fn(), @@ -28,6 +30,10 @@ vi.mock('./cli', () => ({ registerCliHandlers: registerCliHandlersMock })) +vi.mock('./preflight', () => ({ + registerPreflightHandlers: registerPreflightHandlersMock +})) + vi.mock('./github', () => ({ registerGitHubHandlers: registerGitHubHandlersMock })) @@ -66,6 +72,7 @@ import { registerCoreHandlers } from './register-core-handlers' describe('registerCoreHandlers', () => { beforeEach(() => { registerCliHandlersMock.mockReset() + registerPreflightHandlersMock.mockReset() registerGitHubHandlersMock.mockReset() registerSettingsHandlersMock.mockReset() registerShellHandlersMock.mockReset() @@ -90,6 +97,7 @@ describe('registerCoreHandlers', () => { expect(registerFilesystemHandlersMock).toHaveBeenCalledWith(store) expect(registerRuntimeHandlersMock).toHaveBeenCalledWith(runtime) expect(registerCliHandlersMock).toHaveBeenCalled() + expect(registerPreflightHandlersMock).toHaveBeenCalled() expect(registerShellHandlersMock).toHaveBeenCalled() expect(registerClipboardHandlersMock).toHaveBeenCalled() expect(registerUpdaterHandlersMock).toHaveBeenCalled() diff --git a/src/main/ipc/register-core-handlers.ts b/src/main/ipc/register-core-handlers.ts index 992471f86..ae5533a90 100644 --- a/src/main/ipc/register-core-handlers.ts +++ b/src/main/ipc/register-core-handlers.ts @@ -1,4 +1,5 @@ import { registerCliHandlers } from './cli' +import { registerPreflightHandlers } from './preflight' import type { Store } from '../persistence' import type { OrcaRuntimeService } from '../runtime/orca-runtime' import { registerFilesystemHandlers } from './filesystem' @@ -16,6 +17,7 @@ import { export function registerCoreHandlers(store: Store, runtime: OrcaRuntimeService): void { registerCliHandlers() + registerPreflightHandlers() registerGitHubHandlers(store) registerSettingsHandlers(store) registerShellHandlers() diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index ba5aeae56..571b978f3 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -209,6 +209,15 @@ type GitApi = { }) => Promise } +type PreflightStatus = { + git: { installed: boolean } + gh: { installed: boolean; authenticated: boolean } +} + +type PreflightApi = { + check: () => Promise +} + type Api = { repos: ReposApi worktrees: WorktreesApi @@ -216,6 +225,7 @@ type Api = { gh: GhApi settings: SettingsApi cli: CliApi + preflight: PreflightApi shell: ShellApi hooks: HooksApi cache: CacheApi diff --git a/src/preload/index.ts b/src/preload/index.ts index 74700ddb5..dd2183f51 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -222,6 +222,13 @@ const api = { remove: (): Promise => ipcRenderer.invoke('cli:remove') }, + preflight: { + check: (): Promise<{ + git: { installed: boolean } + gh: { installed: boolean; authenticated: boolean } + }> => ipcRenderer.invoke('preflight:check') + }, + shell: { openPath: (path: string): Promise => ipcRenderer.invoke('shell:openPath', path), diff --git a/src/renderer/src/components/Landing.tsx b/src/renderer/src/components/Landing.tsx index ef6acf863..335eeea1d 100644 --- a/src/renderer/src/components/Landing.tsx +++ b/src/renderer/src/components/Landing.tsx @@ -1,5 +1,5 @@ -import { useMemo } from 'react' -import { FolderPlus, GitBranchPlus } from 'lucide-react' +import { useEffect, useMemo, useState } from 'react' +import { AlertTriangle, ExternalLink, FolderPlus, GitBranchPlus } from 'lucide-react' import { useAppStore } from '../store' import logo from '../../../../resources/logo.svg' @@ -9,6 +9,14 @@ type ShortcutItem = { action: string } +type PreflightIssue = { + id: string + title: string + description: string + fixLabel: string + fixUrl: string +} + function KeyCap({ label }: { label: string }): React.JSX.Element { return ( @@ -17,6 +25,34 @@ function KeyCap({ label }: { label: string }): React.JSX.Element { ) } +function PreflightBanner({ issues }: { issues: PreflightIssue[] }): React.JSX.Element { + return ( +
+
+ + Missing dependencies +
+
+ {issues.map((issue) => ( +
+
+

{issue.title}

+

{issue.description}

+
+ +
+ ))} +
+
+ ) +} + export default function Landing(): React.JSX.Element { const repos = useAppStore((s) => s.repos) const addRepo = useAppStore((s) => s.addRepo) @@ -24,6 +60,54 @@ export default function Landing(): React.JSX.Element { const canCreateWorktree = repos.length > 0 + const [preflightIssues, setPreflightIssues] = useState([]) + + useEffect(() => { + let cancelled = false + + void window.api.preflight.check().then((status) => { + if (cancelled) { + return + } + + const issues: PreflightIssue[] = [] + + if (!status.git.installed) { + issues.push({ + id: 'git', + title: 'Git is not installed', + description: 'Orca requires Git to manage repositories and worktrees.', + fixLabel: 'Install Git', + fixUrl: 'https://git-scm.com/downloads' + }) + } + + if (!status.gh.installed) { + issues.push({ + id: 'gh', + title: 'GitHub CLI is not installed', + description: 'Orca uses the GitHub CLI (gh) to show pull requests, issues, and checks.', + fixLabel: 'Install GitHub CLI', + fixUrl: 'https://cli.github.com' + }) + } else if (!status.gh.authenticated) { + issues.push({ + id: 'gh-auth', + title: 'GitHub CLI is not authenticated', + description: 'Run "gh auth login" in a terminal to connect your GitHub account.', + fixLabel: 'Learn more', + fixUrl: 'https://cli.github.com/manual/gh_auth_login' + }) + } + + setPreflightIssues(issues) + }) + + return () => { + cancelled = true + } + }, []) + const shortcuts = useMemo( () => [ { id: 'create', keys: ['⌘', 'N'], action: 'Create worktree' }, @@ -45,6 +129,8 @@ export default function Landing(): React.JSX.Element {

ORCA

+ {preflightIssues.length > 0 && } +

{canCreateWorktree ? 'Select a worktree from the sidebar to begin.'