fix(content): refresh installed provider metadata

This commit is contained in:
objz committed 2026-08-05 15:25:07 +02:00
1 parent 2d0007de52
commit ae7a2de19d
17 files changed
+310 -103

No files matched your search

+1
View File
@@ -337,6 +337,7 @@ fn build_records(
project: item.identity(),
},
provider_aliases: item.provider_aliases.clone(),
provider_checks: vec![item.provider.clone()],
required_dependencies: item.required_dependencies.clone(),
automatic_dependency: item.automatic_dependency,
cleanup_eligible: item.cleanup_eligible,
+2
View File
@@ -90,6 +90,8 @@ pub struct ContentFileRecord {
#[serde(default)]
pub provider_aliases: Vec<ProviderProject>,
#[serde(default)]
pub provider_checks: Vec<String>,
#[serde(default)]
pub required_dependencies: Vec<ProviderProject>,
#[serde(default)]
pub automatic_dependency: bool,
+74 -30
View File
@@ -15,6 +15,7 @@ use crate::storage::InstancePaths;
#[derive(Debug)]
pub struct ReconcileResult {
pub instance_name: String,
pub instance_created: chrono::DateTime<chrono::Utc>,
pub manifest: ContentManifest,
pub error: Option<String>,
}
@@ -32,17 +33,17 @@ struct ReconcileJob {
#[derive(Default)]
struct ReconcileCoordinator {
queue: VecDeque<ReconcileJob>,
scheduled: HashSet<String>,
rerun: HashSet<String>,
scheduled: HashSet<(String, chrono::DateTime<chrono::Utc>)>,
rerun: HashSet<(String, chrono::DateTime<chrono::Utc>)>,
worker_running: bool,
}
impl ReconcileCoordinator {
fn enqueue(&mut self, job: ReconcileJob, rerun_if_scheduled: bool) -> bool {
let instance_name = job.instance.name.clone();
if !self.scheduled.insert(instance_name.clone()) {
let instance = (job.instance.name.clone(), job.instance.created);
if !self.scheduled.insert(instance.clone()) {
if rerun_if_scheduled {
self.rerun.insert(instance_name);
self.rerun.insert(instance);
}
return false;
}
@@ -112,18 +113,21 @@ async fn reconcile_worker() {
}
}
};
let instance_name = job.instance.name.clone();
let instance = (job.instance.name.clone(), job.instance.created);
let rerun_job = job.clone();
let result = reconcile(job, &task).await;
if let Ok(mut results) = PENDING_RECONCILIATIONS.lock() {
results.retain(|pending| pending.instance_name != instance_name);
results.retain(|pending| {
(pending.instance_name.as_str(), pending.instance_created)
!= (instance.0.as_str(), instance.1)
});
results.push(result);
}
if let Ok(mut coordinator) = RECONCILE_COORDINATOR.lock() {
if coordinator.rerun.remove(&instance_name) {
if coordinator.rerun.remove(&instance) {
coordinator.queue.push_back(rerun_job);
} else {
coordinator.scheduled.remove(&instance_name);
coordinator.scheduled.remove(&instance);
}
}
crate::feedback::request_redraw();
@@ -137,6 +141,7 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
client,
} = job;
let instance_name = instance.name;
let instance_created = instance.created;
task.set_action(format!("Checking content for {instance_name}"));
task.set_sub_action("Reading saved content index");
task.set_progress(0, 1);
@@ -183,11 +188,13 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
) {
Ok(manifest) => ReconcileResult {
instance_name,
instance_created,
manifest,
error: None,
},
Err(error) => ReconcileResult {
instance_name,
instance_created,
manifest: ContentManifest::default(),
error: Some(error.to_string()),
},
@@ -200,6 +207,7 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
);
ReconcileResult {
instance_name,
instance_created,
manifest: saved.unwrap_or_default(),
error: Some(error.to_string()),
}
@@ -208,11 +216,13 @@ async fn reconcile(job: ReconcileJob, task: &ProgressTask) -> ReconcileResult {
}
Ok(Err(error)) => ReconcileResult {
instance_name,
instance_created,
manifest: ContentManifest::default(),
error: Some(error.to_string()),
},
Err(error) => ReconcileResult {
instance_name,
instance_created,
manifest: ContentManifest::default(),
error: Some(error.to_string()),
},
@@ -330,6 +340,7 @@ fn reconcile_inventory(
providers: Vec::new(),
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -351,6 +362,7 @@ fn reconcile_inventory(
providers: Vec::new(),
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -363,6 +375,7 @@ fn reconcile_inventory(
fingerprint: fingerprint(&path)?,
resolution: Resolution::Pending,
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -377,9 +390,13 @@ fn reconcile_inventory(
providers: Vec::new(),
};
}
let curseforge_unchecked = crate::net::curseforge::api_key().is_some()
&& provider_was_not_checked(&record.resolution, "curseforge");
if !is_directory && !oversized && curseforge_unchecked {
let provider_unchecked = ["modrinth", "curseforge"].into_iter().any(|provider| {
crate::config::SETTINGS
.content
.discovery_provider_enabled(provider)
&& provider_was_not_checked(&record, provider)
});
if !is_directory && !oversized && provider_unchecked {
if record.fingerprint.hash("curseforge").is_none() {
record.fingerprint = fingerprint(&path)?;
}
@@ -408,12 +425,23 @@ fn reconcile_inventory(
Ok(Inventory { manifest, queries })
}
fn provider_was_not_checked(resolution: &Resolution, provider: &str) -> bool {
matches!(
resolution,
fn provider_was_not_checked(record: &ContentFileRecord, provider: &str) -> bool {
let identified = record
.resolved_project()
.into_iter()
.chain(record.provider_aliases.iter())
.any(|project| project.provider == provider);
let checked_as_unmatched = matches!(
&record.resolution,
Resolution::Unmatched { providers, .. }
if !providers.iter().any(|checked| checked == provider)
)
if providers.iter().any(|checked| checked == provider)
);
!identified
&& !checked_as_unmatched
&& !record
.provider_checks
.iter()
.any(|checked| checked == provider)
}
async fn resolve_queries(
@@ -474,29 +502,45 @@ async fn resolve_queries(
continue;
}
let candidates = matches.remove(key.as_ref()).unwrap_or_default();
record.resolution = match candidates.as_slice() {
[] => Resolution::Unmatched {
checked_at,
providers: checked.clone(),
},
[project] => Resolution::Resolved {
project: project.clone(),
},
let (resolution, aliases) = match candidates.as_slice() {
[] => (
Resolution::Unmatched {
checked_at,
providers: checked.clone(),
},
Vec::new(),
),
[project] => (
Resolution::Resolved {
project: project.clone(),
},
Vec::new(),
),
_ if !crate::config::SETTINGS.content.ask_on_provider_conflict => {
let preferred = crate::config::SETTINGS.content.preferred_provider();
if let Some(project) = candidates
.iter()
.find(|project| project.provider == preferred)
{
Resolution::Resolved {
project: project.clone(),
}
(
Resolution::Resolved {
project: project.clone(),
},
candidates
.iter()
.filter(|candidate| *candidate != project)
.cloned()
.collect(),
)
} else {
Resolution::Ambiguous { candidates }
(Resolution::Ambiguous { candidates }, Vec::new())
}
}
_ => Resolution::Ambiguous { candidates },
_ => (Resolution::Ambiguous { candidates }, Vec::new()),
};
record.resolution = resolution;
record.provider_aliases = aliases;
record.provider_checks.clone_from(&checked);
}
Ok(())
}
+4
View File
@@ -35,6 +35,7 @@ pub struct UpdateCheckFailure {
pub struct PendingUpdateSnapshot {
pub instance_name: String,
pub instance_created: chrono::DateTime<chrono::Utc>,
pub snapshot: UpdateSnapshot,
}
@@ -106,6 +107,7 @@ pub fn spawn(instance: InstanceConfig, manifest: ContentManifest, path: std::pat
if let Ok(mut pending) = PENDING_UPDATE_SNAPSHOTS.lock() {
pending.push(PendingUpdateSnapshot {
instance_name: instance.name,
instance_created: instance.created,
snapshot,
});
crate::feedback::request_redraw();
@@ -419,6 +421,7 @@ mod tests {
},
resolution: crate::instance::Resolution::Resolved { project },
provider_aliases: Vec::new(),
provider_checks: vec!["modrinth".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -454,6 +457,7 @@ mod tests {
project: installed.clone(),
},
provider_aliases: Vec::new(),
provider_checks: vec!["modrinth".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: true,
cleanup_eligible: true,
+1
View File
@@ -403,6 +403,7 @@ fn seed_content_manifest(
},
},
provider_aliases: Vec::new(),
provider_checks: vec!["modrinth".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -278,6 +278,7 @@ fn installed_record(project_id: &str, version_id: &str, enabled: bool) -> Conten
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -823,6 +824,7 @@ async fn exact_cross_provider_match_replaces_only_the_wrong_version() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -946,6 +948,7 @@ async fn installed_incompatible_projects_block_the_plan() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
+3
View File
@@ -36,6 +36,7 @@ fn manifest_round_trip_and_lookup_are_exact() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -89,6 +90,7 @@ fn renaming_a_record_preserves_its_resolution() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -129,6 +131,7 @@ fn managed_record(
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies,
automatic_dependency,
cleanup_eligible: automatic_dependency,
+41 -8
View File
@@ -15,7 +15,7 @@ fn job(name: &str) -> ReconcileJob {
game_version: "1.21.1".to_owned(),
loader: crate::instance::ModLoader::Fabric,
loader_version: None,
created: chrono::Utc::now(),
created: chrono::DateTime::UNIX_EPOCH,
last_played: None,
java_path: None,
memory_max: None,
@@ -33,17 +33,30 @@ fn job(name: &str) -> ReconcileJob {
#[test]
fn coordinator_queues_instances_once_and_preserves_order() {
let mut coordinator = ReconcileCoordinator::default();
let one = ("one".to_owned(), chrono::DateTime::UNIX_EPOCH);
assert!(coordinator.enqueue(job("one"), false));
assert!(!coordinator.enqueue(job("two"), false));
assert!(!coordinator.enqueue(job("one"), false));
assert!(!coordinator.rerun.contains("one"));
assert!(!coordinator.rerun.contains(&one));
assert!(!coordinator.enqueue(job("one"), true));
assert_eq!(coordinator.queue.len(), 2);
assert!(coordinator.rerun.contains("one"));
assert!(coordinator.rerun.contains(&one));
assert_eq!(coordinator.queue.pop_front().unwrap().instance.name, "one");
assert_eq!(coordinator.queue.pop_front().unwrap().instance.name, "two");
}
#[test]
fn coordinator_does_not_merge_recreated_instances_with_the_same_name() {
let mut coordinator = ReconcileCoordinator::default();
let first = job("same");
let mut recreated = job("same");
recreated.instance.created += chrono::TimeDelta::seconds(1);
assert!(coordinator.enqueue(first, false));
assert!(!coordinator.enqueue(recreated, false));
assert_eq!(coordinator.queue.len(), 2);
}
#[test]
fn oversized_content_is_kept_without_hashing_or_provider_query() {
let temp = tempfile::tempdir().unwrap();
@@ -92,13 +105,33 @@ fn unchanged_saved_index_reuses_fingerprint_and_skips_provider_query() {
#[test]
fn newly_configured_provider_retries_an_unmatched_record() {
let resolution = Resolution::Unmatched {
checked_at: chrono::Utc::now().timestamp(),
providers: vec!["modrinth".to_owned()],
let mut record = ContentFileRecord {
relative_path: PathBuf::from("mods/example.jar"),
kind: ContentKind::Mod,
enabled: true,
fingerprint: FileFingerprint {
size: 1,
modified_ns: 1,
hashes: Default::default(),
},
resolution: Resolution::Resolved {
project: ProviderProject {
provider: "modrinth".to_owned(),
project_id: "example".to_owned(),
version_id: "1".to_owned(),
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
};
assert!(provider_was_not_checked(&resolution, "curseforge"));
assert!(!provider_was_not_checked(&resolution, "modrinth"));
assert!(provider_was_not_checked(&record, "curseforge"));
assert!(!provider_was_not_checked(&record, "modrinth"));
record.provider_checks.push("curseforge".to_owned());
assert!(!provider_was_not_checked(&record, "curseforge"));
}
#[test]
+1 -1
View File
@@ -49,7 +49,7 @@ pub struct App {
pub(super) throbber_tick: u8,
pub(super) error_effects: HashMap<u64, ErrorEffectState>,
pub(super) pending_editor: Option<std::path::PathBuf>,
pub(super) reconciliation_for: Option<String>,
pub(super) reconciliation_for: Option<(String, chrono::DateTime<chrono::Utc>)>,
pub(super) content_manifest: Option<(String, crate::instance::ContentManifest)>,
pub(super) content_update_snapshot:
Option<(String, crate::instance::content::updates::UpdateSnapshot)>,
+57 -12
View File
@@ -284,10 +284,11 @@ impl App {
self.content_manifest = None;
return;
};
if !changed && self.reconciliation_for.as_deref() == Some(instance.name.as_str()) {
let instance_id = (instance.name.clone(), instance.created);
if !changed && self.reconciliation_for.as_ref() == Some(&instance_id) {
return;
}
let instance_changed = self.reconciliation_for.as_deref() != Some(instance.name.as_str());
let instance_changed = self.reconciliation_for.as_ref() != Some(&instance_id);
if instance_changed {
self.provider_conflict = None;
self.dismissed_provider_conflicts.clear();
@@ -308,7 +309,7 @@ impl App {
);
}
}
self.reconciliation_for = Some(instance.name.clone());
self.reconciliation_for = Some(instance_id);
if changed {
crate::instance::content::reconcile::spawn_after_change(
instance,
@@ -329,16 +330,25 @@ impl App {
return;
};
let result = match crate::instance::content::reconcile::PENDING_RECONCILIATIONS.lock() {
Ok(mut results) => results
.iter()
.position(|result| result.instance_name == selected.name)
.map(|index| results.remove(index)),
Ok(mut results) => {
results.retain(|result| {
result.instance_name != selected.name
|| result.instance_created == selected.created
});
results
.iter()
.position(|result| {
result.instance_name == selected.name
&& result.instance_created == selected.created
})
.map(|index| results.remove(index))
}
Err(_) => return,
};
let Some(result) = result else {
return;
};
self.reconciliation_for = Some(result.instance_name.clone());
self.reconciliation_for = Some((result.instance_name.clone(), result.instance_created));
if let Some(error) = result.error {
tracing::warn!(
"Content reconciliation for {} was incomplete: {}",
@@ -443,10 +453,19 @@ impl App {
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)),
Ok(mut pending) => {
pending.retain(|pending| {
pending.instance_name != selected.name
|| pending.instance_created == selected.created
});
pending
.iter()
.rposition(|pending| {
pending.instance_name == selected.name
&& pending.instance_created == selected.created
})
.map(|index| pending.remove(index))
}
Err(_) => return,
};
let Some(snapshot) = snapshot else {
@@ -771,12 +790,38 @@ impl App {
fn drain_pending_instances(&mut self) {
if let Ok(mut pending) = PENDING_INSTANCES.lock() {
for config in pending.drain(..) {
self.forget_instance_content(&config.name);
widgets::instances::spawn_modpack_update_check(&config);
self.instances_state.add_instance(config);
}
}
}
pub(super) fn forget_instance_content(&mut self, instance_name: &str) {
for state in [
&mut self.mods_state,
&mut self.resource_packs_state,
&mut self.shaders_state,
&mut self.worlds_state,
&mut self.world_datapacks_state,
] {
state.forget_instance(instance_name);
}
if self.logs_state.loaded_for.as_deref() == Some(instance_name) {
self.logs_state.loaded_for = None;
}
if self.screenshots_state.loaded_for.as_deref() == Some(instance_name) {
self.screenshots_state.loaded_for = None;
}
self.reconciliation_for = None;
self.content_manifest = None;
self.content_update_snapshot = None;
self.content_update_popup = None;
self.provider_conflict = None;
self.dismissed_provider_conflicts.clear();
self.apply_content_update_snapshot();
}
fn drain_pending_last_played(&mut self) {
for (name, time) in crate::instance::runtime::drain_last_played() {
for inst in &mut self.instances_state.instances {
+10
View File
@@ -84,6 +84,13 @@ impl App {
KeyCode::Enter => {
let relative_path = conflict.relative_path.clone();
let project = conflict.candidates.get(conflict.selected).cloned();
let aliases = conflict
.candidates
.iter()
.enumerate()
.filter(|(index, _)| *index != conflict.selected)
.map(|(_, candidate)| candidate.clone())
.collect::<Vec<_>>();
if let Some(project) = project
&& let Some((instance_name, _)) = &self.content_manifest
{
@@ -100,6 +107,7 @@ impl App {
{
record.resolution =
crate::instance::Resolution::Resolved { project };
record.provider_aliases = aliases;
}
Ok(manifest.clone())
})?;
@@ -180,6 +188,7 @@ impl App {
match self.instance_manager.delete(&name) {
Ok(_) => {
self.instances_state.remove_instance(&name);
self.forget_instance_content(&name);
}
Err(e) => {
tracing::error!("Failed to delete instance '{}': {}", name, e);
@@ -1473,6 +1482,7 @@ impl App {
},
},
provider_aliases: Vec::new(),
provider_checks: vec![request.provider.clone()],
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
+11 -1
View File
@@ -28,7 +28,14 @@ fn completed_background_instance_is_drained_into_the_ui() {
let mut ui = UiHarness::new();
ui.add_instance("Existing");
ui.add_instance("Pending");
let config = ui.app.instances_state.instances.pop().unwrap();
let mut config = ui.app.instances_state.instances.pop().unwrap();
ui.app.mods_state.loaded_for = Some("Pending".to_owned());
ui.app.reconciliation_for = Some(("Pending".to_owned(), config.created));
ui.app.content_manifest = Some((
"Pending".to_owned(),
crate::instance::ContentManifest::default(),
));
config.created += chrono::TimeDelta::seconds(1);
ui.app.instances_state.list_state.selected = Some(0);
PENDING_INSTANCES.lock().unwrap().push(config);
@@ -39,6 +46,9 @@ fn completed_background_instance_is_drained_into_the_ui() {
"Pending"
);
assert!(PENDING_INSTANCES.lock().unwrap().is_empty());
assert!(ui.app.reconciliation_for.is_none());
assert!(ui.app.content_manifest.is_none());
assert!(ui.app.mods_state.loaded_for.is_none());
ui.draw();
assert_eq!(ui.app.mods_state.loaded_for.as_deref(), Some("Pending"));
+10
View File
@@ -222,6 +222,7 @@ fn managed_mod_record(
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies,
automatic_dependency,
cleanup_eligible: automatic_dependency,
@@ -466,6 +467,7 @@ fn provider_conflict_selection_is_persisted() {
candidates: candidates.clone(),
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -491,4 +493,12 @@ fn provider_conflict_selection_is_persisted() {
crate::instance::Resolution::Resolved { project }
if project.provider == "curseforge" && project.project_id == "second"
));
assert_eq!(
saved.record(&relative_path).unwrap().provider_aliases,
vec![ProviderProject {
provider: "modrinth".to_owned(),
project_id: "first".to_owned(),
version_id: "1".to_owned(),
}]
);
}
+31 -2
View File
@@ -323,6 +323,7 @@ fn datapack_versions_select_a_world_before_dependency_resolution() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -437,6 +438,7 @@ fn installed_version_popup_tracks_current_version_and_reinstalls_it() {
project_id: "42".to_owned(),
version_id: "84".to_owned(),
}],
provider_checks: vec!["modrinth".to_owned(), "curseforge".to_owned()],
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
@@ -445,15 +447,22 @@ fn installed_version_popup_tracks_current_version_and_reinstalls_it() {
let request = state
.begin_installed_versions(&entry, &record, None)
.unwrap();
assert_eq!(request.current_version_id.as_deref(), Some("current"));
let first_provider = request.provider.clone();
let first_version = request.current_version_id.clone().unwrap();
assert_eq!(state.version_popup.as_ref().unwrap().sources.len(), 2);
state.version_popup.as_mut().unwrap().loading = false;
state.version_popup.as_mut().unwrap().versions = vec![version("current")];
state.version_popup.as_mut().unwrap().versions = vec![version(&first_version)];
assert_eq!(
state.version_popup.as_ref().unwrap().title(),
"Reinstall Project"
);
let switched = state.switch_version_source().unwrap();
assert_ne!(switched.provider, first_provider);
let switched_version = switched.current_version_id.clone().unwrap();
state.version_popup.as_mut().unwrap().loading = false;
state.version_popup.as_mut().unwrap().versions = vec![version(&switched_version)];
let request = state.begin_dependency_resolution().unwrap();
assert!(request.root.force_reinstall);
}
@@ -882,10 +891,30 @@ fn installed_labels_follow_exact_manifest_projects() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
});
let mut sources = vec![(
"example-project".to_owned(),
crate::instance::ProviderProject {
provider: "modrinth".to_owned(),
project_id: "project-id".to_owned(),
version_id: String::new(),
},
)];
refresh_source_installed_versions(
&mut sources,
&DiscoveryTarget::Content(Box::new(ContentDiscoveryTarget {
instance: instance("test", "1.21.1"),
kind: ContentKind::Mod,
manifest: Some(manifest.clone()),
minecraft_dir: PathBuf::from("first"),
})),
);
assert_eq!(sources[0].1.version_id, "version");
state.refresh_installed_manifest(&manifest, std::path::Path::new("first"));
assert_eq!(
state.list.entries[0].title_suffix.as_deref(),
+1
View File
@@ -665,6 +665,7 @@ fn manifest_metadata_keeps_an_embedded_icon_renderer() {
},
},
provider_aliases: Vec::new(),
provider_checks: Vec::new(),
required_dependencies: Vec::new(),
automatic_dependency: false,
cleanup_eligible: false,
+47 -49
View File
@@ -172,11 +172,12 @@ pub(crate) fn spawn_provider_search(
if let Some(Ok(results)) = curseforge_result {
pages.push(("curseforge", results));
}
let merged = merge_provider_results(
let mut merged = merge_provider_results(
pages,
crate::config::SETTINGS.content.preferred_provider(),
known_projects,
);
refresh_source_installed_versions(&mut merged.sources, &target);
let mut returned = std::collections::HashSet::new();
let icon_slots = Arc::new(tokio::sync::Semaphore::new(8));
for merged_project in merged.projects {
@@ -726,53 +727,16 @@ impl DiscoveryState {
.list_state
.selected
.and_then(|selected| filtered.get(selected))?;
let entry = self.list.entries.get(*index)?;
let entry = self.list.entries.get(*index)?.clone();
let installed_path = (self.kind != ContentKind::DataPack)
.then(|| entry.installed_path.clone())
.flatten();
let mut sources = self
let sources = self
.sources
.get(&entry.file_stem)
.cloned()
.unwrap_or_else(|| entry.provider_project.clone().into_iter().collect());
let preferred = crate::config::SETTINGS.content.preferred_provider();
sources.sort_by_key(|source| source.provider != preferred);
let source = sources.first()?.clone();
let project_id = source.project_id.clone();
let current_version_id = (!source.version_id.is_empty()).then(|| source.version_id.clone());
self.next_action_request_id = self.next_action_request_id.wrapping_add(1);
let request_id = self.next_action_request_id;
self.version_popup = Some(VersionPopupState {
request_id,
project_id: project_id.clone(),
provider: source.provider.clone(),
project_title: entry.name.clone(),
sources,
source_index: 0,
installed_path,
current_version_id: current_version_id.clone(),
minecraft_versions: Vec::new(),
selected_minecraft_version: None,
selecting_minecraft_version: self.modpacks,
selecting_world: false,
worlds: ContentListState::default(),
target_world: None,
versions: Vec::new(),
selected: 0,
loading: true,
resolving_dependencies: false,
confirming: false,
installing: false,
dependency_plan: None,
error: None,
});
Some(VersionsRequest {
request_id,
project_id,
provider: source.provider,
current_version_id,
pending: self.pending_actions.clone(),
})
self.open_version_popup(&entry, sources, installed_path, None)
}
pub fn begin_installed_versions(
@@ -807,20 +771,34 @@ impl DiscoveryState {
}
}
}
self.open_version_popup(entry, sources, Some(entry.path.clone()), target_world)
}
fn open_version_popup(
&mut self,
entry: &ContentEntry,
mut sources: Vec<crate::instance::ProviderProject>,
installed_path: Option<PathBuf>,
target_world: Option<(String, PathBuf)>,
) -> Option<VersionsRequest> {
let preferred = crate::config::SETTINGS.content.preferred_provider();
sources.sort_by_key(|source| source.provider != preferred);
let source = sources.first()?.clone();
self.next_action_request_id = self.next_action_request_id.wrapping_add(1);
let request_id = self.next_action_request_id;
let current_version_id = (!source.version_id.is_empty()).then(|| source.version_id.clone());
self.version_popup = Some(VersionPopupState {
request_id,
project_id: current.project_id.clone(),
provider: current.provider.clone(),
project_id: source.project_id.clone(),
provider: source.provider.clone(),
project_title: entry.name.clone(),
sources,
source_index: 0,
installed_path: Some(entry.path.clone()),
current_version_id: Some(current.version_id.clone()),
installed_path,
current_version_id: current_version_id.clone(),
minecraft_versions: Vec::new(),
selected_minecraft_version: None,
selecting_minecraft_version: false,
selecting_minecraft_version: self.modpacks,
selecting_world: false,
worlds: ContentListState::default(),
target_world,
@@ -835,9 +813,9 @@ impl DiscoveryState {
});
Some(VersionsRequest {
request_id,
project_id: current.project_id,
provider: current.provider,
current_version_id: Some(current.version_id),
project_id: source.project_id,
provider: source.provider,
current_version_id,
pending: self.pending_actions.clone(),
})
}
@@ -1809,6 +1787,26 @@ pub(crate) fn merge_provider_results(
}
}
fn refresh_source_installed_versions(
sources: &mut [(String, crate::instance::ProviderProject)],
target: &DiscoveryTarget,
) {
let DiscoveryTarget::Content(content) = target else {
return;
};
let Some(manifest) = &content.manifest else {
return;
};
for (_, source) in sources {
source.version_id = manifest
.files
.iter()
.find_map(|record| record.project_for_provider(&source.provider, &source.project_id))
.map(|installed| installed.version_id.clone())
.unwrap_or_default();
}
}
fn format_downloads(downloads: u64) -> String {
match downloads {
1_000_000.. => format!("{:.1}M", downloads as f64 / 1_000_000.0),
+13
View File
@@ -1151,6 +1151,19 @@ impl ContentListState {
}
impl ContentListState {
pub fn forget_instance(&mut self, instance_name: &str) {
let world_prefix = format!("{instance_name}:");
self.cache
.retain(|source, _| source != instance_name && !source.starts_with(&world_prefix));
if self
.loaded_for
.as_deref()
.is_some_and(|source| source == instance_name || source.starts_with(&world_prefix))
{
self.loaded_for = None;
}
}
// saves current entries to cache before loading new ones, and restores
// from cache if this instance was seen before (avoids re-scanning).
// content_dir is the actual directory to scan (e.g. .minecraft/mods).