fix(discovery): guard unsupported vanilla content
This commit is contained in:
1 parent
23c138dc32
commit
72b8b19f52
4 files changed
+113
-14
No files matched your search
+16
-14
@@ -632,21 +632,15 @@ impl App {
|
||||
let Some(instance) = self.instances_state.selected_instance().cloned() else {
|
||||
return;
|
||||
};
|
||||
let (needs_search, search_due) = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => (
|
||||
self.mods_discovery_state.needs_search(&instance),
|
||||
self.mods_discovery_state.search_due(),
|
||||
),
|
||||
widgets::content::ContentTab::ResourcePacks => (
|
||||
self.resource_packs_discovery_state.needs_search(&instance),
|
||||
self.resource_packs_discovery_state.search_due(),
|
||||
),
|
||||
widgets::content::ContentTab::Shaders => (
|
||||
self.shaders_discovery_state.needs_search(&instance),
|
||||
self.shaders_discovery_state.search_due(),
|
||||
),
|
||||
_ => (false, false),
|
||||
let Some(state) = self.active_discovery_state_mut() else {
|
||||
return;
|
||||
};
|
||||
if state.unavailable_message(&instance).is_some() {
|
||||
state.set_unavailable(&instance);
|
||||
return;
|
||||
}
|
||||
let needs_search = state.needs_search(&instance);
|
||||
let search_due = state.search_due();
|
||||
if needs_search || search_due {
|
||||
self.spawn_active_discovery_search();
|
||||
} else {
|
||||
@@ -996,6 +990,10 @@ impl App {
|
||||
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
||||
_ => return,
|
||||
};
|
||||
if state.unavailable_message(&instance).is_some() {
|
||||
state.set_unavailable(&instance);
|
||||
return;
|
||||
}
|
||||
let kind = state.kind;
|
||||
let query = state.search.query.clone();
|
||||
let request = state.begin_search(&instance);
|
||||
@@ -1031,6 +1029,10 @@ impl App {
|
||||
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
||||
_ => return,
|
||||
};
|
||||
if state.unavailable_message(&instance).is_some() {
|
||||
state.set_unavailable(&instance);
|
||||
return;
|
||||
}
|
||||
let kind = state.kind;
|
||||
let query = state.search.query.clone();
|
||||
let Some(request) = state.begin_next_page() else {
|
||||
|
||||
@@ -215,6 +215,22 @@ impl DiscoveryState {
|
||||
self.context.as_deref() != Some(discovery_context(instance).as_str())
|
||||
}
|
||||
|
||||
pub fn unavailable_message(&self, instance: &InstanceConfig) -> Option<&'static str> {
|
||||
self.kind.unavailable_message(instance.loader)
|
||||
}
|
||||
|
||||
pub fn set_unavailable(&mut self, instance: &InstanceConfig) {
|
||||
let context = discovery_context(instance);
|
||||
if self.context.as_deref() == Some(&context) && self.list.entries.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.context = None;
|
||||
drop(self.begin_search(instance));
|
||||
self.stream = None;
|
||||
self.page_loading = false;
|
||||
self.exhausted = true;
|
||||
}
|
||||
|
||||
pub fn begin_search(&mut self, instance: &InstanceConfig) -> DiscoveryRequest {
|
||||
self.generation = self.generation.wrapping_add(1);
|
||||
self.project_page = None;
|
||||
@@ -1252,6 +1268,31 @@ mod tests {
|
||||
assert!(state.needs_search(&second));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unavailable_vanilla_discovery_clears_cached_results() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
state.list.entries.push(project_entry(
|
||||
DiscoveryProject {
|
||||
id: "cached".to_owned(),
|
||||
slug: "cached".to_owned(),
|
||||
title: "Cached".to_owned(),
|
||||
description: String::new(),
|
||||
downloads: 0,
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
},
|
||||
None,
|
||||
));
|
||||
let mut vanilla = instance("vanilla", "1.21.1");
|
||||
vanilla.loader = ModLoader::Vanilla;
|
||||
|
||||
state.set_unavailable(&vanilla);
|
||||
|
||||
assert!(state.list.entries.is_empty());
|
||||
assert!(!state.page_loading);
|
||||
assert!(state.exhausted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn changing_instance_compatibility_invalidates_results() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
|
||||
@@ -223,11 +223,25 @@ pub fn render(
|
||||
ContentTab::Shaders => shaders_discovery_state.project_page_open(),
|
||||
_ => false,
|
||||
};
|
||||
let discovery_unavailable = mode == ContentMode::Discover
|
||||
&& instance.is_some_and(|instance| match tab {
|
||||
ContentTab::Mods => mods_discovery_state.unavailable_message(instance).is_some(),
|
||||
ContentTab::ResourcePacks => resource_packs_discovery_state
|
||||
.unavailable_message(instance)
|
||||
.is_some(),
|
||||
ContentTab::Shaders => shaders_discovery_state
|
||||
.unavailable_message(instance)
|
||||
.is_some(),
|
||||
_ => false,
|
||||
});
|
||||
|
||||
// keybinds change depending on which tab is active and whether
|
||||
// the content panel or instances panel has focus
|
||||
let kb: Option<&[(&str, &str)]> = if is_focused {
|
||||
Some(match (mode, tab) {
|
||||
(ContentMode::Discover, _) if discovery_unavailable => {
|
||||
&[("h/l", " tabs"), ("Tab", " installed")]
|
||||
}
|
||||
(ContentMode::Discover, _) if discovery_page_open => {
|
||||
&[("j/k", " scroll"), ("g/G", " top/bottom"), ("h", " back")]
|
||||
}
|
||||
@@ -347,6 +361,7 @@ pub fn render(
|
||||
frame,
|
||||
content_area,
|
||||
mods_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
@@ -390,6 +405,7 @@ pub fn render(
|
||||
frame,
|
||||
content_area,
|
||||
resource_packs_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
@@ -433,6 +449,7 @@ pub fn render(
|
||||
frame,
|
||||
content_area,
|
||||
shaders_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
@@ -533,11 +550,19 @@ fn render_discovery(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
state: &mut DiscoveryState,
|
||||
instance: &crate::instance::InstanceConfig,
|
||||
is_focused: bool,
|
||||
loading_text: &str,
|
||||
picker: &ratatui_image::picker::Picker,
|
||||
) {
|
||||
state.set_viewport_rows(area.height);
|
||||
if let Some(message) = state.unavailable_message(instance) {
|
||||
frame.render_widget(
|
||||
Paragraph::new(message).style(Style::default().fg(THEME.as_ref().text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if let Some(page) = state.project_page.as_mut() {
|
||||
if let Some(error) = page.error.as_deref() {
|
||||
frame.render_widget(
|
||||
|
||||
Reference in new issue
Block a user