feat: deliver polished desktop first-launch experience with smart recovery (#850)
* feat: implement desktop boot outcome architecture
- Add structured DesktopBootOutcome with target/status fields
- Implement boot outcome computation and validation
- Add desktop hosts configuration management (Tauri + TypeScript)
- Add desktop hosts probing with timeout and retry logic
- Support local/remote host classification and health checks
This provides the foundational infrastructure for desktop onboarding
flow to determine whether to show local setup, remote connection,
or recovery screens based on OpenCode availability and remote host
reachability.
* feat: add desktop onboarding UI components
Add comprehensive onboarding flow for desktop app:
- ChooserScreen: First-launch local/remote selection
- LocalSetupScreen: CLI installation guidance and manual detection
- RecoveryScreen: Recovery mode with routing to local/remote
- RemoteConnectionForm: Remote host connection with validation
- DesktopConnectionRecovery: Recovery variants and routing logic
- ConnectionSettingsPage: Manage remote connections
Components handle:
- Local vs remote choice persistence
- Recovery scenarios (unreachable, wrong-service, missing)
- Manual CLI detection (replaced auto-polling)
- Back navigation and state preservation
* feat: integrate desktop onboarding with app shell
- Update App.tsx to handle onboarding routing and recovery
- Add onboarding mode switching (first-launch/local-setup/recovery)
- Integrate desktop hosts in SettingsView
- Update DesktopHostSwitcher with recovery routing
- Add desktop shell utilities for onboarding detection
- Update web manifest for desktop app metadata
Completes the desktop onboarding feature integration,
allowing users to choose local or remote OpenCode on
first launch and recover from connection failures.
* fix: hide back button in remote connection form for first-launch chooser
In first-launch chooser mode, the back button is redundant since users
can simply click the "Local Install" tab. The back button is still shown
in recovery mode where there's no tab interface.
Changes:
- Add showBackButton prop to RemoteConnectionForm (default: true)
- Set showBackButton={false} in ChooserScreen remote tab
- Keep showBackButton={true} in RecoveryScreen for navigation
* refactor: remove Connection Settings page and simplify recovery UI
Remove the Connection Settings page as it was redundant:
- Local server is single-instance (no need to "choose")
- Remote servers are one-time setup (first-launch chooser)
- SSH Instances remain for multi-instance management
Changes:
- Remove ConnectionSettingsPage component and directory
- Remove 'connection' from Settings metadata
- Remove "Open Settings" button from recovery screens
- Remove desktopBootBypassToSettings state and logic
- Update recovery config to use 'local' icon instead of 'settings'
- Update tests to reflect removed showOpenSettings field
This simplifies the UX by focusing on:
- First-launch chooser for initial local/remote decision
- Remote Instances (SSH) for managing multiple remote machines
- No persistent "server management" needed for typical desktop usage
* fix: remove unused enableCliPolling prop and clean up TypeScript errors
Remove the obsolete enableCliPolling prop that was used for auto-
polling CLI detection. We replaced this with manual "Check and Continue"
button in a previous commit, so this prop is no longer needed.
Changes:
- Remove enableCliPolling from OnboardingScreen props and usage
- Remove enableCliPolling from App.tsx calls
- Remove unused 'connection' case from getSettingsNavIcon()
- Remove unused RiGlobalLine import
This resolves all TypeScript compilation errors reported by Copilot.
* fix: remove unused onChooseLocal prop and CLI_MISSING_ERROR_REGEX
These were left over from the refactoring:
- onChooseLocal in RecoveryScreen was defined but never used
- CLI_MISSING_ERROR_REGEX in App.tsx was leftover from removed enableCliPolling code
* fix: remove unused variables and fix React Hook dependency warnings
Remove unused memoized components and variables that were causing
lint errors in packages/ui:
- MainLayout.tsx: Remove unused MemoHeader, MemoChatView, MemoPlanView,
MemoGitView, MemoDiffView, MemoTerminalView, MemoFilesView,
MemoRightSidebarTabs, DesktopLeftSidebar, and DesktopRightPanel
- useGitHubPrStatusStore.ts: Remove unused prVisualPriority function
- useChatScrollManager.ts: Add missing markProgrammaticScroll dependency
to React.useEffect hook
These fixes resolve the CI lint failures in PR 850.
* chore: remove local claude settings from repo
* refactor(desktop): drop vibrancy code from onboarding PR
---------
Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
bb1d522838
commit
9b169aaacf
+163
-116
@@ -21,8 +21,18 @@ import { usePwaInstallPrompt } from '@/hooks/usePwaInstallPrompt';
|
||||
import { useWindowTitle } from '@/hooks/useWindowTitle';
|
||||
import { useConfigStore } from '@/stores/useConfigStore';
|
||||
import { hasModifier } from '@/lib/utils';
|
||||
import { isDesktopLocalOriginActive, isDesktopShell } from '@/lib/desktop';
|
||||
import { isDesktopLocalOriginActive, isDesktopShell, isTauriShell, restartDesktopApp } from '@/lib/desktop';
|
||||
import {
|
||||
getInjectedBootOutcome,
|
||||
getBootInjectionStatus,
|
||||
resolveDesktopBootView,
|
||||
canDismissInitialLoading,
|
||||
shouldRestartDesktopBootFlow,
|
||||
type BootInjectionStatus,
|
||||
type DesktopBootView,
|
||||
} from '@/lib/desktopBoot';
|
||||
import { OnboardingScreen } from '@/components/onboarding/OnboardingScreen';
|
||||
import type { RecoveryVariant } from '@/components/onboarding/DesktopConnectionRecovery';
|
||||
import { useSessionUIStore } from '@/sync/session-ui-store';
|
||||
import { useDirectoryStore } from '@/stores/useDirectoryStore';
|
||||
import { opencodeClient } from '@/lib/opencode/client';
|
||||
@@ -42,9 +52,6 @@ import { useFeatureFlagsStore } from '@/stores/useFeatureFlagsStore';
|
||||
import type { RuntimeAPIs } from '@/lib/api/types';
|
||||
import { TooltipProvider } from '@/components/ui/tooltip';
|
||||
|
||||
const CLI_MISSING_ERROR_REGEX =
|
||||
/ENOENT|spawn\s+opencode|Unable\s+to\s+locate\s+the\s+opencode\s+CLI|OpenCode\s+CLI\s+not\s+found|opencode(\.exe)?\s+not\s+found|opencode(\.exe)?:\s*command\s+not\s+found|not\s+recognized\s+as\s+an\s+internal\s+or\s+external\s+command|env:\s*['"]?(node|bun)['"]?:\s*No\s+such\s+file\s+or\s+directory|(node|bun):\s*No\s+such\s+file\s+or\s+directory/i;
|
||||
|
||||
const AboutDialogWrapper: React.FC = () => {
|
||||
const isAboutDialogOpen = useUIStore((s) => s.isAboutDialogOpen);
|
||||
const setAboutDialogOpen = useUIStore((s) => s.setAboutDialogOpen);
|
||||
@@ -168,14 +175,21 @@ function App({ apis }: AppProps) {
|
||||
const { uiFont, monoFont } = useFontPreferences();
|
||||
const refreshGitHubAuthStatus = useGitHubAuthStore((state) => state.refreshStatus);
|
||||
const [isVSCodeRuntime, setIsVSCodeRuntime] = React.useState<boolean>(() => apis.runtime.isVSCode);
|
||||
const [showCliOnboarding, setShowCliOnboarding] = React.useState(false);
|
||||
const [isEmbeddedVisible, setIsEmbeddedVisible] = React.useState(true);
|
||||
const isDesktopRuntime = React.useMemo(() => isDesktopShell(), []);
|
||||
const setPlanModeEnabled = useFeatureFlagsStore((state) => state.setPlanModeEnabled);
|
||||
const [bootInjectionStatus, setBootInjectionStatus] = React.useState<BootInjectionStatus>(() => {
|
||||
return getBootInjectionStatus();
|
||||
});
|
||||
const [bootView, setBootView] = React.useState<DesktopBootView | null>(() => {
|
||||
const outcome = getInjectedBootOutcome();
|
||||
return outcome !== null
|
||||
? resolveDesktopBootView({ isDesktopShell: true, bootOutcome: outcome })
|
||||
: null;
|
||||
});
|
||||
const appReadyDispatchedRef = React.useRef(false);
|
||||
const embeddedSessionChat = React.useMemo<EmbeddedSessionChatConfig | null>(() => readEmbeddedSessionChatConfig(), []);
|
||||
const embeddedBackgroundWorkEnabled = !embeddedSessionChat || isEmbeddedVisible;
|
||||
const recentDesktopNotificationTagsRef = React.useRef<Map<string, number>>(new Map());
|
||||
|
||||
React.useEffect(() => {
|
||||
setStreamPerfEnabled(showMemoryDebug);
|
||||
@@ -221,25 +235,55 @@ function App({ apis }: AppProps) {
|
||||
}
|
||||
}, [uiFont, monoFont]);
|
||||
|
||||
const bootOutcomeKnown = bootInjectionStatus === 'valid';
|
||||
const bootViewIsMain = bootView?.screen === 'main';
|
||||
|
||||
// Splash dismissal: use the authoritative loading gate from desktopBoot.
|
||||
// Desktop shells strictly require a valid boot outcome before dismissing.
|
||||
// Non-main outcomes (chooser/recovery) can dismiss without waiting for init.
|
||||
React.useEffect(() => {
|
||||
if (isInitialized) {
|
||||
const hideInitialLoading = () => {
|
||||
const loadingElement = document.getElementById('initial-loading');
|
||||
if (loadingElement) {
|
||||
loadingElement.classList.add('fade-out');
|
||||
|
||||
setTimeout(() => {
|
||||
loadingElement.remove();
|
||||
}, 300);
|
||||
}
|
||||
};
|
||||
|
||||
const timer = setTimeout(hideInitialLoading, 150);
|
||||
return () => clearTimeout(timer);
|
||||
if (!canDismissInitialLoading({
|
||||
isDesktopShell: isDesktopRuntime,
|
||||
isInitialized,
|
||||
bootOutcomeKnown,
|
||||
bootViewIsMain,
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
}, [isInitialized]);
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
const loadingElement = document.getElementById('initial-loading');
|
||||
if (loadingElement) {
|
||||
loadingElement.classList.add('fade-out');
|
||||
setTimeout(() => {
|
||||
loadingElement.remove();
|
||||
}, 300);
|
||||
}
|
||||
}, 150);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [isDesktopRuntime, isInitialized, bootOutcomeKnown, bootViewIsMain]);
|
||||
|
||||
// Deterministic malformed handling: update splash text so the user
|
||||
// sees a specific error instead of a generic spinner, but do NOT
|
||||
// dismiss the splash (that only happens on a valid outcome).
|
||||
React.useEffect(() => {
|
||||
if (!isDesktopRuntime || bootInjectionStatus !== 'malformed') {
|
||||
return;
|
||||
}
|
||||
|
||||
const loadingElement = document.getElementById('initial-loading');
|
||||
if (loadingElement) {
|
||||
loadingElement.textContent = 'Desktop startup failed — please restart the app.';
|
||||
}
|
||||
}, [isDesktopRuntime, bootInjectionStatus]);
|
||||
|
||||
// Non-desktop fallback: remove splash after 5 seconds even if init stalls.
|
||||
React.useEffect(() => {
|
||||
if (isDesktopRuntime) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fallbackTimer = setTimeout(() => {
|
||||
const loadingElement = document.getElementById('initial-loading');
|
||||
if (loadingElement && !isInitialized) {
|
||||
@@ -251,7 +295,7 @@ function App({ apis }: AppProps) {
|
||||
}, 5000);
|
||||
|
||||
return () => clearTimeout(fallbackTimer);
|
||||
}, [isInitialized]);
|
||||
}, [isDesktopRuntime, isInitialized]);
|
||||
|
||||
React.useEffect(() => {
|
||||
let cancelled = false;
|
||||
@@ -372,68 +416,6 @@ function App({ apis }: AppProps) {
|
||||
};
|
||||
}, [embeddedSessionChat]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (embeddedSessionChat || !isDesktopRuntime || typeof window === 'undefined' || typeof EventSource === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const source = new EventSource('/api/notifications/stream');
|
||||
|
||||
const handleMessage = (event: MessageEvent<string>) => {
|
||||
type DesktopNotificationEvent = {
|
||||
type?: string;
|
||||
properties?: {
|
||||
title?: string;
|
||||
body?: string;
|
||||
tag?: string;
|
||||
desktopStdoutActive?: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
let payload: DesktopNotificationEvent;
|
||||
|
||||
try {
|
||||
payload = JSON.parse(event.data) as DesktopNotificationEvent;
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload?.type !== 'openchamber:notification') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (payload.properties?.desktopStdoutActive === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = typeof payload.properties?.tag === 'string' ? payload.properties.tag : '';
|
||||
if (tag) {
|
||||
const now = Date.now();
|
||||
const lastSeenAt = recentDesktopNotificationTagsRef.current.get(tag) ?? 0;
|
||||
if (now - lastSeenAt < 5000) {
|
||||
return;
|
||||
}
|
||||
recentDesktopNotificationTagsRef.current.set(tag, now);
|
||||
}
|
||||
|
||||
void apis.notifications.notifyAgentCompletion({
|
||||
title: payload.properties?.title,
|
||||
body: payload.properties?.body,
|
||||
tag: tag || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
source.addEventListener('message', handleMessage as EventListener);
|
||||
source.onerror = () => {
|
||||
// Let EventSource reconnect automatically.
|
||||
};
|
||||
|
||||
return () => {
|
||||
source.removeEventListener('message', handleMessage as EventListener);
|
||||
source.close();
|
||||
};
|
||||
}, [apis.notifications, embeddedSessionChat, isDesktopRuntime]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!embeddedSessionChat?.directory || isVSCodeRuntime) {
|
||||
return;
|
||||
@@ -529,54 +511,119 @@ function App({ apis }: AppProps) {
|
||||
}
|
||||
}, [clearError, embeddedSessionChat, error]);
|
||||
|
||||
// Poll for the injected boot outcome until it becomes available (desktop only).
|
||||
// The Rust backend sets window.__OPENCHAMBER_DESKTOP_BOOT_OUTCOME__ once the
|
||||
// sidecar reaches a stable state. We poll with exponential backoff to handle
|
||||
// potential race conditions during startup and config writes.
|
||||
React.useEffect(() => {
|
||||
if (embeddedSessionChat) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDesktopShell() || !isDesktopLocalOriginActive()) {
|
||||
if (!isDesktopRuntime || bootInjectionStatus !== 'not-injected') {
|
||||
return;
|
||||
}
|
||||
|
||||
let cancelled = false;
|
||||
const run = async () => {
|
||||
const res = await fetch('/health', { method: 'GET' }).catch(() => null);
|
||||
if (!res || !res.ok || cancelled) return;
|
||||
const data = (await res.json().catch(() => null)) as null | {
|
||||
openCodeRunning?: unknown;
|
||||
isOpenCodeReady?: unknown;
|
||||
opencodeBinaryResolved?: unknown;
|
||||
lastOpenCodeError?: unknown;
|
||||
};
|
||||
if (!data || cancelled) return;
|
||||
const openCodeRunning = data.openCodeRunning === true;
|
||||
const isOpenCodeReady = data.isOpenCodeReady === true;
|
||||
const resolvedBinary = typeof data.opencodeBinaryResolved === 'string' ? data.opencodeBinaryResolved.trim() : '';
|
||||
const hasResolvedBinary = resolvedBinary.length > 0;
|
||||
const err = typeof data.lastOpenCodeError === 'string' ? data.lastOpenCodeError : '';
|
||||
const cliMissing =
|
||||
!openCodeRunning &&
|
||||
(CLI_MISSING_ERROR_REGEX.test(err) || (!hasResolvedBinary && !isOpenCodeReady));
|
||||
setShowCliOnboarding(cliMissing);
|
||||
let attempts = 0;
|
||||
const BASE_INTERVAL = 200;
|
||||
const MAX_INTERVAL = 2000;
|
||||
const MAX_ATTEMPTS = 50; // 10 seconds total (200ms * 50 with exponential backoff cap)
|
||||
|
||||
const pollWithBackoff = () => {
|
||||
if (cancelled) return;
|
||||
|
||||
attempts++;
|
||||
const status = getBootInjectionStatus();
|
||||
|
||||
if (status !== 'not-injected') {
|
||||
cancelled = true;
|
||||
setBootInjectionStatus(status);
|
||||
|
||||
if (status === 'valid') {
|
||||
const outcome = getInjectedBootOutcome();
|
||||
if (outcome) {
|
||||
setBootView(resolveDesktopBootView({ isDesktopShell: true, bootOutcome: outcome }));
|
||||
}
|
||||
}
|
||||
// If status is 'malformed', we keep the splash visible with error text
|
||||
// handled by the separate useEffect below
|
||||
return;
|
||||
}
|
||||
|
||||
// Exponential backoff with cap
|
||||
const nextInterval = Math.min(BASE_INTERVAL * Math.pow(1.1, attempts), MAX_INTERVAL);
|
||||
|
||||
if (attempts >= MAX_ATTEMPTS) {
|
||||
// Max attempts reached - keep polling but show error
|
||||
const loadingElement = document.getElementById('initial-loading');
|
||||
if (loadingElement && !loadingElement.textContent?.includes('taking longer')) {
|
||||
loadingElement.textContent = 'Desktop startup is taking longer than expected...';
|
||||
}
|
||||
}
|
||||
|
||||
window.setTimeout(pollWithBackoff, nextInterval);
|
||||
};
|
||||
|
||||
void run();
|
||||
// Start polling
|
||||
window.setTimeout(pollWithBackoff, BASE_INTERVAL);
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [embeddedSessionChat]);
|
||||
}, [isDesktopRuntime, bootInjectionStatus]);
|
||||
|
||||
const handleDesktopBootDismiss = React.useCallback(async () => {
|
||||
if (shouldRestartDesktopBootFlow({
|
||||
isTauriShell: isTauriShell(),
|
||||
isDesktopLocalOriginActive: isDesktopLocalOriginActive(),
|
||||
})) {
|
||||
await restartDesktopApp();
|
||||
return;
|
||||
}
|
||||
|
||||
const handleCliAvailable = React.useCallback(() => {
|
||||
setShowCliOnboarding(false);
|
||||
window.location.reload();
|
||||
}, []);
|
||||
|
||||
if (showCliOnboarding) {
|
||||
// Map boot outcome kind to recovery variant
|
||||
const mapBootViewToRecoveryVariant = (view: DesktopBootView): RecoveryVariant | undefined => {
|
||||
if (view.screen === 'recovery') {
|
||||
return view.variant;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
// Desktop boot view routing.
|
||||
// When the boot outcome resolves to a non-main screen (chooser, recovery),
|
||||
// render OnboardingScreen with appropriate mode/variant.
|
||||
if (isDesktopRuntime && bootView && bootView.screen !== 'main') {
|
||||
// First-launch chooser
|
||||
if (bootView.screen === 'chooser') {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<div className="h-full text-foreground bg-transparent">
|
||||
<OnboardingScreen
|
||||
mode="first-launch"
|
||||
onCliAvailable={handleDesktopBootDismiss}
|
||||
onChooseRemote={() => {
|
||||
// Switch to remote tab - handled internally by OnboardingScreen
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
// Recovery screens
|
||||
const recoveryVariant = mapBootViewToRecoveryVariant(bootView);
|
||||
const hostUrl = bootView.screen === 'recovery' && 'url' in bootView ? bootView.url : undefined;
|
||||
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<div className="h-full text-foreground bg-background">
|
||||
<OnboardingScreen onCliAvailable={handleCliAvailable} />
|
||||
<div className="h-full text-foreground bg-transparent">
|
||||
<OnboardingScreen
|
||||
mode="recovery"
|
||||
recoveryVariant={recoveryVariant}
|
||||
recoveryHostUrl={hostUrl}
|
||||
recoveryHostLabel={undefined}
|
||||
onCliAvailable={handleDesktopBootDismiss}
|
||||
/>
|
||||
</div>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
@@ -652,7 +699,7 @@ function App({ apis }: AppProps) {
|
||||
<FireworksProvider>
|
||||
<VoiceProvider>
|
||||
<TooltipProvider delayDuration={700} skipDelayDuration={150}>
|
||||
<div className="h-full text-foreground bg-background">
|
||||
<div className={isDesktopRuntime ? 'h-full text-foreground bg-transparent' : 'h-full text-foreground bg-background'}>
|
||||
<SyncAppEffects embeddedBackgroundWorkEnabled={embeddedBackgroundWorkEnabled} />
|
||||
<MainLayout />
|
||||
<Toaster />
|
||||
|
||||
Reference in New Issue
Block a user