Fix discovery version popup dead end on filtered empty results
When a filtered versions fetch comes back empty, retry unfiltered and open the Minecraft version picker instead of showing No compatible versions found.
This commit is contained in:
1 parent
9c54e8f321
commit
8adadf75a8
3 files changed
+187
-41
No files matched your search
@@ -896,6 +896,13 @@ pub enum DiscoveryActionResult {
|
||||
project_id: String,
|
||||
result: Result<Vec<VersionInfo>, String>,
|
||||
},
|
||||
/// The filtered fetch found nothing, so the task retried unfiltered.
|
||||
/// Drain opens the Minecraft version picker instead of a dead end.
|
||||
VersionsUnfiltered {
|
||||
request_id: u64,
|
||||
project_id: String,
|
||||
result: Result<Vec<VersionInfo>, String>,
|
||||
},
|
||||
Dependencies {
|
||||
request_id: u64,
|
||||
project_id: String,
|
||||
@@ -2547,6 +2554,35 @@ impl DiscoveryState {
|
||||
Err(error) => popup.error = Some(error),
|
||||
}
|
||||
}
|
||||
DiscoveryActionResult::VersionsUnfiltered {
|
||||
request_id,
|
||||
project_id,
|
||||
result,
|
||||
} => {
|
||||
let Some(popup) = self.version_popup.as_mut().filter(|popup| {
|
||||
popup.request_id == request_id && popup.project_id == project_id
|
||||
}) else {
|
||||
continue;
|
||||
};
|
||||
popup.loading = false;
|
||||
match result {
|
||||
Ok(versions) if !versions.is_empty() => {
|
||||
popup.all_game_versions = true;
|
||||
popup.selecting_minecraft_version = true;
|
||||
popup.minecraft_versions = minecraft_versions(&versions);
|
||||
popup.versions = versions;
|
||||
popup.selected = 0;
|
||||
popup.error = None;
|
||||
}
|
||||
Ok(_) => {
|
||||
popup.minecraft_versions = Vec::new();
|
||||
popup.versions = Vec::new();
|
||||
popup.selected = 0;
|
||||
popup.error = None;
|
||||
}
|
||||
Err(error) => popup.error = Some(error),
|
||||
}
|
||||
}
|
||||
DiscoveryActionResult::Dependencies {
|
||||
request_id,
|
||||
project_id,
|
||||
@@ -3016,6 +3052,29 @@ fn loader_slug(loader: ModLoader) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// One popup version fetch: compatible versions for `game_version`
|
||||
/// (empty means unfiltered) plus the installed version when missing.
|
||||
pub async fn fetch_popup_versions(
|
||||
provider: &dyn crate::instance::content::provider::ContentProvider,
|
||||
project_id: &str,
|
||||
kind: ContentKind,
|
||||
game_version: &str,
|
||||
loader: ModLoader,
|
||||
current_version_id: Option<&str>,
|
||||
) -> Result<Vec<VersionInfo>, String> {
|
||||
let mut versions = provider
|
||||
.compatible_versions(project_id, kind, game_version, loader)
|
||||
.await
|
||||
.map_err(|error| error.to_string())?;
|
||||
if let Some(current) = current_version_id
|
||||
&& !versions.iter().any(|version| version.id == current)
|
||||
&& let Ok(version) = provider.version(current).await
|
||||
{
|
||||
versions.push(version);
|
||||
}
|
||||
Ok(versions)
|
||||
}
|
||||
|
||||
pub(crate) fn provider_project_entry(
|
||||
project: DiscoveryProject,
|
||||
provider: &str,
|
||||
|
||||
Reference in new issue
Block a user