feat(modpacks): manage installed pack versions

This commit is contained in:
objz committed 2026-08-05 21:30:57 +02:00
1 parent 16e2f3204d
commit a839925041
13 files changed
+301 -67

No files matched your search

+17 -6
View File
@@ -393,14 +393,15 @@ pub struct VersionPopupState {
impl VersionPopupState {
pub fn title(&self) -> String {
if self.installed_path.is_some()
let installed = self.installed_path.is_some() || self.current_version_id.is_some();
if installed
&& self.current_version_id.as_deref().is_some_and(|current| {
self.selected_version()
.is_some_and(|version| version.id == current)
})
{
format!("Reinstall {}", self.project_title)
} else if self.installed_path.is_some() {
} else if installed {
format!("Change {} version", self.project_title)
} else {
format!("Install {}", self.project_title)
@@ -736,7 +737,7 @@ impl DiscoveryState {
.get(&entry.file_stem)
.cloned()
.unwrap_or_else(|| entry.provider_project.clone().into_iter().collect());
self.open_version_popup(&entry, sources, installed_path, None)
self.open_version_popup(&entry.name, sources, installed_path, None)
}
pub fn begin_installed_versions(
@@ -771,12 +772,22 @@ impl DiscoveryState {
}
}
}
self.open_version_popup(entry, sources, Some(entry.path.clone()), target_world)
self.open_version_popup(&entry.name, sources, Some(entry.path.clone()), target_world)
}
pub fn begin_managed_modpack_versions(
&mut self,
project_title: &str,
source: crate::instance::ProviderProject,
) -> Option<VersionsRequest> {
let request = self.open_version_popup(project_title, vec![source], None, None)?;
self.version_popup.as_mut()?.selecting_minecraft_version = false;
Some(request)
}
fn open_version_popup(
&mut self,
entry: &ContentEntry,
project_title: &str,
mut sources: Vec<crate::instance::ProviderProject>,
installed_path: Option<PathBuf>,
target_world: Option<(String, PathBuf)>,
@@ -791,7 +802,7 @@ impl DiscoveryState {
request_id,
project_id: source.project_id.clone(),
provider: source.provider.clone(),
project_title: entry.name.clone(),
project_title: project_title.to_owned(),
sources,
source_index: 0,
installed_path,
+11 -1
View File
@@ -157,6 +157,7 @@ pub fn render(
tab: ContentTab,
mode: ContentMode,
instance: Option<&crate::instance::InstanceConfig>,
has_modpack_update: bool,
mods_state: &mut super::list::ContentListState,
mods_discovery_state: &mut DiscoveryState,
resource_packs_state: &mut super::list::ContentListState,
@@ -420,6 +421,7 @@ pub fn render(
Some(&[
("l", " launch"),
("⏎", " content"),
("v", " versions"),
("Shift+⏎", " open dir"),
("Esc", " kill"),
("a", " add"),
@@ -440,6 +442,14 @@ pub fn render(
if is_focused && mode == ContentMode::Installed && !can_change_version {
keybinds.retain(|(key, _)| *key != "v");
}
if focused == FocusedArea::Instances
&& instance.is_none_or(|instance| instance.modpack_source.is_none())
{
keybinds.retain(|(key, _)| *key != "v");
}
if focused == FocusedArea::Instances && !has_modpack_update {
keybinds.retain(|(key, _)| *key != "u");
}
if is_focused && !keybinds.iter().any(|(key, _)| key.contains("Esc")) {
keybinds.push(("Esc", " back"));
}
@@ -768,7 +778,7 @@ fn render_discovery_body(
}
}
fn render_version_popup(
pub(crate) fn render_version_popup(
frame: &mut Frame,
area: Rect,
state: &mut DiscoveryState,
-12
View File
@@ -349,18 +349,6 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
} else {
let mut spans = vec![selector.clone()];
spans.extend(state.search.highlight_spans(&instance.name, name_style));
if state.modpack_updates.contains_key(&instance.name) {
spans.extend([
Span::raw(" "),
Span::styled(
"Update",
Style::default()
.fg(theme.background())
.bg(theme.warning())
.add_modifier(Modifier::BOLD),
),
]);
}
Line::from(spans)
};
+31 -5
View File
@@ -26,8 +26,16 @@ pub enum Phase {
Applying,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Action {
Update,
Change,
Reinstall,
}
pub struct State {
pub phase: Phase,
pub action: Action,
pub plan: Option<RefreshPlan>,
pub selected: usize,
pub replace: Vec<bool>,
@@ -37,9 +45,10 @@ pub struct State {
}
impl State {
pub fn preparing() -> Self {
pub fn preparing(action: Action) -> Self {
Self {
phase: Phase::Preparing,
action,
plan: None,
selected: 0,
replace: Vec::new(),
@@ -108,14 +117,31 @@ pub fn render(frame: &mut Frame, state: &State) {
.flex(Flex::Center)
.areas(area);
frame.render_widget(Clear, area);
let action = match state.action {
Action::Update => "update",
Action::Change => "change",
Action::Reinstall => "reinstall",
};
let (title, footer) = match state.phase {
Phase::Preparing => (" Prepare modpack update ", " [Esc] cancel "),
Phase::Preparing => match state.action {
Action::Update => (" Prepare modpack update ", " [Esc] cancel "),
Action::Change => (" Prepare modpack change ", " [Esc] cancel "),
Action::Reinstall => (" Prepare modpack reinstall ", " [Esc] cancel "),
},
Phase::Conflicts => (
" Resolve modpack conflicts ",
" [j/k] select [Space] keep/replace [Enter] continue [Esc] cancel ",
),
Phase::Review => (" Update modpack ", " [Enter] update [Esc] cancel "),
Phase::Applying => (" Updating modpack ", " Please wait "),
Phase::Review => match state.action {
Action::Update => (" Update modpack ", " [Enter] update [Esc] cancel "),
Action::Change => (" Change modpack ", " [Enter] change [Esc] cancel "),
Action::Reinstall => (" Reinstall modpack ", " [Enter] reinstall [Esc] cancel "),
},
Phase::Applying => match state.action {
Action::Update => (" Updating modpack ", " Please wait "),
Action::Change => (" Changing modpack ", " Please wait "),
Action::Reinstall => (" Reinstalling modpack ", " Please wait "),
},
};
let block = Block::default()
.title(title)
@@ -126,7 +152,7 @@ pub fn render(frame: &mut Frame, state: &State) {
.style(Style::default().fg(theme.text()).bg(theme.surface()));
match state.phase {
Phase::Preparing => frame.render_widget(
Paragraph::new("Downloading and validating the target pack…").block(block),
Paragraph::new(format!("Preparing the selected modpack {action}…")).block(block),
area,
),
Phase::Applying => frame.render_widget(