From 2cb04ffb70585972bd7291174ac4e08c3eea2589 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Fri, 11 Sep 2026 16:08:03 +0200 Subject: [PATCH 01/21] feat(ui): add first-run onboarding --- crates/ui/src/lib.rs | 18 +- crates/ui/src/onboarding.rs | 2439 ++++++++++++++++++++++++++++ crates/ui/src/pickers.rs | 39 + crates/ui/src/settings.rs | 70 + crates/ui/src/settings/accounts.rs | 2 +- crates/ui/src/shell.rs | 1441 +++++++++++++++- crates/ui/src/shell/spaces.rs | 4 + 7 files changed, 3968 insertions(+), 45 deletions(-) create mode 100644 crates/ui/src/onboarding.rs diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index f12abcceea..59f8e093b7 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -42,6 +42,7 @@ mod new_thread_background_image; mod new_thread_background_mask; mod notice; pub mod notify; +pub mod onboarding; pub mod pickers; pub mod popover; pub mod project_actions; @@ -158,7 +159,22 @@ pub fn run_app(config: UiConfig) { gpui_tokio::init_from_handle(cx, runtime_handle); gpui_base::init(cx); let data_dir = config.boot().data_dir.clone(); - let ui_settings = settings::UiSettings::load(&data_dir); + let mut ui_settings = settings::UiSettings::load(&data_dir); + let fresh_profile = settings::is_fresh_profile(&data_dir); + if fresh_profile { + ui_settings.onboarding = onboarding::OnboardingState::fresh(); + // Publish the first-run marker before engine bootstrap creates its + // own durable profile files. A crash on the welcome screen must + // resume onboarding rather than look like an established install. + if let Err(error) = ui_settings.save(&data_dir) { + tracing::warn!(%error, "failed to persist initial onboarding state"); + } + } else if ui_settings.onboarding.disposition == onboarding::OnboardingDisposition::Deferred + { + // "Continue later" dismisses the current window only. A new app + // launch resumes the saved step without disturbing its choices. + ui_settings.onboarding.disposition = onboarding::OnboardingDisposition::InProgress; + } settings::init(ui_settings.clone(), data_dir.clone(), cx); let font_availability = typography::register_fonts(cx); // Typography first: theme installation reads the effective family, so diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs new file mode 100644 index 0000000000..5756695fd9 --- /dev/null +++ b/crates/ui/src/onboarding.rs @@ -0,0 +1,2439 @@ +//! First-run onboarding: a six-step, two-panel journey. The leading pane uses +//! the supplied Zeron workspace artwork while the trailing pane holds one +//! decision. Durable choices continue to live in their authoritative stores; +//! this module only persists navigation/lifecycle state in `UiSettings`. + +use std::sync::Arc; + +use gpui::{ + AnyElement, Context, Empty, Entity, FocusHandle, Image, ImageFormat, IntoElement, KeyDownEvent, + ObjectFit, Pixels, ScrollHandle, SharedString, Task, div, prelude::*, px, +}; +use serde::{Deserialize, Serialize}; +use zeron_engine::registry::{HarnessDescriptor, TitleSettings, descriptor_enabled}; +use zeron_proto::{AgentAccountsSnapshot, HarnessId, Model, ReasoningLevel, SteeringMode}; +use zeron_theme::{AccentPreset, AccentSelection, SurfacePreference, ThemeRegistry}; + +use crate::appearance::AppearanceMode; +use crate::icons::icon; +use crate::popover::{self, Loadable, Popup}; +use crate::settings::composer::ComposerDefaults; +use crate::shell::Shell; +use crate::state::AppState; +use crate::theme::{Theme, ink}; + +pub const SCHEMA_VERSION: u16 = 1; +pub const STEP_COUNT: usize = 6; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub enum OnboardingDisposition { + InProgress, + Deferred, + Skipped, + #[default] + Completed, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub enum OnboardingStep { + #[default] + Workspace, + Appearance, + Harnesses, + Defaults, + Titles, + Project, + /// Kept only so an in-progress v1 snapshot from the previous build still + /// deserializes. `OnboardingUi::step` folds it into `Project`. + FirstSession, +} + +impl OnboardingStep { + pub const ALL: [Self; STEP_COUNT] = [ + Self::Workspace, + Self::Appearance, + Self::Harnesses, + Self::Defaults, + Self::Titles, + Self::Project, + ]; + + pub fn index(self) -> usize { + Self::ALL + .iter() + .position(|candidate| *candidate == self) + .unwrap_or(STEP_COUNT - 1) + } + + pub fn next(self) -> Self { + Self::ALL + .get(self.index() + 1) + .copied() + .unwrap_or(Self::Project) + } + + pub fn previous(self) -> Self { + self.index() + .checked_sub(1) + .and_then(|index| Self::ALL.get(index)) + .copied() + .unwrap_or(self) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum WorkspaceMode { + Local, + Synced, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default, rename_all = "camelCase")] +pub struct OnboardingState { + pub schema_version: u16, + pub disposition: OnboardingDisposition, + pub step: OnboardingStep, + #[serde(skip_serializing_if = "Option::is_none")] + pub workspace_mode: Option, +} + +impl Default for OnboardingState { + fn default() -> Self { + Self { + schema_version: SCHEMA_VERSION, + disposition: OnboardingDisposition::Completed, + step: OnboardingStep::Workspace, + workspace_mode: None, + } + } +} + +impl OnboardingState { + pub fn fresh() -> Self { + Self { + disposition: OnboardingDisposition::InProgress, + workspace_mode: Some(WorkspaceMode::Local), + ..Self::default() + } + } + + pub fn is_active(&self) -> bool { + self.disposition == OnboardingDisposition::InProgress + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum OnboardingFixture { + Welcome, + WorkspaceSync, + Appearance, + Harnesses, + HarnessError, + Defaults, + Titles, + Project, + Projectless, + Narrow, +} + +impl OnboardingFixture { + pub fn from_route(route: Option<&str>) -> Option { + match route { + Some("onboarding") | Some("onboarding/welcome") => Some(Self::Welcome), + Some("onboarding/workspace-sync") => Some(Self::WorkspaceSync), + Some("onboarding/appearance") => Some(Self::Appearance), + Some("onboarding/agents") | Some("onboarding/harnesses") => Some(Self::Harnesses), + Some("onboarding/agents-error") | Some("onboarding/harness-error") => { + Some(Self::HarnessError) + } + Some("onboarding/defaults") => Some(Self::Defaults), + Some("onboarding/titles") => Some(Self::Titles), + Some("onboarding/project") => Some(Self::Project), + Some("onboarding/projectless") => Some(Self::Projectless), + Some("onboarding/first-session") => Some(Self::Project), + Some("onboarding/narrow") => Some(Self::Narrow), + _ => None, + } + } + + fn step(self) -> OnboardingStep { + match self { + Self::Welcome | Self::WorkspaceSync => OnboardingStep::Workspace, + Self::Appearance => OnboardingStep::Appearance, + Self::Harnesses | Self::HarnessError => OnboardingStep::Harnesses, + Self::Defaults | Self::Narrow => OnboardingStep::Defaults, + Self::Titles => OnboardingStep::Titles, + Self::Project | Self::Projectless => OnboardingStep::Project, + } + } +} + +/// Session-scoped load and selection state. The persisted lifecycle snapshot is +/// mirrored into `UiSettings`; agent/model/title/project choices are written to +/// their normal stores by `Shell`. +pub struct OnboardingUi { + pub state: OnboardingState, + pub fixture: Option, + pub harnesses: Loadable>, + pub models: Loadable>, + pub accounts: Loadable, + pub title_settings: Loadable, + pub title_models: Loadable>, + pub selected_harness: Option, + pub selected_model: Option, + pub selected_reasoning: Option, + pub error: Option, + pub close_confirm: bool, + pub agent_settings_open: bool, + pub focus: FocusHandle, + pub controls: Vec, + pub artwork: Arc, + pub brand_mark: Arc, + pub theme_menu: Popup, + pub theme_scroll: ScrollHandle, + pub harness_scroll: ScrollHandle, + pub step_scroll: ScrollHandle, + pub harness_task: Option>, + pub model_task: Option>, + pub accounts_task: Option>, + pub title_task: Option>, + pub title_model_task: Option>, +} + +impl OnboardingUi { + pub fn new( + mut state: OnboardingState, + defaults: ComposerDefaults, + fixture: Option, + cx: &mut Context, + ) -> Self { + // The former sixth step only waited for a composer submit. Treat an + // in-progress snapshot already parked there as completed instead of + // sending an upgraded user back through the project choice. + if state.is_active() && state.step == OnboardingStep::FirstSession { + state.step = OnboardingStep::Project; + state.disposition = OnboardingDisposition::Completed; + } + let controls = (0..32).map(|_| cx.focus_handle().tab_stop(true)).collect(); + let mut ui = Self { + selected_harness: defaults.harness, + selected_model: defaults + .harness + .and_then(|harness| defaults.model_for(harness)) + .map(|model| model.id.clone()), + selected_reasoning: defaults.reasoning, + state, + fixture, + harnesses: Loadable::Idle, + models: Loadable::Idle, + accounts: Loadable::Idle, + title_settings: Loadable::Idle, + title_models: Loadable::Idle, + error: None, + close_confirm: false, + agent_settings_open: false, + focus: cx.focus_handle(), + controls, + artwork: Arc::new(Image::from_bytes( + ImageFormat::Jpeg, + include_bytes!("../../../apps/landing/public/assets/app-screenshot.jpg").to_vec(), + )), + brand_mark: Arc::new(Image::from_bytes( + ImageFormat::Png, + include_bytes!("../../../apps/landing/public/assets/zeron-app-icon.png").to_vec(), + )), + theme_menu: Popup::default(), + theme_scroll: ScrollHandle::new(), + harness_scroll: ScrollHandle::new(), + step_scroll: ScrollHandle::new(), + harness_task: None, + model_task: None, + accounts_task: None, + title_task: None, + title_model_task: None, + }; + if let Some(fixture) = fixture { + ui.apply_fixture(fixture); + } + ui + } + + pub fn active(&self) -> bool { + self.fixture.is_some() || (self.state.is_active() && !self.agent_settings_open) + } + + pub fn step(&self) -> OnboardingStep { + let step = self + .fixture + .map(OnboardingFixture::step) + .unwrap_or(self.state.step); + if step == OnboardingStep::FirstSession { + OnboardingStep::Project + } else { + step + } + } + + pub fn control(&self, index: usize) -> &FocusHandle { + &self.controls[index.min(self.controls.len() - 1)] + } + + fn apply_fixture(&mut self, fixture: OnboardingFixture) { + self.state = OnboardingState::fresh(); + self.state.step = fixture.step(); + self.state.workspace_mode = Some(if fixture == OnboardingFixture::WorkspaceSync { + WorkspaceMode::Synced + } else { + WorkspaceMode::Local + }); + self.harnesses = if fixture == OnboardingFixture::HarnessError { + Loadable::Error("Unable to inspect agents on this device.".into()) + } else { + Loadable::Ready(fixture_harnesses()) + }; + self.models = Loadable::Ready(fixture_models()); + self.accounts = Loadable::Ready(AgentAccountsSnapshot { + accounts: vec![zeron_proto::AgentAccount { + id: "fixture-codex".into(), + harness: HarnessId::Codex, + email: Some("you@example.com".into()), + plan_label: Some("Pro".into()), + active: true, + usage_windows: Vec::new(), + display_name: None, + organization: None, + auth_kind: Some(zeron_proto::AgentAuthKind::Oauth), + switchable: true, + saved_at: None, + }], + warnings: Vec::new(), + }); + self.title_settings = Loadable::Ready(TitleSettings::default()); + self.title_models = Loadable::Ready(fixture_models()); + self.selected_harness = Some(HarnessId::Codex); + self.selected_model = Some("gpt-5.6-sol".into()); + self.selected_reasoning = Some(ReasoningLevel::High); + } +} + +fn fixture_harnesses() -> Vec { + let descriptor = |id, name: &str, installed, enabled| HarnessDescriptor { + id, + name: name.into(), + supports_steering: true, + steering_mode: SteeringMode::StepBoundary, + reasoning_levels: vec![ + ReasoningLevel::Low, + ReasoningLevel::Medium, + ReasoningLevel::High, + ], + installed, + enabled: Some(enabled), + }; + vec![ + descriptor(HarnessId::ClaudeCode, "Claude Code", true, true), + descriptor(HarnessId::Codex, "Codex", true, true), + descriptor(HarnessId::Cursor, "Cursor", true, false), + descriptor(HarnessId::Opencode, "OpenCode", false, false), + descriptor(HarnessId::Devin, "Devin", false, false), + descriptor(HarnessId::Grok, "Grok", false, false), + descriptor(HarnessId::Hermes, "Hermes", false, false), + descriptor(HarnessId::Pi, "Pi", false, false), + ] +} + +fn fixture_models() -> Vec { + vec![ + Model { + id: "gpt-5.6-sol".into(), + label: "GPT-5.6 Sol".into(), + description: Some("Reliable agentic workhorse".into()), + reasoning_levels: vec![ + ReasoningLevel::Low, + ReasoningLevel::Medium, + ReasoningLevel::High, + ], + options: Vec::new(), + }, + Model { + id: "gpt-6-astra".into(), + label: "GPT-6 Astra".into(), + description: Some("Most capable for demanding work".into()), + reasoning_levels: vec![ + ReasoningLevel::Medium, + ReasoningLevel::High, + ReasoningLevel::XHigh, + ], + options: Vec::new(), + }, + ] +} + +pub fn harness_name(harness: HarnessId) -> &'static str { + match harness { + HarnessId::ClaudeCode => "Claude Code", + HarnessId::Codex => "Codex", + HarnessId::Cursor => "Cursor", + HarnessId::Devin => "Devin", + HarnessId::Grok => "Grok", + HarnessId::Hermes => "Hermes", + HarnessId::Pi => "Pi", + HarnessId::Opencode => "OpenCode", + HarnessId::Mock => "Mock", + } +} + +pub fn reasoning_name(reasoning: ReasoningLevel) -> &'static str { + match reasoning { + ReasoningLevel::Minimal => "Minimal", + ReasoningLevel::Low => "Low", + ReasoningLevel::Medium => "Medium", + ReasoningLevel::High => "High", + ReasoningLevel::XHigh => "X-high", + ReasoningLevel::Max => "Max", + ReasoningLevel::Ultra => "Ultra", + ReasoningLevel::Ultracode => "Ultracode", + ReasoningLevel::Ultrathink => "Ultrathink", + } +} + +fn heading(theme: &Theme, id: &'static str, text: &'static str) -> gpui::Stateful { + div() + .id(id) + .role(gpui::Role::Heading) + .aria_level(1) + .text_size(crate::typography::ui_rems(28.0)) + .line_height(px(32.0)) + .font_weight(gpui::FontWeight::SEMIBOLD) + .text_color(theme.text) + .child(text) +} + +fn body(theme: &Theme, text: impl Into) -> gpui::Div { + div() + .mt(px(10.0)) + .max_w(px(440.0)) + .text_size(crate::typography::ui_rems(14.0)) + .line_height(px(21.0)) + .text_color(theme.text_muted) + .child(text.into()) +} + +fn choice_card( + theme: &Theme, + label: impl Into, + description: impl Into, + selected: bool, + harness: Option, +) -> gpui::Div { + let label = label.into(); + div() + .w_full() + .min_h(px(76.0)) + .px(px(15.0)) + .py(px(13.0)) + .rounded(px(12.0)) + .border_1() + .border_color(if selected { + theme.accent.opacity(0.65) + } else { + theme.border + }) + .bg(theme.card_glass_bg()) + .flex() + .flex_row() + .items_start() + .gap(px(12.0)) + .cursor_pointer() + .hover(|style| style.bg(theme.element_hover)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .child( + div() + .mt(px(2.0)) + .size(px(18.0)) + .flex_none() + .rounded_full() + .border_1() + .border_color(if selected { + theme.accent + } else { + theme.border_strong + }) + .flex() + .items_center() + .justify_center() + .when(selected, |dot| { + dot.child(div().size(px(8.0)).rounded_full().bg(theme.accent)) + }), + ) + .child( + div() + .min_w_0() + .flex_1() + .flex() + .flex_col() + .gap(px(3.0)) + .child( + div() + .flex() + .items_center() + .gap(px(7.0)) + .text_size(crate::typography::ui_rems(14.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text) + .when_some(harness, |row, harness| { + let (icon_path, tint) = crate::pickers::harness_brand_icon(harness); + row.child( + icon(icon_path) + .size(px(14.0)) + .flex_none() + .text_color(tint.unwrap_or(theme.text)), + ) + }) + .child(label), + ) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .line_height(px(17.0)) + .text_color(theme.text_muted) + .child(description.into()), + ), + ) +} + +fn action_button(theme: &Theme, label: &'static str) -> gpui::Div { + div() + .w_full() + .min_h(px(44.0)) + .px(px(16.0)) + .rounded(px(10.0)) + .bg(theme.solid) + .text_color(theme.on_solid) + .text_size(crate::typography::ui_rems(14.0)) + .font_weight(gpui::FontWeight::SEMIBOLD) + .flex() + .items_center() + .justify_center() + .cursor_pointer() + .hover(|style| style.opacity(0.9)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .child(label) +} + +fn quiet_button(theme: &Theme, label: &'static str) -> gpui::Div { + div() + .min_h(px(36.0)) + .px(px(10.0)) + .rounded(px(8.0)) + .flex() + .items_center() + .justify_center() + .text_size(crate::typography::ui_rems(12.5)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .cursor_pointer() + .hover(|style| style.bg(theme.element_hover).text_color(theme.text)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .child(label) +} + +pub(crate) fn activates(event: &KeyDownEvent) -> bool { + matches!(event.keystroke.key.as_str(), "enter" | "space") + && !event.keystroke.modifiers.modified() +} + +pub(crate) fn close_dialog_tab_target(focused: Option, shift: bool) -> usize { + if shift { + if focused == Some(26) { 27 } else { 26 } + } else if focused == Some(27) { + 26 + } else { + 27 + } +} + +pub(crate) fn project_target_is_chosen(has_project: bool, no_project: bool) -> bool { + has_project || no_project +} + +fn toggled(value: bool) -> gpui::Toggled { + if value { + gpui::Toggled::True + } else { + gpui::Toggled::False + } +} + +fn faded_step_scroll(id: &'static str, handle: &ScrollHandle, content: AnyElement) -> AnyElement { + crate::edge_fade::edge_faded( + 22.0, + true, + true, + div() + .id(id) + .size_full() + .min_w_0() + .min_h_0() + .overflow_y_scroll() + .track_scroll(handle) + .child(content), + ) + .fade_overflow_y(handle) + .into_any_element() +} + +fn harness_status( + descriptor: &HarnessDescriptor, + accounts: &Loadable, +) -> (&'static str, bool) { + if !descriptor.installed { + return ("Not installed", false); + } + if !descriptor_enabled(descriptor) { + return ("Installed but disabled", false); + } + if !matches!( + descriptor.id, + HarnessId::ClaudeCode | HarnessId::Codex | HarnessId::Cursor + ) { + return ("Ready", true); + } + match accounts { + Loadable::Idle | Loadable::Loading => ("Checking sign-in…", false), + Loadable::Error(_) => ("Detection error", false), + Loadable::Ready(snapshot) => { + if snapshot + .warnings + .iter() + .any(|warning| warning.harness == descriptor.id) + { + ("Detection error", false) + } else if snapshot + .accounts + .iter() + .any(|account| account.harness == descriptor.id && account.active) + { + ("Ready", true) + } else { + ("Sign-in required", false) + } + } + } +} + +pub(crate) fn harness_is_ready( + descriptor: &HarnessDescriptor, + accounts: &Loadable, +) -> bool { + harness_status(descriptor, accounts).1 +} + +pub(crate) fn harness_is_interactive(descriptor: &HarnessDescriptor) -> bool { + descriptor.installed || descriptor_enabled(descriptor) +} + +pub(crate) fn title_harness_is_available(descriptor: &HarnessDescriptor) -> bool { + descriptor.installed + && descriptor_enabled(descriptor) + && zeron_harness::supports_titles(descriptor.id) + && descriptor.id != HarnessId::Mock +} + +fn render_workspace_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) -> AnyElement { + let local = ui.state.workspace_mode == Some(WorkspaceMode::Local); + let synced = ui.state.workspace_mode == Some(WorkspaceMode::Synced); + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading(theme, "onboarding-heading-workspace", "Workspace")) + .child(body(theme, "Choose where Zeron keeps your sessions.")) + .child( + div() + .mt(px(28.0)) + .flex_1() + .min_h_0() + .child(faded_step_scroll( + "onboarding-workspace-scroll", + &ui.step_scroll, + div() + .id("onboarding-workspace-choices") + .flex() + .flex_col() + .gap(px(12.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Workspace mode") + .child( + choice_card( + theme, + "This device", + "Store sessions on this device.", + local, + None, + ) + .id("onboarding-workspace-local") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(local)) + .track_focus(ui.control(0)) + .on_click(cx.listener( + |shell, _, _, cx| { + shell.onboarding_pick_workspace(WorkspaceMode::Local, cx) + }, + )), + ) + .child( + choice_card( + theme, + "Sync devices", + "Sign in to use the same workspace on your devices.", + synced, + None, + ) + .id("onboarding-workspace-sync") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(synced)) + .track_focus(ui.control(1)) + .on_click(cx.listener( + |shell, _, _, cx| { + shell.onboarding_pick_workspace(WorkspaceMode::Synced, cx) + }, + )), + ) + .into_any_element(), + )), + ) + .child( + action_button(theme, "Continue") + .mt(px(28.0)) + .id("onboarding-continue-workspace") + .role(gpui::Role::Button) + .track_focus(ui.control(2)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + })), + ) + .into_any_element() +} + +fn model_appearance(appearance: crate::theme::Appearance) -> zeron_theme::Appearance { + if appearance.is_dark() { + zeron_theme::Appearance::Dark + } else { + zeron_theme::Appearance::Light + } +} + +pub(crate) fn theme_variants( + appearance: crate::theme::Appearance, +) -> Vec { + ThemeRegistry::active() + .variants_for(model_appearance(appearance)) + .cloned() + .collect() +} + +fn palette_preview(theme: &Theme) -> gpui::Div { + div() + .flex_none() + .w(px(30.0)) + .h(px(18.0)) + .rounded(px(5.0)) + .overflow_hidden() + .border_1() + .border_color(theme.border) + .flex() + .child(div().w_1_3().h_full().bg(theme.surface)) + .child(div().w_1_3().h_full().bg(theme.bg)) + .child(div().w_1_3().h_full().bg(theme.accent)) +} + +pub(crate) fn surface_label(surface: SurfacePreference) -> &'static str { + match surface { + SurfacePreference::ThemeDefault => "Theme default", + SurfacePreference::Frosted => "Frosted glass", + SurfacePreference::Opaque => "Solid", + } +} + +fn render_appearance_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) -> AnyElement { + let current_mode = crate::appearance::mode(cx); + let current_accent = crate::appearance::accent(cx); + let current_surface = crate::appearance::surface(cx); + let effective_appearance = theme.appearance; + let current_theme_id = theme.variant_id.to_string(); + let theme_variants = theme_variants(effective_appearance); + let selected_variant = theme_variants + .iter() + .find(|variant| variant.id == current_theme_id) + .or_else(|| theme_variants.first()) + .expect("the built-in registry has both appearances"); + let selected_theme = Theme::for_selection( + effective_appearance, + &selected_variant.id, + AccentSelection::ThemeDefault, + theme.surface_preference, + ); + let mode_choices = AppearanceMode::ALL + .into_iter() + .enumerate() + .map(|(index, mode)| { + let selected = mode == current_mode; + chip(theme, mode.label().into(), selected, None) + .id(("onboarding-appearance-mode", index)) + .min_h(px(44.0)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(index)) + .on_click( + cx.listener(move |shell, _, _, cx| shell.onboarding_pick_appearance(mode, cx)), + ) + }); + let theme_rows = theme_variants.iter().enumerate().map(|(index, variant)| { + let id = variant.id.clone(); + let selected = id == current_theme_id; + let sample = Theme::for_selection( + effective_appearance, + &id, + AccentSelection::ThemeDefault, + theme.surface_preference, + ); + popover::menu_row_nav( + theme, + selected, + ui.theme_menu.as_open().copied() == Some(index), + format!("onboarding-theme-row-{index}"), + ) + .id(("onboarding-theme-row", index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_theme(effective_appearance, id.clone(), cx) + })) + .child(palette_preview(&sample)) + .child( + div() + .flex_1() + .min_w_0() + .truncate() + .child(SharedString::from(variant.name.clone())), + ) + .child(div().w(px(18.0)).flex_none().when(selected, |slot| { + slot.child( + icon(crate::icons::CHECK) + .size(px(14.0)) + .text_color(theme.accent), + ) + })) + }); + let theme_menu = popover::popover_card(theme) + .id("onboarding-theme-menu") + .w(px(320.0)) + .max_h(px(320.0)) + .overflow_y_scroll() + .track_scroll(&ui.theme_scroll) + .on_mouse_down_out(cx.listener(|shell, _, _, cx| shell.onboarding_close_theme_menu(cx))) + .flex() + .flex_col() + .gap(px(2.0)) + .child(popover::menu_heading( + theme, + if effective_appearance.is_dark() { + "Dark themes" + } else { + "Light themes" + }, + )) + .children(theme_rows) + .into_any_element(); + let theme_trigger = div() + .id("onboarding-theme-selector") + .relative() + .w_full() + .h(px(42.0)) + .px(px(12.0)) + .rounded(px(9.0)) + .border_1() + .border_color(if ui.theme_menu.is_open() { + theme.border_strong + } else { + theme.border + }) + .bg(theme.card_glass_bg()) + .flex() + .items_center() + .gap(px(9.0)) + .cursor_pointer() + .role(gpui::Role::Button) + .aria_label(format!("Theme, selected {}", selected_variant.name)) + .aria_expanded(ui.theme_menu.is_open()) + .track_focus(ui.control(3)) + .hover(|style| style.bg(theme.element_hover)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .on_mouse_down( + gpui::MouseButton::Left, + cx.listener(|shell, _, _, _| shell.onboarding_note_theme_trigger_press()), + ) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_toggle_theme_menu(cx))) + .child(palette_preview(&selected_theme)) + .child( + div() + .flex_1() + .min_w_0() + .truncate() + .text_size(crate::typography::ui_rems(12.5)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text) + .child(SharedString::from(selected_variant.name.clone())), + ) + .child( + icon(crate::icons::ALT_ARROW_DOWN) + .size(px(14.0)) + .flex_none() + .text_color(theme.text_muted), + ) + .when_some(ui.theme_menu.get(), |trigger, _| { + trigger.child(popover::anchored_menu_below( + "onboarding-theme-menu-layer", + theme_menu, + ui.theme_menu.closing_since(), + )) + }); + let accent_choices = AccentPreset::ALL + .into_iter() + .enumerate() + .map(|(index, preset)| { + let selection = AccentSelection::Preset(preset); + let selected = current_accent == selection + || (preset == AccentPreset::Zeron + && current_accent == AccentSelection::ThemeDefault); + let swatch_theme = Theme::for_preferences(theme.appearance, preset.into()); + div() + .id(("onboarding-accent", index)) + .size(px(44.0)) + .rounded_full() + .border_2() + .border_color(if selected { + theme.text + } else { + theme.border_strong + }) + .bg(swatch_theme.accent) + .cursor_pointer() + .role(gpui::Role::RadioButton) + .aria_label(format!("{} accent", preset.label())) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(8 + index)) + .hover(|style| style.opacity(0.82)) + .focus_visible(|style| style.border_2().border_color(theme.text)) + .on_click( + cx.listener(move |shell, _, _, cx| shell.onboarding_pick_accent(selection, cx)), + ) + }); + let surface_choices = SurfacePreference::ALL + .into_iter() + .enumerate() + .map(|(index, surface)| { + let selected = surface == current_surface; + chip(theme, surface_label(surface).into(), selected, None) + .id(("onboarding-surface", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(16 + index)) + .on_click( + cx.listener(move |shell, _, _, cx| shell.onboarding_pick_surface(surface, cx)), + ) + }); + + let controls = div() + .flex() + .flex_col() + .gap(px(18.0)) + .child( + div() + .flex() + .flex_col() + .gap(px(9.0)) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child("Appearance"), + ) + .child( + div() + .id("onboarding-appearance-modes") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Appearance") + .children(mode_choices), + ), + ) + .child( + div() + .flex() + .flex_col() + .gap(px(9.0)) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child("Theme"), + ) + .child( + div() + .id("onboarding-themes") + .role(gpui::Role::Group) + .aria_label("Theme") + .child(theme_trigger), + ), + ) + .child( + div() + .flex() + .flex_col() + .gap(px(9.0)) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child("Accent color"), + ) + .child( + div() + .id("onboarding-accents") + .flex() + .flex_wrap() + .gap(px(10.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Accent color") + .children(accent_choices), + ), + ) + .child( + div() + .flex() + .flex_col() + .gap(px(9.0)) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child("Surface"), + ) + .child( + div() + .id("onboarding-surfaces") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Surface") + .children(surface_choices), + ), + ) + .into_any_element(); + + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-appearance", + "Appearance", + )) + .child(body(theme, "Choose a theme and accent.")) + .child( + div() + .mt(px(24.0)) + .flex_1() + .min_h_0() + .child(faded_step_scroll( + "onboarding-appearance-scroll", + &ui.step_scroll, + controls, + )), + ) + .child( + action_button(theme, "Continue") + .mt(px(24.0)) + .id("onboarding-continue-appearance") + .role(gpui::Role::Button) + .track_focus(ui.control(25)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + })), + ) + .into_any_element() +} + +fn render_harness_step( + ui: &OnboardingUi, + theme: &Theme, + state: &Entity, + cx: &mut Context, +) -> AnyElement { + let devices = { + let state = state.read(cx); + let effective = state.effective_device_id(); + let now = chrono::Utc::now(); + state + .devices + .iter() + .take(5) + .map(|device| { + ( + device.id.clone(), + device.name.clone(), + state.device_online(&device.id, now), + effective.as_deref() == Some(device.id.as_str()), + ) + }) + .collect::>() + }; + let multiple_devices = devices.len() > 1; + let device_switcher: AnyElement = if multiple_devices { + div() + .mt(px(18.0)) + .flex() + .flex_col() + .gap(px(8.0)) + .child( + div() + .text_size(crate::typography::ui_rems(11.5)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child("Set up agents on"), + ) + .child( + div() + .id("onboarding-device-choices") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Device") + .children(devices.into_iter().enumerate().map( + |(index, (id, name, online, selected))| { + let label: SharedString = if online { + name.into() + } else { + format!("{name} · Offline").into() + }; + chip(theme, label, selected, None) + .id(("onboarding-device", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(20 + index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_device(id.clone(), cx) + })) + }, + )), + ) + .into_any_element() + } else { + Empty.into_any_element() + }; + let list: AnyElement = match &ui.harnesses { + Loadable::Idle | Loadable::Loading => div() + .id("onboarding-harness-loading") + .role(gpui::Role::ProgressIndicator) + .aria_label("Loading coding agents") + .flex() + .flex_col() + .gap(px(8.0)) + .children((0..4).map(|_| div().h(px(54.0)).rounded(px(10.0)).bg(ink(0.045)))) + .into_any_element(), + Loadable::Error(message) => div() + .id("onboarding-harness-load-error") + .role(gpui::Role::Alert) + .p(px(14.0)) + .rounded(px(10.0)) + .border_1() + .border_color(theme.danger_muted.opacity(0.5)) + .bg(theme.danger.opacity(0.06)) + .text_size(crate::typography::ui_rems(12.5)) + .line_height(px(18.0)) + .text_color(theme.danger_muted) + .child(message.clone()) + .child( + quiet_button(theme, "Retry") + .id("onboarding-harness-retry") + .role(gpui::Role::Button) + .track_focus(ui.control(11)) + .mt(px(8.0)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_load_harnesses(cx))), + ) + .into_any_element(), + Loadable::Ready(harnesses) => div() + .flex() + .flex_col() + .gap(px(8.0)) + .children( + harnesses + .iter() + .enumerate() + .filter(|(_, descriptor)| descriptor.id != HarnessId::Mock) + .map(|(index, descriptor)| { + let descriptor = descriptor.clone(); + let installed = descriptor.installed; + let enabled = descriptor_enabled(&descriptor); + let (status, _) = harness_status(&descriptor, &ui.accounts); + let interactive = harness_is_interactive(&descriptor); + let focus_index = harnesses[..index] + .iter() + .filter(|row| row.id != HarnessId::Mock && harness_is_interactive(row)) + .count(); + let (icon_path, tint) = crate::pickers::harness_brand_icon(descriptor.id); + div() + .id(("onboarding-harness", index)) + .min_h(px(54.0)) + .px(px(12.0)) + .rounded(px(10.0)) + .border_1() + .border_color(if enabled { + theme.accent.opacity(0.65) + } else { + theme.border + }) + .bg(theme.card_glass_bg()) + .flex() + .items_center() + .gap(px(10.0)) + .when(interactive, |row| { + let descriptor = descriptor.clone(); + row.cursor_pointer() + .hover(|s| s.bg(theme.element_hover)) + .role(gpui::Role::CheckBox) + .aria_toggled(toggled(enabled)) + .track_focus(ui.control(focus_index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_toggle_harness(descriptor.id, !enabled, cx) + })) + }) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .when(!installed, |row| row.opacity(0.58)) + .when(!interactive, |row| { + row.aria_description(format!( + "{} is unavailable until its command-line tool is installed", + descriptor.name + )) + }) + .child( + div() + .size(px(32.0)) + .rounded(px(9.0)) + .border_1() + .border_color(theme.border) + .flex() + .items_center() + .justify_center() + .child( + icon(icon_path) + .size(px(15.0)) + .text_color(tint.unwrap_or(theme.text_muted)), + ), + ) + .child( + div() + .flex_1() + .min_w_0() + .flex() + .flex_col() + .gap(px(2.0)) + .child( + div() + .text_size(crate::typography::ui_rems(13.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text) + .child(descriptor.name.clone()), + ) + .child( + div() + .text_size(crate::typography::ui_rems(11.0)) + .text_color(theme.text_muted) + .child(if interactive { + SharedString::from(status) + } else { + format!( + "Install {}'s CLI, then retry", + descriptor.name + ) + .into() + }), + ), + ) + .when(interactive, |row| { + row.child( + div() + .w(px(34.0)) + .h(px(20.0)) + .rounded_full() + .p(px(2.0)) + .bg(if enabled { + theme.accent_strong + } else { + theme.border_strong + }) + .flex() + .justify_end() + .when(!enabled, |toggle| toggle.justify_start()) + .child( + div().size(px(16.0)).rounded_full().bg(theme.on_accent), + ), + ) + }) + }), + ) + .into_any_element(), + }; + let ready = matches!(&ui.harnesses, Loadable::Ready(rows) if rows + .iter() + .any(|h| h.id != HarnessId::Mock && harness_is_ready(h, &ui.accounts))); + let harness_list = div() + .mt(px(if multiple_devices { 14.0 } else { 22.0 })) + .flex_1() + .min_h_0() + .child(faded_step_scroll( + "onboarding-harness-scroll", + &ui.harness_scroll, + list, + )); + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-harnesses", + "Coding agents", + )) + .child(body(theme, "Turn on the agents you want to use.")) + .child(device_switcher) + .child(harness_list) + .when(matches!(ui.harnesses, Loadable::Ready(_)), |column| { + column.child( + quiet_button(theme, "Retry agent detection") + .id("onboarding-harness-retry-ready") + .mt(px(8.0)) + .role(gpui::Role::Button) + .track_focus(ui.control(11)) + .on_click(cx.listener(|shell, _, _, cx| { + shell.onboarding_load_harnesses(cx); + shell.onboarding_load_accounts(cx); + })), + ) + }) + .child( + quiet_button(theme, "Manage agent sign-ins") + .id("onboarding-manage-agent-signins") + .mt(px(8.0)) + .role(gpui::Role::Button) + .track_focus(ui.control(12)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_open_agent_settings(cx))), + ) + .when_some(ui.error.clone(), |column, error| { + column.child( + div() + .id("onboarding-harness-error") + .mb(px(10.0)) + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.danger_muted) + .role(gpui::Role::Alert) + .child(error), + ) + }) + .child( + action_button(theme, "Continue") + .mt(px(18.0)) + .id("onboarding-continue-harnesses") + .role(gpui::Role::Button) + .when(!ready, |button| { + button + .opacity(0.45) + .cursor_default() + .aria_description("Unavailable until at least one agent is ready") + }) + .when(ready, |button| { + button.track_focus(ui.control(10)).on_click(cx.listener( + |shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + }, + )) + }), + ) + .into_any_element() +} + +fn chip( + theme: &Theme, + label: SharedString, + selected: bool, + harness: Option, +) -> gpui::Div { + div() + .min_h(px(38.0)) + .px(px(12.0)) + .rounded(px(9.0)) + .border_1() + .border_color(if selected { + theme.accent.opacity(0.65) + } else { + theme.border + }) + .bg(theme.card_glass_bg()) + .text_size(crate::typography::ui_rems(12.5)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(if selected { + theme.text + } else { + theme.text_muted + }) + .flex() + .items_center() + .justify_center() + .gap(px(7.0)) + .cursor_pointer() + .hover(|style| style.bg(theme.element_hover)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .when_some(harness, |chip, harness| { + let (icon_path, tint) = crate::pickers::harness_brand_icon(harness); + chip.child( + icon(icon_path) + .size(px(13.0)) + .flex_none() + .text_color(tint.unwrap_or(if selected { + theme.text + } else { + theme.text_muted + })), + ) + }) + .child(label) +} + +fn render_defaults_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) -> AnyElement { + let harnesses: Vec = ui + .harnesses + .ready() + .map(|rows| { + rows.iter() + .filter(|h| h.id != HarnessId::Mock && harness_is_ready(h, &ui.accounts)) + .cloned() + .collect() + }) + .unwrap_or_default(); + let models = ui.models.ready().cloned().unwrap_or_default(); + let reasoning = models + .iter() + .find(|model| Some(model.id.as_str()) == ui.selected_model.as_deref()) + .map(|model| model.reasoning_levels.clone()) + .or_else(|| { + harnesses + .iter() + .find(|h| Some(h.id) == ui.selected_harness) + .map(|h| h.reasoning_levels.clone()) + }) + .unwrap_or_default(); + let field = |label: &'static str, content: AnyElement| { + div() + .flex() + .flex_col() + .gap(px(9.0)) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child(label), + ) + .child(content) + }; + let harness_chips = div() + .id("onboarding-default-harnesses") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Default agent") + .children( + harnesses + .into_iter() + .enumerate() + .map(|(index, descriptor)| { + let id = descriptor.id; + chip( + theme, + descriptor.name.into(), + ui.selected_harness == Some(id), + Some(id), + ) + .id(("onboarding-default-harness", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(ui.selected_harness == Some(id))) + .track_focus(ui.control(index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_default_harness(id, cx) + })) + }), + ); + let model_content: AnyElement = + match &ui.models { + Loadable::Idle | Loadable::Loading => div() + .id("onboarding-model-loading") + .role(gpui::Role::ProgressIndicator) + .aria_label("Loading models") + .h(px(38.0)) + .rounded(px(9.0)) + .bg(ink(0.045)) + .into_any_element(), + Loadable::Error(error) => div() + .id("onboarding-model-load-error") + .role(gpui::Role::Alert) + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.danger_muted) + .child(error.clone()) + .into_any_element(), + Loadable::Ready(_) => div() + .id("onboarding-default-models") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Default model") + .child( + chip(theme, "Automatic".into(), ui.selected_model.is_none(), None) + .id("onboarding-default-model-auto") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(ui.selected_model.is_none())) + .track_focus(ui.control(8)) + .on_click(cx.listener(|shell, _, _, cx| { + shell.onboarding_pick_default_model(None, cx) + })), + ) + .children( + models + .into_iter() + .take(4) + .enumerate() + .map(|(index, model)| { + let selected = ui.selected_model.as_deref() == Some(model.id.as_str()); + let id = model.id; + chip(theme, model.label.into(), selected, ui.selected_harness) + .id(("onboarding-default-model", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(9 + index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_default_model(Some(id.clone()), cx) + })) + }), + ) + .into_any_element(), + }; + let reasoning_chips = + div() + .id("onboarding-default-reasoning-levels") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Default reasoning level") + .child( + chip( + theme, + "Automatic".into(), + ui.selected_reasoning.is_none(), + None, + ) + .id("onboarding-default-reasoning-auto") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(ui.selected_reasoning.is_none())) + .track_focus(ui.control(16)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_pick_reasoning(None, cx))), + ) + .children(reasoning.into_iter().enumerate().map(|(index, level)| { + chip( + theme, + reasoning_name(level).into(), + ui.selected_reasoning == Some(level), + None, + ) + .id(("onboarding-default-reasoning", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(ui.selected_reasoning == Some(level))) + .track_focus(ui.control(17 + index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_reasoning(Some(level), cx) + })) + })); + let fields = div() + .flex() + .flex_col() + .gap(px(22.0)) + .child(field("Agent", harness_chips.into_any_element())) + .child(field("Model", model_content)) + .child(field("Reasoning", reasoning_chips.into_any_element())) + .into_any_element(); + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-defaults", + "Session defaults", + )) + .child(body(theme, "Choose defaults for new sessions.")) + .child( + div() + .mt(px(26.0)) + .flex_1() + .min_h_0() + .child(faded_step_scroll( + "onboarding-defaults-scroll", + &ui.step_scroll, + fields, + )), + ) + .child( + action_button(theme, "Continue") + .mt(px(28.0)) + .id("onboarding-continue-defaults") + .role(gpui::Role::Button) + // Keep the full nine-level reasoning ladder addressable; its + // final option occupies control 25. + .track_focus(ui.control(26)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + })), + ) + .into_any_element() +} + +fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) -> AnyElement { + let current = match &ui.title_settings { + Loadable::Ready(current) => current.clone(), + Loadable::Idle | Loadable::Loading => { + return div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-titles", + "Session titles", + )) + .child(body(theme, "Choose how new sessions are named.")) + .child( + div() + .id("onboarding-title-settings-loading") + .mt(px(26.0)) + .h(px(44.0)) + .rounded(px(10.0)) + .bg(ink(0.045)) + .role(gpui::Role::ProgressIndicator) + .aria_label("Loading title settings"), + ) + .child( + action_button(theme, "Continue") + .mt(px(28.0)) + .id("onboarding-continue-titles-loading") + .role(gpui::Role::Button) + .track_focus(ui.control(25)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + })), + ) + .into_any_element(); + } + Loadable::Error(error) => { + return div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-titles", + "Session titles", + )) + .child(body(theme, "Choose how new sessions are named.")) + .child( + div() + .id("onboarding-title-settings-error") + .mt(px(26.0)) + .p(px(14.0)) + .rounded(px(10.0)) + .border_1() + .border_color(theme.danger_muted.opacity(0.5)) + .bg(theme.danger.opacity(0.06)) + .text_size(crate::typography::ui_rems(12.5)) + .line_height(px(18.0)) + .text_color(theme.danger_muted) + .role(gpui::Role::Alert) + .child(format!("Could not load title settings: {error}")), + ) + .child( + quiet_button(theme, "Retry") + .id("onboarding-title-settings-retry") + .mt(px(10.0)) + .role(gpui::Role::Button) + .track_focus(ui.control(24)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_load_titles(cx))), + ) + .child( + action_button(theme, "Continue") + .mt(px(18.0)) + .id("onboarding-continue-titles-error") + .role(gpui::Role::Button) + .track_focus(ui.control(25)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + })), + ) + .into_any_element(); + } + }; + let available: Vec = ui + .harnesses + .ready() + .map(|rows| { + rows.iter() + .filter(|h| title_harness_is_available(h)) + .map(|h| h.id) + .collect() + }) + .unwrap_or_default(); + let mut choices = div() + .id("onboarding-title-harnesses") + .flex() + .flex_col() + .gap(px(10.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Title agent") + .child( + choice_card( + theme, + "Automatic", + "Use an available agent, or the first seven words.", + current.harness.is_none(), + None, + ) + .id("onboarding-title-auto") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(current.harness.is_none())) + .track_focus(ui.control(0)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_pick_title_harness(None, cx))), + ); + for (index, harness) in available.into_iter().enumerate() { + choices = choices.child( + choice_card( + theme, + harness_name(harness), + "Generate a title without project tools.", + current.harness == Some(harness), + Some(harness), + ) + .id(("onboarding-title-harness", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(current.harness == Some(harness))) + .track_focus(ui.control(1 + index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_title_harness(Some(harness), cx) + })), + ); + } + let title_models: AnyElement = if current.harness.is_none() { + Empty.into_any_element() + } else { + match &ui.title_models { + Loadable::Idle | Loadable::Loading => div() + .id("onboarding-title-model-loading") + .mt(px(18.0)) + .h(px(38.0)) + .rounded(px(9.0)) + .bg(ink(0.045)) + .role(gpui::Role::ProgressIndicator) + .aria_label("Loading title models") + .into_any_element(), + Loadable::Error(error) => div() + .id("onboarding-title-model-error") + .mt(px(18.0)) + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.danger_muted) + .role(gpui::Role::Alert) + .child(error.clone()) + .into_any_element(), + Loadable::Ready(models) => div() + .mt(px(18.0)) + .flex() + .flex_col() + .gap(px(9.0)) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text_muted) + .child("Title model"), + ) + .child( + div() + .id("onboarding-title-models") + .flex() + .flex_wrap() + .gap(px(8.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Title model") + .child( + chip( + theme, + "Automatic · cheapest suitable".into(), + current.model.is_none(), + None, + ) + .id("onboarding-title-model-auto") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(current.model.is_none())) + .track_focus(ui.control(8)) + .on_click(cx.listener( + |shell, _, _, cx| shell.onboarding_pick_title_model(None, cx), + )), + ) + .children(models.iter().take(4).enumerate().map(|(index, model)| { + let selected = current.model.as_deref() == Some(model.id.as_str()); + let id = model.id.clone(); + chip(theme, model.label.clone().into(), selected, current.harness) + .id(("onboarding-title-model", index)) + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(9 + index)) + .on_click(cx.listener(move |shell, _, _, cx| { + shell.onboarding_pick_title_model(Some(id.clone()), cx) + })) + })), + ) + .into_any_element(), + } + }; + let title_options = div() + .child(choices) + .child(title_models) + .when_some(ui.error.clone(), |column, error| { + column.child( + div() + .id("onboarding-title-save-error") + .mb(px(10.0)) + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.danger_muted) + .role(gpui::Role::Alert) + .child(error), + ) + }) + .into_any_element(); + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-titles", + "Session titles", + )) + .child(body(theme, "Choose how new sessions are named.")) + .child( + div() + .mt(px(25.0)) + .flex_1() + .min_h_0() + .child(faded_step_scroll( + "onboarding-titles-scroll", + &ui.step_scroll, + title_options, + )), + ) + .child( + action_button(theme, "Continue") + .mt(px(28.0)) + .id("onboarding-continue-titles") + .role(gpui::Role::Button) + .track_focus(ui.control(25)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_continue(cx); + shell.onboarding_focus_control(0, window, cx); + })), + ) + .into_any_element() +} + +fn render_project_step( + ui: &OnboardingUi, + theme: &Theme, + state: &Entity, + cx: &mut Context, +) -> AnyElement { + let (selected_name, selected, no_project): (SharedString, bool, bool) = + if ui.fixture == Some(OnboardingFixture::Project) { + ("Comet".into(), true, false) + } else if ui.fixture == Some(OnboardingFixture::Projectless) { + ( + "Choose a folder on any connected device".into(), + false, + true, + ) + } else { + let state = state.read(cx); + let selected = state.selected_space_row(); + ( + selected + .map(|space| space.display_name().to_string().into()) + .unwrap_or_else(|| "Choose a folder on any connected device".into()), + selected.is_some(), + state.no_project, + ) + }; + let choices = div() + .id("onboarding-project-choices") + .flex() + .flex_col() + .gap(px(12.0)) + .role(gpui::Role::RadioGroup) + .aria_label("Project target") + .child( + choice_card( + theme, + "Start in a project", + selected_name, + selected && !no_project, + None, + ) + .id("onboarding-project-choose") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected && !no_project)) + .track_focus(ui.control(0)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_open_project(cx))), + ) + .child( + choice_card( + theme, + "Continue without a project", + "Add a project when you need one.", + no_project, + None, + ) + .id("onboarding-project-none") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(no_project)) + .track_focus(ui.control(1)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_pick_no_project(cx))), + ) + .when_some(ui.error.clone(), |column, error| { + column.child( + div() + .id("onboarding-project-error") + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.danger_muted) + .role(gpui::Role::Alert) + .child(error), + ) + }) + .into_any_element(); + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading(theme, "onboarding-heading-project", "Project")) + .child(body(theme, "Choose a folder now, or add one later.")) + .child( + div() + .mt(px(27.0)) + .flex_1() + .min_h_0() + .child(faded_step_scroll( + "onboarding-project-scroll", + &ui.step_scroll, + choices, + )), + ) + .child( + action_button(theme, "Finish setup") + .mt(px(28.0)) + .id("onboarding-continue-project") + .role(gpui::Role::Button) + .track_focus(ui.control(2)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_continue(cx))), + ) + .into_any_element() +} + +#[derive(Clone, Copy)] +enum ArtworkFocus { + Top, + Right, +} + +fn fitted_artwork_bounds( + bounds: gpui::Bounds, + image_size: gpui::Size, + focus: ArtworkFocus, +) -> gpui::Bounds { + let mut fitted = ObjectFit::Cover.get_bounds(bounds, image_size); + match focus { + ArtworkFocus::Top => fitted.origin.y = bounds.origin.y, + ArtworkFocus::Right => { + fitted.origin.x = bounds.origin.x + bounds.size.width - fitted.size.width + } + } + fitted +} + +fn render_artwork(ui: &OnboardingUi, theme: &Theme, focus: ArtworkFocus) -> AnyElement { + const RADIUS: f32 = 14.0; + let artwork = ui.artwork.clone(); + let image = gpui::canvas( + move |_, window, cx| artwork.use_render_image(window, cx), + move |bounds, image, window, _| { + let Some(image) = image else { + return; + }; + // Preserve ObjectFit::Cover's normal scale and move only the crop + // origin. Expanded panes reveal the right edge; compact panes + // reveal the top edge. + let fitted = fitted_artwork_bounds(bounds, image.size(0), focus); + let _ = window.paint_image_fitted( + bounds, + fitted, + gpui::Corners::all(px(RADIUS)), + image, + 0, + false, + ); + }, + ) + .absolute() + .inset_0(); + div() + .size_full() + .relative() + .rounded(px(RADIUS)) + .overflow_hidden() + .bg(theme.surface) + .child(image) + .child( + div() + .absolute() + .inset_0() + .rounded(px(RADIUS)) + .border_1() + .border_color(theme.border), + ) + .into_any_element() +} + +fn render_progress(step: OnboardingStep, theme: &Theme) -> AnyElement { + div() + .id("onboarding-progress") + .flex() + .gap(px(6.0)) + .role(gpui::Role::ProgressIndicator) + .aria_label(format!("Step {} of {STEP_COUNT}", step.index() + 1)) + .children( + OnboardingStep::ALL + .into_iter() + .enumerate() + .map(|(index, _)| { + div() + .h(px(3.0)) + .w(px(34.0)) + .rounded_full() + .bg(if index <= step.index() { + theme.accent + } else { + theme.border_strong + }) + }), + ) + .into_any_element() +} + +pub fn render( + ui: &OnboardingUi, + state: &Entity, + title_bar: AnyElement, + viewport: gpui::Size, + cx: &mut Context, +) -> AnyElement { + let theme = Theme::of(cx).clone(); + let step = ui.step(); + let viewport_width = f32::from(viewport.width); + let viewport_height = f32::from(viewport.height); + let compact = viewport_width < 980.0 || viewport_height < 620.0; + let compact_preview_height = + ((viewport_height - Theme::TITLEBAR_HEIGHT) * 0.34).clamp(190.0, 280.0); + let decision_top_pad = (viewport_height * 0.15).clamp(88.0, 144.0); + // Let the invisible titlebar establish the top safe area, then leave a + // small visual buffer below it. The remaining edges share a tighter inset + // so they stay balanced without inheriting the titlebar's dimensions. + let panel_edge = 14.0; + let panel_top = Theme::TITLEBAR_HEIGHT + 8.0; + let panel_bottom = panel_edge; + let panel_x = panel_edge; + let panel_gap = if compact { 12.0 } else { 24.0 }; + let wide_preview_width = ((viewport_width - panel_x * 2.0 - panel_gap) * 0.48).max(1.0); + let decision = match step { + OnboardingStep::Workspace => render_workspace_step(ui, &theme, cx), + OnboardingStep::Appearance => render_appearance_step(ui, &theme, cx), + OnboardingStep::Harnesses => render_harness_step(ui, &theme, state, cx), + OnboardingStep::Defaults => render_defaults_step(ui, &theme, cx), + OnboardingStep::Titles => render_titles_step(ui, &theme, cx), + OnboardingStep::Project => render_project_step(ui, &theme, state, cx), + OnboardingStep::FirstSession => render_project_step(ui, &theme, state, cx), + }; + let decision_content = div() + .size_full() + .max_w(px(440.0)) + .min_w_0() + .min_h_0() + .flex() + .flex_col() + // Every step starts on the same baseline. Vertical centering made the + // whole form jump whenever async rows or configuration controls changed + // its height; a stable top inset lets new content grow downward instead. + .when(!compact, |content| { + content.pt(px(decision_top_pad)).pb(px(28.0)) + }) + .child(decision); + let decision_content = crate::motion::fade_quick( + SharedString::from(format!("onboarding-step-{}", step.index())), + decision_content, + ); + let decision_host = div() + .size_full() + .min_w_0() + .min_h_0() + .overflow_hidden() + .px(px(if compact { 18.0 } else { 40.0 })) + .py(px(if compact { 20.0 } else { 28.0 })) + .flex() + .justify_center() + .child(decision_content); + let decision_pane = div() + .flex_1() + .min_w_0() + .min_h_0() + .flex() + .flex_col() + .child(div().flex_1().min_h_0().child(decision_host)) + .child( + div() + .h(px(34.0)) + .flex_none() + .flex() + .items_end() + .justify_center() + .child(render_progress(step, &theme)), + ); + let panel = if compact { + div() + .absolute() + .inset_0() + .pt(px(panel_top)) + .px(px(panel_x)) + .pb(px(panel_bottom)) + .min_w_0() + .min_h_0() + .flex() + .flex_col() + .gap(px(panel_gap)) + // In a reduced window, choices keep the primary/top position and + // the artwork becomes a bottom-anchored visual coda. + .child(decision_pane) + .child( + div() + .w_full() + .h(px(compact_preview_height)) + .min_w_0() + .min_h_0() + .flex_none() + .child(render_artwork(ui, &theme, ArtworkFocus::Top)), + ) + } else { + div() + .absolute() + .inset_0() + .pt(px(panel_top)) + .px(px(panel_x)) + .pb(px(panel_bottom)) + .min_w_0() + .min_h_0() + .flex() + .flex_row() + .gap(px(panel_gap)) + .child( + div() + .w(px(wide_preview_width)) + .h_full() + .min_w_0() + .min_h_0() + .flex_none() + .child(render_artwork(ui, &theme, ArtworkFocus::Right)), + ) + .child(decision_pane) + }; + let close_confirm: AnyElement = if ui.close_confirm { + div() + .absolute() + .inset_0() + .bg(theme.scrim()) + .flex() + .items_center() + .justify_center() + .child(crate::frost::frosted( + 14.0, + crate::frost::MENU_BLUR, + div() + .id("onboarding-close-dialog") + .w(px(360.0)) + .p(px(22.0)) + .rounded(px(14.0)) + .border_1() + .border_color(theme.border_strong) + .bg(theme.glass_overlay()) + .shadow_lg() + .role(gpui::Role::Dialog) + .aria_label("Continue onboarding later") + .child( + div() + .text_size(crate::typography::ui_rems(16.0)) + .font_weight(gpui::FontWeight::SEMIBOLD) + .text_color(theme.text) + .child("Continue setting up later?"), + ) + .child(body( + &theme, + "Your choices are saved. Zeron will return to this step the next time you open the app.", + )) + .child( + div() + .mt(px(20.0)) + .flex() + .justify_end() + .gap(px(8.0)) + .child( + quiet_button(&theme, "Keep setting up") + .id("onboarding-close-cancel") + .role(gpui::Role::Button) + .track_focus(ui.control(26)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_cancel_close(cx); + shell.onboarding_focus_control(29, window, cx); + })), + ) + .child( + action_button(&theme, "Continue later") + .id("onboarding-close-confirm") + .role(gpui::Role::Button) + .track_focus(ui.control(27)) + .w_auto() + .on_click(cx.listener(|shell, _, _, cx| { + shell.onboarding_defer(cx) + })), + ), + ), + )) + .into_any_element() + } else { + Empty.into_any_element() + }; + div() + .id("onboarding-root") + .role(gpui::Role::Main) + .aria_label(format!( + "Zeron setup, step {} of {STEP_COUNT}", + step.index() + 1 + )) + .size_full() + .relative() + .track_focus(&ui.focus) + .text_color(theme.text) + .font_family(theme.font_sans.clone()) + // Keep the dialog's accessibility tree and tab order isolated. The + // underlying journey is remounted when the dialog closes. + .when(!ui.close_confirm, |root| root.child(panel).child(title_bar)) + .child(close_confirm) + .into_any_element() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn step_navigation_is_bounded() { + assert_eq!( + OnboardingStep::Workspace.previous(), + OnboardingStep::Workspace + ); + assert_eq!(OnboardingStep::Workspace.next(), OnboardingStep::Appearance); + assert_eq!(OnboardingStep::Appearance.next(), OnboardingStep::Harnesses); + assert_eq!(OnboardingStep::Project.next(), OnboardingStep::Project); + assert_eq!(OnboardingStep::Project.index() + 1, STEP_COUNT); + } + + #[test] + fn established_profiles_default_to_completed() { + assert_eq!( + OnboardingState::default().disposition, + OnboardingDisposition::Completed + ); + assert!(OnboardingState::fresh().is_active()); + assert_eq!( + OnboardingState::fresh().workspace_mode, + Some(WorkspaceMode::Local) + ); + } + + #[test] + fn fixture_routes_are_stable() { + assert_eq!( + OnboardingFixture::from_route(Some("onboarding/agents")), + Some(OnboardingFixture::Harnesses) + ); + assert_eq!( + OnboardingFixture::from_route(Some("onboarding/appearance")) + .map(OnboardingFixture::step), + Some(OnboardingStep::Appearance) + ); + assert_eq!( + OnboardingFixture::from_route(Some("onboarding/first-session")) + .map(OnboardingFixture::step), + Some(OnboardingStep::Project) + ); + assert_eq!( + OnboardingFixture::from_route(Some("onboarding/narrow")).map(OnboardingFixture::step), + Some(OnboardingStep::Defaults) + ); + } + + #[test] + fn readiness_includes_enablement_installation_and_sign_in() { + let rows = fixture_harnesses(); + let codex = rows.iter().find(|row| row.id == HarnessId::Codex).unwrap(); + let opencode = rows + .iter() + .find(|row| row.id == HarnessId::Opencode) + .unwrap(); + assert!(!harness_is_ready(codex, &Loadable::Loading)); + assert!(!harness_is_ready( + opencode, + &Loadable::Ready(AgentAccountsSnapshot { + accounts: Vec::new(), + warnings: Vec::new(), + }) + )); + let mut enabled_opencode = opencode.clone(); + enabled_opencode.installed = true; + enabled_opencode.enabled = Some(true); + assert!(harness_is_ready(&enabled_opencode, &Loadable::Idle)); + + let accounts = Loadable::Ready(AgentAccountsSnapshot { + accounts: vec![zeron_proto::AgentAccount { + id: "codex".into(), + harness: HarnessId::Codex, + email: None, + plan_label: None, + active: true, + usage_windows: Vec::new(), + display_name: None, + organization: None, + auth_kind: Some(zeron_proto::AgentAuthKind::Oauth), + switchable: true, + saved_at: None, + }], + warnings: Vec::new(), + }); + assert!(harness_is_ready(codex, &accounts)); + } + + #[test] + fn title_harnesses_include_enabled_claude_code_and_codex() { + let rows = fixture_harnesses(); + let claude = rows + .iter() + .find(|row| row.id == HarnessId::ClaudeCode) + .unwrap(); + let codex = rows.iter().find(|row| row.id == HarnessId::Codex).unwrap(); + let cursor = rows.iter().find(|row| row.id == HarnessId::Cursor).unwrap(); + + assert!(title_harness_is_available(claude)); + assert!(title_harness_is_available(codex)); + assert!(!title_harness_is_available(cursor)); + } + + #[test] + fn close_dialog_tabs_never_escape_its_two_actions() { + assert_eq!(close_dialog_tab_target(None, false), 27); + assert_eq!(close_dialog_tab_target(Some(26), false), 27); + assert_eq!(close_dialog_tab_target(Some(27), false), 26); + assert_eq!(close_dialog_tab_target(None, true), 26); + assert_eq!(close_dialog_tab_target(Some(26), true), 27); + assert_eq!(close_dialog_tab_target(Some(27), true), 26); + } + + #[test] + fn project_continue_requires_an_explicit_target() { + assert!(!project_target_is_chosen(false, false)); + assert!(project_target_is_chosen(true, false)); + assert!(project_target_is_chosen(false, true)); + } + + #[test] + fn artwork_focus_moves_only_the_cover_crop_origin() { + let image_size = gpui::size(2560u32.into(), 1655u32.into()); + + let expanded = gpui::Bounds::new( + gpui::point(px(0.0), px(0.0)), + gpui::size(px(500.0), px(900.0)), + ); + let expanded_centered = ObjectFit::Cover.get_bounds(expanded, image_size); + let expanded_right = fitted_artwork_bounds(expanded, image_size, ArtworkFocus::Right); + assert_eq!(expanded_right.size, expanded_centered.size); + assert_eq!(expanded_right.origin.y, expanded_centered.origin.y); + assert_eq!( + expanded_right.origin.x, + expanded.origin.x + expanded.size.width - expanded_right.size.width + ); + + let compact = gpui::Bounds::new( + gpui::point(px(0.0), px(0.0)), + gpui::size(px(900.0), px(260.0)), + ); + let compact_centered = ObjectFit::Cover.get_bounds(compact, image_size); + let compact_top = fitted_artwork_bounds(compact, image_size, ArtworkFocus::Top); + assert_eq!(compact_top.size, compact_centered.size); + assert_eq!(compact_top.origin.x, compact_centered.origin.x); + assert_eq!(compact_top.origin.y, compact.origin.y); + } +} diff --git a/crates/ui/src/pickers.rs b/crates/ui/src/pickers.rs index 8b73e335eb..0f00f3010f 100644 --- a/crates/ui/src/pickers.rs +++ b/crates/ui/src/pickers.rs @@ -1530,6 +1530,45 @@ impl Pickers { cx.notify(); } + /// Apply first-run choices through the same draft/default state used by + /// the real composer. `None` keeps the corresponding Automatic behavior. + pub(crate) fn apply_onboarding_defaults( + &mut self, + harness: HarnessId, + model: Option, + reasoning: Option, + cx: &mut Context, + ) { + let harness_locked = self.harness_locked(cx); + if !harness_locked { + if self.config.harness != Some(harness) { + self.config.model_options.clear(); + } + self.config.harness = Some(harness); + self.config.model = model.clone(); + self.config.reasoning = reasoning; + } + self.defaults.harness = Some(harness); + if let Some(model_id) = model { + let label = self + .models + .get(&harness) + .and_then(|slot| slot.ready()) + .and_then(|models| models.iter().find(|candidate| candidate.id == model_id)) + .map(|model| model.label.clone()) + .unwrap_or_else(|| model_id.clone()); + self.defaults.remember_model(harness, model_id, label); + } else { + self.defaults.model_by_harness.remove(&harness); + } + self.defaults.reasoning = reasoning; + self.save_defaults(); + if !harness_locked { + self.ensure_models(harness, false, cx); + } + cx.notify(); + } + fn pick_option( &mut self, option_id: String, diff --git a/crates/ui/src/settings.rs b/crates/ui/src/settings.rs index bcbd8f74c6..8d713410eb 100644 --- a/crates/ui/src/settings.rs +++ b/crates/ui/src/settings.rs @@ -608,6 +608,9 @@ impl WindowGeometry { pub struct UiSettings { #[serde(skip_serializing_if = "Option::is_none")] pub window_geometry: Option, + /// Device-local first-run journey. Established profiles deserialize a + /// missing field as completed; only a genuinely empty profile opts in. + pub onboarding: crate::onboarding::OnboardingState, /// Submit using Enter or the platform modifier plus Enter. pub composer_send_behavior: ComposerSendBehavior, pub sidebar_width: f32, @@ -753,6 +756,7 @@ impl Default for UiSettings { fn default() -> Self { Self { window_geometry: None, + onboarding: crate::onboarding::OnboardingState::default(), sidebar_width: SIDEBAR_DEFAULT, sidebar_collapsed: false, sidebar_grouped: false, @@ -1475,6 +1479,29 @@ impl UiSettings { } } +/// A missing settings file alone does not mean a profile is new: users may +/// remove it while retaining sessions, authentication, or agent preferences. +/// Automatic onboarding is reserved for a data directory with no durable user +/// state at all. Explicit `ZERON_OPEN_ROUTE=onboarding[/…]` remains available +/// for manual runs and deterministic captures. +pub fn is_fresh_profile(data_dir: &Path) -> bool { + if UiSettings::path(data_dir).exists() { + return false; + } + [ + "docs.sqlite3", + "profiles/local/docs.sqlite3", + "session.json", + "harness-prefs.json", + "composer-defaults.json", + "repos.json", + "agent-accounts", + "orgs", + ] + .into_iter() + .all(|name| !data_dir.join(name).exists()) +} + fn clamp_or(value: f32, min: f32, max: f32, default: f32) -> f32 { if value.is_finite() { value.clamp(min, max) @@ -1972,6 +1999,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let settings = UiSettings { window_geometry: None, + onboarding: crate::onboarding::OnboardingState::fresh(), sidebar_width: 300.0, sidebar_collapsed: true, sidebar_grouped: true, @@ -2467,6 +2495,48 @@ mod tests { assert_eq!(settings.sidebar_pins("synced:org-a:user-a"), ["a-1"]); } + #[test] + fn established_settings_without_onboarding_stay_completed() { + let dir = tempfile::tempdir().unwrap(); + std::fs::write( + UiSettings::path(dir.path()), + r#"{"sidebarWidth": 300, "soundEnabled": false}"#, + ) + .unwrap(); + + let loaded = UiSettings::load(dir.path()); + assert_eq!( + loaded.onboarding.disposition, + crate::onboarding::OnboardingDisposition::Completed + ); + } + + #[test] + fn only_an_empty_profile_is_fresh() { + let dir = tempfile::tempdir().unwrap(); + assert!(is_fresh_profile(dir.path())); + + for durable_file in [ + "docs.sqlite3", + "profiles/local/docs.sqlite3", + "session.json", + "harness-prefs.json", + "composer-defaults.json", + "repos.json", + "agent-accounts/account.json", + "orgs/acme/user/docs.sqlite3", + ] { + let profile = tempfile::tempdir().unwrap(); + let path = profile.path().join(durable_file); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(path, []).unwrap(); + assert!(!is_fresh_profile(profile.path()), "{durable_file}"); + } + + std::fs::write(UiSettings::path(dir.path()), "{}").unwrap(); + assert!(!is_fresh_profile(dir.path())); + } + #[test] fn loaded_values_are_clamped() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/ui/src/settings/accounts.rs b/crates/ui/src/settings/accounts.rs index bbe1c3d8da..27078d3ffd 100644 --- a/crates/ui/src/settings/accounts.rs +++ b/crates/ui/src/settings/accounts.rs @@ -242,7 +242,7 @@ impl AccountsPage { } } - fn set_target_device(&mut self, target: Option, cx: &mut Context) { + pub(crate) fn set_target_device(&mut self, target: Option, cx: &mut Context) { self.close_device_menu(cx); if self.target_device == target { cx.notify(); diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index c29873a640..49e4310caa 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -19,12 +19,12 @@ use gpui::{ Action, AnyElement, App, ClipboardItem, Context, Empty, Entity, FocusHandle, Focusable as _, IntoElement, KeyBinding, Keystroke, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseUpEvent, Pixels, Point, Render, SharedString, Subscription, Task, Window, - WindowControlArea, actions, div, prelude::*, px, + WindowControlArea, actions, div, img, prelude::*, px, }; use gpui_tokio::Tokio; use zeron_engine::InstanceLock; -use zeron_proto::{AuthState, WorkspaceScope}; +use zeron_proto::{AuthState, HarnessId, WorkspaceScope}; use zeron_rpc::methods; use crate::changes::{Changes, ChangesEvent}; @@ -33,6 +33,9 @@ use crate::files::{FilesCloseDisposition, FilesEvent, FilesSurface, WorkspacePat use crate::icons::{self, icon}; use crate::loaders; use crate::motion::{self, AnimationExt as _, MotionSpec, RESIZE, SPLASH_OUT, TAB_SLIDE}; +use crate::onboarding::{ + OnboardingDisposition, OnboardingFixture, OnboardingStep, OnboardingUi, WorkspaceMode, +}; use crate::popover::{self, Loadable}; use crate::rail; use crate::settings::accounts::AccountsPage; @@ -464,6 +467,10 @@ fn right_pane_max_width(viewport: f32, sidebar: f32) -> f32 { (viewport - sidebar - CHAT_PANEL_MIN).max(0.0) } +fn new_session_can_compose(has_spaces: bool, no_project: bool) -> bool { + has_spaces || no_project +} + /// Width used by right-pane takeover. Unlike manual resizing, takeover is /// intentionally allowed to consume the conversation column completely. fn right_pane_takeover_width(viewport: f32, sidebar: f32) -> f32 { @@ -1443,6 +1450,12 @@ pub struct Shell { sidebar_pane: Entity, transcript: Entity, composer: Entity, + /// Full-window first-run flow. Its durable navigation snapshot mirrors the + /// `UiSettings` field; authoritative choices stay in their normal stores. + onboarding: OnboardingUi, + /// External image or workspace-path drag hovering the conversation + /// column; a drop stages an image or inserts a file-mention chip. + file_drag_active: bool, /// Measured height of the bottom chrome stack (status strip + composer + /// terminal dock) the full-height transcript scrolls under. Paint-time /// measurement schedules another frame whenever this value changes. @@ -1819,7 +1832,9 @@ impl Shell { // Dev/testing knob: `ZERON_OPEN_ROUTE=settings[/
]` boots // straight into a settings section — these pages have no deep link and // synthetic input can't reach them on headless compositors. - let route = match std::env::var("ZERON_OPEN_ROUTE").ok().as_deref() { + let open_route = std::env::var("ZERON_OPEN_ROUTE").ok(); + let onboarding_fixture = OnboardingFixture::from_route(open_route.as_deref()); + let route = match open_route.as_deref() { Some("settings") | Some("settings/devices") => { Route::Settings(SettingsSection::Devices) } @@ -1869,11 +1884,22 @@ impl Shell { shell: shell.downgrade(), _observation: cx.observe(&shell, |_, _, cx| cx.notify()), }); + let composer_defaults = crate::settings::composer::ComposerDefaults::load(&data_dir); + let mut onboarding_state = settings.onboarding.clone(); + if open_route.is_some() && onboarding_fixture.is_none() { + // Explicit debug/deep-link routes win for this launch without + // destroying the user's saved onboarding progress. + onboarding_state.disposition = OnboardingDisposition::Completed; + } + let onboarding = + OnboardingUi::new(onboarding_state, composer_defaults, onboarding_fixture, cx); Self { state, sidebar_pane, transcript, composer, + onboarding, + file_drag_active: false, // Seed with the compact composer stack's rough height so the // first frame's clearance isn't zero (the measure corrects it). bottom_stack: std::rc::Rc::new(std::cell::Cell::new(120.0)), @@ -2093,6 +2119,9 @@ impl Shell { self.org = None; } } + if matches!(state.read(cx).gate(), GatePhase::Ready) { + self.ensure_onboarding_data(cx); + } // The in-place local→synced switch: once the replacement runtime is // attached and Ready, kick the import (or finish) from here. self.drive_sync_switch(cx); @@ -3710,39 +3739,809 @@ impl Shell { cx.notify(); } - /// Publish this view's working copy to the central settings store. The - /// store owns the single debounce task and the only production writer. - fn schedule_save(&mut self, cx: &mut Context) { - self.settings.appearance = crate::appearance::mode(cx); - self.settings.git_history_columns = crate::history::configured_columns(cx); - self.settings.git_history_column_widths = crate::history::configured_column_widths(cx); - self.settings.git_history_column_order = crate::history::configured_column_order(cx); - self.settings.git_history_author_display = crate::history::configured_author_display(cx); - self.settings.theme_selection = crate::appearance::themes(cx); - self.settings.accent = crate::appearance::accent(cx); - self.settings.surface = crate::appearance::surface(cx); - self.sync_independent_settings(cx); - settings::replace(self.settings.clone(), SavePolicy::Debounced, cx); + /// Publish this view's working copy to the central settings store. The + /// store owns the single debounce task and the only production writer. + fn schedule_save(&mut self, cx: &mut Context) { + self.settings.appearance = crate::appearance::mode(cx); + self.settings.git_history_columns = crate::history::configured_columns(cx); + self.settings.git_history_column_widths = crate::history::configured_column_widths(cx); + self.settings.git_history_column_order = crate::history::configured_column_order(cx); + self.settings.git_history_author_display = crate::history::configured_author_display(cx); + self.settings.theme_selection = crate::appearance::themes(cx); + self.settings.accent = crate::appearance::accent(cx); + self.settings.surface = crate::appearance::surface(cx); + self.sync_independent_settings(cx); + settings::replace(self.settings.clone(), SavePolicy::Debounced, cx); + } + + /// Controls outside the Shell mutate these choices directly. A geometry + /// save must never publish the Shell's older values over those selections. + /// The typography globals own the font choices but persist every change + /// immediately, so the central store is an equally canonical read and + /// keeps this block on a single source. + fn sync_independent_settings(&mut self, cx: &App) { + let current = settings::current(cx); + self.settings.window_geometry = current.window_geometry; + self.settings.new_thread_composer_background = current.new_thread_composer_background; + self.settings.new_thread_background_effect = current.new_thread_background_effect; + self.settings.open_web_links_in_zeron = current.open_web_links_in_zeron; + self.settings.ui_font_family = current.ui_font_family; + self.settings.ui_font_size = current.ui_font_size; + self.settings.terminal_font_family = current.terminal_font_family; + self.settings.terminal_font_size = current.terminal_font_size; + self.settings.code_font_family = current.code_font_family; + self.settings.code_font_size = current.code_font_size; + self.settings.transcript_width = current.transcript_width; + } + + fn persist_onboarding(&mut self, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + // Appearance choices are applied by their global owner immediately. + // Refresh this view's settings mirror before replacing the full file so + // advancing a setup step cannot write an older palette back over them. + self.settings.appearance = crate::appearance::mode(cx); + self.settings.theme_selection = crate::appearance::themes(cx); + self.settings.accent = crate::appearance::accent(cx); + self.settings.surface = crate::appearance::surface(cx); + self.settings.onboarding = self.onboarding.state.clone(); + settings::replace(self.settings.clone(), SavePolicy::Immediate, cx); + } + + fn onboarding_target_params( + &self, + mut params: serde_json::Value, + cx: &App, + ) -> serde_json::Value { + let state = self.state.read(cx); + let target = state.effective_device_id(); + if target.as_deref() != state.local_device_id.as_deref() + && let (Some(target), Some(object)) = (target, params.as_object_mut()) + { + object.insert("targetDeviceId".into(), serde_json::Value::String(target)); + } + params + } + + fn ensure_onboarding_data(&mut self, cx: &mut Context) { + if !self.onboarding.active() || self.onboarding.fixture.is_some() { + return; + } + let step = self.onboarding.step(); + if step.index() >= OnboardingStep::Harnesses.index() + && matches!(self.onboarding.harnesses, Loadable::Idle) + { + self.onboarding_load_harnesses(cx); + } + if step.index() >= OnboardingStep::Harnesses.index() + && matches!(self.onboarding.accounts, Loadable::Idle) + { + self.onboarding_load_accounts(cx); + } + if step.index() >= OnboardingStep::Titles.index() + && matches!(self.onboarding.title_settings, Loadable::Idle) + { + self.onboarding_load_titles(cx); + } + } + + pub(crate) fn onboarding_pick_workspace( + &mut self, + mode: WorkspaceMode, + cx: &mut Context, + ) { + self.onboarding.state.workspace_mode = Some(mode); + self.onboarding.error = None; + self.persist_onboarding(cx); + cx.notify(); + } + + pub(crate) fn onboarding_pick_appearance( + &mut self, + mode: crate::appearance::AppearanceMode, + cx: &mut Context, + ) { + self.onboarding_close_theme_menu(cx); + if self.onboarding.fixture.is_none() { + crate::appearance::set_mode(mode, cx); + self.settings.appearance = mode; + } + cx.notify(); + } + + pub(crate) fn onboarding_note_theme_trigger_press(&mut self) { + self.onboarding.theme_menu.note_trigger_press(); + } + + pub(crate) fn onboarding_close_theme_menu(&mut self, cx: &mut Context) { + if self.onboarding.theme_menu.begin_close() { + popover::reap_popup(cx, |shell: &mut Self| &mut shell.onboarding.theme_menu); + cx.notify(); + } + } + + pub(crate) fn onboarding_toggle_theme_menu(&mut self, cx: &mut Context) { + if self.onboarding.theme_menu.take_press_was_open() { + self.onboarding_close_theme_menu(cx); + return; + } + let appearance = Theme::of(cx).appearance; + let variants = crate::onboarding::theme_variants(appearance); + let selected = variants + .iter() + .position(|variant| variant.id == Theme::of(cx).variant_id.as_ref()) + .unwrap_or(0); + self.onboarding.theme_menu.open(selected); + let scroll = self.onboarding.theme_scroll.clone(); + cx.defer(move |_| scroll.scroll_to_item(selected + 1)); + cx.notify(); + } + + pub(crate) fn onboarding_pick_accent( + &mut self, + accent: zeron_theme::AccentSelection, + cx: &mut Context, + ) { + if self.onboarding.fixture.is_none() { + crate::appearance::set_accent(accent, cx); + self.settings.accent = accent; + } + cx.notify(); + } + + pub(crate) fn onboarding_pick_theme( + &mut self, + appearance: crate::theme::Appearance, + variant_id: String, + cx: &mut Context, + ) { + self.onboarding_close_theme_menu(cx); + if self.onboarding.fixture.is_none() { + crate::appearance::set_theme(appearance, variant_id, cx); + self.settings.theme_selection = crate::appearance::themes(cx); + } + cx.notify(); + } + + pub(crate) fn onboarding_pick_surface( + &mut self, + surface: zeron_theme::SurfacePreference, + cx: &mut Context, + ) { + if self.onboarding.fixture.is_none() { + crate::appearance::set_surface(surface, cx); + self.settings.surface = surface; + } + cx.notify(); + } + + pub(crate) fn onboarding_continue(&mut self, cx: &mut Context) { + let step = self.onboarding.step(); + if step == OnboardingStep::Appearance { + self.onboarding_close_theme_menu(cx); + } + match step { + OnboardingStep::Workspace => { + let mode = self + .onboarding + .state + .workspace_mode + .unwrap_or(WorkspaceMode::Local); + self.onboarding.state.workspace_mode = Some(mode); + if mode == WorkspaceMode::Local + && self.state.read(cx).workspace_scope == Some(WorkspaceScope::Synced) + { + // A manual onboarding rerun is also allowed to change the + // workspace boundary. Keep this step mounted while the + // existing sign-out confirmation performs that transition; + // once the local runtime is ready, Continue advances. + self.persist_onboarding(cx); + self.request_sign_out(cx); + return; + } + self.onboarding.state.step = OnboardingStep::Appearance; + self.persist_onboarding(cx); + if self.onboarding.fixture.is_none() + && mode == WorkspaceMode::Synced + && self.state.read(cx).workspace_scope == Some(WorkspaceScope::Local) + { + self.start_sign_in(cx); + } + } + OnboardingStep::Appearance => { + self.onboarding.state.step = OnboardingStep::Harnesses; + self.persist_onboarding(cx); + self.onboarding_load_harnesses(cx); + self.onboarding_load_accounts(cx); + } + OnboardingStep::Harnesses => { + let ready_harnesses: Vec<_> = self + .onboarding + .harnesses + .ready() + .map(|rows| { + rows.iter() + .filter(|row| { + row.id != zeron_proto::HarnessId::Mock + && crate::onboarding::harness_is_ready( + row, + &self.onboarding.accounts, + ) + }) + .map(|row| row.id) + .collect() + }) + .unwrap_or_default(); + let Some(harness) = self + .onboarding + .selected_harness + .filter(|selected| ready_harnesses.contains(selected)) + .or_else(|| ready_harnesses.first().copied()) + else { + self.onboarding.error = + Some("Turn on at least one installed agent to continue.".into()); + cx.notify(); + return; + }; + self.onboarding.selected_harness = Some(harness); + self.persist_onboarding_defaults(cx); + self.onboarding.state.step = OnboardingStep::Defaults; + self.persist_onboarding(cx); + self.onboarding_load_models(harness, cx); + } + OnboardingStep::Defaults => { + if let Some(harness) = self.onboarding.selected_harness { + let model = self.onboarding.selected_model.clone(); + let reasoning = self.onboarding.selected_reasoning; + let pickers = self.composer.read(cx).pickers().clone(); + pickers.update(cx, |pickers, cx| { + pickers.apply_onboarding_defaults(harness, model, reasoning, cx) + }); + } + self.onboarding.state.step = OnboardingStep::Titles; + self.persist_onboarding(cx); + self.onboarding_load_titles(cx); + } + OnboardingStep::Titles => { + self.onboarding.state.step = OnboardingStep::Project; + self.persist_onboarding(cx); + } + OnboardingStep::Project => { + let target_is_chosen = { + let state = self.state.read(cx); + crate::onboarding::project_target_is_chosen( + state.selected_space.is_some(), + state.no_project, + ) + }; + if !target_is_chosen { + self.onboarding.error = + Some("Choose a project or continue without one.".into()); + cx.notify(); + return; + } + self.onboarding.state.disposition = OnboardingDisposition::Completed; + self.persist_onboarding(cx); + self.route = Route::Chat; + self.state.update(cx, |state, cx| { + state.auto_selected = true; + state.select_chat(None, cx); + }); + self.focus_composer(cx); + } + OnboardingStep::FirstSession => unreachable!("legacy onboarding step is normalized"), + } + self.onboarding + .step_scroll + .set_offset(gpui::Point::default()); + self.onboarding + .harness_scroll + .set_offset(gpui::Point::default()); + self.ensure_onboarding_data(cx); + cx.notify(); + } + + pub(crate) fn onboarding_back(&mut self, cx: &mut Context) { + self.onboarding_close_theme_menu(cx); + self.onboarding.close_confirm = false; + self.onboarding.agent_settings_open = false; + self.onboarding.state.step = self.onboarding.step().previous(); + self.onboarding + .step_scroll + .set_offset(gpui::Point::default()); + self.onboarding + .harness_scroll + .set_offset(gpui::Point::default()); + self.persist_onboarding(cx); + cx.notify(); + } + + pub(crate) fn onboarding_skip(&mut self, cx: &mut Context) { + self.onboarding_close_theme_menu(cx); + self.onboarding.state.disposition = OnboardingDisposition::Skipped; + self.persist_onboarding(cx); + cx.notify(); + } + + pub(crate) fn onboarding_request_close(&mut self, cx: &mut Context) { + self.onboarding_close_theme_menu(cx); + self.onboarding.close_confirm = true; + cx.notify(); + } + + pub(crate) fn onboarding_cancel_close(&mut self, cx: &mut Context) { + self.onboarding.close_confirm = false; + cx.notify(); + } + + pub(crate) fn onboarding_focus_control( + &self, + index: usize, + window: &mut Window, + cx: &mut Context, + ) { + window.focus(self.onboarding.control(index), cx); + } + + pub(crate) fn onboarding_defer(&mut self, cx: &mut Context) { + self.onboarding.close_confirm = false; + self.onboarding.state.disposition = OnboardingDisposition::Deferred; + self.persist_onboarding(cx); + cx.notify(); + } + + fn restart_onboarding(&mut self, cx: &mut Context) { + self.close_user_menu(cx); + let defaults = crate::settings::composer::ComposerDefaults::load(&self.data_dir); + let mut state = crate::onboarding::OnboardingState::fresh(); + state.workspace_mode = Some( + if self.state.read(cx).workspace_scope == Some(WorkspaceScope::Synced) { + WorkspaceMode::Synced + } else { + WorkspaceMode::Local + }, + ); + self.onboarding = OnboardingUi::new(state, defaults, None, cx); + self.persist_onboarding(cx); + cx.notify(); + } + + pub(crate) fn onboarding_load_harnesses(&mut self, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params(serde_json::json!({}), cx); + self.onboarding.harnesses = Loadable::Loading; + self.onboarding.error = None; + self.onboarding.harness_task = Some(cx.spawn(async move |this, cx| { + let result = engine.client().call(methods::LIST_HARNESSES, params).await; + this.update(cx, |shell, cx| { + shell.onboarding.harnesses = match result { + Ok(value) => serde_json::from_value(value) + .map(Loadable::Ready) + .unwrap_or_else(|error| Loadable::Error(error.to_string())), + Err(error) => Loadable::Error(error.to_string()), + }; + let selected_is_ready = shell.onboarding.harnesses.ready().is_some_and( + |rows: &Vec| { + rows.iter().any(|row| { + Some(row.id) == shell.onboarding.selected_harness + && row.id != zeron_proto::HarnessId::Mock + && crate::onboarding::harness_is_ready( + row, + &shell.onboarding.accounts, + ) + }) + }, + ); + if !selected_is_ready { + shell.onboarding.selected_harness = + shell.onboarding.harnesses.ready().and_then( + |rows: &Vec| { + rows.iter() + .find(|row| { + row.id != zeron_proto::HarnessId::Mock + && crate::onboarding::harness_is_ready( + row, + &shell.onboarding.accounts, + ) + }) + .map(|row| row.id) + }, + ); + } + cx.notify(); + }) + .ok(); + })); + cx.notify(); + } + + pub(crate) fn onboarding_load_accounts(&mut self, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params(serde_json::json!({ "forceUsage": false }), cx); + self.onboarding.accounts = Loadable::Loading; + self.onboarding.accounts_task = Some(cx.spawn(async move |this, cx| { + let result = engine + .client() + .call(methods::LIST_AGENT_ACCOUNTS, params) + .await; + this.update(cx, |shell, cx| { + shell.onboarding.accounts = match result { + Ok(value) => serde_json::from_value(value) + .map(Loadable::Ready) + .unwrap_or_else(|error| Loadable::Error(error.to_string())), + Err(error) => Loadable::Error(error.to_string()), + }; + let selected_is_ready = shell.onboarding.harnesses.ready().is_some_and(|rows| { + rows.iter().any(|row| { + Some(row.id) == shell.onboarding.selected_harness + && crate::onboarding::harness_is_ready(row, &shell.onboarding.accounts) + }) + }); + if !selected_is_ready { + shell.onboarding.selected_harness = + shell.onboarding.harnesses.ready().and_then(|rows| { + rows.iter() + .find(|row| { + row.id != HarnessId::Mock + && crate::onboarding::harness_is_ready( + row, + &shell.onboarding.accounts, + ) + }) + .map(|row| row.id) + }); + } + cx.notify(); + }) + .ok(); + })); + } + + pub(crate) fn onboarding_open_agent_settings(&mut self, cx: &mut Context) { + self.onboarding.agent_settings_open = true; + let target = { + let state = self.state.read(cx); + state + .effective_device_id() + .filter(|target| Some(target.as_str()) != state.local_device_id.as_deref()) + }; + if self.accounts_page.is_none() { + let state = self.state.clone(); + self.accounts_page = Some(cx.new(|cx| AccountsPage::new(state, cx))); + } + if let Some(page) = &self.accounts_page { + page.update(cx, |page, cx| page.set_target_device(target, cx)); + } + self.open_settings(SettingsSection::Agents, cx); + } + + pub(crate) fn onboarding_pick_device(&mut self, device_id: String, cx: &mut Context) { + self.state + .update(cx, |state, cx| state.select_device(device_id, cx)); + self.onboarding.harnesses = Loadable::Idle; + self.onboarding.models = Loadable::Idle; + self.onboarding.accounts = Loadable::Idle; + self.onboarding.title_settings = Loadable::Idle; + self.onboarding.title_models = Loadable::Idle; + self.onboarding.selected_harness = None; + self.onboarding.selected_model = None; + self.onboarding.selected_reasoning = None; + self.onboarding_remember_target(cx); + self.onboarding_load_harnesses(cx); + self.onboarding_load_accounts(cx); + cx.notify(); + } + + pub(crate) fn onboarding_toggle_harness( + &mut self, + harness: zeron_proto::HarnessId, + enabled: bool, + cx: &mut Context, + ) { + if self.onboarding.fixture.is_some() { + if let Some(rows) = match &mut self.onboarding.harnesses { + Loadable::Ready(rows) => Some(rows), + _ => None, + } && let Some(row) = rows.iter_mut().find(|row| row.id == harness) + { + row.enabled = Some(enabled); + } + cx.notify(); + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params( + serde_json::json!({ "harness": harness, "enabled": enabled }), + cx, + ); + self.onboarding.error = None; + self.onboarding.harness_task = Some(cx.spawn(async move |this, cx| { + let result = engine + .client() + .call(methods::SET_HARNESS_ENABLED, params) + .await; + this.update(cx, |shell, cx| { + match result { + Ok(value) => match serde_json::from_value(value) { + Ok(rows) => { + shell.onboarding.harnesses = Loadable::Ready(rows); + crate::pickers::bump_harness_catalog(cx); + } + Err(error) => shell.onboarding.error = Some(error.to_string().into()), + }, + Err(error) => shell.onboarding.error = Some(error.to_string().into()), + } + cx.notify(); + }) + .ok(); + })); + cx.notify(); + } + + pub(crate) fn onboarding_pick_default_harness( + &mut self, + harness: zeron_proto::HarnessId, + cx: &mut Context, + ) { + self.onboarding.selected_harness = Some(harness); + self.onboarding.selected_model = None; + self.onboarding.selected_reasoning = None; + self.persist_onboarding_defaults(cx); + self.onboarding_load_models(harness, cx); + cx.notify(); + } + + fn onboarding_load_models(&mut self, harness: zeron_proto::HarnessId, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params(serde_json::json!({ "harness": harness }), cx); + self.onboarding.models = Loadable::Loading; + self.onboarding.model_task = Some(cx.spawn(async move |this, cx| { + let result = engine.client().call(methods::LIST_MODELS, params).await; + this.update(cx, |shell, cx| { + shell.onboarding.models = match result { + Ok(value) => serde_json::from_value(value) + .map(Loadable::Ready) + .unwrap_or_else(|error| Loadable::Error(error.to_string())), + Err(error) => Loadable::Error(error.to_string()), + }; + cx.notify(); + }) + .ok(); + })); + } + + pub(crate) fn onboarding_pick_default_model( + &mut self, + model: Option, + cx: &mut Context, + ) { + self.onboarding.selected_model = model; + self.onboarding.selected_reasoning = None; + self.persist_onboarding_defaults(cx); + cx.notify(); + } + + pub(crate) fn onboarding_pick_reasoning( + &mut self, + reasoning: Option, + cx: &mut Context, + ) { + self.onboarding.selected_reasoning = reasoning; + self.persist_onboarding_defaults(cx); + cx.notify(); + } + + fn persist_onboarding_defaults(&mut self, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + let Some(harness) = self.onboarding.selected_harness else { + return; + }; + let model = self.onboarding.selected_model.clone(); + let reasoning = self.onboarding.selected_reasoning; + let pickers = self.composer.read(cx).pickers().clone(); + pickers.update(cx, |pickers, cx| { + pickers.apply_onboarding_defaults(harness, model, reasoning, cx) + }); + } + + pub(crate) fn onboarding_load_titles(&mut self, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params(serde_json::json!({}), cx); + self.onboarding.title_settings = Loadable::Loading; + self.onboarding.title_task = Some(cx.spawn(async move |this, cx| { + let result = engine + .client() + .call(methods::GET_TITLE_SETTINGS, params) + .await; + this.update(cx, |shell, cx| { + shell.onboarding.title_settings = match result { + Ok(value) => serde_json::from_value(value) + .map(Loadable::Ready) + .unwrap_or_else(|error| Loadable::Error(error.to_string())), + Err(error) => Loadable::Error(error.to_string()), + }; + if let Some(harness) = shell + .onboarding + .title_settings + .ready() + .and_then(|settings| settings.harness) + { + shell.onboarding_load_title_models(harness, cx); + } else { + shell.onboarding.title_models = Loadable::Idle; + } + cx.notify(); + }) + .ok(); + })); + } + + pub(crate) fn onboarding_pick_title_harness( + &mut self, + harness: Option, + cx: &mut Context, + ) { + let choice = zeron_engine::registry::TitleSettings { + harness, + model: None, + }; + self.onboarding.title_models = if harness.is_some() { + Loadable::Loading + } else { + Loadable::Idle + }; + self.onboarding_save_title_settings(choice, cx); + if let Some(harness) = harness { + self.onboarding_load_title_models(harness, cx); + } + } + + pub(crate) fn onboarding_pick_title_model( + &mut self, + model: Option, + cx: &mut Context, + ) { + let Some(harness) = self + .onboarding + .title_settings + .ready() + .and_then(|settings| settings.harness) + else { + return; + }; + self.onboarding_save_title_settings( + zeron_engine::registry::TitleSettings { + harness: Some(harness), + model, + }, + cx, + ); + } + + fn onboarding_save_title_settings( + &mut self, + choice: zeron_engine::registry::TitleSettings, + cx: &mut Context, + ) { + if self.onboarding.fixture.is_some() { + self.onboarding.title_settings = Loadable::Ready(choice); + cx.notify(); + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params( + serde_json::to_value(&choice).unwrap_or_else(|_| serde_json::json!({})), + cx, + ); + self.onboarding.error = None; + self.onboarding.title_task = Some(cx.spawn(async move |this, cx| { + let result = engine + .client() + .call(methods::SET_TITLE_SETTINGS, params) + .await; + this.update(cx, |shell, cx| { + match result { + Ok(value) => match serde_json::from_value(value) { + Ok(settings) => shell.onboarding.title_settings = Loadable::Ready(settings), + Err(error) => shell.onboarding.error = Some(error.to_string().into()), + }, + Err(error) => shell.onboarding.error = Some(error.to_string().into()), + } + cx.notify(); + }) + .ok(); + })); + cx.notify(); + } + + fn onboarding_load_title_models( + &mut self, + harness: zeron_proto::HarnessId, + cx: &mut Context, + ) { + if self.onboarding.fixture.is_some() { + return; + } + let Some(engine) = self.state.read(cx).engine().cloned() else { + return; + }; + let params = self.onboarding_target_params(serde_json::json!({ "harness": harness }), cx); + self.onboarding.title_models = Loadable::Loading; + self.onboarding.title_model_task = Some(cx.spawn(async move |this, cx| { + let result = engine.client().call(methods::LIST_MODELS, params).await; + this.update(cx, |shell, cx| { + shell.onboarding.title_models = match result { + Ok(value) => serde_json::from_value(value) + .map(Loadable::Ready) + .unwrap_or_else(|error| Loadable::Error(error.to_string())), + Err(error) => Loadable::Error(error.to_string()), + }; + cx.notify(); + }) + .ok(); + })); } - /// Controls outside the Shell mutate these choices directly. A geometry - /// save must never publish the Shell's older values over those selections. - /// The typography globals own the font choices but persist every change - /// immediately, so the central store is an equally canonical read and - /// keeps this block on a single source. - fn sync_independent_settings(&mut self, cx: &App) { - let current = settings::current(cx); - self.settings.window_geometry = current.window_geometry; - self.settings.new_thread_composer_background = current.new_thread_composer_background; - self.settings.new_thread_background_effect = current.new_thread_background_effect; - self.settings.open_web_links_in_zeron = current.open_web_links_in_zeron; - self.settings.ui_font_family = current.ui_font_family; - self.settings.ui_font_size = current.ui_font_size; - self.settings.terminal_font_family = current.terminal_font_family; - self.settings.terminal_font_size = current.terminal_font_size; - self.settings.code_font_family = current.code_font_family; - self.settings.code_font_size = current.code_font_size; - self.settings.transcript_width = current.transcript_width; + pub(crate) fn onboarding_open_project(&mut self, cx: &mut Context) { + self.onboarding.error = None; + self.open_add_space(cx); + } + + pub(crate) fn onboarding_pick_no_project(&mut self, cx: &mut Context) { + self.onboarding.error = None; + self.state.update(cx, |state, cx| { + state.auto_selected = true; + state.select_space(None, cx); + state.select_chat(None, cx); + }); + self.onboarding_remember_target(cx); + cx.notify(); + } + + pub(super) fn onboarding_remember_target(&mut self, cx: &mut Context) { + if self.onboarding.fixture.is_some() { + return; + } + let mut defaults = crate::settings::composer::ComposerDefaults::load(&self.data_dir); + { + let state = self.state.read(cx); + defaults.device = state + .selected_device + .clone() + .or_else(|| state.local_device_id.clone()); + defaults.project = state.selected_space.clone(); + defaults.no_project = state.no_project; + } + if let Err(error) = defaults.save(&self.data_dir) { + self.onboarding.error = Some(format!("Unable to remember this choice: {error}").into()); + } } fn retry_engine(&mut self, cx: &mut Context) { @@ -3842,6 +4641,11 @@ impl Shell { fn close_settings(&mut self, cx: &mut Context) { self.route = Route::Chat; + if self.onboarding.agent_settings_open { + self.onboarding.agent_settings_open = false; + self.onboarding.accounts = Loadable::Idle; + self.onboarding_load_accounts(cx); + } self.focus_composer(cx); self.nav.push(NavEntry::Chat(self.active_chat.clone())); cx.notify(); @@ -5156,9 +5960,136 @@ impl Shell { cluster + CLUSTER_BUTTONS_WIDTH + TITLEBAR_IDENTITY_GAP } - /// The unified window titlebar: chat → the session tab strip; settings → - /// the section label. Full-width on the glass shell; the traffic lights - /// and control cluster overlay its left end. + /// Compact onboarding titlebar: preserve the native traffic-light safe + /// area and window drag/double-click behavior while keeping a centered app + /// identity. Journey controls occupy the trailing safe area and explicitly + /// occlude the native drag target beneath them. + fn render_onboarding_title_bar( + &mut self, + viewport_width: f32, + cx: &mut Context, + ) -> AnyElement { + let theme = Theme::of(cx).clone(); + let at_first_step = self.onboarding.step() == OnboardingStep::Workspace; + let icon_only_skip = viewport_width < 420.0; + let back = div() + .id("onboarding-back") + .size(px(24.0)) + .flex_none() + .rounded_full() + .border_1() + .border_color(theme.border_strong.opacity(0.72)) + .bg(theme.glass_hover()) + .flex() + .items_center() + .justify_center() + .role(gpui::Role::Button) + .aria_label("Previous setup step") + .occlude() + .on_mouse_down(MouseButton::Left, |_, window, _| window.prevent_default()) + .when(at_first_step, |button| { + button + .opacity(0.32) + .aria_description("Unavailable on the first step") + }) + .when(!at_first_step, |button| { + button + .cursor_pointer() + .track_focus(self.onboarding.control(28)) + .hover(|style| style.bg(theme.element_hover)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .on_click(cx.listener(|shell, _, window, cx| { + cx.stop_propagation(); + shell.onboarding_back(cx); + shell.onboarding_focus_control(0, window, cx); + })) + }) + .child( + icon(icons::ALT_ARROW_LEFT) + .size(px(11.0)) + .text_color(theme.text), + ); + let skip = div() + .id("onboarding-skip") + .h(px(24.0)) + .when(icon_only_skip, |button| button.w(px(24.0))) + .when(!icon_only_skip, |button| button.px(px(8.0))) + .flex_none() + .rounded_full() + .border_1() + .border_color(theme.border_strong.opacity(0.72)) + .bg(theme.glass_hover()) + .flex() + .items_center() + .justify_center() + .gap(px(4.0)) + .cursor_pointer() + .text_size(crate::typography::ui_rems(11.0)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(theme.text) + .role(gpui::Role::Button) + .aria_label("Skip setup") + .track_focus(self.onboarding.control(29)) + .hover(|style| style.bg(theme.element_hover)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .occlude() + .on_mouse_down(MouseButton::Left, |_, window, _| window.prevent_default()) + .on_click(cx.listener(|shell, _, _, cx| { + cx.stop_propagation(); + shell.onboarding_skip(cx); + })) + .when(!icon_only_skip, |button| button.child("Skip")) + .child( + icon(icons::ALT_ARROW_RIGHT) + .size(px(11.0)) + .text_color(theme.text), + ); + let controls = div() + .absolute() + .top_0() + .right(px(self.titlebar_right_pad(14.0))) + .h(px(Theme::TITLEBAR_HEIGHT)) + .pt(px(Theme::TITLEBAR_TOP_PAD)) + .flex() + .items_center() + .gap(px(6.0)) + .child(back) + .child(skip); + let identity = div() + .absolute() + .top_0() + .left_0() + .right_0() + .h(px(Theme::TITLEBAR_HEIGHT)) + .pt(px(Theme::TITLEBAR_TOP_PAD)) + .flex() + .items_center() + .justify_center() + .gap(px(7.0)) + .text_size(crate::typography::ui_rems(12.0)) + .font_weight(gpui::FontWeight::SEMIBOLD) + .text_color(theme.text_muted) + .child( + img(self.onboarding.brand_mark.clone()) + .size(px(18.0)) + .rounded(px(4.0)), + ) + .child("Zeron"); + self.titlebar_drag_region( + "onboarding-titlebar-drag", + div() + .absolute() + .top_0() + .left_0() + .right_0() + .h(px(Theme::TITLEBAR_HEIGHT)) + .child(identity) + .child(controls), + cx, + ) + .into_any_element() + } + fn render_title_bar(&mut self, viewport_height: Pixels, cx: &mut Context) -> AnyElement { match self.route { Route::Chat => self.render_session_title_bar(viewport_height, cx), @@ -7343,6 +8274,17 @@ impl Shell { ) .child(SharedString::from("Settings")), ) + .child( + popover::menu_row(theme, false, "user-menu-onboarding") + .id("user-menu-onboarding") + .on_click(cx.listener(|this, _, _, cx| this.restart_onboarding(cx))) + .child( + icon(icons::CHECKLIST) + .size(px(16.0)) + .text_color(theme.text_muted), + ) + .child(SharedString::from("Show onboarding")), + ) .into_any_element(); trigger = trigger.child(popover::anchored_menu_above( "user-menu-popover", @@ -7743,7 +8685,7 @@ impl Shell { /// Resolve shell-owned Escape surfaces in capture phase, before focused /// descendants such as an integrated terminal can consume the key. - fn capture_escape_surface(&mut self, cx: &mut Context) -> bool { + fn capture_escape_surface(&mut self, window: &mut Window, cx: &mut Context) -> bool { // Modals and context menus sit above the rest of the shell. Preserve // their existing behavior: only surfaces that already have a Cancel // path close here; the others remain explicit blockers. @@ -7771,6 +8713,16 @@ impl Shell { cx.notify(); return true; } + if self.onboarding.active() { + if self.onboarding.close_confirm { + self.onboarding_cancel_close(cx); + self.onboarding_focus_control(29, window, cx); + } else { + self.onboarding_request_close(cx); + self.onboarding_focus_control(26, window, cx); + } + return true; + } if self.spaces_menu.is_open() { self.close_spaces_menu(cx); return true; @@ -7807,17 +8759,391 @@ impl Shell { cx.stop_propagation(); return; } - if event.keystroke.key == "escape" && self.capture_escape_surface(cx) { + if event.keystroke.key == "escape" && self.capture_escape_surface(window, cx) { cx.stop_propagation(); } } + fn onboarding_key_down( + &mut self, + event: &gpui::KeyDownEvent, + window: &mut Window, + cx: &mut Context, + ) -> bool { + if !self.onboarding.active() { + return false; + } + if self.onboarding.step() == OnboardingStep::Appearance + && self.onboarding.theme_menu.is_open() + { + let key = popover::classify_key( + event.keystroke.key.as_str(), + event.keystroke.modifiers.platform, + event.keystroke.modifiers.control, + ); + match key { + popover::MenuKey::Escape => { + self.onboarding_close_theme_menu(cx); + return true; + } + popover::MenuKey::Up | popover::MenuKey::Down => { + let count = crate::onboarding::theme_variants(Theme::of(cx).appearance).len(); + let delta = if key == popover::MenuKey::Up { -1 } else { 1 }; + let current = self.onboarding.theme_menu.as_open().copied(); + if let Some(next) = popover::menu_step(current, count, delta) { + if let Some(active) = self.onboarding.theme_menu.open_mut() { + *active = next; + } + self.onboarding.theme_scroll.scroll_to_item(next + 1); + cx.notify(); + } + return true; + } + popover::MenuKey::Enter | popover::MenuKey::ModEnter => { + let appearance = Theme::of(cx).appearance; + let active = self.onboarding.theme_menu.as_open().copied().unwrap_or(0); + if let Some(variant) = crate::onboarding::theme_variants(appearance).get(active) + { + self.onboarding_pick_theme(appearance, variant.id.clone(), cx); + } + return true; + } + popover::MenuKey::Backspace | popover::MenuKey::Other => { + if event.keystroke.key == "tab" { + self.onboarding_close_theme_menu(cx); + } + } + } + } + if self.onboarding.close_confirm + && event.keystroke.key == "tab" + && !event.keystroke.modifiers.control + && !event.keystroke.modifiers.alt + && !event.keystroke.modifiers.platform + { + let focused = self + .onboarding + .controls + .iter() + .position(|handle| handle.is_focused(window)); + let target = crate::onboarding::close_dialog_tab_target( + focused, + event.keystroke.modifiers.shift, + ); + window.focus(self.onboarding.control(target), cx); + return true; + } + let focused = self + .onboarding + .controls + .iter() + .position(|handle| handle.is_focused(window)); + let Some(focused) = focused else { + return false; + }; + let starting_step = self.onboarding.step(); + + if matches!( + event.keystroke.key.as_str(), + "left" | "right" | "up" | "down" + ) && !event.keystroke.modifiers.modified() + { + let step = self.onboarding.step(); + let group = match step { + OnboardingStep::Workspace if focused <= 1 => Some((0, 1)), + OnboardingStep::Appearance if focused <= 2 => Some((0, 2)), + OnboardingStep::Appearance if (8..15).contains(&focused) => Some((8, 14)), + OnboardingStep::Appearance if (16..19).contains(&focused) => Some((16, 18)), + OnboardingStep::Harnesses if focused < 8 => { + self.onboarding.harnesses.ready().map(|rows| { + ( + 0, + rows.iter() + .filter(|row| { + row.id != HarnessId::Mock + && crate::onboarding::harness_is_interactive(row) + }) + .count() + .saturating_sub(1), + ) + }) + } + OnboardingStep::Harnesses if (20..25).contains(&focused) => { + let count = self.state.read(cx).devices.len().min(5); + (count > 1).then_some((20, 20 + count - 1)) + } + OnboardingStep::Defaults if focused < 8 => { + self.onboarding.harnesses.ready().map(|rows| { + let count = rows + .iter() + .filter(|row| { + row.id != HarnessId::Mock + && crate::onboarding::harness_is_ready( + row, + &self.onboarding.accounts, + ) + }) + .count(); + (0, count.saturating_sub(1)) + }) + } + OnboardingStep::Defaults if (8..16).contains(&focused) => self + .onboarding + .models + .ready() + .map(|models| (8, 8 + models.len().min(4))), + OnboardingStep::Defaults if (16..26).contains(&focused) => { + let count = self + .onboarding + .models + .ready() + .and_then(|models| { + models + .iter() + .find(|model| { + Some(model.id.as_str()) + == self.onboarding.selected_model.as_deref() + }) + .map(|model| model.reasoning_levels.len()) + }) + .unwrap_or(0); + Some((16, 16 + count.min(9))) + } + OnboardingStep::Titles if focused < 8 => { + let count = self + .onboarding + .harnesses + .ready() + .map(|rows| { + rows.iter() + .filter(|row| crate::onboarding::title_harness_is_available(row)) + .count() + }) + .unwrap_or(0); + Some((0, count.min(7))) + } + OnboardingStep::Titles if (8..16).contains(&focused) => self + .onboarding + .title_models + .ready() + .map(|models| (8, 8 + models.len().min(4))), + OnboardingStep::Project if focused <= 1 => Some((0, 1)), + _ => None, + }; + if let Some((start, end)) = group + && end >= start + { + let forward = matches!(event.keystroke.key.as_str(), "right" | "down"); + let next = if forward { + if focused >= end { start } else { focused + 1 } + } else if focused <= start { + end + } else { + focused - 1 + }; + window.focus(self.onboarding.control(next), cx); + return true; + } + } + + if !crate::onboarding::activates(event) { + return false; + } + if self.onboarding.close_confirm { + match focused { + 26 => self.onboarding_cancel_close(cx), + 27 => self.onboarding_defer(cx), + _ => return false, + } + return true; + } + match focused { + 28 if self.onboarding.step() != OnboardingStep::Workspace => self.onboarding_back(cx), + 29 => self.onboarding_skip(cx), + 30 => self.onboarding_request_close(cx), + _ => match self.onboarding.step() { + OnboardingStep::Workspace => match focused { + 0 => self.onboarding_pick_workspace(WorkspaceMode::Local, cx), + 1 => self.onboarding_pick_workspace(WorkspaceMode::Synced, cx), + 2 => self.onboarding_continue(cx), + _ => return false, + }, + OnboardingStep::Appearance => { + if focused == 25 { + self.onboarding_continue(cx); + } else if focused == 3 { + self.onboarding_toggle_theme_menu(cx); + } else if focused <= 2 { + let Some(mode) = + crate::appearance::AppearanceMode::ALL.get(focused).copied() + else { + return false; + }; + self.onboarding_pick_appearance(mode, cx); + } else if (8..15).contains(&focused) { + let Some(accent) = zeron_theme::AccentPreset::ALL.get(focused - 8).copied() + else { + return false; + }; + self.onboarding_pick_accent( + zeron_theme::AccentSelection::Preset(accent), + cx, + ); + } else if (16..19).contains(&focused) { + let Some(surface) = zeron_theme::SurfacePreference::ALL + .get(focused - 16) + .copied() + else { + return false; + }; + self.onboarding_pick_surface(surface, cx); + } else { + return false; + } + } + OnboardingStep::Harnesses => { + if focused == 10 { + self.onboarding_continue(cx); + } else if focused == 11 { + self.onboarding_load_harnesses(cx); + } else if focused == 12 { + self.onboarding_open_agent_settings(cx); + } else if (20..25).contains(&focused) { + let device = self + .state + .read(cx) + .devices + .iter() + .take(5) + .nth(focused - 20) + .map(|device| device.id.clone()); + let Some(device) = device else { return false }; + self.onboarding_pick_device(device, cx); + } else { + let descriptor = self.onboarding.harnesses.ready().and_then(|rows| { + rows.iter() + .filter(|row| { + row.id != HarnessId::Mock + && crate::onboarding::harness_is_interactive(row) + }) + .nth(focused) + .cloned() + }); + let Some(descriptor) = descriptor else { + return false; + }; + self.onboarding_toggle_harness( + descriptor.id, + !zeron_engine::registry::descriptor_enabled(&descriptor), + cx, + ); + } + } + OnboardingStep::Defaults => { + if focused == 26 { + self.onboarding_continue(cx); + } else if focused == 8 { + self.onboarding_pick_default_model(None, cx); + } else if (9..16).contains(&focused) { + let model = self.onboarding.models.ready().and_then(|models| { + models.get(focused - 9).map(|model| model.id.clone()) + }); + let Some(model) = model else { return false }; + self.onboarding_pick_default_model(Some(model), cx); + } else if focused == 16 { + self.onboarding_pick_reasoning(None, cx); + } else if (17..26).contains(&focused) { + let levels = self + .onboarding + .models + .ready() + .and_then(|models| { + models + .iter() + .find(|model| { + Some(model.id.as_str()) + == self.onboarding.selected_model.as_deref() + }) + .map(|model| model.reasoning_levels.clone()) + }) + .unwrap_or_default(); + let Some(level) = levels.get(focused - 17).copied() else { + return false; + }; + self.onboarding_pick_reasoning(Some(level), cx); + } else { + let harness = self.onboarding.harnesses.ready().and_then(|rows| { + rows.iter() + .filter(|row| { + row.id != HarnessId::Mock + && crate::onboarding::harness_is_ready( + row, + &self.onboarding.accounts, + ) + }) + .nth(focused) + .map(|row| row.id) + }); + let Some(harness) = harness else { return false }; + self.onboarding_pick_default_harness(harness, cx); + } + } + OnboardingStep::Titles => { + if focused == 25 { + self.onboarding_continue(cx); + } else if focused == 24 { + self.onboarding_load_titles(cx); + } else if focused == 0 { + self.onboarding_pick_title_harness(None, cx); + } else if (1..8).contains(&focused) { + let harness = self.onboarding.harnesses.ready().and_then(|rows| { + rows.iter() + .filter(|row| crate::onboarding::title_harness_is_available(row)) + .nth(focused - 1) + .map(|row| row.id) + }); + let Some(harness) = harness else { return false }; + self.onboarding_pick_title_harness(Some(harness), cx); + } else if focused == 8 { + self.onboarding_pick_title_model(None, cx); + } else if (9..16).contains(&focused) { + let model = self.onboarding.title_models.ready().and_then(|models| { + models.get(focused - 9).map(|model| model.id.clone()) + }); + let Some(model) = model else { return false }; + self.onboarding_pick_title_model(Some(model), cx); + } else { + return false; + } + } + OnboardingStep::Project => match focused { + 0 => self.onboarding_open_project(cx), + 1 => self.onboarding_pick_no_project(cx), + 2 => self.onboarding_continue(cx), + _ => return false, + }, + OnboardingStep::FirstSession => return false, + }, + } + if self.onboarding.step() != starting_step + && self.onboarding.step() != OnboardingStep::FirstSession + { + window.focus(self.onboarding.control(0), cx); + } + true + } + fn on_key_down( &mut self, event: &gpui::KeyDownEvent, window: &mut Window, cx: &mut Context, ) { + if self.onboarding_key_down(event, window, cx) { + cx.stop_propagation(); + return; + } + // Inputs and completion menus consume Tab first. Unhandled Tab walks // accessible controls, including individual transcript link ranges. let modifiers = event.keystroke.modifiers; @@ -8552,7 +9878,7 @@ impl Shell { .inset_0(), ) .child(status) - .when(has_spaces || no_project || has_appshots, |el| { + .when(new_session_can_compose(has_spaces, no_project) || has_appshots, |el| { let composer_opacity = self.composer_dock.borrow().opacity(); el.child(crate::composer_dock::docked_composer( div() @@ -10468,8 +11794,11 @@ impl Render for Shell { self.settings.surface = crate::appearance::surface(cx); self.sync_independent_settings(cx); let theme = Theme::of(cx); - // The shell frost sits over native desktop blur on macOS and Windows. - // Content surfaces add their own backgrounds over this shared tint. + // The shell tone (zeron `.frost`): the shared surface beneath regular + // inset app panels and the directly composited onboarding journey. On + // macOS the window background is the blurred desktop (lib.rs + // `Blurred`), so this single translucent paint reads as real shell + // glass instead of stacked opaque-looking overlays. let (frost, text, font) = (theme.glass(), theme.text, theme.font_sans.clone()); let (workspace_scope, auth) = { let state = self.state.read(cx); @@ -10503,6 +11832,7 @@ impl Render for Shell { } let browser_active = matches!(gate, GatePhase::Ready) && !restart_required + && !self.onboarding.active() && matches!(self.route, Route::Chat) && (self.right_pane_open(cx) || self.tween_active(self.right_tween)); // Native clipping follows the animated GPUI mask. Drags only transfer @@ -10587,7 +11917,12 @@ impl Render for Shell { } let shortcut_focus = self.shortcut_focus.clone(); let unfocused = self.unfocused.clone(); - let preferred_focus = self.composer.focus_handle(cx); + let preferred_focus = + if self.onboarding.active() && self.onboarding.step() != OnboardingStep::FirstSession { + self.onboarding.control(0).clone() + } else { + self.composer.focus_handle(cx) + }; window.defer(cx, move |window, cx| { restore_mounted_focus(&shortcut_focus, &preferred_focus, &unfocused, window, cx); }); @@ -10739,6 +12074,19 @@ impl Render for Shell { gate.clone() }; let root = match &render_gate { + GatePhase::Ready if self.onboarding.active() => { + let viewport = window.viewport_size(); + let title_bar = self.render_onboarding_title_bar(f32::from(viewport.width), cx); + let page = crate::onboarding::render( + &self.onboarding, + &self.state, + title_bar, + viewport, + cx, + ); + let overlays = self.render_overlays(viewport, window, cx); + root.child(page).children(overlays) + } GatePhase::Ready => { // Focus is a sync signal: on the rising edge of window // activation, nudge every open room to verify liveness — a @@ -11169,6 +12517,13 @@ mod tests { ); } + #[test] + fn projectless_new_sessions_keep_the_composer_available() { + assert!(new_session_can_compose(false, true)); + assert!(new_session_can_compose(true, false)); + assert!(!new_session_can_compose(false, false)); + } + #[test] fn every_default_shortcut_binds_on_this_platform() { // `apply_keymap` silently falls back on an unparseable combo, so a diff --git a/crates/ui/src/shell/spaces.rs b/crates/ui/src/shell/spaces.rs index 7cd91a80e5..2aff9cda69 100644 --- a/crates/ui/src/shell/spaces.rs +++ b/crates/ui/src/shell/spaces.rs @@ -2228,6 +2228,10 @@ impl Shell { s.select_chat(None, cx); }); self.schedule_save(cx); + if self.onboarding.active() { + self.onboarding.error = None; + self.onboarding_remember_target(cx); + } cx.notify(); } From 4b836e75b814435dd9c103680427c54ce35e6c42 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Fri, 11 Sep 2026 18:19:26 +0200 Subject: [PATCH 02/21] refactor(ui): center onboarding journey --- crates/ui/src/onboarding.rs | 215 ++++++------------------------------ 1 file changed, 33 insertions(+), 182 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 5756695fd9..4e327d4c59 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -1,13 +1,12 @@ -//! First-run onboarding: a six-step, two-panel journey. The leading pane uses -//! the supplied Zeron workspace artwork while the trailing pane holds one -//! decision. Durable choices continue to live in their authoritative stores; -//! this module only persists navigation/lifecycle state in `UiSettings`. +//! First-run onboarding: a focused six-step journey. Durable choices continue +//! to live in their authoritative stores; this module only persists +//! navigation/lifecycle state in `UiSettings`. use std::sync::Arc; use gpui::{ AnyElement, Context, Empty, Entity, FocusHandle, Image, ImageFormat, IntoElement, KeyDownEvent, - ObjectFit, Pixels, ScrollHandle, SharedString, Task, div, prelude::*, px, + Pixels, ScrollHandle, SharedString, Task, div, prelude::*, px, }; use serde::{Deserialize, Serialize}; use zeron_engine::registry::{HarnessDescriptor, TitleSettings, descriptor_enabled}; @@ -190,7 +189,6 @@ pub struct OnboardingUi { pub agent_settings_open: bool, pub focus: FocusHandle, pub controls: Vec, - pub artwork: Arc, pub brand_mark: Arc, pub theme_menu: Popup, pub theme_scroll: ScrollHandle, @@ -237,10 +235,6 @@ impl OnboardingUi { agent_settings_open: false, focus: cx.focus_handle(), controls, - artwork: Arc::new(Image::from_bytes( - ImageFormat::Jpeg, - include_bytes!("../../../apps/landing/public/assets/app-screenshot.jpg").to_vec(), - )), brand_mark: Arc::new(Image::from_bytes( ImageFormat::Png, include_bytes!("../../../apps/landing/public/assets/zeron-app-icon.png").to_vec(), @@ -1988,70 +1982,6 @@ fn render_project_step( .into_any_element() } -#[derive(Clone, Copy)] -enum ArtworkFocus { - Top, - Right, -} - -fn fitted_artwork_bounds( - bounds: gpui::Bounds, - image_size: gpui::Size, - focus: ArtworkFocus, -) -> gpui::Bounds { - let mut fitted = ObjectFit::Cover.get_bounds(bounds, image_size); - match focus { - ArtworkFocus::Top => fitted.origin.y = bounds.origin.y, - ArtworkFocus::Right => { - fitted.origin.x = bounds.origin.x + bounds.size.width - fitted.size.width - } - } - fitted -} - -fn render_artwork(ui: &OnboardingUi, theme: &Theme, focus: ArtworkFocus) -> AnyElement { - const RADIUS: f32 = 14.0; - let artwork = ui.artwork.clone(); - let image = gpui::canvas( - move |_, window, cx| artwork.use_render_image(window, cx), - move |bounds, image, window, _| { - let Some(image) = image else { - return; - }; - // Preserve ObjectFit::Cover's normal scale and move only the crop - // origin. Expanded panes reveal the right edge; compact panes - // reveal the top edge. - let fitted = fitted_artwork_bounds(bounds, image.size(0), focus); - let _ = window.paint_image_fitted( - bounds, - fitted, - gpui::Corners::all(px(RADIUS)), - image, - 0, - false, - ); - }, - ) - .absolute() - .inset_0(); - div() - .size_full() - .relative() - .rounded(px(RADIUS)) - .overflow_hidden() - .bg(theme.surface) - .child(image) - .child( - div() - .absolute() - .inset_0() - .rounded(px(RADIUS)) - .border_1() - .border_color(theme.border), - ) - .into_any_element() -} - fn render_progress(step: OnboardingStep, theme: &Theme) -> AnyElement { div() .id("onboarding-progress") @@ -2089,19 +2019,10 @@ pub fn render( let step = ui.step(); let viewport_width = f32::from(viewport.width); let viewport_height = f32::from(viewport.height); - let compact = viewport_width < 980.0 || viewport_height < 620.0; - let compact_preview_height = - ((viewport_height - Theme::TITLEBAR_HEIGHT) * 0.34).clamp(190.0, 280.0); - let decision_top_pad = (viewport_height * 0.15).clamp(88.0, 144.0); - // Let the invisible titlebar establish the top safe area, then leave a - // small visual buffer below it. The remaining edges share a tighter inset - // so they stay balanced without inheriting the titlebar's dimensions. - let panel_edge = 14.0; - let panel_top = Theme::TITLEBAR_HEIGHT + 8.0; - let panel_bottom = panel_edge; - let panel_x = panel_edge; - let panel_gap = if compact { 12.0 } else { 24.0 }; - let wide_preview_width = ((viewport_width - panel_x * 2.0 - panel_gap) * 0.48).max(1.0); + let constrained = viewport_width < 680.0 || viewport_height < 680.0; + let outer_x = if constrained { 12.0 } else { 32.0 }; + let outer_y = if constrained { 12.0 } else { 24.0 }; + let inner_pad = if constrained { 20.0 } else { 32.0 }; let decision = match step { OnboardingStep::Workspace => render_workspace_step(ui, &theme, cx), OnboardingStep::Appearance => render_appearance_step(ui, &theme, cx), @@ -2113,95 +2034,53 @@ pub fn render( }; let decision_content = div() .size_full() - .max_w(px(440.0)) .min_w_0() .min_h_0() .flex() .flex_col() - // Every step starts on the same baseline. Vertical centering made the - // whole form jump whenever async rows or configuration controls changed - // its height; a stable top inset lets new content grow downward instead. - .when(!compact, |content| { - content.pt(px(decision_top_pad)).pb(px(28.0)) - }) .child(decision); let decision_content = crate::motion::fade_quick( SharedString::from(format!("onboarding-step-{}", step.index())), decision_content, ); - let decision_host = div() - .size_full() + let journey = div() + .w_full() + .h_full() + .max_w(px(560.0)) + .max_h(px(720.0)) .min_w_0() .min_h_0() .overflow_hidden() - .px(px(if compact { 18.0 } else { 40.0 })) - .py(px(if compact { 20.0 } else { 28.0 })) - .flex() - .justify_center() - .child(decision_content); - let decision_pane = div() - .flex_1() - .min_w_0() - .min_h_0() + .p(px(inner_pad)) + .rounded(px(18.0)) + .border_1() + .border_color(theme.border) + .bg(theme.card_glass_bg()) + .shadow_sm() .flex() .flex_col() - .child(div().flex_1().min_h_0().child(decision_host)) + .child(div().flex_1().min_h_0().child(decision_content)) .child( div() - .h(px(34.0)) + .h(px(40.0)) .flex_none() .flex() .items_end() .justify_center() .child(render_progress(step, &theme)), ); - let panel = if compact { - div() - .absolute() - .inset_0() - .pt(px(panel_top)) - .px(px(panel_x)) - .pb(px(panel_bottom)) - .min_w_0() - .min_h_0() - .flex() - .flex_col() - .gap(px(panel_gap)) - // In a reduced window, choices keep the primary/top position and - // the artwork becomes a bottom-anchored visual coda. - .child(decision_pane) - .child( - div() - .w_full() - .h(px(compact_preview_height)) - .min_w_0() - .min_h_0() - .flex_none() - .child(render_artwork(ui, &theme, ArtworkFocus::Top)), - ) - } else { - div() - .absolute() - .inset_0() - .pt(px(panel_top)) - .px(px(panel_x)) - .pb(px(panel_bottom)) - .min_w_0() - .min_h_0() - .flex() - .flex_row() - .gap(px(panel_gap)) - .child( - div() - .w(px(wide_preview_width)) - .h_full() - .min_w_0() - .min_h_0() - .flex_none() - .child(render_artwork(ui, &theme, ArtworkFocus::Right)), - ) - .child(decision_pane) - }; + let panel = div() + .absolute() + .inset_0() + .pt(px(Theme::TITLEBAR_HEIGHT + outer_y)) + .px(px(outer_x)) + .pb(px(outer_y)) + .min_w_0() + .min_h_0() + .flex() + .items_center() + .justify_center() + .child(journey); let close_confirm: AnyElement = if ui.close_confirm { div() .absolute() @@ -2408,32 +2287,4 @@ mod tests { assert!(project_target_is_chosen(true, false)); assert!(project_target_is_chosen(false, true)); } - - #[test] - fn artwork_focus_moves_only_the_cover_crop_origin() { - let image_size = gpui::size(2560u32.into(), 1655u32.into()); - - let expanded = gpui::Bounds::new( - gpui::point(px(0.0), px(0.0)), - gpui::size(px(500.0), px(900.0)), - ); - let expanded_centered = ObjectFit::Cover.get_bounds(expanded, image_size); - let expanded_right = fitted_artwork_bounds(expanded, image_size, ArtworkFocus::Right); - assert_eq!(expanded_right.size, expanded_centered.size); - assert_eq!(expanded_right.origin.y, expanded_centered.origin.y); - assert_eq!( - expanded_right.origin.x, - expanded.origin.x + expanded.size.width - expanded_right.size.width - ); - - let compact = gpui::Bounds::new( - gpui::point(px(0.0), px(0.0)), - gpui::size(px(900.0), px(260.0)), - ); - let compact_centered = ObjectFit::Cover.get_bounds(compact, image_size); - let compact_top = fitted_artwork_bounds(compact, image_size, ArtworkFocus::Top); - assert_eq!(compact_top.size, compact_centered.size); - assert_eq!(compact_top.origin.x, compact_centered.origin.x); - assert_eq!(compact_top.origin.y, compact.origin.y); - } } From de684d1bb73f4c196c39634c433583e4e2f8108c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Cado?= Date: Sat, 12 Sep 2026 07:15:20 +0000 Subject: [PATCH 03/21] fix(ui): address onboarding review feedback --- crates/ui/src/onboarding.rs | 308 ++++++++++++++++++++++++++---------- crates/ui/src/pickers.rs | 47 +++++- crates/ui/src/shell.rs | 174 ++++++++------------ 3 files changed, 327 insertions(+), 202 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 4e327d4c59..03b97aa24a 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -186,6 +186,10 @@ pub struct OnboardingUi { pub selected_reasoning: Option, pub error: Option, pub close_confirm: bool, + /// Control that owned focus before the close confirmation opened. + pub close_return_focus: Option, + /// The first mounted frame explicitly places keyboard focus in the journey. + pub focus_initialized: bool, pub agent_settings_open: bool, pub focus: FocusHandle, pub controls: Vec, @@ -232,6 +236,8 @@ impl OnboardingUi { title_models: Loadable::Idle, error: None, close_confirm: false, + close_return_focus: None, + focus_initialized: false, agent_settings_open: false, focus: cx.focus_handle(), controls, @@ -275,6 +281,32 @@ impl OnboardingUi { &self.controls[index.min(self.controls.len() - 1)] } + /// Keep a valid saved choice, otherwise choose the first usable agent in + /// registry order. Usability deliberately does not depend on OAuth account + /// discovery: API-key-backed CLIs are valid even without an account row. + pub(crate) fn resolve_default_harness(&mut self) { + let selected = self + .harnesses + .ready() + .and_then(|rows| preferred_harness(rows, &self.accounts, self.selected_harness)); + if self.selected_harness != selected { + self.selected_harness = selected; + self.selected_model = None; + self.selected_reasoning = None; + } + } + + /// Resolve the reasoning ladder exactly once for rendering and keyboard + /// interaction. Automatic model selection falls back to the harness ladder. + pub(crate) fn reasoning_levels(&self) -> Vec { + reasoning_levels( + &self.models, + self.selected_model.as_deref(), + &self.harnesses, + self.selected_harness, + ) + } + fn apply_fixture(&mut self, fixture: OnboardingFixture) { self.state = OnboardingState::fresh(); self.state.step = fixture.step(); @@ -597,15 +629,15 @@ fn harness_status( return ("Ready", true); } match accounts { - Loadable::Idle | Loadable::Loading => ("Checking sign-in…", false), - Loadable::Error(_) => ("Detection error", false), + Loadable::Idle | Loadable::Loading => ("Checking sign-in…", true), + Loadable::Error(_) => ("Sign-in status unavailable", true), Loadable::Ready(snapshot) => { if snapshot .warnings .iter() .any(|warning| warning.harness == descriptor.id) { - ("Detection error", false) + ("Sign-in status unavailable", true) } else if snapshot .accounts .iter() @@ -613,19 +645,61 @@ fn harness_status( { ("Ready", true) } else { - ("Sign-in required", false) + ("Sign-in not detected", true) } } } } -pub(crate) fn harness_is_ready( +pub(crate) fn harness_is_usable( descriptor: &HarnessDescriptor, accounts: &Loadable, ) -> bool { harness_status(descriptor, accounts).1 } +fn preferred_harness( + rows: &[HarnessDescriptor], + accounts: &Loadable, + selected: Option, +) -> Option { + selected + .filter(|selected| { + rows.iter().any(|row| { + row.id == *selected && row.id != HarnessId::Mock && harness_is_usable(row, accounts) + }) + }) + .or_else(|| { + rows.iter() + .find(|row| row.id != HarnessId::Mock && harness_is_usable(row, accounts)) + .map(|row| row.id) + }) +} + +fn reasoning_levels( + models: &Loadable>, + selected_model: Option<&str>, + harnesses: &Loadable>, + selected_harness: Option, +) -> Vec { + models + .ready() + .and_then(|models| { + models + .iter() + .find(|model| Some(model.id.as_str()) == selected_model) + .map(|model| model.reasoning_levels.clone()) + }) + .or_else(|| { + harnesses.ready().and_then(|rows| { + rows.iter() + .find(|row| Some(row.id) == selected_harness) + .map(|row| row.reasoning_levels.clone()) + }) + }) + .unwrap_or_default() +} + pub(crate) fn harness_is_interactive(descriptor: &HarnessDescriptor) -> bool { descriptor.installed || descriptor_enabled(descriptor) } @@ -767,9 +841,11 @@ fn render_appearance_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context render_workspace_step(ui, &theme, cx), OnboardingStep::Appearance => render_appearance_step(ui, &theme, cx), @@ -2047,7 +2120,7 @@ pub fn render( .w_full() .h_full() .max_w(px(560.0)) - .max_h(px(720.0)) + .max_h(px(card_max_height)) .min_w_0() .min_h_0() .overflow_hidden() @@ -2086,6 +2159,7 @@ pub fn render( .absolute() .inset_0() .bg(theme.scrim()) + .occlude() .flex() .items_center() .justify_center() @@ -2126,8 +2200,7 @@ pub fn render( .role(gpui::Role::Button) .track_focus(ui.control(26)) .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_cancel_close(cx); - shell.onboarding_focus_control(29, window, cx); + shell.onboarding_cancel_close(window, cx); })), ) .child( @@ -2158,9 +2231,11 @@ pub fn render( .track_focus(&ui.focus) .text_color(theme.text) .font_family(theme.font_sans.clone()) - // Keep the dialog's accessibility tree and tab order isolated. The - // underlying journey is remounted when the dialog closes. - .when(!ui.close_confirm, |root| root.child(panel).child(title_bar)) + // Keep the journey and native drag region mounted behind the modal. + // The full-window occluding scrim owns pointer input, while the shell's + // key handler traps focus inside the dialog. + .child(panel) + .child(title_bar) .child(close_confirm) .into_any_element() } @@ -2217,15 +2292,22 @@ mod tests { } #[test] - fn readiness_includes_enablement_installation_and_sign_in() { + fn readiness_requires_installation_and_enablement_but_not_oauth_detection() { let rows = fixture_harnesses(); let codex = rows.iter().find(|row| row.id == HarnessId::Codex).unwrap(); let opencode = rows .iter() .find(|row| row.id == HarnessId::Opencode) .unwrap(); - assert!(!harness_is_ready(codex, &Loadable::Loading)); - assert!(!harness_is_ready( + assert!(harness_is_usable(codex, &Loadable::Loading)); + assert!(harness_is_usable( + codex, + &Loadable::Ready(AgentAccountsSnapshot { + accounts: Vec::new(), + warnings: Vec::new(), + }) + )); + assert!(!harness_is_usable( opencode, &Loadable::Ready(AgentAccountsSnapshot { accounts: Vec::new(), @@ -2235,7 +2317,7 @@ mod tests { let mut enabled_opencode = opencode.clone(); enabled_opencode.installed = true; enabled_opencode.enabled = Some(true); - assert!(harness_is_ready(&enabled_opencode, &Loadable::Idle)); + assert!(harness_is_usable(&enabled_opencode, &Loadable::Idle)); let accounts = Loadable::Ready(AgentAccountsSnapshot { accounts: vec![zeron_proto::AgentAccount { @@ -2253,7 +2335,59 @@ mod tests { }], warnings: Vec::new(), }); - assert!(harness_is_ready(codex, &accounts)); + assert!(harness_is_usable(codex, &accounts)); + } + + #[test] + fn default_harness_is_stable_across_account_callback_order() { + let rows = fixture_harnesses(); + let no_accounts = Loadable::Ready(AgentAccountsSnapshot { + accounts: Vec::new(), + warnings: Vec::new(), + }); + + assert_eq!( + preferred_harness(&rows, &Loadable::Loading, None), + Some(HarnessId::ClaudeCode) + ); + assert_eq!( + preferred_harness(&rows, &no_accounts, None), + Some(HarnessId::ClaudeCode) + ); + assert_eq!( + preferred_harness(&rows, &no_accounts, Some(HarnessId::Codex)), + Some(HarnessId::Codex) + ); + } + + #[test] + fn automatic_model_uses_the_selected_harness_reasoning_ladder() { + let harnesses = Loadable::Ready(fixture_harnesses()); + let models = Loadable::Ready(fixture_models()); + let automatic = reasoning_levels(&models, None, &harnesses, Some(HarnessId::ClaudeCode)); + assert_eq!( + automatic, + vec![ + ReasoningLevel::Low, + ReasoningLevel::Medium, + ReasoningLevel::High + ] + ); + + let explicit = reasoning_levels( + &models, + Some("gpt-6-astra"), + &harnesses, + Some(HarnessId::ClaudeCode), + ); + assert_eq!( + explicit, + vec![ + ReasoningLevel::Medium, + ReasoningLevel::High, + ReasoningLevel::XHigh + ] + ); } #[test] diff --git a/crates/ui/src/pickers.rs b/crates/ui/src/pickers.rs index 0f00f3010f..1e068fffda 100644 --- a/crates/ui/src/pickers.rs +++ b/crates/ui/src/pickers.rs @@ -1994,7 +1994,7 @@ impl Pickers { s.auto_selected = true; s.select_space(Some(space_id), cx); }); - self.remember_target(cx); + let _ = self.remember_target(cx); self.close(cx); } @@ -2005,20 +2005,20 @@ impl Pickers { s.auto_selected = true; s.select_space(None, cx); }); - self.remember_target(cx); + let _ = self.remember_target(cx); self.close(cx); } fn pick_device(&mut self, device_id: String, cx: &mut Context) { self.state .update(cx, |s, cx| s.select_device(device_id, cx)); - self.remember_target(cx); + let _ = self.remember_target(cx); self.close(cx); } /// Persist the device/project picks — the "last selected" defaults the /// next boot's canvas restores. - fn remember_target(&mut self, cx: &App) { + pub(crate) fn remember_target(&mut self, cx: &App) -> std::io::Result<()> { { let state = self.state.read(cx); self.defaults.device = state @@ -2029,10 +2029,13 @@ impl Pickers { self.defaults.no_project = state.no_project; } if let Some(dir) = &self.data_dir { - if let Err(err) = self.defaults.save(dir) { + let result = self.defaults.save(dir); + if let Err(err) = &result { tracing::warn!(error = %err, "composer-defaults save failed"); } + result?; } + Ok(()) } /// Devices in picker order: this device first, then by name. @@ -5133,6 +5136,40 @@ mod tests { }); } + #[gpui::test] + fn remembered_projectless_target_survives_later_catalog_saves(cx: &mut gpui::TestAppContext) { + let dir = tempfile::tempdir().unwrap(); + let state = cx.new(|_| { + let mut state = AppState::new(); + state.data_dir = Some(dir.path().to_path_buf()); + state.local_device_id = Some("local".into()); + state + }); + let pickers = cx.new(|cx| Pickers::new(state.clone(), cx)); + + state.update(cx, |state, cx| { + state.auto_selected = true; + state.select_space(None, cx); + state.select_chat(None, cx); + }); + pickers.update(cx, |pickers, cx| { + pickers.remember_target(cx).unwrap(); + assert!(pickers.defaults.no_project); + assert_eq!(pickers.defaults.device.as_deref(), Some("local")); + + pickers + .defaults + .remember_labels([("new-model", "New model")].into_iter()); + pickers.save_defaults(); + }); + + let saved = ComposerDefaults::load(dir.path()); + assert!(saved.no_project); + assert!(saved.project.is_none()); + assert_eq!(saved.device.as_deref(), Some("local")); + assert_eq!(saved.label_for("new-model"), Some("New model")); + } + fn bare_model(id: &str, label: &str) -> Model { Model { id: id.into(), diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index 49e4310caa..15477926b2 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -3964,7 +3964,7 @@ impl Shell { rows.iter() .filter(|row| { row.id != zeron_proto::HarnessId::Mock - && crate::onboarding::harness_is_ready( + && crate::onboarding::harness_is_usable( row, &self.onboarding.accounts, ) @@ -4064,14 +4064,23 @@ impl Shell { cx.notify(); } - pub(crate) fn onboarding_request_close(&mut self, cx: &mut Context) { + pub(crate) fn onboarding_request_close(&mut self, window: &mut Window, cx: &mut Context) { self.onboarding_close_theme_menu(cx); + self.onboarding.close_return_focus = self + .onboarding + .controls + .iter() + .position(|handle| handle.is_focused(window)) + .filter(|index| !matches!(index, 26 | 27)) + .or(Some(0)); self.onboarding.close_confirm = true; cx.notify(); } - pub(crate) fn onboarding_cancel_close(&mut self, cx: &mut Context) { + pub(crate) fn onboarding_cancel_close(&mut self, window: &mut Window, cx: &mut Context) { self.onboarding.close_confirm = false; + let target = self.onboarding.close_return_focus.take().unwrap_or(0); + window.focus(self.onboarding.control(target), cx); cx.notify(); } @@ -4086,6 +4095,7 @@ impl Shell { pub(crate) fn onboarding_defer(&mut self, cx: &mut Context) { self.onboarding.close_confirm = false; + self.onboarding.close_return_focus = None; self.onboarding.state.disposition = OnboardingDisposition::Deferred; self.persist_onboarding(cx); cx.notify(); @@ -4126,34 +4136,7 @@ impl Shell { .unwrap_or_else(|error| Loadable::Error(error.to_string())), Err(error) => Loadable::Error(error.to_string()), }; - let selected_is_ready = shell.onboarding.harnesses.ready().is_some_and( - |rows: &Vec| { - rows.iter().any(|row| { - Some(row.id) == shell.onboarding.selected_harness - && row.id != zeron_proto::HarnessId::Mock - && crate::onboarding::harness_is_ready( - row, - &shell.onboarding.accounts, - ) - }) - }, - ); - if !selected_is_ready { - shell.onboarding.selected_harness = - shell.onboarding.harnesses.ready().and_then( - |rows: &Vec| { - rows.iter() - .find(|row| { - row.id != zeron_proto::HarnessId::Mock - && crate::onboarding::harness_is_ready( - row, - &shell.onboarding.accounts, - ) - }) - .map(|row| row.id) - }, - ); - } + shell.onboarding.resolve_default_harness(); cx.notify(); }) .ok(); @@ -4182,26 +4165,7 @@ impl Shell { .unwrap_or_else(|error| Loadable::Error(error.to_string())), Err(error) => Loadable::Error(error.to_string()), }; - let selected_is_ready = shell.onboarding.harnesses.ready().is_some_and(|rows| { - rows.iter().any(|row| { - Some(row.id) == shell.onboarding.selected_harness - && crate::onboarding::harness_is_ready(row, &shell.onboarding.accounts) - }) - }); - if !selected_is_ready { - shell.onboarding.selected_harness = - shell.onboarding.harnesses.ready().and_then(|rows| { - rows.iter() - .find(|row| { - row.id != HarnessId::Mock - && crate::onboarding::harness_is_ready( - row, - &shell.onboarding.accounts, - ) - }) - .map(|row| row.id) - }); - } + shell.onboarding.resolve_default_harness(); cx.notify(); }) .ok(); @@ -4257,6 +4221,7 @@ impl Shell { { row.enabled = Some(enabled); } + self.onboarding.resolve_default_harness(); cx.notify(); return; } @@ -4278,6 +4243,7 @@ impl Shell { Ok(value) => match serde_json::from_value(value) { Ok(rows) => { shell.onboarding.harnesses = Loadable::Ready(rows); + shell.onboarding.resolve_default_harness(); crate::pickers::bump_harness_catalog(cx); } Err(error) => shell.onboarding.error = Some(error.to_string().into()), @@ -4529,17 +4495,8 @@ impl Shell { if self.onboarding.fixture.is_some() { return; } - let mut defaults = crate::settings::composer::ComposerDefaults::load(&self.data_dir); - { - let state = self.state.read(cx); - defaults.device = state - .selected_device - .clone() - .or_else(|| state.local_device_id.clone()); - defaults.project = state.selected_space.clone(); - defaults.no_project = state.no_project; - } - if let Err(error) = defaults.save(&self.data_dir) { + let pickers = self.composer.read(cx).pickers().clone(); + if let Err(error) = pickers.update(cx, |pickers, cx| pickers.remember_target(cx)) { self.onboarding.error = Some(format!("Unable to remember this choice: {error}").into()); } } @@ -8714,11 +8671,14 @@ impl Shell { return true; } if self.onboarding.active() { + if self.onboarding.theme_menu.is_open() { + self.onboarding_close_theme_menu(cx); + return true; + } if self.onboarding.close_confirm { - self.onboarding_cancel_close(cx); - self.onboarding_focus_control(29, window, cx); + self.onboarding_cancel_close(window, cx); } else { - self.onboarding_request_close(cx); + self.onboarding_request_close(window, cx); self.onboarding_focus_control(26, window, cx); } return true; @@ -8815,22 +8775,27 @@ impl Shell { } } } - if self.onboarding.close_confirm - && event.keystroke.key == "tab" + if event.keystroke.key == "tab" && !event.keystroke.modifiers.control && !event.keystroke.modifiers.alt && !event.keystroke.modifiers.platform { - let focused = self - .onboarding - .controls - .iter() - .position(|handle| handle.is_focused(window)); - let target = crate::onboarding::close_dialog_tab_target( - focused, - event.keystroke.modifiers.shift, - ); - window.focus(self.onboarding.control(target), cx); + if self.onboarding.close_confirm { + let focused = self + .onboarding + .controls + .iter() + .position(|handle| handle.is_focused(window)); + let target = crate::onboarding::close_dialog_tab_target( + focused, + event.keystroke.modifiers.shift, + ); + window.focus(self.onboarding.control(target), cx); + } else if event.keystroke.modifiers.shift { + window.focus_prev(cx); + } else { + window.focus_next(cx); + } return true; } let focused = self @@ -8878,7 +8843,7 @@ impl Shell { .iter() .filter(|row| { row.id != HarnessId::Mock - && crate::onboarding::harness_is_ready( + && crate::onboarding::harness_is_usable( row, &self.onboarding.accounts, ) @@ -8893,20 +8858,7 @@ impl Shell { .ready() .map(|models| (8, 8 + models.len().min(4))), OnboardingStep::Defaults if (16..26).contains(&focused) => { - let count = self - .onboarding - .models - .ready() - .and_then(|models| { - models - .iter() - .find(|model| { - Some(model.id.as_str()) - == self.onboarding.selected_model.as_deref() - }) - .map(|model| model.reasoning_levels.len()) - }) - .unwrap_or(0); + let count = self.onboarding.reasoning_levels().len(); Some((16, 16 + count.min(9))) } OnboardingStep::Titles if focused < 8 => { @@ -8951,7 +8903,7 @@ impl Shell { } if self.onboarding.close_confirm { match focused { - 26 => self.onboarding_cancel_close(cx), + 26 => self.onboarding_cancel_close(window, cx), 27 => self.onboarding_defer(cx), _ => return false, } @@ -8960,7 +8912,10 @@ impl Shell { match focused { 28 if self.onboarding.step() != OnboardingStep::Workspace => self.onboarding_back(cx), 29 => self.onboarding_skip(cx), - 30 => self.onboarding_request_close(cx), + 30 => { + self.onboarding_request_close(window, cx); + self.onboarding_focus_control(26, window, cx); + } _ => match self.onboarding.step() { OnboardingStep::Workspace => match focused { 0 => self.onboarding_pick_workspace(WorkspaceMode::Local, cx), @@ -9053,20 +9008,7 @@ impl Shell { } else if focused == 16 { self.onboarding_pick_reasoning(None, cx); } else if (17..26).contains(&focused) { - let levels = self - .onboarding - .models - .ready() - .and_then(|models| { - models - .iter() - .find(|model| { - Some(model.id.as_str()) - == self.onboarding.selected_model.as_deref() - }) - .map(|model| model.reasoning_levels.clone()) - }) - .unwrap_or_default(); + let levels = self.onboarding.reasoning_levels(); let Some(level) = levels.get(focused - 17).copied() else { return false; }; @@ -9076,7 +9018,7 @@ impl Shell { rows.iter() .filter(|row| { row.id != HarnessId::Mock - && crate::onboarding::harness_is_ready( + && crate::onboarding::harness_is_usable( row, &self.onboarding.accounts, ) @@ -11917,6 +11859,14 @@ impl Render for Shell { } let shortcut_focus = self.shortcut_focus.clone(); let unfocused = self.unfocused.clone(); + let onboarding_needs_initial_focus = matches!(gate, GatePhase::Ready) + && !restart_required + && self.onboarding.active() + && self.onboarding.step() != OnboardingStep::FirstSession + && !self.onboarding.focus_initialized; + if onboarding_needs_initial_focus { + self.onboarding.focus_initialized = true; + } let preferred_focus = if self.onboarding.active() && self.onboarding.step() != OnboardingStep::FirstSession { self.onboarding.control(0).clone() @@ -11924,7 +11874,11 @@ impl Render for Shell { self.composer.focus_handle(cx) }; window.defer(cx, move |window, cx| { - restore_mounted_focus(&shortcut_focus, &preferred_focus, &unfocused, window, cx); + if onboarding_needs_initial_focus && window.focused(cx).is_none() { + window.focus(&preferred_focus, cx); + } else { + restore_mounted_focus(&shortcut_focus, &preferred_focus, &unfocused, window, cx); + } }); // Modifier events follow focus too. Reconcile from the window's input From ae3acf415bb563399f18b8d2bda1b3557993cabb Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 00:46:25 +0200 Subject: [PATCH 04/21] fix(ui): reconcile centered cardless onboarding --- crates/ui/src/onboarding.rs | 477 ++++++++++++++++++++++-------------- crates/ui/src/shell.rs | 99 +------- 2 files changed, 291 insertions(+), 285 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 03b97aa24a..c9e9d55bea 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -23,6 +23,14 @@ use crate::theme::{Theme, ink}; pub const SCHEMA_VERSION: u16 = 1; pub const STEP_COUNT: usize = 6; +const CONTENT_MAX_WIDTH: f32 = Theme::SPACE_LG * 30.0; +// The journey grows with the window until this cap; dense steps should expose +// several useful rows before their overflow affordance becomes necessary. +const CONTENT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 35.0; +const STEP_GROUP_GAP: f32 = Theme::SPACE_LG + Theme::SPACE_SM; +const VIEWPORT_INSET: f32 = Theme::SPACE_LG; +const ROOMY_VIEWPORT_INSET: f32 = Theme::SPACE_LG * 2.0; +const COMPACT_NAVIGATION_WIDTH: f32 = Theme::SPACE_LG * 26.0; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] @@ -431,6 +439,8 @@ fn heading(theme: &Theme, id: &'static str, text: &'static str) -> gpui::Statefu .id(id) .role(gpui::Role::Heading) .aria_level(1) + .w_full() + .text_center() .text_size(crate::typography::ui_rems(28.0)) .line_height(px(32.0)) .font_weight(gpui::FontWeight::SEMIBOLD) @@ -440,8 +450,10 @@ fn heading(theme: &Theme, id: &'static str, text: &'static str) -> gpui::Statefu fn body(theme: &Theme, text: impl Into) -> gpui::Div { div() - .mt(px(10.0)) - .max_w(px(440.0)) + .mt(px(Theme::SPACE_SM)) + .w_full() + .max_w(px(CONTENT_MAX_WIDTH)) + .text_center() .text_size(crate::typography::ui_rems(14.0)) .line_height(px(21.0)) .text_color(theme.text_muted) @@ -567,6 +579,81 @@ fn quiet_button(theme: &Theme, label: &'static str) -> gpui::Div { .child(label) } +fn footer_secondary_button( + theme: &Theme, + id: &'static str, + label: &'static str, + icon_path: Option<&'static str>, +) -> gpui::Stateful { + div() + .id(id) + .h(px(Theme::SPACE_SM * 5.0)) + .flex_none() + .px(px(Theme::SPACE_MD)) + .rounded(px(Theme::CONTROL_RADIUS)) + .border_1() + .border_color(theme.border.opacity(0.72)) + .bg(crate::motion::hover_blend( + id, + gpui::transparent_black(), + theme.glass_hover(), + )) + .flex() + .items_center() + .justify_center() + .gap(px(Theme::SPACE_XS)) + .text_size(crate::typography::ui_rems(12.5)) + .font_weight(gpui::FontWeight::MEDIUM) + .text_color(crate::motion::hover_blend(id, theme.text_muted, theme.text)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .when_some(icon_path, |button, icon_path| { + button.child(icon(icon_path).size(px(Theme::SPACE_MD))) + }) + .child(label) +} + +fn footer_primary_button( + theme: &Theme, + id: &'static str, + label: &'static str, + compact: bool, +) -> gpui::Stateful { + let wash = + crate::motion::hover_blend(id, gpui::transparent_black(), theme.on_solid.opacity(0.10)); + div() + .id(id) + .h(px(Theme::SPACE_SM * 5.0)) + .min_w_0() + .rounded(px(Theme::CONTROL_RADIUS)) + .border_1() + .border_color(theme.solid) + .bg(theme.solid) + .text_color(theme.on_solid) + .cursor_pointer() + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .child( + div() + .size_full() + .px(px(Theme::SPACE_MD)) + .rounded(px(Theme::CONTROL_RADIUS)) + .bg(wash) + .flex() + .items_center() + .justify_center() + .gap(px(Theme::SPACE_XS)) + .text_size(crate::typography::ui_rems(12.5)) + .font_weight(gpui::FontWeight::SEMIBOLD) + .child(label) + .when(!compact, |content| { + content.child( + icon(crate::icons::ALT_ARROW_RIGHT) + .size(px(Theme::SPACE_MD)) + .text_color(theme.on_solid), + ) + }), + ) +} + pub(crate) fn activates(event: &KeyDownEvent) -> bool { matches!(event.keystroke.key.as_str(), "enter" | "space") && !event.keystroke.modifiers.modified() @@ -722,69 +809,47 @@ fn render_workspace_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .child( div() .id("onboarding-title-settings-loading") - .mt(px(26.0)) + .mt(px(STEP_GROUP_GAP)) .h(px(44.0)) .rounded(px(10.0)) .bg(ink(0.045)) .role(gpui::Role::ProgressIndicator) .aria_label("Loading title settings"), ) - .child( - action_button(theme, "Continue") - .mt(px(28.0)) - .id("onboarding-continue-titles-loading") - .role(gpui::Role::Button) - .track_focus(ui.control(25)) - .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_continue(cx); - shell.onboarding_focus_control(0, window, cx); - })), - ) .into_any_element(); } Loadable::Error(error) => { @@ -1743,7 +1754,7 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .child( div() .id("onboarding-title-settings-error") - .mt(px(26.0)) + .mt(px(STEP_GROUP_GAP)) .p(px(14.0)) .rounded(px(10.0)) .border_1() @@ -1763,17 +1774,6 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .track_focus(ui.control(24)) .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_load_titles(cx))), ) - .child( - action_button(theme, "Continue") - .mt(px(18.0)) - .id("onboarding-continue-titles-error") - .role(gpui::Role::Button) - .track_focus(ui.control(25)) - .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_continue(cx); - shell.onboarding_focus_control(0, window, cx); - })), - ) .into_any_element(); } }; @@ -1926,7 +1926,7 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .child(body(theme, "Choose how new sessions are named.")) .child( div() - .mt(px(25.0)) + .mt(px(STEP_GROUP_GAP)) .flex_1() .min_h_0() .child(faded_step_scroll( @@ -1935,17 +1935,6 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) title_options, )), ) - .child( - action_button(theme, "Continue") - .mt(px(28.0)) - .id("onboarding-continue-titles") - .role(gpui::Role::Button) - .track_focus(ui.control(25)) - .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_continue(cx); - shell.onboarding_focus_control(0, window, cx); - })), - ) .into_any_element() } @@ -2030,31 +2019,21 @@ fn render_project_step( .child(body(theme, "Choose a folder now, or add one later.")) .child( div() - .mt(px(27.0)) + .mt(px(STEP_GROUP_GAP)) .flex_1() .min_h_0() - .child(faded_step_scroll( - "onboarding-project-scroll", - &ui.step_scroll, - choices, - )), - ) - .child( - action_button(theme, "Finish setup") - .mt(px(28.0)) - .id("onboarding-continue-project") - .role(gpui::Role::Button) - .track_focus(ui.control(2)) - .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_continue(cx))), + .child(choices), ) .into_any_element() } -fn render_progress(step: OnboardingStep, theme: &Theme) -> AnyElement { +fn render_progress(step: OnboardingStep, theme: &Theme, compact: bool) -> AnyElement { div() .id("onboarding-progress") .flex() - .gap(px(6.0)) + .items_center() + .justify_center() + .gap(px(Theme::SPACE_SM)) .role(gpui::Role::ProgressIndicator) .aria_label(format!("Step {} of {STEP_COUNT}", step.index() + 1)) .children( @@ -2063,10 +2042,20 @@ fn render_progress(step: OnboardingStep, theme: &Theme) -> AnyElement { .enumerate() .map(|(index, _)| { div() - .h(px(3.0)) - .w(px(34.0)) + .h(px(Theme::SPACE_XS)) + .w(px(if index == step.index() { + if compact { + Theme::SPACE_LG + Theme::SPACE_SM + } else { + Theme::SPACE_LG * 2.0 + } + } else { + Theme::SPACE_SM + })) .rounded_full() - .bg(if index <= step.index() { + .bg(if index < step.index() { + theme.accent.opacity(0.62) + } else if index == step.index() { theme.accent } else { theme.border_strong @@ -2076,6 +2065,118 @@ fn render_progress(step: OnboardingStep, theme: &Theme) -> AnyElement { .into_any_element() } +fn continue_control(step: OnboardingStep) -> usize { + match step { + OnboardingStep::Workspace | OnboardingStep::Project | OnboardingStep::FirstSession => 2, + OnboardingStep::Appearance | OnboardingStep::Titles => 25, + OnboardingStep::Harnesses => 10, + OnboardingStep::Defaults => 26, + } +} + +fn continue_id(step: OnboardingStep) -> &'static str { + match step { + OnboardingStep::Workspace => "onboarding-continue-workspace", + OnboardingStep::Appearance => "onboarding-continue-appearance", + OnboardingStep::Harnesses => "onboarding-continue-harnesses", + OnboardingStep::Defaults => "onboarding-continue-defaults", + OnboardingStep::Titles => "onboarding-continue-titles", + OnboardingStep::Project | OnboardingStep::FirstSession => "onboarding-continue-project", + } +} + +fn can_continue(ui: &OnboardingUi, step: OnboardingStep) -> bool { + step != OnboardingStep::Harnesses + || matches!(&ui.harnesses, Loadable::Ready(rows) if rows + .iter() + .any(|h| h.id != HarnessId::Mock && harness_is_usable(h, &ui.accounts))) +} + +fn render_footer( + ui: &OnboardingUi, + step: OnboardingStep, + theme: &Theme, + compact: bool, + cx: &mut Context, +) -> AnyElement { + let at_first_step = step == OnboardingStep::Workspace; + let previous = footer_secondary_button( + theme, + "onboarding-back", + "Previous", + (!compact).then_some(crate::icons::ALT_ARROW_LEFT), + ) + .role(gpui::Role::Button) + .aria_label("Previous setup step") + .when(at_first_step, |button| { + button + .opacity(0.38) + .cursor_default() + .aria_description("Unavailable on the first step") + }) + .when(!at_first_step, |button| { + button + .cursor_pointer() + .on_hover(crate::motion::hover_listener("onboarding-back")) + .track_focus(ui.control(28)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_back(cx); + shell.onboarding_focus_control(0, window, cx); + })) + }); + let skip = footer_secondary_button(theme, "onboarding-skip", "Skip", None) + .role(gpui::Role::Button) + .aria_label("Skip setup") + .cursor_pointer() + .on_hover(crate::motion::hover_listener("onboarding-skip")) + .track_focus(ui.control(29)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_skip(cx))); + let enabled = can_continue(ui, step); + let finishes = matches!(step, OnboardingStep::Project | OnboardingStep::FirstSession); + let continue_button = footer_primary_button( + theme, + continue_id(step), + if finishes { "Finish setup" } else { "Continue" }, + compact, + ) + .flex_1() + .role(gpui::Role::Button) + .when(!enabled, |button| { + button + .opacity(0.45) + .cursor_default() + .aria_description("Unavailable until at least one agent is ready") + }) + .when(enabled, |button| { + button + .on_hover(crate::motion::hover_listener(continue_id(step))) + .track_focus(ui.control(continue_control(step))) + .on_click(cx.listener(move |shell, _, window, cx| { + shell.onboarding_continue(cx); + if !finishes { + shell.onboarding_focus_control(0, window, cx); + } + })) + }); + let actions = div() + .w_full() + .flex() + .items_center() + .gap(px(Theme::SPACE_XS + 2.0)) + .child(previous) + .child(skip) + .child(continue_button); + div() + .w_full() + .flex_none() + .flex() + .flex_col() + .gap(px(Theme::SPACE_MD)) + .child(actions) + .child(render_progress(step, theme, compact)) + .into_any_element() +} + pub fn render( ui: &OnboardingUi, state: &Entity, @@ -2087,14 +2188,19 @@ pub fn render( let step = ui.step(); let viewport_width = f32::from(viewport.width); let viewport_height = f32::from(viewport.height); - let constrained = viewport_width < 680.0 || viewport_height < 680.0; - let outer_x = if constrained { 12.0 } else { 32.0 }; - let outer_y = if constrained { 12.0 } else { 24.0 }; - let inner_pad = if constrained { 20.0 } else { 32.0 }; - let card_max_height = if matches!(step, OnboardingStep::Workspace | OnboardingStep::Project) { - 480.0 + let compact_navigation = viewport_width < COMPACT_NAVIGATION_WIDTH; + let roomy_x = viewport_width >= CONTENT_MAX_WIDTH + ROOMY_VIEWPORT_INSET * 2.0; + let roomy_y = + viewport_height >= Theme::TITLEBAR_HEIGHT + CONTENT_MAX_HEIGHT + ROOMY_VIEWPORT_INSET * 2.0; + let outer_x = if roomy_x { + ROOMY_VIEWPORT_INSET + } else { + VIEWPORT_INSET + }; + let outer_y = if roomy_y { + ROOMY_VIEWPORT_INSET } else { - 720.0 + VIEWPORT_INSET }; let decision = match step { OnboardingStep::Workspace => render_workspace_step(ui, &theme, cx), @@ -2119,28 +2225,19 @@ pub fn render( let journey = div() .w_full() .h_full() - .max_w(px(560.0)) - .max_h(px(card_max_height)) + .max_w(px(CONTENT_MAX_WIDTH)) + .max_h(px(CONTENT_MAX_HEIGHT)) + .mx_auto() .min_w_0() .min_h_0() - .overflow_hidden() - .p(px(inner_pad)) - .rounded(px(18.0)) - .border_1() - .border_color(theme.border) - .bg(theme.card_glass_bg()) - .shadow_sm() .flex() .flex_col() .child(div().flex_1().min_h_0().child(decision_content)) .child( div() - .h(px(40.0)) + .mt(px(STEP_GROUP_GAP)) .flex_none() - .flex() - .items_end() - .justify_center() - .child(render_progress(step, &theme)), + .child(render_footer(ui, step, &theme, compact_navigation, cx)), ); let panel = div() .absolute() diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index 15477926b2..d0308cae8f 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -5919,99 +5919,9 @@ impl Shell { /// Compact onboarding titlebar: preserve the native traffic-light safe /// area and window drag/double-click behavior while keeping a centered app - /// identity. Journey controls occupy the trailing safe area and explicitly - /// occlude the native drag target beneath them. - fn render_onboarding_title_bar( - &mut self, - viewport_width: f32, - cx: &mut Context, - ) -> AnyElement { + /// identity. Journey navigation lives with the onboarding content. + fn render_onboarding_title_bar(&mut self, cx: &mut Context) -> AnyElement { let theme = Theme::of(cx).clone(); - let at_first_step = self.onboarding.step() == OnboardingStep::Workspace; - let icon_only_skip = viewport_width < 420.0; - let back = div() - .id("onboarding-back") - .size(px(24.0)) - .flex_none() - .rounded_full() - .border_1() - .border_color(theme.border_strong.opacity(0.72)) - .bg(theme.glass_hover()) - .flex() - .items_center() - .justify_center() - .role(gpui::Role::Button) - .aria_label("Previous setup step") - .occlude() - .on_mouse_down(MouseButton::Left, |_, window, _| window.prevent_default()) - .when(at_first_step, |button| { - button - .opacity(0.32) - .aria_description("Unavailable on the first step") - }) - .when(!at_first_step, |button| { - button - .cursor_pointer() - .track_focus(self.onboarding.control(28)) - .hover(|style| style.bg(theme.element_hover)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) - .on_click(cx.listener(|shell, _, window, cx| { - cx.stop_propagation(); - shell.onboarding_back(cx); - shell.onboarding_focus_control(0, window, cx); - })) - }) - .child( - icon(icons::ALT_ARROW_LEFT) - .size(px(11.0)) - .text_color(theme.text), - ); - let skip = div() - .id("onboarding-skip") - .h(px(24.0)) - .when(icon_only_skip, |button| button.w(px(24.0))) - .when(!icon_only_skip, |button| button.px(px(8.0))) - .flex_none() - .rounded_full() - .border_1() - .border_color(theme.border_strong.opacity(0.72)) - .bg(theme.glass_hover()) - .flex() - .items_center() - .justify_center() - .gap(px(4.0)) - .cursor_pointer() - .text_size(crate::typography::ui_rems(11.0)) - .font_weight(gpui::FontWeight::MEDIUM) - .text_color(theme.text) - .role(gpui::Role::Button) - .aria_label("Skip setup") - .track_focus(self.onboarding.control(29)) - .hover(|style| style.bg(theme.element_hover)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) - .occlude() - .on_mouse_down(MouseButton::Left, |_, window, _| window.prevent_default()) - .on_click(cx.listener(|shell, _, _, cx| { - cx.stop_propagation(); - shell.onboarding_skip(cx); - })) - .when(!icon_only_skip, |button| button.child("Skip")) - .child( - icon(icons::ALT_ARROW_RIGHT) - .size(px(11.0)) - .text_color(theme.text), - ); - let controls = div() - .absolute() - .top_0() - .right(px(self.titlebar_right_pad(14.0))) - .h(px(Theme::TITLEBAR_HEIGHT)) - .pt(px(Theme::TITLEBAR_TOP_PAD)) - .flex() - .items_center() - .gap(px(6.0)) - .child(back) - .child(skip); let identity = div() .absolute() .top_0() @@ -6040,8 +5950,7 @@ impl Shell { .left_0() .right_0() .h(px(Theme::TITLEBAR_HEIGHT)) - .child(identity) - .child(controls), + .child(identity), cx, ) .into_any_element() @@ -12030,7 +11939,7 @@ impl Render for Shell { let root = match &render_gate { GatePhase::Ready if self.onboarding.active() => { let viewport = window.viewport_size(); - let title_bar = self.render_onboarding_title_bar(f32::from(viewport.width), cx); + let title_bar = self.render_onboarding_title_bar(cx); let page = crate::onboarding::render( &self.onboarding, &self.state, From ec6cac28cf48fa5c441753200a7a43d528f8ff33 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 00:56:56 +0200 Subject: [PATCH 05/21] fix(ui): center compact onboarding steps --- crates/ui/src/onboarding.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index c9e9d55bea..eb432717d5 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -27,6 +27,8 @@ const CONTENT_MAX_WIDTH: f32 = Theme::SPACE_LG * 30.0; // The journey grows with the window until this cap; dense steps should expose // several useful rows before their overflow affordance becomes necessary. const CONTENT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 35.0; +const WORKSPACE_MAX_HEIGHT: f32 = Theme::SPACE_LG * 23.0; +const PROJECT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 30.0; const STEP_GROUP_GAP: f32 = Theme::SPACE_LG + Theme::SPACE_SM; const VIEWPORT_INSET: f32 = Theme::SPACE_LG; const ROOMY_VIEWPORT_INSET: f32 = Theme::SPACE_LG * 2.0; @@ -2092,6 +2094,17 @@ fn can_continue(ui: &OnboardingUi, step: OnboardingStep) -> bool { .any(|h| h.id != HarnessId::Mock && harness_is_usable(h, &ui.accounts))) } +fn journey_max_height(step: OnboardingStep) -> f32 { + match step { + OnboardingStep::Workspace => WORKSPACE_MAX_HEIGHT, + OnboardingStep::Project | OnboardingStep::FirstSession => PROJECT_MAX_HEIGHT, + OnboardingStep::Appearance + | OnboardingStep::Harnesses + | OnboardingStep::Defaults + | OnboardingStep::Titles => CONTENT_MAX_HEIGHT, + } +} + fn render_footer( ui: &OnboardingUi, step: OnboardingStep, @@ -2188,10 +2201,11 @@ pub fn render( let step = ui.step(); let viewport_width = f32::from(viewport.width); let viewport_height = f32::from(viewport.height); + let journey_max_height = journey_max_height(step); let compact_navigation = viewport_width < COMPACT_NAVIGATION_WIDTH; let roomy_x = viewport_width >= CONTENT_MAX_WIDTH + ROOMY_VIEWPORT_INSET * 2.0; let roomy_y = - viewport_height >= Theme::TITLEBAR_HEIGHT + CONTENT_MAX_HEIGHT + ROOMY_VIEWPORT_INSET * 2.0; + viewport_height >= Theme::TITLEBAR_HEIGHT + journey_max_height + ROOMY_VIEWPORT_INSET * 2.0; let outer_x = if roomy_x { ROOMY_VIEWPORT_INSET } else { @@ -2226,8 +2240,7 @@ pub fn render( .w_full() .h_full() .max_w(px(CONTENT_MAX_WIDTH)) - .max_h(px(CONTENT_MAX_HEIGHT)) - .mx_auto() + .max_h(px(journey_max_height)) .min_w_0() .min_h_0() .flex() @@ -2353,6 +2366,13 @@ mod tests { assert_eq!(OnboardingStep::Project.index() + 1, STEP_COUNT); } + #[test] + fn simple_steps_do_not_inherit_the_dense_journey_height() { + assert_eq!(journey_max_height(OnboardingStep::Workspace), 368.0); + assert_eq!(journey_max_height(OnboardingStep::Project), 480.0); + assert_eq!(journey_max_height(OnboardingStep::Appearance), 560.0); + } + #[test] fn established_profiles_default_to_completed() { assert_eq!( From 533314d61755cdb605f6ca487027bdc0c1d54d0b Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 01:06:51 +0200 Subject: [PATCH 06/21] fix(ui): refine onboarding navigation and agent list --- crates/ui/src/onboarding.rs | 198 +++++++++++++++++++++++------------- 1 file changed, 130 insertions(+), 68 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index eb432717d5..81fc663c00 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -28,7 +28,13 @@ const CONTENT_MAX_WIDTH: f32 = Theme::SPACE_LG * 30.0; // several useful rows before their overflow affordance becomes necessary. const CONTENT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 35.0; const WORKSPACE_MAX_HEIGHT: f32 = Theme::SPACE_LG * 23.0; +const HARNESS_MAX_HEIGHT: f32 = Theme::SPACE_LG * 40.0; const PROJECT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 30.0; +const HARNESS_ROW_HEIGHT: f32 = 54.0; +const HARNESS_ROW_GAP: f32 = 8.0; +// Five complete rows plus half of the next one makes the list's overflow +// obvious without spending the entire step on agent detection. +const HARNESS_LIST_MAX_HEIGHT: f32 = HARNESS_ROW_HEIGHT * 5.5 + HARNESS_ROW_GAP * 5.0; const STEP_GROUP_GAP: f32 = Theme::SPACE_LG + Theme::SPACE_SM; const VIEWPORT_INSET: f32 = Theme::SPACE_LG; const ROOMY_VIEWPORT_INSET: f32 = Theme::SPACE_LG * 2.0; @@ -478,11 +484,15 @@ fn choice_card( .rounded(px(12.0)) .border_1() .border_color(if selected { - theme.accent.opacity(0.65) + theme.border_strong } else { theme.border }) - .bg(theme.card_glass_bg()) + .bg(if selected { + theme.element_active + } else { + theme.card_glass_bg() + }) .flex() .flex_row() .items_start() @@ -609,11 +619,47 @@ fn footer_secondary_button( .text_color(crate::motion::hover_blend(id, theme.text_muted, theme.text)) .focus_visible(|style| style.border_2().border_color(theme.accent)) .when_some(icon_path, |button, icon_path| { - button.child(icon(icon_path).size(px(Theme::SPACE_MD))) + button.child( + icon(icon_path) + .size(px(Theme::SPACE_MD)) + .text_color(theme.text_muted), + ) }) .child(label) } +fn footer_back_button(theme: &Theme, enabled: bool) -> gpui::Stateful { + let id = "onboarding-back"; + div() + .id(id) + .size(px(Theme::SPACE_SM * 5.0)) + .flex_none() + .rounded(px(Theme::CONTROL_RADIUS)) + .border_1() + .border_color(theme.border.opacity(0.72)) + .bg(crate::motion::hover_blend( + id, + gpui::transparent_black(), + theme.glass_hover(), + )) + .flex() + .items_center() + .justify_center() + .text_color(crate::motion::hover_blend(id, theme.text_muted, theme.text)) + .focus_visible(|style| style.border_2().border_color(theme.accent)) + .when(enabled, |button| button.cursor_pointer()) + .when(!enabled, |button| button.opacity(0.38).cursor_default()) + .child( + icon(crate::icons::ALT_ARROW_LEFT) + .size(px(Theme::SPACE_MD)) + .text_color(if enabled { + theme.text_muted + } else { + theme.text_faint + }), + ) +} + fn footer_primary_button( theme: &Theme, id: &'static str, @@ -1328,16 +1374,20 @@ fn render_harness_step( let (icon_path, tint) = crate::pickers::harness_brand_icon(descriptor.id); div() .id(("onboarding-harness", index)) - .min_h(px(54.0)) + .min_h(px(HARNESS_ROW_HEIGHT)) .px(px(12.0)) .rounded(px(10.0)) .border_1() .border_color(if enabled { - theme.accent.opacity(0.65) + theme.border_strong } else { theme.border }) - .bg(theme.card_glass_bg()) + .bg(if enabled { + theme.element_active + } else { + theme.card_glass_bg() + }) .flex() .items_center() .gap(px(10.0)) @@ -1436,29 +1486,22 @@ fn render_harness_step( })) .flex_1() .min_h_0() + .max_h(px(HARNESS_LIST_MAX_HEIGHT)) .child(faded_step_scroll( "onboarding-harness-scroll", &ui.harness_scroll, list, )); - div() - .size_full() - .min_h_0() + let agent_actions = div() + .mt(px(Theme::SPACE_SM)) .flex() - .flex_col() - .child(heading( - theme, - "onboarding-heading-harnesses", - "Coding agents", - )) - .child(body(theme, "Turn on the agents you want to use.")) - .child(device_switcher) - .child(harness_list) - .when(matches!(ui.harnesses, Loadable::Ready(_)), |column| { - column.child( + .items_center() + .gap(px(Theme::SPACE_SM)) + .when(matches!(ui.harnesses, Loadable::Ready(_)), |row| { + row.child( quiet_button(theme, "Retry agent detection") .id("onboarding-harness-retry-ready") - .mt(px(8.0)) + .flex_1() .role(gpui::Role::Button) .track_focus(ui.control(11)) .on_click(cx.listener(|shell, _, _, cx| { @@ -1470,11 +1513,25 @@ fn render_harness_step( .child( quiet_button(theme, "Manage agent sign-ins") .id("onboarding-manage-agent-signins") - .mt(px(8.0)) + .flex_1() .role(gpui::Role::Button) .track_focus(ui.control(12)) .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_open_agent_settings(cx))), - ) + ); + div() + .size_full() + .min_h_0() + .flex() + .flex_col() + .child(heading( + theme, + "onboarding-heading-harnesses", + "Coding agents", + )) + .child(body(theme, "Turn on the agents you want to use.")) + .child(device_switcher) + .child(harness_list) + .child(agent_actions) .when_some(ui.error.clone(), |column, error| { column.child( div() @@ -1501,11 +1558,15 @@ fn chip( .rounded(px(9.0)) .border_1() .border_color(if selected { - theme.accent.opacity(0.65) + theme.border_strong } else { theme.border }) - .bg(theme.card_glass_bg()) + .bg(if selected { + theme.element_active + } else { + theme.card_glass_bg() + }) .text_size(crate::typography::ui_rems(12.5)) .font_weight(gpui::FontWeight::MEDIUM) .text_color(if selected { @@ -2097,15 +2158,15 @@ fn can_continue(ui: &OnboardingUi, step: OnboardingStep) -> bool { fn journey_max_height(step: OnboardingStep) -> f32 { match step { OnboardingStep::Workspace => WORKSPACE_MAX_HEIGHT, + OnboardingStep::Harnesses => HARNESS_MAX_HEIGHT, OnboardingStep::Project | OnboardingStep::FirstSession => PROJECT_MAX_HEIGHT, - OnboardingStep::Appearance - | OnboardingStep::Harnesses - | OnboardingStep::Defaults - | OnboardingStep::Titles => CONTENT_MAX_HEIGHT, + OnboardingStep::Appearance | OnboardingStep::Defaults | OnboardingStep::Titles => { + CONTENT_MAX_HEIGHT + } } } -fn render_footer( +fn render_footer_actions( ui: &OnboardingUi, step: OnboardingStep, theme: &Theme, @@ -2113,30 +2174,22 @@ fn render_footer( cx: &mut Context, ) -> AnyElement { let at_first_step = step == OnboardingStep::Workspace; - let previous = footer_secondary_button( - theme, - "onboarding-back", - "Previous", - (!compact).then_some(crate::icons::ALT_ARROW_LEFT), - ) - .role(gpui::Role::Button) - .aria_label("Previous setup step") - .when(at_first_step, |button| { - button - .opacity(0.38) - .cursor_default() - .aria_description("Unavailable on the first step") - }) - .when(!at_first_step, |button| { - button - .cursor_pointer() - .on_hover(crate::motion::hover_listener("onboarding-back")) - .track_focus(ui.control(28)) - .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_back(cx); - shell.onboarding_focus_control(0, window, cx); - })) - }); + let previous = footer_back_button(theme, !at_first_step) + .role(gpui::Role::Button) + .aria_label("Previous setup step") + .when(at_first_step, |button| { + button.aria_description("Unavailable on the first step") + }) + .when(!at_first_step, |button| { + button + .cursor_pointer() + .on_hover(crate::motion::hover_listener("onboarding-back")) + .track_focus(ui.control(28)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_back(cx); + shell.onboarding_focus_control(0, window, cx); + })) + }); let skip = footer_secondary_button(theme, "onboarding-skip", "Skip", None) .role(gpui::Role::Button) .aria_label("Skip setup") @@ -2177,17 +2230,9 @@ fn render_footer( .items_center() .gap(px(Theme::SPACE_XS + 2.0)) .child(previous) - .child(skip) - .child(continue_button); - div() - .w_full() - .flex_none() - .flex() - .flex_col() - .gap(px(Theme::SPACE_MD)) - .child(actions) - .child(render_progress(step, theme, compact)) - .into_any_element() + .child(continue_button) + .child(skip); + actions.into_any_element() } pub fn render( @@ -2216,6 +2261,7 @@ pub fn render( } else { VIEWPORT_INSET }; + let progress_reserve = Theme::SPACE_LG + Theme::SPACE_SM; let decision = match step { OnboardingStep::Workspace => render_workspace_step(ui, &theme, cx), OnboardingStep::Appearance => render_appearance_step(ui, &theme, cx), @@ -2250,20 +2296,34 @@ pub fn render( div() .mt(px(STEP_GROUP_GAP)) .flex_none() - .child(render_footer(ui, step, &theme, compact_navigation, cx)), + .child(render_footer_actions( + ui, + step, + &theme, + compact_navigation, + cx, + )), ); let panel = div() .absolute() .inset_0() .pt(px(Theme::TITLEBAR_HEIGHT + outer_y)) .px(px(outer_x)) - .pb(px(outer_y)) + .pb(px(outer_y + progress_reserve)) .min_w_0() .min_h_0() .flex() .items_center() .justify_center() - .child(journey); + .child(journey) + .child( + div() + .absolute() + .left_0() + .right_0() + .bottom(px(outer_y)) + .child(render_progress(step, &theme, compact_navigation)), + ); let close_confirm: AnyElement = if ui.close_confirm { div() .absolute() @@ -2370,7 +2430,9 @@ mod tests { fn simple_steps_do_not_inherit_the_dense_journey_height() { assert_eq!(journey_max_height(OnboardingStep::Workspace), 368.0); assert_eq!(journey_max_height(OnboardingStep::Project), 480.0); + assert_eq!(journey_max_height(OnboardingStep::Harnesses), 640.0); assert_eq!(journey_max_height(OnboardingStep::Appearance), 560.0); + assert_eq!(HARNESS_LIST_MAX_HEIGHT, 337.0); } #[test] From df3e434224f5f4b56fd022e8bb9934ab4811995c Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 01:15:29 +0200 Subject: [PATCH 07/21] fix(ui): unify onboarding selection and actions --- crates/ui/src/onboarding.rs | 261 ++++++++++++++++++------------------ 1 file changed, 130 insertions(+), 131 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 81fc663c00..b813a98884 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -32,9 +32,9 @@ const HARNESS_MAX_HEIGHT: f32 = Theme::SPACE_LG * 40.0; const PROJECT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 30.0; const HARNESS_ROW_HEIGHT: f32 = 54.0; const HARNESS_ROW_GAP: f32 = 8.0; -// Five complete rows plus half of the next one makes the list's overflow -// obvious without spending the entire step on agent detection. -const HARNESS_LIST_MAX_HEIGHT: f32 = HARNESS_ROW_HEIGHT * 5.5 + HARNESS_ROW_GAP * 5.0; +// Six complete rows plus half of the next one uses the available height while +// still making the list's overflow obvious. +const HARNESS_LIST_MAX_HEIGHT: f32 = HARNESS_ROW_HEIGHT * 6.5 + HARNESS_ROW_GAP * 6.0; const STEP_GROUP_GAP: f32 = Theme::SPACE_LG + Theme::SPACE_SM; const VIEWPORT_INSET: f32 = Theme::SPACE_LG; const ROOMY_VIEWPORT_INSET: f32 = Theme::SPACE_LG * 2.0; @@ -483,23 +483,19 @@ fn choice_card( .py(px(13.0)) .rounded(px(12.0)) .border_1() - .border_color(if selected { - theme.border_strong - } else { - theme.border - }) - .bg(if selected { - theme.element_active - } else { - theme.card_glass_bg() - }) + .border_color(theme.border) + .bg(theme.card_glass_bg()) .flex() .flex_row() .items_start() .gap(px(12.0)) .cursor_pointer() .hover(|style| style.bg(theme.element_hover)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) + .focus_visible(|style| style.border_2().border_color(theme.text)) + .when(selected, |card| { + card.bg(crate::theme::card_selected_bg()) + .shadow(crate::theme::card_selected_shadows()) + }) .child( div() .mt(px(2.0)) @@ -508,7 +504,7 @@ fn choice_card( .rounded_full() .border_1() .border_color(if selected { - theme.accent + theme.text } else { theme.border_strong }) @@ -516,7 +512,7 @@ fn choice_card( .items_center() .justify_center() .when(selected, |dot| { - dot.child(div().size(px(8.0)).rounded_full().bg(theme.accent)) + dot.child(div().size(px(8.0)).rounded_full().bg(theme.text)) }), ) .child( @@ -570,7 +566,7 @@ fn action_button(theme: &Theme, label: &'static str) -> gpui::Div { .justify_center() .cursor_pointer() .hover(|style| style.opacity(0.9)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) + .focus_visible(|style| style.border_2().border_color(theme.bg)) .child(label) } @@ -587,7 +583,7 @@ fn quiet_button(theme: &Theme, label: &'static str) -> gpui::Div { .text_color(theme.text_muted) .cursor_pointer() .hover(|style| style.bg(theme.element_hover).text_color(theme.text)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) + .focus_visible(|style| style.border_2().border_color(theme.text)) .child(label) } @@ -600,11 +596,9 @@ fn footer_secondary_button( div() .id(id) .h(px(Theme::SPACE_SM * 5.0)) - .flex_none() + .min_w_0() .px(px(Theme::SPACE_MD)) .rounded(px(Theme::CONTROL_RADIUS)) - .border_1() - .border_color(theme.border.opacity(0.72)) .bg(crate::motion::hover_blend( id, gpui::transparent_black(), @@ -617,7 +611,7 @@ fn footer_secondary_button( .text_size(crate::typography::ui_rems(12.5)) .font_weight(gpui::FontWeight::MEDIUM) .text_color(crate::motion::hover_blend(id, theme.text_muted, theme.text)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) + .focus_visible(|style| style.border_2().border_color(theme.text)) .when_some(icon_path, |button, icon_path| { button.child( icon(icon_path) @@ -628,38 +622,6 @@ fn footer_secondary_button( .child(label) } -fn footer_back_button(theme: &Theme, enabled: bool) -> gpui::Stateful { - let id = "onboarding-back"; - div() - .id(id) - .size(px(Theme::SPACE_SM * 5.0)) - .flex_none() - .rounded(px(Theme::CONTROL_RADIUS)) - .border_1() - .border_color(theme.border.opacity(0.72)) - .bg(crate::motion::hover_blend( - id, - gpui::transparent_black(), - theme.glass_hover(), - )) - .flex() - .items_center() - .justify_center() - .text_color(crate::motion::hover_blend(id, theme.text_muted, theme.text)) - .focus_visible(|style| style.border_2().border_color(theme.accent)) - .when(enabled, |button| button.cursor_pointer()) - .when(!enabled, |button| button.opacity(0.38).cursor_default()) - .child( - icon(crate::icons::ALT_ARROW_LEFT) - .size(px(Theme::SPACE_MD)) - .text_color(if enabled { - theme.text_muted - } else { - theme.text_faint - }), - ) -} - fn footer_primary_button( theme: &Theme, id: &'static str, @@ -678,7 +640,7 @@ fn footer_primary_button( .bg(theme.solid) .text_color(theme.on_solid) .cursor_pointer() - .focus_visible(|style| style.border_2().border_color(theme.accent)) + .focus_visible(|style| style.border_2().border_color(theme.bg)) .child( div() .size_full() @@ -970,6 +932,7 @@ fn render_appearance_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) None, ) .id("onboarding-title-model-auto") + .flex_1() + .min_w(px(180.0)) .role(gpui::Role::RadioButton) .aria_toggled(toggled(current.model.is_none())) .track_focus(ui.control(8)) @@ -1950,6 +1897,8 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) let id = model.id.clone(); chip(theme, model.label.clone().into(), selected, current.harness) .id(("onboarding-title-model", index)) + .flex_1() + .min_w(px(120.0)) .role(gpui::Role::RadioButton) .aria_toggled(toggled(selected)) .track_focus(ui.control(9 + index)) @@ -2117,9 +2066,9 @@ fn render_progress(step: OnboardingStep, theme: &Theme, compact: bool) -> AnyEle })) .rounded_full() .bg(if index < step.index() { - theme.accent.opacity(0.62) + theme.text_muted } else if index == step.index() { - theme.accent + theme.text } else { theme.border_strong }) @@ -2174,23 +2123,33 @@ fn render_footer_actions( cx: &mut Context, ) -> AnyElement { let at_first_step = step == OnboardingStep::Workspace; - let previous = footer_back_button(theme, !at_first_step) - .role(gpui::Role::Button) - .aria_label("Previous setup step") - .when(at_first_step, |button| { - button.aria_description("Unavailable on the first step") - }) - .when(!at_first_step, |button| { - button - .cursor_pointer() - .on_hover(crate::motion::hover_listener("onboarding-back")) - .track_focus(ui.control(28)) - .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_back(cx); - shell.onboarding_focus_control(0, window, cx); - })) - }); + let previous = footer_secondary_button( + theme, + "onboarding-back", + "Previous", + Some(crate::icons::ALT_ARROW_LEFT), + ) + .flex_1() + .role(gpui::Role::Button) + .aria_label("Previous setup step") + .when(at_first_step, |button| { + button + .opacity(0.38) + .cursor_default() + .aria_description("Unavailable on the first step") + }) + .when(!at_first_step, |button| { + button + .cursor_pointer() + .on_hover(crate::motion::hover_listener("onboarding-back")) + .track_focus(ui.control(28)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_back(cx); + shell.onboarding_focus_control(0, window, cx); + })) + }); let skip = footer_secondary_button(theme, "onboarding-skip", "Skip", None) + .flex_1() .role(gpui::Role::Button) .aria_label("Skip setup") .cursor_pointer() @@ -2205,7 +2164,7 @@ fn render_footer_actions( if finishes { "Finish setup" } else { "Continue" }, compact, ) - .flex_1() + .w_full() .role(gpui::Role::Button) .when(!enabled, |button| { button @@ -2224,14 +2183,54 @@ fn render_footer_actions( } })) }); - let actions = div() + let secondary_navigation = div() .w_full() .flex() .items_center() .gap(px(Theme::SPACE_XS + 2.0)) .child(previous) - .child(continue_button) .child(skip); + let actions = div() + .w_full() + .flex() + .flex_col() + .gap(px(Theme::SPACE_SM)) + .when(step == OnboardingStep::Harnesses, |column| { + column.child( + div() + .w_full() + .flex() + .items_center() + .gap(px(Theme::SPACE_SM)) + .when(matches!(ui.harnesses, Loadable::Ready(_)), |row| { + row.child( + quiet_button(theme, "Retry agent detection") + .id("onboarding-harness-retry-ready") + .h(px(Theme::SPACE_SM * 5.0)) + .flex_1() + .role(gpui::Role::Button) + .track_focus(ui.control(11)) + .on_click(cx.listener(|shell, _, _, cx| { + shell.onboarding_load_harnesses(cx); + shell.onboarding_load_accounts(cx); + })), + ) + }) + .child( + quiet_button(theme, "Manage agent sign-ins") + .id("onboarding-manage-agent-signins") + .h(px(Theme::SPACE_SM * 5.0)) + .flex_1() + .role(gpui::Role::Button) + .track_focus(ui.control(12)) + .on_click(cx.listener(|shell, _, _, cx| { + shell.onboarding_open_agent_settings(cx) + })), + ), + ) + }) + .child(continue_button) + .child(secondary_navigation); actions.into_any_element() } @@ -2294,7 +2293,7 @@ pub fn render( .child(div().flex_1().min_h_0().child(decision_content)) .child( div() - .mt(px(STEP_GROUP_GAP)) + .mt(px(Theme::SPACE_MD)) .flex_none() .child(render_footer_actions( ui, @@ -2432,7 +2431,7 @@ mod tests { assert_eq!(journey_max_height(OnboardingStep::Project), 480.0); assert_eq!(journey_max_height(OnboardingStep::Harnesses), 640.0); assert_eq!(journey_max_height(OnboardingStep::Appearance), 560.0); - assert_eq!(HARNESS_LIST_MAX_HEIGHT, 337.0); + assert_eq!(HARNESS_LIST_MAX_HEIGHT, 399.0); } #[test] From 765fd27c2eae238316b4e8d4a58c97cbf064a584 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 01:23:26 +0200 Subject: [PATCH 08/21] fix(ui): separate onboarding navigation from choices --- crates/ui/src/onboarding.rs | 113 ++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index b813a98884..c9fc2191a9 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -1616,8 +1616,7 @@ fn render_defaults_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) None, ) .id("onboarding-title-model-auto") - .flex_1() - .min_w(px(180.0)) + .flex_none() .role(gpui::Role::RadioButton) .aria_toggled(toggled(current.model.is_none())) .track_focus(ui.control(8)) @@ -1897,8 +1892,7 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) let id = model.id.clone(); chip(theme, model.label.clone().into(), selected, current.harness) .id(("onboarding-title-model", index)) - .flex_1() - .min_w(px(120.0)) + .flex_none() .role(gpui::Role::RadioButton) .aria_toggled(toggled(selected)) .track_focus(ui.control(9 + index)) @@ -2122,40 +2116,6 @@ fn render_footer_actions( compact: bool, cx: &mut Context, ) -> AnyElement { - let at_first_step = step == OnboardingStep::Workspace; - let previous = footer_secondary_button( - theme, - "onboarding-back", - "Previous", - Some(crate::icons::ALT_ARROW_LEFT), - ) - .flex_1() - .role(gpui::Role::Button) - .aria_label("Previous setup step") - .when(at_first_step, |button| { - button - .opacity(0.38) - .cursor_default() - .aria_description("Unavailable on the first step") - }) - .when(!at_first_step, |button| { - button - .cursor_pointer() - .on_hover(crate::motion::hover_listener("onboarding-back")) - .track_focus(ui.control(28)) - .on_click(cx.listener(|shell, _, window, cx| { - shell.onboarding_back(cx); - shell.onboarding_focus_control(0, window, cx); - })) - }); - let skip = footer_secondary_button(theme, "onboarding-skip", "Skip", None) - .flex_1() - .role(gpui::Role::Button) - .aria_label("Skip setup") - .cursor_pointer() - .on_hover(crate::motion::hover_listener("onboarding-skip")) - .track_focus(ui.control(29)) - .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_skip(cx))); let enabled = can_continue(ui, step); let finishes = matches!(step, OnboardingStep::Project | OnboardingStep::FirstSession); let continue_button = footer_primary_button( @@ -2183,13 +2143,6 @@ fn render_footer_actions( } })) }); - let secondary_navigation = div() - .w_full() - .flex() - .items_center() - .gap(px(Theme::SPACE_XS + 2.0)) - .child(previous) - .child(skip); let actions = div() .w_full() .flex() @@ -2229,11 +2182,53 @@ fn render_footer_actions( ), ) }) - .child(continue_button) - .child(secondary_navigation); + .child(continue_button); actions.into_any_element() } +fn render_global_navigation( + ui: &OnboardingUi, + step: OnboardingStep, + theme: &Theme, + cx: &mut Context, +) -> AnyElement { + let previous: AnyElement = if step == OnboardingStep::Workspace { + Empty.into_any_element() + } else { + footer_secondary_button( + theme, + "onboarding-back", + "Previous", + Some(crate::icons::ALT_ARROW_LEFT), + ) + .role(gpui::Role::Button) + .aria_label("Previous setup step") + .cursor_pointer() + .on_hover(crate::motion::hover_listener("onboarding-back")) + .track_focus(ui.control(28)) + .on_click(cx.listener(|shell, _, window, cx| { + shell.onboarding_back(cx); + shell.onboarding_focus_control(0, window, cx); + })) + .into_any_element() + }; + let skip = footer_secondary_button(theme, "onboarding-skip", "Skip", None) + .role(gpui::Role::Button) + .aria_label("Skip setup") + .cursor_pointer() + .on_hover(crate::motion::hover_listener("onboarding-skip")) + .track_focus(ui.control(29)) + .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_skip(cx))); + + div() + .w_full() + .flex() + .items_center() + .child(previous) + .child(skip.ml_auto()) + .into_any_element() +} + pub fn render( ui: &OnboardingUi, state: &Entity, @@ -2314,6 +2309,14 @@ pub fn render( .flex() .items_center() .justify_center() + .child( + div() + .absolute() + .top(px(Theme::TITLEBAR_HEIGHT + outer_y)) + .left(px(outer_x)) + .right(px(outer_x)) + .child(render_global_navigation(ui, step, &theme, cx)), + ) .child(journey) .child( div() From 7b129690255b2a21c24753b4c849eed3d5124474 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 01:44:21 +0200 Subject: [PATCH 09/21] Tighten onboarding spacing and clarify navigation controls --- crates/ui/src/onboarding.rs | 80 +++++++++++++++++++++++++++---------- crates/ui/src/shell.rs | 1 - 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index c9fc2191a9..d78c19337a 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -27,9 +27,9 @@ const CONTENT_MAX_WIDTH: f32 = Theme::SPACE_LG * 30.0; // The journey grows with the window until this cap; dense steps should expose // several useful rows before their overflow affordance becomes necessary. const CONTENT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 35.0; -const WORKSPACE_MAX_HEIGHT: f32 = Theme::SPACE_LG * 23.0; +const WORKSPACE_MAX_HEIGHT: f32 = Theme::SPACE_LG * 18.0; const HARNESS_MAX_HEIGHT: f32 = Theme::SPACE_LG * 40.0; -const PROJECT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 30.0; +const PROJECT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 18.0; const HARNESS_ROW_HEIGHT: f32 = 54.0; const HARNESS_ROW_GAP: f32 = 8.0; // Six complete rows plus half of the next one uses the available height while @@ -817,7 +817,6 @@ fn render_workspace_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) "onboarding-heading-titles", "Session titles", )) - .child(body(theme, "Choose how new sessions are named.")) .child( div() .id("onboarding-title-settings-loading") @@ -1754,7 +1749,6 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) "onboarding-heading-titles", "Session titles", )) - .child(body(theme, "Choose how new sessions are named.")) .child( div() .id("onboarding-title-settings-error") @@ -1929,7 +1923,6 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) "onboarding-heading-titles", "Session titles", )) - .child(body(theme, "Choose how new sessions are named.")) .child( div() .mt(px(STEP_GROUP_GAP)) @@ -1944,6 +1937,33 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .into_any_element() } +fn project_action( + theme: &Theme, + label: &'static str, + description: impl Into, + selected: bool, +) -> gpui::Div { + quiet_button(theme, label) + .w_full() + .border_1() + .border_color(theme.border) + .bg(theme.card_glass_bg()) + .min_h(px(76.0)) + .flex_col() + .items_start() + .gap(px(Theme::SPACE_XS)) + .px(px(Theme::SPACE_MD)) + .when(selected, |button| { + button.bg(crate::theme::card_selected_bg()) + }) + .child( + div() + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.text_muted) + .child(description.into()), + ) +} + fn render_project_step( ui: &OnboardingUi, theme: &Theme, @@ -1975,33 +1995,28 @@ fn render_project_step( .flex() .flex_col() .gap(px(12.0)) - .role(gpui::Role::RadioGroup) .aria_label("Project target") .child( - choice_card( + project_action( theme, "Start in a project", selected_name, selected && !no_project, - None, ) .id("onboarding-project-choose") - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(selected && !no_project)) + .role(gpui::Role::Button) .track_focus(ui.control(0)) .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_open_project(cx))), ) .child( - choice_card( + project_action( theme, "Continue without a project", "Add a project when you need one.", no_project, - None, ) .id("onboarding-project-none") - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(no_project)) + .role(gpui::Role::Button) .track_focus(ui.control(1)) .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_pick_no_project(cx))), ) @@ -2022,7 +2037,6 @@ fn render_project_step( .flex() .flex_col() .child(heading(theme, "onboarding-heading-project", "Project")) - .child(body(theme, "Choose a folder now, or add one later.")) .child( div() .mt(px(STEP_GROUP_GAP)) @@ -2201,6 +2215,9 @@ fn render_global_navigation( "Previous", Some(crate::icons::ALT_ARROW_LEFT), ) + .border_1() + .border_color(theme.border_strong) + .flex_none() .role(gpui::Role::Button) .aria_label("Previous setup step") .cursor_pointer() @@ -2240,7 +2257,26 @@ pub fn render( let step = ui.step(); let viewport_width = f32::from(viewport.width); let viewport_height = f32::from(viewport.height); - let journey_max_height = journey_max_height(step); + let journey_max_height = if step == OnboardingStep::Titles { + let rows = ui.harnesses.ready().map_or(0, |rows| { + rows.iter() + .filter(|h| title_harness_is_available(h)) + .count() + }) + 1; + let has_models = ui + .title_settings + .ready() + .is_some_and(|s| s.harness.is_some()); + (32.0 + + STEP_GROUP_GAP + + rows as f32 * 86.0 + + if has_models { 132.0 } else { 0.0 } + + Theme::SPACE_MD + + 40.0) + .min(journey_max_height(step)) + } else { + journey_max_height(step) + }; let compact_navigation = viewport_width < COMPACT_NAVIGATION_WIDTH; let roomy_x = viewport_width >= CONTENT_MAX_WIDTH + ROOMY_VIEWPORT_INSET * 2.0; let roomy_y = @@ -2430,8 +2466,8 @@ mod tests { #[test] fn simple_steps_do_not_inherit_the_dense_journey_height() { - assert_eq!(journey_max_height(OnboardingStep::Workspace), 368.0); - assert_eq!(journey_max_height(OnboardingStep::Project), 480.0); + assert_eq!(journey_max_height(OnboardingStep::Workspace), 288.0); + assert_eq!(journey_max_height(OnboardingStep::Project), 288.0); assert_eq!(journey_max_height(OnboardingStep::Harnesses), 640.0); assert_eq!(journey_max_height(OnboardingStep::Appearance), 560.0); assert_eq!(HARNESS_LIST_MAX_HEIGHT, 399.0); diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index d0308cae8f..994d604112 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -8788,7 +8788,6 @@ impl Shell { .title_models .ready() .map(|models| (8, 8 + models.len().min(4))), - OnboardingStep::Project if focused <= 1 => Some((0, 1)), _ => None, }; if let Some((start, end)) = group From 49f756314893e4c556f8e24effc6f63c41788580 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 01:49:28 +0200 Subject: [PATCH 10/21] Reuse shared controls in onboarding --- crates/ui/src/onboarding.rs | 101 ++++++++---------------------------- 1 file changed, 23 insertions(+), 78 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index d78c19337a..fea4a10196 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -17,6 +17,7 @@ use crate::appearance::AppearanceMode; use crate::icons::icon; use crate::popover::{self, Loadable, Popup}; use crate::settings::composer::ComposerDefaults; +use crate::settings::widgets; use crate::shell::Shell; use crate::state::AppState; use crate::theme::{Theme, ink}; @@ -552,37 +553,20 @@ fn choice_card( } fn action_button(theme: &Theme, label: &'static str) -> gpui::Div { - div() + popover::btn_primary(theme, label) .w_full() - .min_h(px(44.0)) - .px(px(16.0)) - .rounded(px(10.0)) - .bg(theme.solid) - .text_color(theme.on_solid) - .text_size(crate::typography::ui_rems(14.0)) - .font_weight(gpui::FontWeight::SEMIBOLD) + .min_h(px(40.0)) .flex() .items_center() .justify_center() - .cursor_pointer() - .hover(|style| style.opacity(0.9)) .focus_visible(|style| style.border_2().border_color(theme.bg)) - .child(label) } fn quiet_button(theme: &Theme, label: &'static str) -> gpui::Div { - div() + widgets::ghost_action(theme) .min_h(px(36.0)) - .px(px(10.0)) - .rounded(px(8.0)) - .flex() - .items_center() .justify_center() - .text_size(crate::typography::ui_rems(12.5)) - .font_weight(gpui::FontWeight::MEDIUM) - .text_color(theme.text_muted) - .cursor_pointer() - .hover(|style| style.bg(theme.element_hover).text_color(theme.text)) + .hover(|style| widgets::ghost_hover(theme, style)) .focus_visible(|style| style.border_2().border_color(theme.text)) .child(label) } @@ -593,12 +577,12 @@ fn footer_secondary_button( label: &'static str, icon_path: Option<&'static str>, ) -> gpui::Stateful { - div() + widgets::ghost_action(theme) .id(id) .h(px(Theme::SPACE_SM * 5.0)) .min_w_0() .px(px(Theme::SPACE_MD)) - .rounded(px(Theme::CONTROL_RADIUS)) + .rounded(px(8.0)) .bg(crate::motion::hover_blend( id, gpui::transparent_black(), @@ -608,8 +592,7 @@ fn footer_secondary_button( .items_center() .justify_center() .gap(px(Theme::SPACE_XS)) - .text_size(crate::typography::ui_rems(12.5)) - .font_weight(gpui::FontWeight::MEDIUM) + .text_size(crate::typography::ui_rems(13.0)) .text_color(crate::motion::hover_blend(id, theme.text_muted, theme.text)) .focus_visible(|style| style.border_2().border_color(theme.text)) .when_some(icon_path, |button, icon_path| { @@ -628,40 +611,22 @@ fn footer_primary_button( label: &'static str, compact: bool, ) -> gpui::Stateful { - let wash = - crate::motion::hover_blend(id, gpui::transparent_black(), theme.on_solid.opacity(0.10)); - div() + popover::btn_primary(theme, label) .id(id) .h(px(Theme::SPACE_SM * 5.0)) .min_w_0() - .rounded(px(Theme::CONTROL_RADIUS)) - .border_1() - .border_color(theme.solid) - .bg(theme.solid) - .text_color(theme.on_solid) - .cursor_pointer() + .flex() + .items_center() + .justify_center() + .gap(px(Theme::SPACE_XS)) .focus_visible(|style| style.border_2().border_color(theme.bg)) - .child( - div() - .size_full() - .px(px(Theme::SPACE_MD)) - .rounded(px(Theme::CONTROL_RADIUS)) - .bg(wash) - .flex() - .items_center() - .justify_center() - .gap(px(Theme::SPACE_XS)) - .text_size(crate::typography::ui_rems(12.5)) - .font_weight(gpui::FontWeight::SEMIBOLD) - .child(label) - .when(!compact, |content| { - content.child( - icon(crate::icons::ALT_ARROW_RIGHT) - .size(px(Theme::SPACE_MD)) - .text_color(theme.on_solid), - ) - }), - ) + .when(!compact, |button| { + button.child( + icon(crate::icons::ALT_ARROW_RIGHT) + .size(px(Theme::SPACE_MD)) + .text_color(theme.on_solid), + ) + }) } pub(crate) fn activates(event: &KeyDownEvent) -> bool { @@ -1415,28 +1380,7 @@ fn render_harness_step( ), ) .when(interactive, |row| { - row.child( - div() - .w(px(34.0)) - .h(px(20.0)) - .rounded_full() - .p(px(2.0)) - .bg(if enabled { - theme.text - } else { - theme.border_strong - }) - .flex() - .justify_end() - .when(!enabled, |toggle| toggle.justify_start()) - .child( - div().size(px(16.0)).rounded_full().bg(if enabled { - theme.bg - } else { - theme.text_muted - }), - ), - ) + row.child(widgets::toggle_switch(theme, enabled)) }) }), ) @@ -2216,8 +2160,9 @@ fn render_global_navigation( Some(crate::icons::ALT_ARROW_LEFT), ) .border_1() - .border_color(theme.border_strong) + .border_color(theme.border) .flex_none() + .text_color(theme.text) .role(gpui::Role::Button) .aria_label("Previous setup step") .cursor_pointer() From 773e7a8111d487e1ce619fece73fa0bb5124d7ea Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 02:04:50 +0200 Subject: [PATCH 11/21] Fix onboarding resume, keyboard isolation, and complete model selection --- crates/ui/src/onboarding.rs | 357 ++++++++++++++++++++++++---------- crates/ui/src/shell.rs | 207 +++++++++++++++++--- crates/ui/src/shell/spaces.rs | 1 + 3 files changed, 438 insertions(+), 127 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index fea4a10196..10fc916ba0 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -215,6 +215,8 @@ pub struct OnboardingUi { pub theme_scroll: ScrollHandle, pub harness_scroll: ScrollHandle, pub step_scroll: ScrollHandle, + pub model_scroll: ScrollHandle, + model_scroll_selection: Option<(OnboardingStep, Option, usize)>, pub harness_task: Option>, pub model_task: Option>, pub accounts_task: Option>, @@ -227,7 +229,7 @@ impl OnboardingUi { mut state: OnboardingState, defaults: ComposerDefaults, fixture: Option, - cx: &mut Context, + cx: &mut gpui::App, ) -> Self { // The former sixth step only waited for a composer submit. Treat an // in-progress snapshot already parked there as completed instead of @@ -266,6 +268,8 @@ impl OnboardingUi { theme_scroll: ScrollHandle::new(), harness_scroll: ScrollHandle::new(), step_scroll: ScrollHandle::new(), + model_scroll: ScrollHandle::new(), + model_scroll_selection: None, harness_task: None, model_task: None, accounts_task: None, @@ -302,14 +306,58 @@ impl OnboardingUi { /// registry order. Usability deliberately does not depend on OAuth account /// discovery: API-key-backed CLIs are valid even without an account row. pub(crate) fn resolve_default_harness(&mut self) { - let selected = self - .harnesses - .ready() - .and_then(|rows| preferred_harness(rows, &self.accounts, self.selected_harness)); + let Some(rows) = self.harnesses.ready() else { + return; + }; + let selected = preferred_harness(rows, &self.accounts, self.selected_harness); if self.selected_harness != selected { self.selected_harness = selected; self.selected_model = None; self.selected_reasoning = None; + self.models = Loadable::Idle; + self.model_task = None; + } + } + + /// Resume loading only after discovery has validated the saved harness. + pub(crate) fn models_to_load(&self) -> Option { + if self.active() + && self.step().index() >= OnboardingStep::Defaults.index() + && self.harnesses.ready().is_some() + && matches!(self.models, Loadable::Idle) + { + self.selected_harness + } else { + None + } + } + + pub(crate) fn prepare_model_controls(&mut self, cx: &mut gpui::App) { + let count = self + .models + .ready() + .map_or(0, Vec::len) + .max(self.title_models.ready().map_or(0, Vec::len)); + while self.controls.len() < 32 + count { + self.controls.push(cx.focus_handle().tab_stop(true)); + } + let (models, selected) = match self.step() { + OnboardingStep::Defaults => (self.models.ready(), self.selected_model.as_ref()), + OnboardingStep::Titles => ( + self.title_models.ready(), + self.title_settings.ready().and_then(|s| s.model.as_ref()), + ), + _ => return, + }; + if let Some(models) = models { + let selection = (self.step(), selected.cloned(), models.len()); + if self.model_scroll_selection.as_ref() != Some(&selection) { + let index = selected + .and_then(|id| models.iter().position(|m| &m.id == id)) + .map_or(0, |index| index + 1); + self.model_scroll.scroll_to_item(index); + self.model_scroll_selection = Some(selection); + } } } @@ -1473,6 +1521,82 @@ fn chip( .child(label) } +/// Model rows use a separate focus range, so a complete catalog never collides +/// with reasoning, navigation, or dialog controls. +pub(crate) fn model_control(index: usize) -> usize { + if index == 0 { 8 } else { 31 + index } +} + +pub(crate) fn model_choice(control: usize) -> Option { + match control { + 8 => Some(0), + 32.. => Some(control - 31), + _ => None, + } +} + +fn render_model_choices( + ui: &OnboardingUi, + theme: &Theme, + models: &[Model], + selected: Option<&str>, + titles: bool, + cx: &mut Context, +) -> AnyElement { + let prefix = if titles { + "onboarding-title-model" + } else { + "onboarding-default-model" + }; + let automatic = if titles { + "Automatic · cheapest suitable" + } else { + "Automatic" + }; + let choices = std::iter::once((None, automatic.to_string())).chain( + models + .iter() + .map(|model| (Some(model.id.clone()), model.label.clone())), + ); + div() + .id(prefix) + .w_full() + .h(px(((models.len() + 1) as f32 * 34.0).min(153.0))) + .overflow_y_scroll() + .track_scroll(&ui.model_scroll) + .role(gpui::Role::RadioGroup) + .aria_label(if titles { + "Title model" + } else { + "Default model" + }) + .children(choices.enumerate().map(|(index, (id, label))| { + let selected = selected == id.as_deref(); + popover::menu_row(theme, selected, format!("{prefix}-{index}")) + .id((prefix, index)) + .h(px(34.0)) + .w_full() + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(selected)) + .track_focus(ui.control(model_control(index))) + .focus_visible(|style| style.border_1().border_color(theme.text)) + .child(div().flex_1().min_w_0().text_ellipsis().child(label)) + .child( + icon(crate::icons::CHECK) + .size(px(14.0)) + .opacity(if selected { 1.0 } else { 0.0 }), + ) + .on_click(cx.listener(move |shell, _, _, cx| { + if titles { + shell.onboarding_pick_title_model(id.clone(), cx); + } else { + shell.onboarding_pick_default_model(id.clone(), cx); + } + })) + })) + .into_any_element() +} + fn render_defaults_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) -> AnyElement { let harnesses: Vec = ui .harnesses @@ -1530,62 +1654,26 @@ fn render_defaults_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context div() - .id("onboarding-model-loading") - .role(gpui::Role::ProgressIndicator) - .aria_label("Loading models") - .h(px(38.0)) - .rounded(px(9.0)) - .bg(ink(0.045)) - .into_any_element(), - Loadable::Error(error) => div() - .id("onboarding-model-load-error") - .role(gpui::Role::Alert) - .text_size(crate::typography::ui_rems(12.0)) - .text_color(theme.danger_muted) - .child(error.clone()) - .into_any_element(), - Loadable::Ready(_) => div() - .id("onboarding-default-models") - .flex() - .flex_wrap() - .gap(px(8.0)) - .role(gpui::Role::RadioGroup) - .aria_label("Default model") - .child( - chip(theme, "Automatic".into(), ui.selected_model.is_none(), None) - .id("onboarding-default-model-auto") - .flex_none() - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(ui.selected_model.is_none())) - .track_focus(ui.control(8)) - .on_click(cx.listener(|shell, _, _, cx| { - shell.onboarding_pick_default_model(None, cx) - })), - ) - .children( - models - .into_iter() - .take(4) - .enumerate() - .map(|(index, model)| { - let selected = ui.selected_model.as_deref() == Some(model.id.as_str()); - let id = model.id; - chip(theme, model.label.into(), selected, ui.selected_harness) - .id(("onboarding-default-model", index)) - .flex_none() - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(selected)) - .track_focus(ui.control(9 + index)) - .on_click(cx.listener(move |shell, _, _, cx| { - shell.onboarding_pick_default_model(Some(id.clone()), cx) - })) - }), - ) - .into_any_element(), - }; + let model_content: AnyElement = match &ui.models { + Loadable::Idle | Loadable::Loading => div() + .id("onboarding-model-loading") + .role(gpui::Role::ProgressIndicator) + .aria_label("Loading models") + .h(px(38.0)) + .rounded(px(9.0)) + .bg(ink(0.045)) + .into_any_element(), + Loadable::Error(error) => div() + .id("onboarding-model-load-error") + .role(gpui::Role::Alert) + .text_size(crate::typography::ui_rems(12.0)) + .text_color(theme.danger_muted) + .child(error.clone()) + .into_any_element(), + Loadable::Ready(_) => { + render_model_choices(ui, theme, &models, ui.selected_model.as_deref(), false, cx) + } + }; let reasoning_chips = div() .id("onboarding-default-reasoning-levels") @@ -1801,44 +1889,14 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .text_color(theme.text_muted) .child("Title model"), ) - .child( - div() - .id("onboarding-title-models") - .flex() - .flex_wrap() - .gap(px(8.0)) - .role(gpui::Role::RadioGroup) - .aria_label("Title model") - .child( - chip( - theme, - "Automatic · cheapest suitable".into(), - current.model.is_none(), - None, - ) - .id("onboarding-title-model-auto") - .flex_none() - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(current.model.is_none())) - .track_focus(ui.control(8)) - .on_click(cx.listener( - |shell, _, _, cx| shell.onboarding_pick_title_model(None, cx), - )), - ) - .children(models.iter().take(4).enumerate().map(|(index, model)| { - let selected = current.model.as_deref() == Some(model.id.as_str()); - let id = model.id.clone(); - chip(theme, model.label.clone().into(), selected, current.harness) - .id(("onboarding-title-model", index)) - .flex_none() - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(selected)) - .track_focus(ui.control(9 + index)) - .on_click(cx.listener(move |shell, _, _, cx| { - shell.onboarding_pick_title_model(Some(id.clone()), cx) - })) - })), - ) + .child(render_model_choices( + ui, + theme, + models, + current.model.as_deref(), + true, + cx, + )) .into_any_element(), } }; @@ -2215,7 +2273,7 @@ pub fn render( (32.0 + STEP_GROUP_GAP + rows as f32 * 86.0 - + if has_models { 132.0 } else { 0.0 } + + if has_models { 196.0 } else { 0.0 } + Theme::SPACE_MD + 40.0) .min(journey_max_height(step)) @@ -2522,6 +2580,105 @@ mod tests { ); } + #[gpui::test] + fn discovery_preserves_saved_choices_until_harnesses_are_ready(cx: &mut gpui::TestAppContext) { + cx.update(|cx| { + let mut defaults = ComposerDefaults::default(); + defaults.harness = Some(HarnessId::Codex); + defaults.remember_model(HarnessId::Codex, "saved-model".into(), "Saved model".into()); + defaults.reasoning = Some(ReasoningLevel::High); + for accounts_first in [true, false] { + let mut ui = + OnboardingUi::new(OnboardingState::fresh(), defaults.clone(), None, cx); + ui.harnesses = Loadable::Loading; + ui.accounts = Loadable::Loading; + if !accounts_first { + ui.harnesses = Loadable::Ready(fixture_harnesses()); + } + ui.resolve_default_harness(); + ui.accounts = Loadable::Error("account discovery failed".into()); + ui.resolve_default_harness(); + assert_eq!(ui.selected_harness, Some(HarnessId::Codex)); + assert_eq!(ui.selected_model.as_deref(), Some("saved-model")); + assert_eq!(ui.selected_reasoning, Some(ReasoningLevel::High)); + ui.harnesses = Loadable::Ready(fixture_harnesses()); + ui.resolve_default_harness(); + assert_eq!(ui.selected_model.as_deref(), Some("saved-model")); + ui.harnesses = Loadable::Error("catalog unavailable".into()); + ui.resolve_default_harness(); + assert_eq!(ui.selected_harness, Some(HarnessId::Codex)); + assert_eq!(ui.selected_reasoning, Some(ReasoningLevel::High)); + } + }); + } + + #[gpui::test] + fn resumed_defaults_load_once_after_discovery_without_resetting_selection( + cx: &mut gpui::TestAppContext, + ) { + cx.update(|cx| { + for step in [ + OnboardingStep::Defaults, + OnboardingStep::Titles, + OnboardingStep::Project, + ] { + let mut state = OnboardingState::fresh(); + state.step = step; + let mut ui = OnboardingUi::new(state, ComposerDefaults::default(), None, cx); + ui.selected_harness = Some(HarnessId::Codex); + ui.selected_model = Some("saved-model".into()); + assert_eq!(ui.models_to_load(), None); + ui.harnesses = Loadable::Ready(fixture_harnesses()); + ui.resolve_default_harness(); + assert_eq!(ui.models_to_load(), Some(HarnessId::Codex)); + assert_eq!(ui.selected_model.as_deref(), Some("saved-model")); + ui.models = Loadable::Loading; + assert_eq!(ui.models_to_load(), None); + ui.models = Loadable::Ready(fixture_models()); + ui.state.step = OnboardingStep::Defaults; + assert_eq!(ui.models_to_load(), None); + ui.models = Loadable::Error("offline".into()); + assert_eq!( + ui.models_to_load(), + None, + "do not retry failures every render" + ); + } + }); + } + + #[gpui::test] + fn full_catalog_has_unique_focus_handles_outside_navigation(cx: &mut gpui::TestAppContext) { + cx.update(|cx| { + let mut ui = OnboardingUi::new( + OnboardingState::fresh(), + ComposerDefaults::default(), + None, + cx, + ); + let template = fixture_models().remove(0); + let models: Vec<_> = (0..100) + .map(|index| { + let mut model = template.clone(); + model.id = format!("model-{index}"); + model + }) + .collect(); + ui.models = Loadable::Ready(models.clone()); + ui.title_models = Loadable::Ready(models); + ui.prepare_model_controls(cx); + for index in 0..=100 { + let control = model_control(index); + assert_eq!(model_choice(control), Some(index)); + assert!(control == 8 || control >= 32); + assert!(control < ui.controls.len()); + if index > 0 { + assert_ne!(ui.control(control), ui.control(model_control(index - 1))); + } + } + }); + } + #[test] fn automatic_model_uses_the_selected_harness_reasoning_ladder() { let harnesses = Loadable::Ready(fixture_harnesses()); diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index 994d604112..f3d2bc64f4 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -3824,6 +3824,9 @@ impl Shell { { self.onboarding_load_titles(cx); } + if let Some(harness) = self.onboarding.models_to_load() { + self.onboarding_load_models(harness, cx); + } } pub(crate) fn onboarding_pick_workspace( @@ -4137,6 +4140,7 @@ impl Shell { Err(error) => Loadable::Error(error.to_string()), }; shell.onboarding.resolve_default_harness(); + shell.ensure_onboarding_data(cx); cx.notify(); }) .ok(); @@ -8639,7 +8643,11 @@ impl Shell { window: &mut Window, cx: &mut Context, ) -> bool { - if !self.onboarding.active() { + if !self.onboarding.active() + || self.overlay_owns_keyboard(cx) + || self.onboarding.agent_settings_open + || self.sync_flow.has_visible_overlay() + { return false; } if self.onboarding.step() == OnboardingStep::Appearance @@ -8705,6 +8713,9 @@ impl Shell { } else { window.focus_next(cx); } + if !self.onboarding.close_confirm { + self.onboarding_reveal_model_focus(window); + } return true; } let focused = self @@ -8717,6 +8728,52 @@ impl Shell { }; let starting_step = self.onboarding.step(); + if !self.onboarding.close_confirm + && matches!( + starting_step, + OnboardingStep::Defaults | OnboardingStep::Titles + ) + && let Some(index) = crate::onboarding::model_choice(focused) + { + let models = if starting_step == OnboardingStep::Titles { + self.onboarding.title_models.ready() + } else { + self.onboarding.models.ready() + }; + let Some(models) = models else { return false }; + if index > models.len() { + return false; + } + if matches!( + event.keystroke.key.as_str(), + "left" | "right" | "up" | "down" + ) && !event.keystroke.modifiers.modified() + { + let count = models.len() + 1; + let next = if matches!(event.keystroke.key.as_str(), "right" | "down") { + (index + 1) % count + } else { + (index + count - 1) % count + }; + window.focus( + self.onboarding + .control(crate::onboarding::model_control(next)), + cx, + ); + self.onboarding_reveal_model_focus(window); + return true; + } + if crate::onboarding::activates(event) { + let model = index.checked_sub(1).map(|index| models[index].id.clone()); + if starting_step == OnboardingStep::Titles { + self.onboarding_pick_title_model(model, cx); + } else { + self.onboarding_pick_default_model(model, cx); + } + return true; + } + } + if matches!( event.keystroke.key.as_str(), "left" | "right" | "up" | "down" @@ -8761,11 +8818,6 @@ impl Shell { (0, count.saturating_sub(1)) }) } - OnboardingStep::Defaults if (8..16).contains(&focused) => self - .onboarding - .models - .ready() - .map(|models| (8, 8 + models.len().min(4))), OnboardingStep::Defaults if (16..26).contains(&focused) => { let count = self.onboarding.reasoning_levels().len(); Some((16, 16 + count.min(9))) @@ -8783,11 +8835,6 @@ impl Shell { .unwrap_or(0); Some((0, count.min(7))) } - OnboardingStep::Titles if (8..16).contains(&focused) => self - .onboarding - .title_models - .ready() - .map(|models| (8, 8 + models.len().min(4))), _ => None, }; if let Some((start, end)) = group @@ -8905,14 +8952,6 @@ impl Shell { OnboardingStep::Defaults => { if focused == 26 { self.onboarding_continue(cx); - } else if focused == 8 { - self.onboarding_pick_default_model(None, cx); - } else if (9..16).contains(&focused) { - let model = self.onboarding.models.ready().and_then(|models| { - models.get(focused - 9).map(|model| model.id.clone()) - }); - let Some(model) = model else { return false }; - self.onboarding_pick_default_model(Some(model), cx); } else if focused == 16 { self.onboarding_pick_reasoning(None, cx); } else if (17..26).contains(&focused) { @@ -8954,14 +8993,6 @@ impl Shell { }); let Some(harness) = harness else { return false }; self.onboarding_pick_title_harness(Some(harness), cx); - } else if focused == 8 { - self.onboarding_pick_title_model(None, cx); - } else if (9..16).contains(&focused) { - let model = self.onboarding.title_models.ready().and_then(|models| { - models.get(focused - 9).map(|model| model.id.clone()) - }); - let Some(model) = model else { return false }; - self.onboarding_pick_title_model(Some(model), cx); } else { return false; } @@ -8983,6 +9014,21 @@ impl Shell { true } + fn onboarding_reveal_model_focus(&self, window: &Window) { + if matches!( + self.onboarding.step(), + OnboardingStep::Defaults | OnboardingStep::Titles + ) && let Some(index) = self + .onboarding + .controls + .iter() + .position(|handle| handle.is_focused(window)) + .and_then(crate::onboarding::model_choice) + { + self.onboarding.model_scroll.scroll_to_item(index); + } + } + fn on_key_down( &mut self, event: &gpui::KeyDownEvent, @@ -11937,6 +11983,7 @@ impl Render for Shell { }; let root = match &render_gate { GatePhase::Ready if self.onboarding.active() => { + self.onboarding.prepare_model_controls(cx); let viewport = window.viewport_size(); let title_bar = self.render_onboarding_title_bar(cx); let page = crate::onboarding::render( @@ -13375,6 +13422,112 @@ mod exit_regressions { .unwrap(); } + #[gpui::test] + fn onboarding_keyboard_yields_to_project_palette_and_reaches_full_model_catalog( + cx: &mut TestAppContext, + ) { + let dir = tempfile::tempdir().unwrap(); + cx.update(|cx| { + gpui_base::init(cx); + cx.set_global(Theme::default()); + crate::app_menus::init(cx); + }); + let window = cx.add_window(|_, cx| { + let state = cx.new(|_| AppState::new()); + Shell::new( + state, + EngineBootConfig { + data_dir: dir.path().into(), + ipc_port: 0, + edge_url: "http://127.0.0.1:1".into(), + edge_token: None, + org_id: None, + workos_client_id: None, + default_harness: zeron_proto::HarnessId::Mock, + }, + cx, + ) + }); + window + .update(cx, |shell, window, cx| { + shell.onboarding = OnboardingUi::new( + crate::onboarding::OnboardingState::fresh(), + Default::default(), + Some(crate::onboarding::OnboardingFixture::Defaults), + cx, + ); + let key = |value: &str| gpui::KeyDownEvent { + keystroke: gpui::Keystroke::parse(value).unwrap(), + is_held: false, + prefer_character_input: false, + }; + shell.onboarding.state.step = OnboardingStep::Project; + shell.onboarding.fixture = Some(crate::onboarding::OnboardingFixture::Project); + window.focus(shell.onboarding.control(2), cx); + shell.open_add_space(cx); + for value in ["tab", "shift-tab", "enter", "space", "down"] { + assert!(!shell.onboarding_key_down(&key(value), window, cx)); + assert_eq!(shell.onboarding.step(), OnboardingStep::Project); + assert!(shell.add_space.is_some()); + } + assert!(shell.capture_escape_surface(window, cx)); + assert!(shell.add_space.is_none()); + assert!(!shell.onboarding.close_confirm); + + let template = shell.onboarding.models.ready().unwrap()[0].clone(); + let models: Vec<_> = (0..12) + .map(|index| { + let mut model = template.clone(); + model.id = format!("catalog-{index}"); + model + }) + .collect(); + shell.onboarding.models = Loadable::Ready(models.clone()); + shell.onboarding.title_models = Loadable::Ready(models); + shell.onboarding.title_settings = + Loadable::Ready(zeron_engine::registry::TitleSettings { + harness: Some(zeron_proto::HarnessId::Codex), + model: None, + }); + shell.onboarding.prepare_model_controls(cx); + for step in [OnboardingStep::Defaults, OnboardingStep::Titles] { + shell.onboarding.state.step = step; + shell.onboarding.fixture = Some(if step == OnboardingStep::Defaults { + crate::onboarding::OnboardingFixture::Defaults + } else { + crate::onboarding::OnboardingFixture::Titles + }); + window.focus(shell.onboarding.control(8), cx); + for _ in 0..12 { + assert!(shell.onboarding_key_down(&key("down"), window, cx)); + } + assert!( + shell + .onboarding + .control(crate::onboarding::model_control(12)) + .is_focused(window) + ); + assert!(shell.onboarding_key_down(&key("enter"), window, cx)); + let selected = if step == OnboardingStep::Defaults { + shell.onboarding.selected_model.as_deref() + } else { + shell + .onboarding + .title_settings + .ready() + .unwrap() + .model + .as_deref() + }; + assert_eq!(selected, Some("catalog-11")); + assert!(shell.onboarding_key_down(&key("down"), window, cx)); + assert!(shell.onboarding.control(8).is_focused(window)); + } + }) + .unwrap(); + } + + #[gpui::test] fn pane_geometry_uses_one_animation_time_per_frame(cx: &mut TestAppContext) { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/ui/src/shell/spaces.rs b/crates/ui/src/shell/spaces.rs index 2aff9cda69..ac3c54fa7a 100644 --- a/crates/ui/src/shell/spaces.rs +++ b/crates/ui/src/shell/spaces.rs @@ -5121,6 +5121,7 @@ impl Shell { // instead of editing text or moving focus. "tab" => { self.add_space_accept_completion(cx); + cx.stop_propagation(); return; } _ => {} From 2a2af80d7482cf011ba607fad4a12b72e3c69dd8 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 02:14:20 +0200 Subject: [PATCH 12/21] Shorten automatic title model label to Cheapest --- crates/ui/src/onboarding.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 10fc916ba0..1d88d8c713 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -1548,11 +1548,7 @@ fn render_model_choices( } else { "onboarding-default-model" }; - let automatic = if titles { - "Automatic · cheapest suitable" - } else { - "Automatic" - }; + let automatic = if titles { "Cheapest" } else { "Automatic" }; let choices = std::iter::once((None, automatic.to_string())).chain( models .iter() From 585dea2122dc43cae6550ab2a372ff39a0fa2b58 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 14:43:31 +0200 Subject: [PATCH 13/21] Fix onboarding defaults after model options removal --- crates/ui/src/pickers.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/ui/src/pickers.rs b/crates/ui/src/pickers.rs index 1e068fffda..bda9b6549f 100644 --- a/crates/ui/src/pickers.rs +++ b/crates/ui/src/pickers.rs @@ -1541,9 +1541,6 @@ impl Pickers { ) { let harness_locked = self.harness_locked(cx); if !harness_locked { - if self.config.harness != Some(harness) { - self.config.model_options.clear(); - } self.config.harness = Some(harness); self.config.model = model.clone(); self.config.reasoning = reasoning; From c2166bf95cb7fcdc42ceab2d0c18bd08664867f8 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 14:50:15 +0200 Subject: [PATCH 14/21] Add frame-aware onboarding keyboard regression tests --- crates/ui/src/shell.rs | 279 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 278 insertions(+), 1 deletion(-) diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index f3d2bc64f4..bab47e8f90 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -13422,6 +13422,284 @@ mod exit_regressions { .unwrap(); } + fn onboarding_test_window( + cx: &mut TestAppContext, + dir: &std::path::Path, + fixture: OnboardingFixture, + ) -> gpui::WindowHandle { + cx.update(|cx| { + settings::init(settings::UiSettings::default(), dir, cx); + crate::history::init( + Default::default(), + Default::default(), + Default::default(), + Default::default(), + cx, + ); + gpui_base::init(cx); + cx.set_global(Theme::default()); + crate::app_menus::init(cx); + }); + let handle = cx.add_window(|window, cx| { + let state = cx.new(|_| AppState::new()); + let mut shell = Shell::new( + state, + EngineBootConfig { + data_dir: dir.into(), + ipc_port: 0, + edge_url: "http://127.0.0.1:1".into(), + edge_token: None, + org_id: None, + workos_client_id: None, + default_harness: zeron_proto::HarnessId::Mock, + }, + cx, + ); + shell.debug_gate = Some(GatePhase::Loading); + shell.splash = SplashPhase::Gone; + shell.onboarding = OnboardingUi::new( + crate::onboarding::OnboardingState::fresh(), + Default::default(), + Some(fixture), + cx, + ); + shell.onboarding.state.step = shell.onboarding.step(); + shell.onboarding.fixture = None; + window.focus(&shell.shortcut_focus, cx); + shell + }); + handle + .update(cx, |shell, window, cx| { + shell.debug_gate = Some(GatePhase::Ready); + // The gate has focus before the first onboarding frame mounts. + window.focus(&shell.onboarding.focus, cx); + cx.notify(); + }) + .unwrap(); + handle + } + + fn onboarding_frame(cx: &mut TestAppContext, window: gpui::WindowHandle) { + cx.update_window(window.into(), |_, window, cx| window.draw(cx).clear()) + .unwrap(); + cx.run_until_parked(); + } + + fn onboarding_press(cx: &mut TestAppContext, handle: gpui::WindowHandle, keys: &str) { + for key in keys.split(' ') { + let keystroke = gpui::Keystroke::parse(key).unwrap(); + cx.update_window(handle.into(), |_, window, cx| { + window.dispatch_event( + gpui::PlatformInput::KeyDown(gpui::KeyDownEvent { + keystroke: keystroke.clone(), + is_held: false, + prefer_character_input: false, + }), + cx, + ); + // GPUI synthesizes button clicks on release, not key-down. + window.dispatch_event( + gpui::PlatformInput::KeyUp(gpui::KeyUpEvent { keystroke }), + cx, + ); + }) + .unwrap(); + onboarding_frame(cx, handle); + } + } + + #[gpui::test] + fn onboarding_boot_focus_and_immediate_arrow_space(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().unwrap(); + let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Welcome); + window + .update(cx, |shell, window, _| { + assert!(shell.onboarding.focus.is_focused(window)) + }) + .unwrap(); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(shell.onboarding.control(0).is_focused(window)) + }) + .unwrap(); + onboarding_press(cx, window, "right space"); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(shell.onboarding.control(1).is_focused(window)); + assert_eq!( + shell.onboarding.state.workspace_mode, + Some(WorkspaceMode::Synced) + ); + }) + .unwrap(); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(shell.onboarding.control(1).is_focused(window)) + }) + .unwrap(); + } + + #[gpui::test] + fn onboarding_modal_mount_tab_trap_and_exact_cancel_focus(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().unwrap(); + let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Appearance); + for (step, control) in [ + (OnboardingStep::Appearance, 1), + (OnboardingStep::Appearance, 25), + (OnboardingStep::Project, 2), + ] { + window + .update(cx, |shell, _, cx| { + shell.onboarding.state.step = step; + shell.settings.appearance = crate::appearance::AppearanceMode::Dark; + cx.notify(); + }) + .unwrap(); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, cx| { + window.focus(shell.onboarding.control(control), cx) + }) + .unwrap(); + onboarding_press(cx, window, "escape"); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(shell.onboarding.close_confirm); + assert!(shell.onboarding.control(26).is_focused(window)); + }) + .unwrap(); + for (key, target) in [ + ("tab", 27), + ("tab", 26), + ("shift-tab", 27), + ("shift-tab", 26), + ] { + onboarding_press(cx, window, key); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(shell.onboarding.control(target).is_focused(window)) + }) + .unwrap(); + } + onboarding_press(cx, window, "space"); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(!shell.onboarding.close_confirm); + assert_eq!(shell.onboarding.step(), step); + assert!(shell.onboarding.control(control).is_focused(window)); + }) + .unwrap(); + onboarding_press(cx, window, "escape"); + onboarding_frame(cx, window); + onboarding_press(cx, window, "escape"); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, _| { + assert!(!shell.onboarding.close_confirm); + assert!(shell.onboarding.control(control).is_focused(window)); + }) + .unwrap(); + } + } + + #[gpui::test] + fn onboarding_modal_consumes_activation_with_stale_background_focus(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().unwrap(); + let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Appearance); + for (step, control) in [ + (OnboardingStep::Appearance, 0), + (OnboardingStep::Appearance, 25), + (OnboardingStep::Project, 2), + ] { + window + .update(cx, |shell, _, cx| { + shell.onboarding.state.step = step; + shell.settings.appearance = crate::appearance::AppearanceMode::Dark; + cx.notify(); + }) + .unwrap(); + onboarding_frame(cx, window); + window + .update(cx, |shell, window, cx| { + shell.onboarding_request_close(window, cx) + }) + .unwrap(); + onboarding_frame(cx, window); + for key in ["space", "enter"] { + window + .update(cx, |shell, window, cx| { + window.focus(shell.onboarding.control(control), cx); + let event = gpui::KeyDownEvent { + keystroke: gpui::Keystroke::parse(key).unwrap(), + is_held: false, + prefer_character_input: false, + }; + assert!( + shell.onboarding_key_down(&event, window, cx), + "modal must consume {key} on {control}" + ); + }) + .unwrap(); + onboarding_press(cx, window, key); + onboarding_frame(cx, window); + window + .update(cx, |shell, _, _| { + assert!(shell.onboarding.close_confirm); + assert_eq!(shell.onboarding.step(), step); + assert_eq!( + shell.onboarding.state.disposition, + OnboardingDisposition::InProgress + ); + assert!(shell.onboarding.error.is_none()); + assert_eq!( + shell.settings.appearance, + crate::appearance::AppearanceMode::Dark + ); + }) + .unwrap(); + } + window + .update(cx, |shell, window, cx| { + shell.onboarding_cancel_close(window, cx) + }) + .unwrap(); + } + } + + #[gpui::test] + fn onboarding_modal_continue_later_persists(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().unwrap(); + let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Appearance); + onboarding_frame(cx, window); + onboarding_press(cx, window, "escape"); + onboarding_frame(cx, window); + onboarding_press(cx, window, "tab"); + onboarding_frame(cx, window); + onboarding_press(cx, window, "space"); + onboarding_frame(cx, window); + window + .update(cx, |shell, _, _| { + assert!(!shell.onboarding.close_confirm); + assert_eq!( + shell.onboarding.state.disposition, + OnboardingDisposition::Deferred + ); + assert_eq!( + settings::UiSettings::load(dir.path()) + .onboarding + .disposition, + OnboardingDisposition::Deferred + ); + }) + .unwrap(); + } + #[gpui::test] fn onboarding_keyboard_yields_to_project_palette_and_reaches_full_model_catalog( cx: &mut TestAppContext, @@ -13527,7 +13805,6 @@ mod exit_regressions { .unwrap(); } - #[gpui::test] fn pane_geometry_uses_one_animation_time_per_frame(cx: &mut TestAppContext) { let dir = tempfile::tempdir().unwrap(); From bd45701fb593776b20ee6585fc3fbac5bbf11525 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 15:02:38 +0200 Subject: [PATCH 15/21] Give onboarding dialog keyboard ownership and initialize mounted focus --- crates/ui/src/onboarding.rs | 3 +- crates/ui/src/shell.rs | 142 +++++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 52 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 1d88d8c713..0836b1648c 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -2088,7 +2088,8 @@ fn continue_control(step: OnboardingStep) -> usize { OnboardingStep::Workspace | OnboardingStep::Project | OnboardingStep::FirstSession => 2, OnboardingStep::Appearance | OnboardingStep::Titles => 25, OnboardingStep::Harnesses => 10, - OnboardingStep::Defaults => 26, + // Keep 26/27 exclusive to the mounted leave dialog. + OnboardingStep::Defaults => 31, } } diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index bab47e8f90..2803e870dc 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -8634,6 +8634,13 @@ impl Shell { } if event.keystroke.key == "escape" && self.capture_escape_surface(window, cx) { cx.stop_propagation(); + } else if self.onboarding.close_confirm + && crate::onboarding::activates(event) + && self.onboarding_key_down(event, window, cx) + { + // Consume before the focused div can arm a synthesized click on + // key-up, including when focus still belongs to the journey. + cx.stop_propagation(); } } @@ -8644,9 +8651,10 @@ impl Shell { cx: &mut Context, ) -> bool { if !self.onboarding.active() - || self.overlay_owns_keyboard(cx) - || self.onboarding.agent_settings_open - || self.sync_flow.has_visible_overlay() + || (!self.onboarding.close_confirm + && (self.overlay_owns_keyboard(cx) + || self.onboarding.agent_settings_open + || self.sync_flow.has_visible_overlay())) { return false; } @@ -8723,6 +8731,18 @@ impl Shell { .controls .iter() .position(|handle| handle.is_focused(window)); + if self.onboarding.close_confirm { + if crate::onboarding::activates(event) { + match focused { + Some(26) => self.onboarding_cancel_close(window, cx), + Some(27) => self.onboarding_defer(cx), + _ => {} + } + } + // The modal owns keyboard input even if focus was lost or a + // background control retained it while the dialog was mounting. + return true; + } let Some(focused) = focused else { return false; }; @@ -8856,14 +8876,6 @@ impl Shell { if !crate::onboarding::activates(event) { return false; } - if self.onboarding.close_confirm { - match focused { - 26 => self.onboarding_cancel_close(window, cx), - 27 => self.onboarding_defer(cx), - _ => return false, - } - return true; - } match focused { 28 if self.onboarding.step() != OnboardingStep::Workspace => self.onboarding_back(cx), 29 => self.onboarding_skip(cx), @@ -8950,7 +8962,7 @@ impl Shell { } } OnboardingStep::Defaults => { - if focused == 26 { + if focused == 31 { self.onboarding_continue(cx); } else if focused == 16 { self.onboarding_pick_reasoning(None, cx); @@ -11818,18 +11830,34 @@ impl Render for Shell { && self.onboarding.active() && self.onboarding.step() != OnboardingStep::FirstSession && !self.onboarding.focus_initialized; - if onboarding_needs_initial_focus { - self.onboarding.focus_initialized = true; - } - let preferred_focus = - if self.onboarding.active() && self.onboarding.step() != OnboardingStep::FirstSession { - self.onboarding.control(0).clone() + cx.defer_in(window, move |this, window, cx| { + if this.onboarding.active() && this.onboarding.close_confirm { + // Reconcile against the completed frame. Keep Tab's second + // action focused, but never restore a control behind the scrim. + let cancel = this.onboarding.control(26); + let confirm = this.onboarding.control(27); + if shortcut_focus.contains(cancel, window) { + if !cancel.is_focused(window) && !confirm.is_focused(window) { + window.focus(cancel, cx); + } + this.onboarding.focus_initialized = true; + } + return; + } + let preferred_focus = if this.onboarding.active() + && this.onboarding.step() != OnboardingStep::FirstSession + { + this.onboarding.control(0).clone() } else { - self.composer.focus_handle(cx) + this.composer.focus_handle(cx) }; - window.defer(cx, move |window, cx| { - if onboarding_needs_initial_focus && window.focused(cx).is_none() { - window.focus(&preferred_focus, cx); + if onboarding_needs_initial_focus && !this.onboarding.focus_initialized { + // Root/gate focus does not initialize the onboarding scope. + // Retry on later frames if its first control is not mounted yet. + if shortcut_focus.contains(&preferred_focus, window) { + window.focus(&preferred_focus, cx); + this.onboarding.focus_initialized = true; + } } else { restore_mounted_focus(&shortcut_focus, &preferred_focus, &unfocused, window, cx); } @@ -13472,7 +13500,10 @@ mod exit_regressions { .update(cx, |shell, window, cx| { shell.debug_gate = Some(GatePhase::Ready); // The gate has focus before the first onboarding frame mounts. + assert!(!shell.onboarding.focus_initialized); window.focus(&shell.onboarding.focus, cx); + assert!(shell.onboarding.focus.is_focused(window)); + assert!(window.focused(cx).is_some()); cx.notify(); }) .unwrap(); @@ -13485,23 +13516,27 @@ mod exit_regressions { cx.run_until_parked(); } + fn onboarding_dispatch_key(window: &mut Window, cx: &mut App, key: &str) { + let keystroke = gpui::Keystroke::parse(key).unwrap(); + window.dispatch_event( + gpui::PlatformInput::KeyDown(gpui::KeyDownEvent { + keystroke: keystroke.clone(), + is_held: false, + prefer_character_input: false, + }), + cx, + ); + // GPUI synthesizes button clicks on release, not key-down. + window.dispatch_event( + gpui::PlatformInput::KeyUp(gpui::KeyUpEvent { keystroke }), + cx, + ); + } + fn onboarding_press(cx: &mut TestAppContext, handle: gpui::WindowHandle, keys: &str) { for key in keys.split(' ') { - let keystroke = gpui::Keystroke::parse(key).unwrap(); cx.update_window(handle.into(), |_, window, cx| { - window.dispatch_event( - gpui::PlatformInput::KeyDown(gpui::KeyDownEvent { - keystroke: keystroke.clone(), - is_held: false, - prefer_character_input: false, - }), - cx, - ); - // GPUI synthesizes button clicks on release, not key-down. - window.dispatch_event( - gpui::PlatformInput::KeyUp(gpui::KeyUpEvent { keystroke }), - cx, - ); + onboarding_dispatch_key(window, cx, key) }) .unwrap(); onboarding_frame(cx, handle); @@ -13512,11 +13547,6 @@ mod exit_regressions { fn onboarding_boot_focus_and_immediate_arrow_space(cx: &mut TestAppContext) { let dir = tempfile::tempdir().unwrap(); let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Welcome); - window - .update(cx, |shell, window, _| { - assert!(shell.onboarding.focus.is_focused(window)) - }) - .unwrap(); onboarding_frame(cx, window); window .update(cx, |shell, window, _| { @@ -13549,12 +13579,12 @@ mod exit_regressions { for (step, control) in [ (OnboardingStep::Appearance, 1), (OnboardingStep::Appearance, 25), + (OnboardingStep::Defaults, 31), (OnboardingStep::Project, 2), ] { window .update(cx, |shell, _, cx| { shell.onboarding.state.step = step; - shell.settings.appearance = crate::appearance::AppearanceMode::Dark; cx.notify(); }) .unwrap(); @@ -13613,14 +13643,14 @@ mod exit_regressions { let dir = tempfile::tempdir().unwrap(); let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Appearance); for (step, control) in [ - (OnboardingStep::Appearance, 0), + (OnboardingStep::Appearance, 1), (OnboardingStep::Appearance, 25), + (OnboardingStep::Defaults, 31), (OnboardingStep::Project, 2), ] { window .update(cx, |shell, _, cx| { shell.onboarding.state.step = step; - shell.settings.appearance = crate::appearance::AppearanceMode::Dark; cx.notify(); }) .unwrap(); @@ -13632,9 +13662,17 @@ mod exit_regressions { .unwrap(); onboarding_frame(cx, window); for key in ["space", "enter"] { - window - .update(cx, |shell, window, cx| { + cx.update_window(window.into(), |_, window, cx| { + let shell = window.root::().flatten().unwrap(); + shell.update(cx, |shell, cx| { window.focus(shell.onboarding.control(control), cx); + cx.notify(); + }); + // Render the retained background focus, then dispatch before + // the deferred reconciliation can move it into the dialog. + window.draw(cx).clear(); + shell.update(cx, |shell, cx| { + assert!(shell.onboarding.control(control).is_focused(window)); let event = gpui::KeyDownEvent { keystroke: gpui::Keystroke::parse(key).unwrap(), is_held: false, @@ -13644,13 +13682,15 @@ mod exit_regressions { shell.onboarding_key_down(&event, window, cx), "modal must consume {key} on {control}" ); - }) - .unwrap(); - onboarding_press(cx, window, key); + }); + onboarding_dispatch_key(window, cx, key); + }) + .unwrap(); onboarding_frame(cx, window); window - .update(cx, |shell, _, _| { + .update(cx, |shell, window, _| { assert!(shell.onboarding.close_confirm); + assert!(shell.onboarding.control(26).is_focused(window)); assert_eq!(shell.onboarding.step(), step); assert_eq!( shell.onboarding.state.disposition, @@ -13659,7 +13699,7 @@ mod exit_regressions { assert!(shell.onboarding.error.is_none()); assert_eq!( shell.settings.appearance, - crate::appearance::AppearanceMode::Dark + crate::appearance::AppearanceMode::System ); }) .unwrap(); From 83fca612838084d7b80248335978c8321aeee2be Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 18:36:15 +0200 Subject: [PATCH 16/21] Place Show onboarding before Settings in user menu --- crates/ui/src/shell.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index 2803e870dc..e97dd8208f 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -8059,7 +8059,8 @@ impl Shell { // (exactly as wide as the trigger row — sidebar minus its p-2 // gutters), `flex-col gap-0.5`, then: one small muted email line // (`px-2 pb-1 pt-1.5 text-[11px] text-muted-foreground/70`), - // the action selected by the runtime scope, then "Settings". + // the action selected by the runtime scope, "Show onboarding", + // then "Settings". let menu = popover::popover_card(theme) .w(px(self.settings.sidebar_width - 2.0 * Theme::SPACE_SM)) .on_mouse_down_out(cx.listener(|this, _, _, cx| { @@ -8131,6 +8132,17 @@ impl Shell { }; menu.child(row).child(popover::menu_separator()) }) + .child( + popover::menu_row(theme, false, "user-menu-onboarding") + .id("user-menu-onboarding") + .on_click(cx.listener(|this, _, _, cx| this.restart_onboarding(cx))) + .child( + icon(icons::CHECKLIST) + .size(px(16.0)) + .text_color(theme.text_muted), + ) + .child(SharedString::from("Show onboarding")), + ) .child( popover::menu_row(theme, false, "user-menu-settings") .id("user-menu-settings") @@ -8144,17 +8156,6 @@ impl Shell { ) .child(SharedString::from("Settings")), ) - .child( - popover::menu_row(theme, false, "user-menu-onboarding") - .id("user-menu-onboarding") - .on_click(cx.listener(|this, _, _, cx| this.restart_onboarding(cx))) - .child( - icon(icons::CHECKLIST) - .size(px(16.0)) - .text_color(theme.text_muted), - ) - .child(SharedString::from("Show onboarding")), - ) .into_any_element(); trigger = trigger.child(popover::anchored_menu_above( "user-menu-popover", From 528b2e62a4d66fdec10ba2ee6ce7908a791d5edc Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sat, 19 Sep 2026 16:29:38 +0200 Subject: [PATCH 17/21] Handle Antigravity in onboarding harness labels --- crates/ui/src/onboarding.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 0836b1648c..986a8b9409 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -473,6 +473,7 @@ pub fn harness_name(harness: HarnessId) -> &'static str { HarnessId::Hermes => "Hermes", HarnessId::Pi => "Pi", HarnessId::Opencode => "OpenCode", + HarnessId::Antigravity => "Antigravity", HarnessId::Mock => "Mock", } } From 5fe716b82f15fcf70212dbcaf2920130304dbefe Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 13 Sep 2026 11:56:45 +0200 Subject: [PATCH 18/21] Polish onboarding agent actions and keep setup local --- crates/ui/src/onboarding.rs | 193 +++++++++-------------------- crates/ui/src/settings/accounts.rs | 41 ++++++ crates/ui/src/shell.rs | 78 +++++------- 3 files changed, 130 insertions(+), 182 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index 986a8b9409..b25168df6c 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -731,7 +731,7 @@ fn harness_status( return ("Not installed", false); } if !descriptor_enabled(descriptor) { - return ("Installed but disabled", false); + return ("Installed", false); } if !matches!( descriptor.id, @@ -1232,73 +1232,9 @@ fn render_appearance_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context, + _state: &Entity, cx: &mut Context, ) -> AnyElement { - let devices = { - let state = state.read(cx); - let effective = state.effective_device_id(); - let now = chrono::Utc::now(); - state - .devices - .iter() - .take(5) - .map(|device| { - ( - device.id.clone(), - device.name.clone(), - state.device_online(&device.id, now), - effective.as_deref() == Some(device.id.as_str()), - ) - }) - .collect::>() - }; - let multiple_devices = devices.len() > 1; - let device_switcher: AnyElement = if multiple_devices { - div() - .mt(px(18.0)) - .flex() - .flex_col() - .gap(px(8.0)) - .child( - div() - .text_size(crate::typography::ui_rems(11.5)) - .font_weight(gpui::FontWeight::MEDIUM) - .text_color(theme.text_muted) - .child("Set up agents on"), - ) - .child( - div() - .id("onboarding-device-choices") - .flex() - .flex_wrap() - .gap(px(8.0)) - .role(gpui::Role::RadioGroup) - .aria_label("Device") - .children(devices.into_iter().enumerate().map( - |(index, (id, name, online, selected))| { - let label: SharedString = if online { - name.into() - } else { - format!("{name} · Offline").into() - }; - chip(theme, label, selected, None) - .id(("onboarding-device", index)) - .flex_1() - .min_w(px(120.0)) - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(selected)) - .track_focus(ui.control(20 + index)) - .on_click(cx.listener(move |shell, _, _, cx| { - shell.onboarding_pick_device(id.clone(), cx) - })) - }, - )), - ) - .into_any_element() - } else { - Empty.into_any_element() - }; let list: AnyElement = match &ui.harnesses { Loadable::Idle | Loadable::Loading => div() .id("onboarding-harness-loading") @@ -1321,14 +1257,6 @@ fn render_harness_step( .line_height(px(18.0)) .text_color(theme.danger_muted) .child(message.clone()) - .child( - quiet_button(theme, "Retry") - .id("onboarding-harness-retry") - .role(gpui::Role::Button) - .track_focus(ui.control(11)) - .mt(px(8.0)) - .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_load_harnesses(cx))), - ) .into_any_element(), Loadable::Ready(harnesses) => div() .flex() @@ -1436,11 +1364,7 @@ fn render_harness_step( .into_any_element(), }; let harness_list = div() - .mt(px(if multiple_devices { - Theme::SPACE_MD - } else { - STEP_GROUP_GAP - })) + .mt(px(Theme::SPACE_SM)) .flex_1() .min_h_0() .max_h(px(HARNESS_LIST_MAX_HEIGHT)) @@ -1459,7 +1383,39 @@ fn render_harness_step( "onboarding-heading-harnesses", "Coding agents", )) - .child(device_switcher) + .child( + div() + .mt(px(STEP_GROUP_GAP)) + .flex() + .items_center() + .justify_between() + .child( + quiet_button(theme, "Manage sign-ins") + .id("onboarding-manage-agent-signins") + .role(gpui::Role::Button) + .aria_label("Manage agent sign-ins on this device") + .track_focus(ui.control(12)) + .on_click( + cx.listener(|shell, _, _, cx| shell.onboarding_open_agent_settings(cx)), + ), + ) + .child( + widgets::ghost_action(theme) + .id("onboarding-harness-refresh") + .size(px(36.0)) + .justify_center() + .hover(|style| widgets::ghost_hover(theme, style)) + .focus_visible(|style| style.border_2().border_color(theme.text)) + .role(gpui::Role::Button) + .aria_label("Refresh coding agents") + .track_focus(ui.control(11)) + .child(crate::icons::icon(crate::icons::REFRESH).size(px(16.0))) + .on_click(cx.listener(|shell, _, _, cx| { + shell.onboarding_load_harnesses(cx); + shell.onboarding_load_accounts(cx); + })), + ), + ) .child(harness_list) .when_some(ui.error.clone(), |column, error| { column.child( @@ -2138,7 +2094,7 @@ fn render_footer_actions( if finishes { "Finish setup" } else { "Continue" }, compact, ) - .w_full() + .flex_1() .role(gpui::Role::Button) .when(!enabled, |button| { button @@ -2162,51 +2118,25 @@ fn render_footer_actions( .flex() .flex_col() .gap(px(Theme::SPACE_SM)) - .when(step == OnboardingStep::Harnesses, |column| { - column.child( - div() - .w_full() - .flex() - .items_center() - .gap(px(Theme::SPACE_SM)) - .when(matches!(ui.harnesses, Loadable::Ready(_)), |row| { - row.child( - quiet_button(theme, "Retry agent detection") - .id("onboarding-harness-retry-ready") - .h(px(Theme::SPACE_SM * 5.0)) - .flex_1() - .role(gpui::Role::Button) - .track_focus(ui.control(11)) - .on_click(cx.listener(|shell, _, _, cx| { - shell.onboarding_load_harnesses(cx); - shell.onboarding_load_accounts(cx); - })), - ) - }) - .child( - quiet_button(theme, "Manage agent sign-ins") - .id("onboarding-manage-agent-signins") - .h(px(Theme::SPACE_SM * 5.0)) - .flex_1() - .role(gpui::Role::Button) - .track_focus(ui.control(12)) - .on_click(cx.listener(|shell, _, _, cx| { - shell.onboarding_open_agent_settings(cx) - })), - ), - ) - }) - .child(continue_button); + .child( + div() + .w_full() + .flex() + .items_center() + .gap(px(Theme::SPACE_SM)) + .child(render_previous(ui, step, theme, cx)) + .child(continue_button), + ); actions.into_any_element() } -fn render_global_navigation( +fn render_previous( ui: &OnboardingUi, step: OnboardingStep, theme: &Theme, cx: &mut Context, ) -> AnyElement { - let previous: AnyElement = if step == OnboardingStep::Workspace { + if step == OnboardingStep::Workspace { Empty.into_any_element() } else { footer_secondary_button( @@ -2229,8 +2159,17 @@ fn render_global_navigation( shell.onboarding_focus_control(0, window, cx); })) .into_any_element() - }; + } +} + +pub(super) fn render_skip(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) -> AnyElement { let skip = footer_secondary_button(theme, "onboarding-skip", "Skip", None) + .h(px(28.0)) + .px(px(Theme::SPACE_SM)) + .occlude() + .on_mouse_down(gpui::MouseButton::Left, |_, _, cx| { + cx.stop_propagation(); + }) .role(gpui::Role::Button) .aria_label("Skip setup") .cursor_pointer() @@ -2238,13 +2177,7 @@ fn render_global_navigation( .track_focus(ui.control(29)) .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_skip(cx))); - div() - .w_full() - .flex() - .items_center() - .child(previous) - .child(skip.ml_auto()) - .into_any_element() + skip.into_any_element() } pub fn render( @@ -2346,14 +2279,6 @@ pub fn render( .flex() .items_center() .justify_center() - .child( - div() - .absolute() - .top(px(Theme::TITLEBAR_HEIGHT + outer_y)) - .left(px(outer_x)) - .right(px(outer_x)) - .child(render_global_navigation(ui, step, &theme, cx)), - ) .child(journey) .child( div() diff --git a/crates/ui/src/settings/accounts.rs b/crates/ui/src/settings/accounts.rs index 27078d3ffd..19973eb5cb 100644 --- a/crates/ui/src/settings/accounts.rs +++ b/crates/ui/src/settings/accounts.rs @@ -184,6 +184,7 @@ pub struct AccountsPage { /// Retargeted by the page-header device switcher (zeron parity: the /// accounts RPCs are relay-forwardable, CLI logins are per-device). target_device: Option, + local_only: bool, device_menu: popover::Popup<()>, snapshot: Loadable, /// Account id with an in-flight Switch/Forget. @@ -211,6 +212,7 @@ impl AccountsPage { state, scroll: widgets::PageScroll::default(), target_device: None, + local_only: false, device_menu: popover::Popup::default(), snapshot: Loadable::Idle, busy_account: None, @@ -243,6 +245,7 @@ impl AccountsPage { } pub(crate) fn set_target_device(&mut self, target: Option, cx: &mut Context) { + let target = if self.local_only { None } else { target }; self.close_device_menu(cx); if self.target_device == target { cx.notify(); @@ -258,6 +261,15 @@ impl AccountsPage { self.load(force_usage_for(LoadTrigger::Mount), cx); } + /// Onboarding exposes only this device; regular Settings retains switching. + pub(crate) fn set_local_only(&mut self, local_only: bool, cx: &mut Context) { + self.local_only = local_only; + if local_only { + self.set_target_device(None, cx); + } + cx.notify(); + } + /// Params with the `targetDeviceId` passthrough merged in. fn params(&self, value: serde_json::Value) -> serde_json::Value { let mut value = value; @@ -277,6 +289,12 @@ impl AccountsPage { /// trigger — platform glyph · name · presence dot · sort glyph — opening a /// dropdown of every registered device. Selecting one retargets the page. fn render_device_switcher(&mut self, theme: &Theme, cx: &mut Context) -> AnyElement { + if self.local_only { + return div() + .text_color(theme.text_muted) + .child("This device") + .into_any_element(); + } use crate::icons::{self, icon}; let (mut devices, local_id) = { let s = self.state.read(cx); @@ -1518,6 +1536,29 @@ mod tests { use super::*; use chrono::TimeDelta; + #[gpui::test] + fn onboarding_sign_ins_cannot_target_another_device(cx: &mut gpui::TestAppContext) { + cx.update(|cx| { + gpui_base::init(cx); + cx.set_global(Theme::default()); + let state = cx.new(|_| AppState::new()); + let page = cx.new(|cx| AccountsPage::new(state, cx)); + page.update(cx, |page, cx| { + page.set_target_device(Some("remote".into()), cx); + page.set_local_only(true, cx); + assert_eq!(page.target_device, None); + page.set_target_device(Some("other-remote".into()), cx); + assert_eq!(page.params(serde_json::json!({})), serde_json::json!({})); + page.set_local_only(false, cx); + page.set_target_device(Some("remote".into()), cx); + assert_eq!( + page.params(serde_json::json!({}))["targetDeviceId"], + "remote" + ); + }); + }); + } + #[test] fn first_load_of_a_visit_forces_the_usage_probe() { // The engine only probes usage when forced (M5c); without forcing on diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index e97dd8208f..8c84665c44 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -3789,18 +3789,9 @@ impl Shell { settings::replace(self.settings.clone(), SavePolicy::Immediate, cx); } - fn onboarding_target_params( - &self, - mut params: serde_json::Value, - cx: &App, - ) -> serde_json::Value { - let state = self.state.read(cx); - let target = state.effective_device_id(); - if target.as_deref() != state.local_device_id.as_deref() - && let (Some(target), Some(object)) = (target, params.as_object_mut()) - { - object.insert("targetDeviceId".into(), serde_json::Value::String(target)); - } + fn onboarding_target_params(&self, params: serde_json::Value, _cx: &App) -> serde_json::Value { + // Onboarding configures this device, regardless of the selected space. + // Omitting targetDeviceId keeps all setup RPCs on the local engine. params } @@ -4178,39 +4169,16 @@ impl Shell { pub(crate) fn onboarding_open_agent_settings(&mut self, cx: &mut Context) { self.onboarding.agent_settings_open = true; - let target = { - let state = self.state.read(cx); - state - .effective_device_id() - .filter(|target| Some(target.as_str()) != state.local_device_id.as_deref()) - }; if self.accounts_page.is_none() { let state = self.state.clone(); self.accounts_page = Some(cx.new(|cx| AccountsPage::new(state, cx))); } if let Some(page) = &self.accounts_page { - page.update(cx, |page, cx| page.set_target_device(target, cx)); + page.update(cx, |page, cx| page.set_local_only(true, cx)); } self.open_settings(SettingsSection::Agents, cx); } - pub(crate) fn onboarding_pick_device(&mut self, device_id: String, cx: &mut Context) { - self.state - .update(cx, |state, cx| state.select_device(device_id, cx)); - self.onboarding.harnesses = Loadable::Idle; - self.onboarding.models = Loadable::Idle; - self.onboarding.accounts = Loadable::Idle; - self.onboarding.title_settings = Loadable::Idle; - self.onboarding.title_models = Loadable::Idle; - self.onboarding.selected_harness = None; - self.onboarding.selected_model = None; - self.onboarding.selected_reasoning = None; - self.onboarding_remember_target(cx); - self.onboarding_load_harnesses(cx); - self.onboarding_load_accounts(cx); - cx.notify(); - } - pub(crate) fn onboarding_toggle_harness( &mut self, harness: zeron_proto::HarnessId, @@ -4604,6 +4572,9 @@ impl Shell { self.route = Route::Chat; if self.onboarding.agent_settings_open { self.onboarding.agent_settings_open = false; + if let Some(page) = &self.accounts_page { + page.update(cx, |page, cx| page.set_local_only(false, cx)); + } self.onboarding.accounts = Loadable::Idle; self.onboarding_load_accounts(cx); } @@ -5946,6 +5917,7 @@ impl Shell { .rounded(px(4.0)), ) .child("Zeron"); + let skip = crate::onboarding::render_skip(&self.onboarding, &theme, cx); self.titlebar_drag_region( "onboarding-titlebar-drag", div() @@ -5954,7 +5926,18 @@ impl Shell { .left_0() .right_0() .h(px(Theme::TITLEBAR_HEIGHT)) - .child(identity), + .child(identity) + .child( + div() + .absolute() + .top_0() + .right(px(self.titlebar_right_pad(TITLEBAR_ACTION_EDGE_INSET))) + .h(px(Theme::TITLEBAR_HEIGHT)) + .pt(px(Theme::TITLEBAR_TOP_PAD)) + .flex() + .items_center() + .child(skip), + ), cx, ) .into_any_element() @@ -8929,19 +8912,9 @@ impl Shell { self.onboarding_continue(cx); } else if focused == 11 { self.onboarding_load_harnesses(cx); + self.onboarding_load_accounts(cx); } else if focused == 12 { self.onboarding_open_agent_settings(cx); - } else if (20..25).contains(&focused) { - let device = self - .state - .read(cx) - .devices - .iter() - .take(5) - .nth(focused - 20) - .map(|device| device.id.clone()); - let Some(device) = device else { return false }; - self.onboarding_pick_device(device, cx); } else { let descriptor = self.onboarding.harnesses.ready().and_then(|rows| { rows.iter() @@ -13769,6 +13742,15 @@ mod exit_regressions { }); window .update(cx, |shell, window, cx| { + shell.state.update(cx, |state, _| { + state.local_device_id = Some("local".into()); + state.selected_device = Some("remote".into()); + }); + assert_eq!( + shell.onboarding_target_params(serde_json::json!({"forceUsage": false}), cx), + serde_json::json!({"forceUsage": false}), + "onboarding must not forward to the selected remote device", + ); shell.onboarding = OnboardingUi::new( crate::onboarding::OnboardingState::fresh(), Default::default(), From f20f71b56ddd9ab000a7bc0d854fb1465102c023 Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 20 Sep 2026 13:22:03 +0200 Subject: [PATCH 19/21] Polish compact onboarding layout and window transitions --- crates/ui/src/lib.rs | 48 ++++-- crates/ui/src/onboarding.rs | 120 +++++++-------- crates/ui/src/onboarding/window.rs | 228 +++++++++++++++++++++++++++++ crates/ui/src/shell.rs | 70 +++++++++ 4 files changed, 388 insertions(+), 78 deletions(-) create mode 100644 crates/ui/src/onboarding/window.rs diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 59f8e093b7..207c3ce120 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -325,7 +325,7 @@ fn restored_main_window_bounds(cx: &App) -> (Bounds, Option(window: &mut gpui::Window, cx: &gpui::Context) { - cx.observe_window_bounds(window, |_, window, cx| { - save_main_window_geometry(window, cx); +fn observe_main_window_geometry(window: &mut gpui::Window, cx: &gpui::Context) { + cx.observe_window_bounds(window, |shell, window, cx| { + if !shell.onboarding_window.owns_geometry() { + save_main_window_geometry(window, cx); + } }) .detach(); } @@ -355,12 +357,29 @@ fn open_main_window( cx: &mut App, ) -> gpui::WindowHandle { let (bounds, display_id) = restored_main_window_bounds(cx); + let workspace_size = bounds.size; + let setup = &settings::current(cx).onboarding; + let setup_step = setup.is_active().then_some(setup.step); + let bounds = setup_step.map_or(bounds, |step| { + let compact = onboarding::window::preferred_size(step); + Bounds::new( + gpui::point( + bounds.origin.x + (bounds.size.width - compact.width) / 2.0, + bounds.origin.y + (bounds.size.height - compact.height) / 2.0, + ), + compact, + ) + }); let handle = cx .open_window( WindowOptions { window_bounds: Some(WindowBounds::Windowed(bounds)), display_id, - window_min_size: Some(size(px(900.), px(600.))), + window_min_size: Some(if setup_step.is_some() { + size(px(520.), px(440.)) + } else { + size(px(900.), px(600.)) + }), // `kind` is deliberately left at its default `WindowKind::Normal` // (gpui platform.rs WindowOptions::default), which on macOS maps // to `NSNormalWindowLevel` (gpui_macos window.rs) — same as zed's @@ -417,16 +436,25 @@ fn open_main_window( appearance::observe_window(window, cx).detach(); let shell = cx.new(|cx| { observe_main_window_geometry(window, cx); - shell::Shell::new(state, boot, cx) + let mut shell = shell::Shell::new(state, boot, cx); + if let Some(step) = setup_step { + shell.onboarding_window.start(workspace_size, step); + } + shell }); save_main_window_geometry(window, cx); let weak_shell = shell.downgrade(); window.on_window_should_close(cx, move |window, cx| { - let should_close = weak_shell - .update(cx, |shell, cx| shell.prepare_window_close(cx)) - .unwrap_or(true); + let (should_close, setup_geometry) = weak_shell + .update(cx, |shell, cx| { + let setup_geometry = shell.onboarding_window.owns_geometry(); + (shell.prepare_window_close(cx), setup_geometry) + }) + .unwrap_or((true, false)); if should_close { - save_main_window_geometry(window, cx); + if !setup_geometry { + save_main_window_geometry(window, cx); + } settings::flush(cx); } should_close diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index b25168df6c..ab5680c190 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -4,6 +4,8 @@ use std::sync::Arc; +pub(crate) mod window; + use gpui::{ AnyElement, Context, Empty, Entity, FocusHandle, Image, ImageFormat, IntoElement, KeyDownEvent, Pixels, ScrollHandle, SharedString, Task, div, prelude::*, px, @@ -27,16 +29,16 @@ pub const STEP_COUNT: usize = 6; const CONTENT_MAX_WIDTH: f32 = Theme::SPACE_LG * 30.0; // The journey grows with the window until this cap; dense steps should expose // several useful rows before their overflow affordance becomes necessary. -const CONTENT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 35.0; -const WORKSPACE_MAX_HEIGHT: f32 = Theme::SPACE_LG * 18.0; -const HARNESS_MAX_HEIGHT: f32 = Theme::SPACE_LG * 40.0; -const PROJECT_MAX_HEIGHT: f32 = Theme::SPACE_LG * 18.0; +const CONTENT_MAX_HEIGHT: f32 = 448.0; +const WORKSPACE_MAX_HEIGHT: f32 = 312.0; +const HARNESS_MAX_HEIGHT: f32 = 488.0; +const PROJECT_MAX_HEIGHT: f32 = 312.0; const HARNESS_ROW_HEIGHT: f32 = 54.0; const HARNESS_ROW_GAP: f32 = 8.0; -// Six complete rows plus half of the next one uses the available height while +// Four complete rows plus half of the next one uses the available height while // still making the list's overflow obvious. -const HARNESS_LIST_MAX_HEIGHT: f32 = HARNESS_ROW_HEIGHT * 6.5 + HARNESS_ROW_GAP * 6.0; -const STEP_GROUP_GAP: f32 = Theme::SPACE_LG + Theme::SPACE_SM; +const HARNESS_LIST_MAX_HEIGHT: f32 = HARNESS_ROW_HEIGHT * 4.5 + HARNESS_ROW_GAP * 4.0; +const STEP_GROUP_GAP: f32 = 20.0; const VIEWPORT_INSET: f32 = Theme::SPACE_LG; const ROOMY_VIEWPORT_INSET: f32 = Theme::SPACE_LG * 2.0; const COMPACT_NAVIGATION_WIDTH: f32 = Theme::SPACE_LG * 26.0; @@ -498,8 +500,7 @@ fn heading(theme: &Theme, id: &'static str, text: &'static str) -> gpui::Statefu .role(gpui::Role::Heading) .aria_level(1) .w_full() - .text_center() - .text_size(crate::typography::ui_rems(28.0)) + .text_size(crate::typography::ui_rems(24.0)) .line_height(px(32.0)) .font_weight(gpui::FontWeight::SEMIBOLD) .text_color(theme.text) @@ -662,6 +663,7 @@ fn footer_primary_button( ) -> gpui::Stateful { popover::btn_primary(theme, label) .id(id) + .debug_selector(move || id.into()) .h(px(Theme::SPACE_SM * 5.0)) .min_w_0() .flex() @@ -835,6 +837,7 @@ fn render_workspace_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) let mut choices = div() .id("onboarding-title-harnesses") .flex() - .flex_col() - .gap(px(10.0)) + .flex_wrap() + .gap(px(8.0)) .role(gpui::Role::RadioGroup) .aria_label("Title agent") .child( - choice_card( - theme, - "Automatic", - "Use an available agent, or the first seven words.", - current.harness.is_none(), - None, - ) - .id("onboarding-title-auto") - .role(gpui::Role::RadioButton) - .aria_toggled(toggled(current.harness.is_none())) - .track_focus(ui.control(0)) - .on_click(cx.listener(|shell, _, _, cx| shell.onboarding_pick_title_harness(None, cx))), + chip(theme, "Automatic".into(), current.harness.is_none(), None) + .id("onboarding-title-auto") + .role(gpui::Role::RadioButton) + .aria_toggled(toggled(current.harness.is_none())) + .track_focus(ui.control(0)) + .on_click( + cx.listener(|shell, _, _, cx| shell.onboarding_pick_title_harness(None, cx)), + ), ); for (index, harness) in available.into_iter().enumerate() { choices = choices.child( - choice_card( + chip( theme, - harness_name(harness), - "Generate a title without project tools.", + harness_name(harness).into(), current.harness == Some(harness), Some(harness), ) @@ -1854,7 +1858,8 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) } }; let title_options = div() - .child(choices) + .child(body(theme, "Choose an agent to name your sessions. Automatic uses an available agent, or the first seven words.")) + .child(div().mt(px(16.0)).child(choices)) .child(title_models) .when_some(ui.error.clone(), |column, error| { column.child( @@ -1947,6 +1952,7 @@ fn render_project_step( }; let choices = div() .id("onboarding-project-choices") + .debug_selector(|| "onboarding-project-choices".into()) .flex() .flex_col() .gap(px(12.0)) @@ -2005,6 +2011,7 @@ fn render_project_step( fn render_progress(step: OnboardingStep, theme: &Theme, compact: bool) -> AnyElement { div() .id("onboarding-progress") + .debug_selector(|| "onboarding-progress".into()) .flex() .items_center() .justify_center() @@ -2073,9 +2080,9 @@ fn journey_max_height(step: OnboardingStep) -> f32 { OnboardingStep::Workspace => WORKSPACE_MAX_HEIGHT, OnboardingStep::Harnesses => HARNESS_MAX_HEIGHT, OnboardingStep::Project | OnboardingStep::FirstSession => PROJECT_MAX_HEIGHT, - OnboardingStep::Appearance | OnboardingStep::Defaults | OnboardingStep::Titles => { - CONTENT_MAX_HEIGHT - } + OnboardingStep::Titles => 400.0, + OnboardingStep::Defaults => 488.0, + OnboardingStep::Appearance => CONTENT_MAX_HEIGHT, } } @@ -2191,26 +2198,7 @@ pub fn render( let step = ui.step(); let viewport_width = f32::from(viewport.width); let viewport_height = f32::from(viewport.height); - let journey_max_height = if step == OnboardingStep::Titles { - let rows = ui.harnesses.ready().map_or(0, |rows| { - rows.iter() - .filter(|h| title_harness_is_available(h)) - .count() - }) + 1; - let has_models = ui - .title_settings - .ready() - .is_some_and(|s| s.harness.is_some()); - (32.0 - + STEP_GROUP_GAP - + rows as f32 * 86.0 - + if has_models { 196.0 } else { 0.0 } - + Theme::SPACE_MD - + 40.0) - .min(journey_max_height(step)) - } else { - journey_max_height(step) - }; + let journey_max_height = journey_max_height(step); let compact_navigation = viewport_width < COMPACT_NAVIGATION_WIDTH; let roomy_x = viewport_width >= CONTENT_MAX_WIDTH + ROOMY_VIEWPORT_INSET * 2.0; let roomy_y = @@ -2225,7 +2213,6 @@ pub fn render( } else { VIEWPORT_INSET }; - let progress_reserve = Theme::SPACE_LG + Theme::SPACE_SM; let decision = match step { OnboardingStep::Workspace => render_workspace_step(ui, &theme, cx), OnboardingStep::Appearance => render_appearance_step(ui, &theme, cx), @@ -2267,27 +2254,24 @@ pub fn render( compact_navigation, cx, )), - ); + ) + .child(div().mt(px(20.0)).flex_none().child(render_progress( + step, + &theme, + compact_navigation, + ))); let panel = div() .absolute() .inset_0() .pt(px(Theme::TITLEBAR_HEIGHT + outer_y)) .px(px(outer_x)) - .pb(px(outer_y + progress_reserve)) + .pb(px(outer_y)) .min_w_0() .min_h_0() .flex() .items_center() .justify_center() - .child(journey) - .child( - div() - .absolute() - .left_0() - .right_0() - .bottom(px(outer_y)) - .child(render_progress(step, &theme, compact_navigation)), - ); + .child(journey); let close_confirm: AnyElement = if ui.close_confirm { div() .absolute() @@ -2392,11 +2376,11 @@ mod tests { #[test] fn simple_steps_do_not_inherit_the_dense_journey_height() { - assert_eq!(journey_max_height(OnboardingStep::Workspace), 288.0); - assert_eq!(journey_max_height(OnboardingStep::Project), 288.0); - assert_eq!(journey_max_height(OnboardingStep::Harnesses), 640.0); - assert_eq!(journey_max_height(OnboardingStep::Appearance), 560.0); - assert_eq!(HARNESS_LIST_MAX_HEIGHT, 399.0); + assert_eq!(journey_max_height(OnboardingStep::Workspace), 312.0); + assert_eq!(journey_max_height(OnboardingStep::Project), 312.0); + assert_eq!(journey_max_height(OnboardingStep::Harnesses), 488.0); + assert_eq!(journey_max_height(OnboardingStep::Appearance), 448.0); + assert_eq!(HARNESS_LIST_MAX_HEIGHT, 275.0); } #[test] diff --git a/crates/ui/src/onboarding/window.rs b/crates/ui/src/onboarding/window.rs new file mode 100644 index 0000000000..bc7c01f220 --- /dev/null +++ b/crates/ui/src/onboarding/window.rs @@ -0,0 +1,228 @@ +//! Temporary setup geometry. Never persist intermediate animation frames as +//! the user's workspace geometry. +use gpui::{App, Pixels, Size, Window, px, size}; +use std::time::Instant; + +use super::OnboardingStep; + +pub(crate) fn preferred_size(step: OnboardingStep) -> Size { + size( + px(560.0), + px(match step { + OnboardingStep::Workspace | OnboardingStep::Project | OnboardingStep::FirstSession => { + 440.0 + } + OnboardingStep::Appearance => 560.0, + OnboardingStep::Harnesses | OnboardingStep::Defaults => 620.0, + OnboardingStep::Titles => 500.0, + }), + ) +} + +#[derive(Default)] +pub(crate) struct WindowSizing { + restore: Option>, + target: Option>, + transition: Option<(Size, Instant)>, + step: Option, +} + +impl WindowSizing { + pub(crate) fn start(&mut self, restore: Size, step: OnboardingStep) { + self.restore = Some(restore); + self.target = Some(preferred_size(step)); + self.step = Some(step); + } + + pub(crate) fn owns_geometry(&self) -> bool { + self.restore.is_some() + } + + pub(crate) fn update( + &mut self, + step: Option, + window: &mut Window, + cx: &App, + ) -> bool { + // Do not fight the OS fullscreen animation or alter fullscreen bounds. + if window.is_fullscreen() { + return false; + } + let current = window.viewport_size(); + if self.step != step { + if let Some(step) = step { + self.restore.get_or_insert(current); + self.target = Some(preferred_size(step)); + } else { + self.target = self.restore; + } + // Retarget from the actual presented size, including an interrupted + // transition or a manual resize. No jump to an obsolete endpoint. + self.transition = self.target.map(|_| (current, Instant::now())); + self.step = step; + } + let Some(target) = self.target else { + return false; + }; + let Some((from, started)) = self.transition else { + return false; + }; + let target = window.display(cx).map_or(target, |display| { + let visible = display.visible_bounds().size; + size( + target.width.min(visible.width), + target.height.min(visible.height), + ) + }); + let duration = crate::motion::RESIZE + .total() + .mul_f32(crate::motion::speed_scale()); + let progress = if cx.reduce_motion() { + 1.0 + } else { + (started.elapsed().as_secs_f32() / duration.as_secs_f32()).min(1.0) + }; + let eased = crate::motion::RESIZE.progress(progress); + let next = size( + px(crate::motion::lerp( + from.width.into(), + target.width.into(), + eased, + )), + px(crate::motion::lerp( + from.height.into(), + target.height.into(), + eased, + )), + ); + resize(window, next, step.is_some() || progress < 1.0, cx); + if progress < 1.0 { + true + } else { + self.transition = None; + if step.is_none() { + self.restore = None; + self.target = None; + } + false + } + } +} + +fn resize(window: &mut Window, next: Size, compact: bool, cx: &App) { + // Test windows deliberately panic when asked for a native handle. + if cx + .background_executor() + .scheduler_executor() + .scheduler() + .as_test() + .is_some() + { + window.resize(next); + return; + } + #[cfg(target_os = "macos")] + { + use objc2_app_kit::NSView; + use objc2_foundation::NSSize; + use raw_window_handle::{HasWindowHandle, RawWindowHandle}; + if let Ok(handle) = window.window_handle() + && let RawWindowHandle::AppKit(handle) = handle.as_raw() + { + // GPUI owns this NSView and calls render on the main thread. Keep + // the native frame centered while allowing the setup's smaller min. + let view = unsafe { &*handle.ns_view.as_ptr().cast::() }; + if let Some(native) = view.window() { + // AppKit sends resize notifications synchronously. Follow + // GPUI's native resize path and run after the current render + // releases its window borrow. + cx.foreground_executor() + .spawn(async move { + native.setContentMinSize(if compact { + NSSize::new(520.0, 440.0) + } else { + NSSize::new(900.0, 600.0) + }); + let old = native.frame(); + let mut frame = + native.frameRectForContentRect(objc2_foundation::NSRect::new( + old.origin, + NSSize::new( + f32::from(next.width) as f64, + f32::from(next.height) as f64, + ), + )); + frame.origin.x = old.origin.x + (old.size.width - frame.size.width) / 2.0; + frame.origin.y = old.origin.y + (old.size.height - frame.size.height) / 2.0; + if let Some(screen) = native.screen() { + let visible = screen.visibleFrame(); + frame.origin.x = frame.origin.x.clamp( + visible.origin.x, + (visible.origin.x + visible.size.width - frame.size.width) + .max(visible.origin.x), + ); + frame.origin.y = frame.origin.y.clamp( + visible.origin.y, + (visible.origin.y + visible.size.height - frame.size.height) + .max(visible.origin.y), + ); + } + native.setFrame_display(frame, false); + }) + .detach(); + return; + } + } + } + let _ = compact; + window.resize(next); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[gpui::test] + fn onboarding_resize_retargets_and_restores_without_saving_intermediate_geometry( + cx: &mut gpui::TestAppContext, + ) { + let cx = cx.add_empty_window(); + let original = size(px(1320.0), px(880.0)); + cx.simulate_resize(original); + let mut sizing = WindowSizing::default(); + cx.update(|window, cx| { + cx.set_reduce_motion(false); + sizing.update(Some(OnboardingStep::Workspace), window, cx); + assert!(sizing.owns_geometry()); + assert_eq!(sizing.restore, Some(original)); + + // Sample a presented frame halfway through the collapse, then + // reverse direction. The new transition must start at that frame. + sizing.transition.as_mut().unwrap().1 = + Instant::now() - crate::motion::RESIZE.total() / 2; + sizing.update(Some(OnboardingStep::Workspace), window, cx); + window.bounds_changed(cx); + let midway = window.viewport_size(); + assert!(midway.width > px(560.0) && midway.width < original.width); + sizing.update(Some(OnboardingStep::Harnesses), window, cx); + assert_eq!(sizing.transition.unwrap().0, midway); + assert_eq!(sizing.restore, Some(original)); + + cx.set_reduce_motion(true); + sizing.update(Some(OnboardingStep::Harnesses), window, cx); + window.bounds_changed(cx); + assert_eq!( + window.viewport_size(), + preferred_size(OnboardingStep::Harnesses) + ); + assert!(sizing.transition.is_none()); + assert!(sizing.owns_geometry()); + + sizing.update(None, window, cx); + window.bounds_changed(cx); + assert_eq!(window.viewport_size(), original); + assert!(!sizing.owns_geometry()); + assert!(sizing.transition.is_none()); + }); + } +} diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index 8c84665c44..a89912bb17 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -1453,6 +1453,7 @@ pub struct Shell { /// Full-window first-run flow. Its durable navigation snapshot mirrors the /// `UiSettings` field; authoritative choices stay in their normal stores. onboarding: OnboardingUi, + pub(crate) onboarding_window: crate::onboarding::window::WindowSizing, /// External image or workspace-path drag hovering the conversation /// column; a drop stages an image or inserts a file-mention chip. file_drag_active: bool, @@ -1899,6 +1900,7 @@ impl Shell { transcript, composer, onboarding, + onboarding_window: Default::default(), file_drag_active: false, // Seed with the compact composer stack's rough height so the // first frame's clearance isn't zero (the measure corrects it). @@ -11769,6 +11771,16 @@ impl Render for Shell { self.reduced_motion = motion::reduced_motion(cx); self.motion_active.set(false); + if matches!(gate, GatePhase::Ready) && !restart_required { + if self.onboarding_window.update( + self.onboarding.active().then(|| self.onboarding.step()), + window, + cx, + ) { + self.motion_active.set(true); + } + } + if self.activation_sub.is_none() { self.activation_sub = Some(cx.observe_window_activation( window, @@ -13490,6 +13502,64 @@ mod exit_regressions { cx.run_until_parked(); } + #[gpui::test] + fn onboarding_compact_navigation_stays_inside_every_step(cx: &mut TestAppContext) { + let dir = tempfile::tempdir().unwrap(); + let window = onboarding_test_window(cx, dir.path(), OnboardingFixture::Defaults); + cx.update(|cx| cx.set_reduce_motion(true)); + for step in OnboardingStep::ALL { + window + .update(cx, |shell, _, cx| { + shell.onboarding.state.step = step; + cx.notify(); + }) + .unwrap(); + onboarding_frame(cx, window); + for size in [ + crate::onboarding::window::preferred_size(step), + gpui::size(px(520.0), px(440.0)), + ] { + cx.simulate_window_resize(window.into(), size); + onboarding_frame(cx, window); + let mut visual = gpui::VisualTestContext::from_window(window.into(), cx); + let action = visual + .debug_bounds(match step { + OnboardingStep::Workspace => "onboarding-continue-workspace", + OnboardingStep::Appearance => "onboarding-continue-appearance", + OnboardingStep::Harnesses => "onboarding-continue-harnesses", + OnboardingStep::Defaults => "onboarding-continue-defaults", + OnboardingStep::Titles => "onboarding-continue-titles", + _ => "onboarding-continue-project", + }) + .expect("primary action must be mounted"); + let progress = visual.debug_bounds("onboarding-progress").unwrap(); + assert!(action.origin.y >= px(38.0), "{step:?}: {action:?}"); + assert!( + action.bottom() < progress.origin.y, + "{step:?}: navigation overlaps progress" + ); + assert!( + progress.bottom() <= size.height, + "{step:?}: progress is clipped" + ); + assert!(action.origin.x >= px(16.0) && action.right() <= size.width - px(16.0)); + if matches!(step, OnboardingStep::Workspace | OnboardingStep::Project) { + let choices = visual + .debug_bounds(if step == OnboardingStep::Workspace { + "onboarding-workspace-choices" + } else { + "onboarding-project-choices" + }) + .unwrap(); + assert!( + choices.bottom() <= action.origin.y - px(8.0), + "{step:?}: choices overlap navigation" + ); + } + } + } + } + fn onboarding_dispatch_key(window: &mut Window, cx: &mut App, key: &str) { let keystroke = gpui::Keystroke::parse(key).unwrap(); window.dispatch_event( From a52aa7dce20281c1c50eddb899e8f4c45e5cfafc Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 20 Sep 2026 13:28:50 +0200 Subject: [PATCH 20/21] Give onboarding more room --- crates/ui/src/onboarding.rs | 22 +++++++++++----------- crates/ui/src/onboarding/window.rs | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index ab5680c190..fcd33b2618 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -26,13 +26,13 @@ use crate::theme::{Theme, ink}; pub const SCHEMA_VERSION: u16 = 1; pub const STEP_COUNT: usize = 6; -const CONTENT_MAX_WIDTH: f32 = Theme::SPACE_LG * 30.0; +const CONTENT_MAX_WIDTH: f32 = 520.0; // The journey grows with the window until this cap; dense steps should expose // several useful rows before their overflow affordance becomes necessary. -const CONTENT_MAX_HEIGHT: f32 = 448.0; -const WORKSPACE_MAX_HEIGHT: f32 = 312.0; -const HARNESS_MAX_HEIGHT: f32 = 488.0; -const PROJECT_MAX_HEIGHT: f32 = 312.0; +const CONTENT_MAX_HEIGHT: f32 = 488.0; +const WORKSPACE_MAX_HEIGHT: f32 = 336.0; +const HARNESS_MAX_HEIGHT: f32 = 528.0; +const PROJECT_MAX_HEIGHT: f32 = 336.0; const HARNESS_ROW_HEIGHT: f32 = 54.0; const HARNESS_ROW_GAP: f32 = 8.0; // Four complete rows plus half of the next one uses the available height while @@ -2080,8 +2080,8 @@ fn journey_max_height(step: OnboardingStep) -> f32 { OnboardingStep::Workspace => WORKSPACE_MAX_HEIGHT, OnboardingStep::Harnesses => HARNESS_MAX_HEIGHT, OnboardingStep::Project | OnboardingStep::FirstSession => PROJECT_MAX_HEIGHT, - OnboardingStep::Titles => 400.0, - OnboardingStep::Defaults => 488.0, + OnboardingStep::Titles => 440.0, + OnboardingStep::Defaults => 528.0, OnboardingStep::Appearance => CONTENT_MAX_HEIGHT, } } @@ -2376,10 +2376,10 @@ mod tests { #[test] fn simple_steps_do_not_inherit_the_dense_journey_height() { - assert_eq!(journey_max_height(OnboardingStep::Workspace), 312.0); - assert_eq!(journey_max_height(OnboardingStep::Project), 312.0); - assert_eq!(journey_max_height(OnboardingStep::Harnesses), 488.0); - assert_eq!(journey_max_height(OnboardingStep::Appearance), 448.0); + assert_eq!(journey_max_height(OnboardingStep::Workspace), 336.0); + assert_eq!(journey_max_height(OnboardingStep::Project), 336.0); + assert_eq!(journey_max_height(OnboardingStep::Harnesses), 528.0); + assert_eq!(journey_max_height(OnboardingStep::Appearance), 488.0); assert_eq!(HARNESS_LIST_MAX_HEIGHT, 275.0); } diff --git a/crates/ui/src/onboarding/window.rs b/crates/ui/src/onboarding/window.rs index bc7c01f220..fbefa9b028 100644 --- a/crates/ui/src/onboarding/window.rs +++ b/crates/ui/src/onboarding/window.rs @@ -7,14 +7,14 @@ use super::OnboardingStep; pub(crate) fn preferred_size(step: OnboardingStep) -> Size { size( - px(560.0), + px(620.0), px(match step { OnboardingStep::Workspace | OnboardingStep::Project | OnboardingStep::FirstSession => { - 440.0 + 480.0 } - OnboardingStep::Appearance => 560.0, - OnboardingStep::Harnesses | OnboardingStep::Defaults => 620.0, - OnboardingStep::Titles => 500.0, + OnboardingStep::Appearance => 600.0, + OnboardingStep::Harnesses | OnboardingStep::Defaults => 680.0, + OnboardingStep::Titles => 560.0, }), ) } From 93abcd43924a6c34e94001eba5d81e12093e893f Mon Sep 17 00:00:00 2001 From: gaelcado Date: Sun, 20 Sep 2026 14:20:19 +0200 Subject: [PATCH 21/21] Smooth onboarding handoff and fill a stable portrait layout --- crates/ui/src/onboarding.rs | 54 ++++--------- crates/ui/src/onboarding/window.rs | 118 +++++++++++++++++++++++------ crates/ui/src/shell.rs | 11 ++- 3 files changed, 119 insertions(+), 64 deletions(-) diff --git a/crates/ui/src/onboarding.rs b/crates/ui/src/onboarding.rs index fcd33b2618..e22db8daaf 100644 --- a/crates/ui/src/onboarding.rs +++ b/crates/ui/src/onboarding.rs @@ -27,17 +27,8 @@ use crate::theme::{Theme, ink}; pub const SCHEMA_VERSION: u16 = 1; pub const STEP_COUNT: usize = 6; const CONTENT_MAX_WIDTH: f32 = 520.0; -// The journey grows with the window until this cap; dense steps should expose -// several useful rows before their overflow affordance becomes necessary. -const CONTENT_MAX_HEIGHT: f32 = 488.0; -const WORKSPACE_MAX_HEIGHT: f32 = 336.0; -const HARNESS_MAX_HEIGHT: f32 = 528.0; -const PROJECT_MAX_HEIGHT: f32 = 336.0; const HARNESS_ROW_HEIGHT: f32 = 54.0; const HARNESS_ROW_GAP: f32 = 8.0; -// Four complete rows plus half of the next one uses the available height while -// still making the list's overflow obvious. -const HARNESS_LIST_MAX_HEIGHT: f32 = HARNESS_ROW_HEIGHT * 4.5 + HARNESS_ROW_GAP * 4.0; const STEP_GROUP_GAP: f32 = 20.0; const VIEWPORT_INSET: f32 = Theme::SPACE_LG; const ROOMY_VIEWPORT_INSET: f32 = Theme::SPACE_LG * 2.0; @@ -714,6 +705,7 @@ fn faded_step_scroll(id: &'static str, handle: &ScrollHandle, content: AnyElemen true, div() .id(id) + .debug_selector(move || id.into()) .size_full() .min_w_0() .min_h_0() @@ -1370,7 +1362,6 @@ fn render_harness_step( .mt(px(Theme::SPACE_SM)) .flex_1() .min_h_0() - .max_h(px(HARNESS_LIST_MAX_HEIGHT)) .child(faded_step_scroll( "onboarding-harness-scroll", &ui.harness_scroll, @@ -1514,11 +1505,11 @@ fn render_model_choices( .iter() .map(|model| (Some(model.id.clone()), model.label.clone())), ); - div() + let list = div() .id(prefix) .w_full() - .h(px(((models.len() + 1) as f32 * 34.0).min(119.0))) - .flex_none() + .min_h(px(102.0)) + .flex_1() .rounded(px(10.0)) .border_1() .border_color(theme.border) @@ -1555,7 +1546,9 @@ fn render_model_choices( shell.onboarding_pick_default_model(id.clone(), cx); } })) - })) + })); + crate::edge_fade::edge_faded(16.0, true, true, list) + .fade_overflow_y(&ui.model_scroll) .into_any_element() } @@ -1675,11 +1668,12 @@ fn render_defaults_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) .child(error.clone()) .into_any_element(), Loadable::Ready(models) => div() + .flex_1() + .min_h(px(132.0)) .mt(px(18.0)) .flex() .flex_col() @@ -1858,6 +1854,9 @@ fn render_titles_step(ui: &OnboardingUi, theme: &Theme, cx: &mut Context) } }; let title_options = div() + .min_h_full() + .flex() + .flex_col() .child(body(theme, "Choose an agent to name your sessions. Automatic uses an available agent, or the first seven words.")) .child(div().mt(px(16.0)).child(choices)) .child(title_models) @@ -2075,17 +2074,6 @@ fn can_continue(ui: &OnboardingUi, step: OnboardingStep) -> bool { .any(|h| h.id != HarnessId::Mock && harness_is_usable(h, &ui.accounts))) } -fn journey_max_height(step: OnboardingStep) -> f32 { - match step { - OnboardingStep::Workspace => WORKSPACE_MAX_HEIGHT, - OnboardingStep::Harnesses => HARNESS_MAX_HEIGHT, - OnboardingStep::Project | OnboardingStep::FirstSession => PROJECT_MAX_HEIGHT, - OnboardingStep::Titles => 440.0, - OnboardingStep::Defaults => 528.0, - OnboardingStep::Appearance => CONTENT_MAX_HEIGHT, - } -} - fn render_footer_actions( ui: &OnboardingUi, step: OnboardingStep, @@ -2198,11 +2186,9 @@ pub fn render( let step = ui.step(); let viewport_width = f32::from(viewport.width); let viewport_height = f32::from(viewport.height); - let journey_max_height = journey_max_height(step); let compact_navigation = viewport_width < COMPACT_NAVIGATION_WIDTH; let roomy_x = viewport_width >= CONTENT_MAX_WIDTH + ROOMY_VIEWPORT_INSET * 2.0; - let roomy_y = - viewport_height >= Theme::TITLEBAR_HEIGHT + journey_max_height + ROOMY_VIEWPORT_INSET * 2.0; + let roomy_y = viewport_height >= 600.0; let outer_x = if roomy_x { ROOMY_VIEWPORT_INSET } else { @@ -2237,7 +2223,6 @@ pub fn render( .w_full() .h_full() .max_w(px(CONTENT_MAX_WIDTH)) - .max_h(px(journey_max_height)) .min_w_0() .min_h_0() .flex() @@ -2374,15 +2359,6 @@ mod tests { assert_eq!(OnboardingStep::Project.index() + 1, STEP_COUNT); } - #[test] - fn simple_steps_do_not_inherit_the_dense_journey_height() { - assert_eq!(journey_max_height(OnboardingStep::Workspace), 336.0); - assert_eq!(journey_max_height(OnboardingStep::Project), 336.0); - assert_eq!(journey_max_height(OnboardingStep::Harnesses), 528.0); - assert_eq!(journey_max_height(OnboardingStep::Appearance), 488.0); - assert_eq!(HARNESS_LIST_MAX_HEIGHT, 275.0); - } - #[test] fn established_profiles_default_to_completed() { assert_eq!( diff --git a/crates/ui/src/onboarding/window.rs b/crates/ui/src/onboarding/window.rs index fbefa9b028..e916ef33ad 100644 --- a/crates/ui/src/onboarding/window.rs +++ b/crates/ui/src/onboarding/window.rs @@ -5,18 +5,10 @@ use std::time::Instant; use super::OnboardingStep; -pub(crate) fn preferred_size(step: OnboardingStep) -> Size { - size( - px(620.0), - px(match step { - OnboardingStep::Workspace | OnboardingStep::Project | OnboardingStep::FirstSession => { - 480.0 - } - OnboardingStep::Appearance => 600.0, - OnboardingStep::Harnesses | OnboardingStep::Defaults => 680.0, - OnboardingStep::Titles => 560.0, - }), - ) +pub(crate) fn preferred_size(_step: OnboardingStep) -> Size { + // Keep the same portrait canvas throughout setup; only entering/leaving + // setup changes the native window geometry. + size(px(620.0), px(680.0)) } #[derive(Default)] @@ -25,6 +17,12 @@ pub(crate) struct WindowSizing { target: Option>, transition: Option<(Size, Instant)>, step: Option, + presented_setup: Option, + content_opacity: Option, + outgoing_setup: bool, + outgoing_opacity: f32, + configure_initial_geometry: bool, + observed: bool, } impl WindowSizing { @@ -32,12 +30,23 @@ impl WindowSizing { self.restore = Some(restore); self.target = Some(preferred_size(step)); self.step = Some(step); + self.presented_setup = Some(true); + self.configure_initial_geometry = true; + self.observed = true; } pub(crate) fn owns_geometry(&self) -> bool { self.restore.is_some() } + pub(crate) fn shows_setup(&self, active: bool) -> bool { + self.presented_setup.unwrap_or(active) + } + + pub(crate) fn content_opacity(&self) -> f32 { + self.content_opacity.unwrap_or(1.0) + } + pub(crate) fn update( &mut self, step: Option, @@ -46,10 +55,19 @@ impl WindowSizing { ) -> bool { // Do not fight the OS fullscreen animation or alter fullscreen bounds. if window.is_fullscreen() { + self.presented_setup = Some(step.is_some()); + self.content_opacity = Some(1.0); return false; } + let first_frame = !std::mem::replace(&mut self.observed, true); let current = window.viewport_size(); + if self.step.is_some() == step.is_some() { + // Step navigation is a content transition, not a window resize. + self.step = step; + } if self.step != step { + self.outgoing_opacity = self.content_opacity(); + self.outgoing_setup = self.presented_setup.unwrap_or(self.step.is_some()); if let Some(step) = step { self.restore.get_or_insert(current); self.target = Some(preferred_size(step)); @@ -65,24 +83,47 @@ impl WindowSizing { return false; }; let Some((from, started)) = self.transition else { + if std::mem::take(&mut self.configure_initial_geometry) { + resize(window, current, true, true, cx); + } return false; }; let target = window.display(cx).map_or(target, |display| { let visible = display.visible_bounds().size; - size( - target.width.min(visible.width), - target.height.min(visible.height), - ) + if step.is_some() { + let scale = (f32::from(visible.width) / f32::from(target.width)) + .min(f32::from(visible.height) / f32::from(target.height)) + .min(1.0); + size(target.width * scale, target.height * scale) + } else { + size( + target.width.min(visible.width), + target.height.min(visible.height), + ) + } }); - let duration = crate::motion::RESIZE + let duration = crate::motion::NEW_THREAD_TRANSITION .total() .mul_f32(crate::motion::speed_scale()); - let progress = if cx.reduce_motion() { + let progress = if cx.reduce_motion() || first_frame { 1.0 } else { (started.elapsed().as_secs_f32() / duration.as_secs_f32()).min(1.0) }; - let eased = crate::motion::RESIZE.progress(progress); + // Fade the outgoing surface before swapping it. Geometry uses the + // established new-thread transition curve in both directions. + self.presented_setup = Some(if progress < 0.25 { + self.outgoing_setup + } else { + step.is_some() + }); + self.content_opacity = Some(if progress < 0.25 { + self.outgoing_opacity * (1.0 - crate::motion::FADE_QUICK.progress(progress / 0.25)) + } else { + crate::motion::FADE_QUICK.progress(((progress - 0.65) / 0.35).clamp(0.0, 1.0)) + }); + let eased = crate::motion::NEW_THREAD_TRANSITION + .progress(((progress - 0.15) / 0.85).clamp(0.0, 1.0)); let next = size( px(crate::motion::lerp( from.width.into(), @@ -95,7 +136,13 @@ impl WindowSizing { eased, )), ); - resize(window, next, step.is_some() || progress < 1.0, cx); + resize( + window, + next, + step.is_some() || progress < 1.0, + step.is_some() && progress >= 1.0, + cx, + ); if progress < 1.0 { true } else { @@ -109,7 +156,7 @@ impl WindowSizing { } } -fn resize(window: &mut Window, next: Size, compact: bool, cx: &App) { +fn resize(window: &mut Window, next: Size, compact: bool, portrait: bool, cx: &App) { // Test windows deliberately panic when asked for a native handle. if cx .background_executor() @@ -138,6 +185,12 @@ fn resize(window: &mut Window, next: Size, compact: bool, cx: &App) { // releases its window borrow. cx.foreground_executor() .spawn(async move { + // Unlock before interpolating to/from the workspace. + native.setContentAspectRatio(if portrait { + NSSize::new(620.0, 680.0) + } else { + NSSize::new(0.0, 0.0) + }); native.setContentMinSize(if compact { NSSize::new(520.0, 440.0) } else { @@ -174,7 +227,7 @@ fn resize(window: &mut Window, next: Size, compact: bool, cx: &App) { } } } - let _ = compact; + let _ = (compact, portrait); window.resize(next); } @@ -182,6 +235,13 @@ fn resize(window: &mut Window, next: Size, compact: bool, cx: &App) { mod tests { use super::*; + #[test] + fn setup_steps_share_a_portrait_canvas() { + for step in OnboardingStep::ALL { + assert_eq!(preferred_size(step), size(px(620.0), px(680.0))); + } + } + #[gpui::test] fn onboarding_resize_retargets_and_restores_without_saving_intermediate_geometry( cx: &mut gpui::TestAppContext, @@ -192,20 +252,28 @@ mod tests { let mut sizing = WindowSizing::default(); cx.update(|window, cx| { cx.set_reduce_motion(false); + sizing.update(None, window, cx); sizing.update(Some(OnboardingStep::Workspace), window, cx); assert!(sizing.owns_geometry()); assert_eq!(sizing.restore, Some(original)); + assert!( + !sizing.shows_setup(true), + "keep outgoing workspace during fade" + ); // Sample a presented frame halfway through the collapse, then // reverse direction. The new transition must start at that frame. sizing.transition.as_mut().unwrap().1 = - Instant::now() - crate::motion::RESIZE.total() / 2; + Instant::now() - crate::motion::NEW_THREAD_TRANSITION.total() / 2; sizing.update(Some(OnboardingStep::Workspace), window, cx); window.bounds_changed(cx); + assert!(sizing.shows_setup(true)); + assert_eq!(sizing.content_opacity(), 0.0); let midway = window.viewport_size(); assert!(midway.width > px(560.0) && midway.width < original.width); - sizing.update(Some(OnboardingStep::Harnesses), window, cx); + sizing.update(None, window, cx); assert_eq!(sizing.transition.unwrap().0, midway); + sizing.update(Some(OnboardingStep::Harnesses), window, cx); assert_eq!(sizing.restore, Some(original)); cx.set_reduce_motion(true); @@ -217,11 +285,13 @@ mod tests { ); assert!(sizing.transition.is_none()); assert!(sizing.owns_geometry()); + assert_eq!(sizing.content_opacity(), 1.0); sizing.update(None, window, cx); window.bounds_changed(cx); assert_eq!(window.viewport_size(), original); assert!(!sizing.owns_geometry()); + assert!(!sizing.shows_setup(false)); assert!(sizing.transition.is_none()); }); } diff --git a/crates/ui/src/shell.rs b/crates/ui/src/shell.rs index a89912bb17..f3668a662a 100644 --- a/crates/ui/src/shell.rs +++ b/crates/ui/src/shell.rs @@ -11996,7 +11996,7 @@ impl Render for Shell { gate.clone() }; let root = match &render_gate { - GatePhase::Ready if self.onboarding.active() => { + GatePhase::Ready if self.onboarding_window.shows_setup(self.onboarding.active()) => { self.onboarding.prepare_model_controls(cx); let viewport = window.viewport_size(); let title_bar = self.render_onboarding_title_bar(cx); @@ -12278,6 +12278,8 @@ impl Render for Shell { root }; + let root = root.opacity(self.onboarding_window.content_opacity()); + // A manually-driven tween is mid-flight: keep frames coming (the same // scheduling `with_animation` would have requested). Hover color fades // ride the same clock; their once-per-frame tick lives here (this is @@ -13543,6 +13545,13 @@ mod exit_regressions { "{step:?}: progress is clipped" ); assert!(action.origin.x >= px(16.0) && action.right() <= size.width - px(16.0)); + if step == OnboardingStep::Harnesses { + let list = visual.debug_bounds("onboarding-harness-scroll").unwrap(); + assert!( + (action.origin.y - list.bottom() - px(Theme::SPACE_MD)).abs() < px(2.0), + "agent scroll area must fill the space above the footer: {list:?} {action:?}" + ); + } if matches!(step, OnboardingStep::Workspace | OnboardingStep::Project) { let choices = visual .debug_bounds(if step == OnboardingStep::Workspace {