feat(content): update installed content atomically

This commit is contained in:
objz committed 2026-08-04 23:57:49 +02:00
1 parent aa03dac34d
commit bbf0317775
14 files changed
+877 -101

No files matched your search

+5
View File
@@ -51,6 +51,9 @@ pub struct App {
pub(super) pending_editor: Option<std::path::PathBuf>,
pub(super) reconciliation_for: Option<String>,
pub(super) content_manifest: Option<(String, crate::instance::ContentManifest)>,
pub(super) content_update_snapshot:
Option<(String, crate::instance::content::updates::UpdateSnapshot)>,
pub(super) content_update_popup: Option<widgets::content::update::State>,
pub(super) provider_conflict: Option<ProviderConflictState>,
pub(super) dismissed_provider_conflicts: HashSet<PathBuf>,
}
@@ -179,6 +182,8 @@ impl App {
pending_editor: None,
reconciliation_for: None,
content_manifest: None,
content_update_snapshot: None,
content_update_popup: None,
provider_conflict: None,
dismissed_provider_conflicts: HashSet::new(),
}
+61 -21
View File
@@ -42,6 +42,12 @@ impl App {
self.drain_pending_instances();
self.instances_state.drain_modpack_updates();
self.drain_pending_last_played();
if let Some(update) = self.content_update_popup.as_mut() {
update.drain();
if update.completed {
self.content_update_popup = None;
}
}
let mut local_streamed = false;
let mut content_changed = false;
let mut toggles = Vec::new();
@@ -118,6 +124,7 @@ impl App {
results.retain(|result| result.instance_name != instance.name);
}
self.drain_content_reconciliation();
self.drain_content_update_snapshots();
self.ensure_content_reconciliation(content_changed);
if local_streamed {
self.apply_cached_content_manifest();
@@ -175,6 +182,7 @@ impl App {
+ usize::from(self.focused == super::app::FocusedArea::OverviewExpanded)
+ usize::from(self.focused == super::app::FocusedArea::ConfirmDelete)
+ usize::from(self.provider_conflict.is_some())
+ usize::from(self.content_update_popup.is_some())
+ usize::from(!matches!(
&self.account_state.add_mode,
widgets::account::AddMode::None
@@ -257,6 +265,7 @@ impl App {
self.provider_conflict = None;
self.dismissed_provider_conflicts.clear();
self.content_manifest = None;
self.content_update_snapshot = None;
for discovery in [
&mut self.mods_discovery_state,
&mut self.resource_packs_discovery_state,
@@ -289,7 +298,7 @@ impl App {
}
fn drain_content_reconciliation(&mut self) {
let Some(selected) = self.instances_state.selected_instance() else {
let Some(selected) = self.instances_state.selected_instance().cloned() else {
return;
};
let result = match crate::instance::content::reconcile::PENDING_RECONCILIATIONS.lock() {
@@ -314,14 +323,6 @@ impl App {
self.instance_manager.instances_dir.join(&selected.name),
)
.minecraft();
self.mods_state
.set_provider_update_context(selected, crate::instance::ContentKind::Mod);
self.resource_packs_state
.set_provider_update_context(selected, crate::instance::ContentKind::ResourcePack);
self.shaders_state
.set_provider_update_context(selected, crate::instance::ContentKind::Shader);
self.world_datapacks_state
.set_provider_update_context(selected, crate::instance::ContentKind::DataPack);
self.mods_state.apply_manifest(
&result.manifest,
&minecraft_dir,
@@ -355,7 +356,22 @@ impl App {
details.datapacks = crate::instance::content::worlds::datapack_names(&world.path);
}
}
self.content_manifest = Some((result.instance_name, result.manifest));
let paths = crate::storage::InstancePaths::new(
self.instance_manager
.instances_dir
.join(&result.instance_name),
);
self.content_update_snapshot =
crate::instance::content::updates::UpdateSnapshot::load(&paths.content_updates())
.filter(|snapshot| snapshot.applies_to(&selected))
.map(|snapshot| (result.instance_name.clone(), snapshot));
self.content_manifest = Some((result.instance_name.clone(), result.manifest.clone()));
self.apply_content_update_snapshot();
crate::instance::content::updates::spawn(
selected,
result.manifest,
paths.content_updates(),
);
}
fn apply_cached_content_manifest(&mut self) {
@@ -373,17 +389,6 @@ impl App {
self.instance_manager.instances_dir.join(instance_name),
)
.minecraft();
let Some(instance) = self.instances_state.selected_instance() else {
return;
};
self.mods_state
.set_provider_update_context(instance, crate::instance::ContentKind::Mod);
self.resource_packs_state
.set_provider_update_context(instance, crate::instance::ContentKind::ResourcePack);
self.shaders_state
.set_provider_update_context(instance, crate::instance::ContentKind::Shader);
self.world_datapacks_state
.set_provider_update_context(instance, crate::instance::ContentKind::DataPack);
self.mods_state
.apply_manifest(manifest, &minecraft_dir, crate::instance::ContentKind::Mod);
self.resource_packs_state.apply_manifest(
@@ -401,6 +406,41 @@ impl App {
&minecraft_dir,
crate::instance::ContentKind::DataPack,
);
self.apply_content_update_snapshot();
}
fn drain_content_update_snapshots(&mut self) {
let Some(selected) = self.instances_state.selected_instance() else {
return;
};
let snapshot = match crate::instance::content::updates::PENDING_UPDATE_SNAPSHOTS.lock() {
Ok(mut pending) => pending
.iter()
.rposition(|pending| pending.instance_name == selected.name)
.map(|index| pending.remove(index)),
Err(_) => return,
};
let Some(snapshot) = snapshot else {
return;
};
self.content_update_snapshot = Some((snapshot.instance_name, snapshot.snapshot));
self.apply_content_update_snapshot();
}
fn apply_content_update_snapshot(&mut self) {
let snapshot = self
.content_update_snapshot
.as_ref()
.and_then(|(name, snapshot)| {
self.instances_state
.selected_instance()
.filter(|instance| instance.name == *name && snapshot.applies_to(instance))
.map(|_| snapshot)
});
self.mods_state.apply_update_snapshot(snapshot);
self.resource_packs_state.apply_update_snapshot(snapshot);
self.shaders_state.apply_update_snapshot(snapshot);
self.world_datapacks_state.apply_update_snapshot(snapshot);
}
fn ensure_provider_conflict_popup(&mut self) {
+199
View File
@@ -60,6 +60,10 @@ impl App {
}
pub(super) fn handle_key_event(&mut self, key_event: KeyEvent) -> color_eyre::Result<()> {
if self.content_update_popup.is_some() {
self.handle_content_update_key(key_event);
return Ok(());
}
if let Some(conflict) = self.provider_conflict.as_mut() {
match key_event.code {
KeyCode::Char('j') | KeyCode::Down => {
@@ -404,6 +408,12 @@ impl App {
}
} else if self.content_tab == widgets::content::ContentTab::Worlds {
if self.open_world_datapacks.is_some() {
if key_event.code == KeyCode::Char('u')
&& !self.world_datapacks_state.search.active
{
self.spawn_bulk_content_updates();
return Ok(());
}
if key_event.code == KeyCode::Char('v')
&& !self.world_datapacks_state.search.active
{
@@ -474,6 +484,10 @@ impl App {
_ => None,
};
if let Some(state) = state {
if key_event.code == KeyCode::Char('u') && !state.search.active {
self.spawn_bulk_content_updates();
return Ok(());
}
if key_event.code == KeyCode::Char('v') && !state.search.active {
self.spawn_installed_versions();
return Ok(());
@@ -840,6 +854,191 @@ impl App {
}
}
fn spawn_bulk_content_updates(&mut self) {
let Some(instance) = self.instances_state.selected_instance().cloned() else {
return;
};
let (kind, target_world) = match self.content_tab {
widgets::content::ContentTab::Mods => (crate::instance::ContentKind::Mod, None),
widgets::content::ContentTab::ResourcePacks => {
(crate::instance::ContentKind::ResourcePack, None)
}
widgets::content::ContentTab::Shaders => (crate::instance::ContentKind::Shader, None),
widgets::content::ContentTab::Worlds => (
crate::instance::ContentKind::DataPack,
self.open_world_datapacks.clone(),
),
_ => return,
};
if kind == crate::instance::ContentKind::DataPack && target_world.is_none() {
return;
}
let Some((_, manifest)) = self
.content_manifest
.as_ref()
.filter(|(name, _)| name == &instance.name)
.cloned()
else {
return;
};
let paths = crate::storage::InstancePaths::new(
self.instance_manager.instances_dir.join(&instance.name),
);
let state = widgets::content::update::State::checking(kind, target_world.clone());
let pending = state.pending.clone();
self.content_update_popup = Some(state);
tokio::spawn(async move {
let snapshot = crate::instance::content::updates::scan(&instance, &manifest).await;
if let Ok(bytes) = serde_json::to_vec_pretty(&snapshot) {
let _ = crate::storage::write_atomic(&paths.content_updates(), &bytes);
}
let target_directory = target_world
.as_ref()
.map(|(_, world)| world.join("datapacks"));
let mut requests = Vec::new();
let mut conflicts = Vec::new();
for record in manifest.files.iter().filter(|record| {
record.kind == kind
&& target_directory.as_ref().is_none_or(|directory| {
paths
.minecraft()
.join(&record.relative_path)
.starts_with(directory)
})
}) {
let Some(installed) = record.resolved_project() else {
continue;
};
let installed_path = paths.minecraft().join(&record.relative_path);
let title = record
.relative_path
.file_stem()
.and_then(|name| name.to_str())
.unwrap_or("content")
.to_owned();
if let Some(update) = snapshot.update_for(installed) {
requests.push(crate::instance::content::updates::UpdateRequest {
title,
installed_path,
target_world: target_world.as_ref().map(|(_, path)| path.clone()),
update: update.clone(),
});
} else if let Some(failure) = snapshot
.failures
.iter()
.find(|failure| failure.installed == *installed && failure.kind == kind)
{
conflicts.push(crate::instance::content::updates::UpdateConflict {
title,
installed_path,
reason: failure.reason.clone(),
});
}
}
let plan = crate::instance::content::updates::plan_bulk(
&instance,
&manifest,
&paths.minecraft(),
requests,
conflicts,
)
.await;
if let Ok(mut pending) = pending.lock() {
pending.push(widgets::content::update::PendingResult::Prepared(
snapshot, plan,
));
crate::feedback::request_redraw();
}
});
}
fn handle_content_update_key(&mut self, key_event: KeyEvent) {
let Some(state) = self.content_update_popup.as_mut() else {
return;
};
match (state.phase, key_event.code) {
(widgets::content::update::Phase::Checking, KeyCode::Esc)
| (widgets::content::update::Phase::Review, KeyCode::Esc)
| (widgets::content::update::Phase::Conflicts, KeyCode::Esc) => {
self.content_update_popup = None;
}
(widgets::content::update::Phase::Conflicts, KeyCode::Char('j') | KeyCode::Down) => {
let count = state.plan.as_ref().map_or(0, |plan| plan.conflicts.len());
state.selected = (state.selected + 1).min(count.saturating_sub(1));
}
(widgets::content::update::Phase::Conflicts, KeyCode::Char('k') | KeyCode::Up) => {
state.selected = state.selected.saturating_sub(1);
}
(widgets::content::update::Phase::Conflicts, KeyCode::Char(' ')) => {
if let Some(retry) = state.retry_conflicts.get_mut(state.selected) {
*retry = !*retry;
}
}
(widgets::content::update::Phase::Conflicts, KeyCode::Enter) => {
if state.has_retry() {
self.spawn_bulk_content_updates();
} else {
state.phase = widgets::content::update::Phase::Review;
state.selected = 0;
}
}
(widgets::content::update::Phase::Review, KeyCode::Enter) => {
self.spawn_bulk_content_install();
}
_ => {}
}
}
fn spawn_bulk_content_install(&mut self) {
let Some(instance) = self.instances_state.selected_instance().cloned() else {
return;
};
let Some(state) = self.content_update_popup.as_mut() else {
return;
};
let Some(plan) = state.plan.as_ref().map(|plan| plan.dependency_plan.clone()) else {
return;
};
if plan.items.is_empty() {
self.content_update_popup = None;
return;
}
state.phase = widgets::content::update::Phase::Applying;
state.error = None;
let pending = state.pending.clone();
let instances_dir = self.instance_manager.instances_dir.clone();
let paths = crate::storage::InstancePaths::new(instances_dir.join(&instance.name));
tokio::spawn(async move {
let progress = crate::feedback::progress::ProgressTask::start("Updating content");
let registry = crate::instance::content::provider::ProviderRegistry::configured(
crate::net::HttpClient::new(),
);
let result = crate::instance::content::dependencies::install(
&registry,
&paths.content_manifest(),
&paths.minecraft(),
&plan,
)
.await
.map(|_| ())
.map_err(|error| error.to_string());
if let Err(error) = &result {
progress.fail(error);
} else {
progress.finish();
crate::instance::content::reconcile::spawn_after_change(
instance,
instances_dir,
crate::net::HttpClient::new(),
);
}
if let Ok(mut pending) = pending.lock() {
pending.push(widgets::content::update::PendingResult::Applied(result));
crate::feedback::request_redraw();
}
});
}
fn spawn_installed_versions(&mut self) {
let Some(instance) = self.instances_state.selected_instance().cloned() else {
return;
+4
View File
@@ -178,6 +178,10 @@ impl App {
if let Some(conflict) = &self.provider_conflict {
render_provider_conflict(frame, conflict);
}
if let Some(update) = &self.content_update_popup {
widgets::content::update::render(frame, update);
}
}
// full-screen log viewer with search highlighting and auto-scroll.
+2
View File
@@ -92,6 +92,8 @@ impl UiHarness {
pending_editor: None,
reconciliation_for: None,
content_manifest: None,
content_update_snapshot: None,
content_update_popup: None,
provider_conflict: None,
dismissed_provider_conflicts: HashSet::new(),
};
@@ -735,6 +735,7 @@ fn dependency_resolution_opens_the_existing_confirmation() {
cleanup_eligible: false,
replacement: false,
}],
root_count: 1,
optional_dependencies: 0,
}),
},
+5 -11
View File
@@ -633,13 +633,12 @@ fn provider_metadata_fills_a_missing_installed_description() {
project_id: "shader-project".to_owned(),
bytes: Vec::new(),
description: "A cached shader description".to_owned(),
update_available: true,
});
assert!(state.drain_provider_icons());
assert_eq!(state.entries[0].description, "A cached shader description");
assert!(state.entries[0].provider_description);
assert_eq!(state.entries[0].title_suffix.as_deref(), Some("Update"));
assert_eq!(state.entries[0].title_suffix, None);
}
#[tokio::test]
@@ -682,16 +681,11 @@ async fn provider_metadata_loads_from_cache_without_network() {
project_id: "cached-project".to_owned(),
version_id: "cached-version".to_owned(),
};
let (bytes, description, update_available) = load_provider_metadata(
&crate::net::HttpClient::new(),
temp.path(),
&installed,
None,
)
.await
.unwrap();
let (bytes, description) =
load_provider_metadata(&crate::net::HttpClient::new(), temp.path(), &installed)
.await
.unwrap();
assert_eq!(bytes, png);
assert_eq!(description, "Cached description");
assert!(!update_available);
}
+24 -67
View File
@@ -135,14 +135,6 @@ struct PendingProviderIcon {
project_id: String,
bytes: Vec<u8>,
description: String,
update_available: bool,
}
#[derive(Clone, PartialEq, Eq)]
struct ProviderUpdateContext {
game_version: String,
loader: crate::instance::ModLoader,
kind: crate::instance::ContentKind,
}
struct DisplayMetadata {
@@ -189,7 +181,6 @@ pub struct ContentListState {
requested_provider_icons: HashSet<(String, String)>,
provider_icon_meta_dir: Option<std::path::PathBuf>,
provider_icon_client: Option<crate::net::HttpClient>,
provider_update_context: Option<ProviderUpdateContext>,
images_dirty: bool,
display_metadata: HashMap<String, DisplayMetadata>,
pub search: crate::tui::widgets::search::SearchState,
@@ -231,7 +222,6 @@ impl Default for ContentListState {
requested_provider_icons: HashSet::new(),
provider_icon_meta_dir: None,
provider_icon_client: None,
provider_update_context: None,
images_dirty: true,
display_metadata: HashMap::new(),
search: crate::tui::widgets::search::SearchState::default(),
@@ -330,25 +320,27 @@ impl ContentListState {
self.provider_icon_client = Some(client);
}
pub fn set_provider_update_context(
pub fn apply_update_snapshot(
&mut self,
instance: &crate::instance::InstanceConfig,
kind: crate::instance::ContentKind,
) {
let context = ProviderUpdateContext {
game_version: instance.game_version.clone(),
loader: instance.loader,
kind,
};
if self.provider_update_context.as_ref() != Some(&context) {
self.provider_update_context = Some(context);
self.requested_provider_icons.clear();
for entry in &mut self.entries {
if entry.title_suffix.as_deref() == Some("Update") {
entry.title_suffix = None;
}
snapshot: Option<&crate::instance::content::updates::UpdateSnapshot>,
) -> bool {
let mut changed = false;
for entry in &mut self.entries {
let update = entry.provider_project.as_ref().is_some_and(|installed| {
snapshot
.and_then(|snapshot| snapshot.update_for(installed))
.is_some()
});
let suffix = update.then(|| "Update".to_owned());
if entry.title_suffix != suffix {
entry.title_suffix = suffix;
changed = true;
}
}
if changed {
crate::feedback::request_redraw();
}
changed
}
pub fn drain_provider_icons(&mut self) -> bool {
@@ -378,11 +370,6 @@ impl ContentListState {
.insert(entry.file_stem.clone(), display_metadata(entry));
changed = true;
}
let suffix = metadata.update_available.then(|| "Update".to_owned());
if entry.title_suffix != suffix {
entry.title_suffix = suffix;
changed = true;
}
}
}
if changed {
@@ -409,22 +396,18 @@ impl ContentListState {
let slots = PROVIDER_ICON_SLOTS.clone();
let meta_dir = meta_dir.clone();
let client = client.clone();
let update_context = self.provider_update_context.clone();
tokio::spawn(async move {
let Ok(_permit) = slots.acquire_owned().await else {
return;
};
match load_provider_metadata(&client, &meta_dir, &project, update_context.as_ref())
.await
{
Ok((bytes, description, update_available)) => {
match load_provider_metadata(&client, &meta_dir, &project).await {
Ok((bytes, description)) => {
if let Ok(mut pending) = pending.lock() {
pending.push(PendingProviderIcon {
provider: project.provider,
project_id: project.project_id,
bytes,
description,
update_available,
});
crate::feedback::request_redraw();
}
@@ -463,9 +446,7 @@ impl ContentListState {
if visible_height == 0 {
continue;
}
if (entry.icon_bytes.is_none()
|| entry.description.trim().is_empty()
|| self.provider_update_context.is_some())
if (entry.icon_bytes.is_none() || entry.description.trim().is_empty())
&& let Some(project) = entry.provider_project.clone()
{
projects.push(project);
@@ -1346,8 +1327,7 @@ async fn load_provider_metadata(
client: &crate::net::HttpClient,
meta_dir: &Path,
installed: &crate::instance::ProviderProject,
update_context: Option<&ProviderUpdateContext>,
) -> Result<(Vec<u8>, String, bool), crate::net::NetError> {
) -> Result<(Vec<u8>, String), crate::net::NetError> {
let provider_id = &installed.provider;
let project_id = &installed.project_id;
let metadata = crate::storage::MetadataPaths::new(meta_dir);
@@ -1376,9 +1356,7 @@ async fn load_provider_metadata(
let project = match provider.project(project_id).await {
Ok(project) => project,
Err(error) => {
return cached_icon
.map(|bytes| (bytes, String::new(), false))
.ok_or(error);
return cached_icon.map(|bytes| (bytes, String::new())).ok_or(error);
}
};
crate::storage::write_atomic(
@@ -1389,27 +1367,6 @@ async fn load_provider_metadata(
project
}
};
let update_available = match update_context {
Some(context) => match provider
.compatible_versions(
project_id,
context.kind,
&context.game_version,
context.loader,
)
.await
{
Ok(versions) => crate::instance::content::provider::has_newer_compatible_version(
&versions,
&installed.version_id,
),
Err(error) => {
tracing::debug!("Could not check updates for project '{project_id}': {error}");
false
}
},
None => false,
};
let bytes = match (cached_icon, project.icon_url.as_deref()) {
(Some(bytes), _) => bytes,
(None, Some(url)) => match provider.icon(url).await {
@@ -1428,7 +1385,7 @@ async fn load_provider_metadata(
},
(None, None) => Vec::new(),
};
Ok((bytes, project.description, update_available))
Ok((bytes, project.description))
}
pub fn handle_key_no_toggle(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
+1
View File
@@ -3,6 +3,7 @@
pub mod discovery;
pub mod list;
pub mod tabs;
pub mod update;
pub use discovery::{ContentMode, DiscoveryState};
pub use list::{ContentListState, handle_key, handle_key_no_toggle};
+202
View File
@@ -0,0 +1,202 @@
use std::sync::{Arc, Mutex};
use ratatui::{
Frame,
layout::{Constraint, Flex, Layout},
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, Borders, Clear, List, ListItem, ListState, Paragraph},
};
use crate::config::theme::{BORDER_STYLE, THEME};
use crate::instance::ContentKind;
use crate::instance::content::updates::{BulkUpdatePlan, UpdateSnapshot};
pub enum PendingResult {
Prepared(UpdateSnapshot, BulkUpdatePlan),
Applied(Result<(), String>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Phase {
Checking,
Conflicts,
Review,
Applying,
}
pub struct State {
pub phase: Phase,
pub plan: Option<BulkUpdatePlan>,
pub snapshot: Option<UpdateSnapshot>,
pub selected: usize,
pub retry_conflicts: Vec<bool>,
pub error: Option<String>,
pub pending: Arc<Mutex<Vec<PendingResult>>>,
pub kind: ContentKind,
pub target_world: Option<(String, std::path::PathBuf)>,
pub completed: bool,
}
impl State {
pub fn checking(kind: ContentKind, target_world: Option<(String, std::path::PathBuf)>) -> Self {
Self {
phase: Phase::Checking,
plan: None,
snapshot: None,
selected: 0,
retry_conflicts: Vec::new(),
error: None,
pending: Arc::new(Mutex::new(Vec::new())),
kind,
target_world,
completed: false,
}
}
pub fn drain(&mut self) -> bool {
let pending = match self.pending.lock() {
Ok(mut pending) => pending.drain(..).collect::<Vec<_>>(),
Err(_) => return false,
};
let mut changed = false;
for result in pending {
changed = true;
match result {
PendingResult::Prepared(snapshot, plan) => {
self.retry_conflicts = vec![false; plan.conflicts.len()];
self.phase = if plan.conflicts.is_empty() {
Phase::Review
} else {
Phase::Conflicts
};
self.selected = 0;
self.snapshot = Some(snapshot);
self.plan = Some(plan);
self.error = None;
}
PendingResult::Applied(Ok(())) => self.completed = true,
PendingResult::Applied(Err(error)) => {
self.phase = Phase::Review;
self.error = Some(error);
}
}
}
changed
}
pub fn push(&self, result: PendingResult) {
if let Ok(mut pending) = self.pending.lock() {
pending.push(result);
crate::feedback::request_redraw();
}
}
pub fn has_retry(&self) -> bool {
self.retry_conflicts.iter().any(|retry| *retry)
}
}
pub fn render(frame: &mut Frame, state: &State) {
let theme = THEME.as_ref();
let item_count = match state.phase {
Phase::Conflicts => state.plan.as_ref().map_or(0, |plan| plan.conflicts.len()),
Phase::Review => state.plan.as_ref().map_or(0, |plan| plan.roots.len()),
_ => 1,
};
let height = (item_count as u16 + 5).clamp(7, 20);
let [area] = Layout::vertical([Constraint::Length(height)])
.flex(Flex::Center)
.areas(frame.area());
let [area] = Layout::horizontal([Constraint::Percentage(62)])
.flex(Flex::Center)
.areas(area);
frame.render_widget(Clear, area);
let (title, footer) = match state.phase {
Phase::Checking => (" Check for updates ", " [Esc] close "),
Phase::Conflicts => (
" Resolve update conflicts ",
" [j/k] select [Space] keep/retry [Enter] continue [Esc] close ",
),
Phase::Review => (
" Update installed content ",
" [Enter] update all [Esc] close ",
),
Phase::Applying => (" Updating installed content ", " Please wait "),
};
let block = Block::default()
.title(title)
.title_bottom(Line::from(footer).centered())
.borders(Borders::ALL)
.border_type(BORDER_STYLE.to_border_type())
.border_style(Style::default().fg(theme.accent()))
.style(Style::default().fg(theme.text()).bg(theme.surface()));
match state.phase {
Phase::Checking | Phase::Applying => {
let message = if state.phase == Phase::Checking {
"Checking compatible versions and dependencies…"
} else {
"Installing the accepted update set…"
};
frame.render_widget(Paragraph::new(message).block(block), area);
}
Phase::Conflicts => {
let items = state
.plan
.as_ref()
.into_iter()
.flat_map(|plan| plan.conflicts.iter())
.enumerate()
.map(|(index, conflict)| {
let action = if state.retry_conflicts.get(index) == Some(&true) {
"Retry"
} else {
"Keep"
};
ListItem::new(vec![
Line::from(vec![
Span::styled(
conflict.title.clone(),
Style::default().add_modifier(Modifier::BOLD),
),
Span::raw(" "),
Span::styled(action, Style::default().fg(theme.accent())),
]),
Line::from(conflict.reason.clone())
.style(Style::default().fg(theme.text_dim())),
])
});
let mut selected = ListState::default().with_selected(Some(state.selected));
let list = List::new(items)
.block(block)
.highlight_symbol("▌")
.highlight_style(Style::default().bg(theme.stripe()));
frame.render_stateful_widget(list, area, &mut selected);
}
Phase::Review => {
let mut items = state
.plan
.as_ref()
.into_iter()
.flat_map(|plan| plan.roots.iter())
.map(|root| {
ListItem::new(Line::from(format!(
"• {} {} → {}",
root.title, root.current_version, root.target.version_number
)))
})
.collect::<Vec<_>>();
if items.is_empty() {
items.push(ListItem::new("No compatible updates available."));
}
if let Some(error) = &state.error {
items.push(ListItem::new(
Line::from(error.clone()).style(Style::default().fg(theme.error())),
));
}
frame.render_widget(List::new(items).block(block), area);
}
}
}