Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ impl EventHandler {
match key_event.code {
KeyCode::Char('q') => Ok(AppEvent::Quit),
KeyCode::Esc => Ok(AppEvent::CloseSettings),
KeyCode::Char(',') | KeyCode::Char('s') | KeyCode::Char('S') => Ok(AppEvent::OpenSettings),
KeyCode::Char(',') | KeyCode::Char('s') | KeyCode::Char('S') => {
Ok(AppEvent::OpenSettings)
}
KeyCode::Up | KeyCode::Char('k') => Ok(AppEvent::NavigateUp),
KeyCode::Down | KeyCode::Char('j') => Ok(AppEvent::NavigateDown),
KeyCode::Enter | KeyCode::Char(' ') => Ok(AppEvent::Select),
Expand Down
16 changes: 8 additions & 8 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,28 +1129,28 @@ impl Settings {
},
}
}

/// Check if at least one provider is valid and ready for queries
pub fn has_valid_provider(&self) -> bool {
self.local_provider.validation_status == ValidationStatus::Valid
|| self.openrouter_provider.validation_status == ValidationStatus::Valid
}

/// Get list of available (valid) providers
pub fn get_available_providers(&self) -> Vec<ProviderType> {
let mut providers = Vec::new();

if self.local_provider.validation_status == ValidationStatus::Valid {
providers.push(ProviderType::Local);
}

if self.openrouter_provider.validation_status == ValidationStatus::Valid {
providers.push(ProviderType::OpenRouter);
}

providers
}

/// Get provider configuration status for UI display
pub fn get_provider_status_summary(&self) -> Vec<(ProviderType, ValidationStatus, String)> {
vec![
Expand All @@ -1160,15 +1160,15 @@ impl Settings {
match &self.local_provider.endpoint_url {
Some(url) => url.clone(),
None => "Not configured".to_string(),
}
},
),
(
ProviderType::OpenRouter,
self.openrouter_provider.validation_status.clone(),
match &self.openrouter_provider.api_key {
Some(_) => "API configured".to_string(),
None => "Not configured".to_string(),
}
},
),
]
}
Expand Down
16 changes: 9 additions & 7 deletions src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl App {
} else {
AppState::WaitingForConfig
};

Self {
state: initial_state,
previous_state: AppState::Main,
Expand Down Expand Up @@ -361,7 +361,7 @@ impl App {
AppState::WaitingForConfig => {
let provider_status = self.settings().get_provider_status_summary();
let available_providers = self.settings().get_available_providers();

let status_display = if provider_status.is_empty() {
" No providers configured yet".to_string()
} else {
Expand All @@ -378,7 +378,7 @@ impl App {
.collect::<Vec<_>>()
.join("\n")
};

format!(r#"

╔═══════════════════════════════════════════════════════════════╗
Expand Down Expand Up @@ -530,7 +530,7 @@ impl App {
self.settings.reset_to_defaults();
self.settings.get().apply_theme(&mut self.theme);
}

/// Check provider readiness and update app state accordingly
pub fn check_provider_readiness(&mut self) {
if !self.settings.get().has_valid_provider() {
Expand All @@ -543,12 +543,14 @@ impl App {
}
}
}

/// Handle validation event results and update provider status
pub fn update_provider_status(&mut self, validation_event: crate::settings::ValidationEvent) {
// Update the provider status through settings
self.settings.get_mut().handle_validation_event(validation_event);

self.settings
.get_mut()
.handle_validation_event(validation_event);

// Check if we need to change app state
self.check_provider_readiness();
}
Expand Down