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
@@ -80,6 +80,17 @@ impl DiscoveryKind {
|
|||||||
Self::Shader => "shader",
|
Self::Shader => "shader",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unavailable_message(self, loader: ModLoader) -> Option<&'static str> {
|
||||||
|
if loader != ModLoader::Vanilla {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
match self {
|
||||||
|
Self::Mod => Some("Vanilla does not support mods."),
|
||||||
|
Self::Shader => Some("Vanilla does not support shaders."),
|
||||||
|
Self::ResourcePack => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
@@ -589,6 +600,26 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn vanilla_discovery_only_supports_resource_packs() {
|
||||||
|
assert_eq!(
|
||||||
|
DiscoveryKind::Mod.unavailable_message(ModLoader::Vanilla),
|
||||||
|
Some("Vanilla does not support mods.")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
DiscoveryKind::Shader.unavailable_message(ModLoader::Vanilla),
|
||||||
|
Some("Vanilla does not support shaders.")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
DiscoveryKind::ResourcePack.unavailable_message(ModLoader::Vanilla),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
DiscoveryKind::Mod.unavailable_message(ModLoader::Fabric),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn compatible_mod_versions_filter_by_game_and_loader() {
|
fn compatible_mod_versions_filter_by_game_and_loader() {
|
||||||
let url = content_versions_url(
|
let url = content_versions_url(
|
||||||
|
|||||||
+16
-14
@@ -632,21 +632,15 @@ impl App {
|
|||||||
let Some(instance) = self.instances_state.selected_instance().cloned() else {
|
let Some(instance) = self.instances_state.selected_instance().cloned() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let (needs_search, search_due) = match self.content_tab {
|
let Some(state) = self.active_discovery_state_mut() else {
|
||||||
widgets::content::ContentTab::Mods => (
|
return;
|
||||||
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),
|
|
||||||
};
|
};
|
||||||
|
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 {
|
if needs_search || search_due {
|
||||||
self.spawn_active_discovery_search();
|
self.spawn_active_discovery_search();
|
||||||
} else {
|
} else {
|
||||||
@@ -996,6 +990,10 @@ impl App {
|
|||||||
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
if state.unavailable_message(&instance).is_some() {
|
||||||
|
state.set_unavailable(&instance);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let kind = state.kind;
|
let kind = state.kind;
|
||||||
let query = state.search.query.clone();
|
let query = state.search.query.clone();
|
||||||
let request = state.begin_search(&instance);
|
let request = state.begin_search(&instance);
|
||||||
@@ -1031,6 +1029,10 @@ impl App {
|
|||||||
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
if state.unavailable_message(&instance).is_some() {
|
||||||
|
state.set_unavailable(&instance);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let kind = state.kind;
|
let kind = state.kind;
|
||||||
let query = state.search.query.clone();
|
let query = state.search.query.clone();
|
||||||
let Some(request) = state.begin_next_page() else {
|
let Some(request) = state.begin_next_page() else {
|
||||||
|
|||||||
@@ -215,6 +215,22 @@ impl DiscoveryState {
|
|||||||
self.context.as_deref() != Some(discovery_context(instance).as_str())
|
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 {
|
pub fn begin_search(&mut self, instance: &InstanceConfig) -> DiscoveryRequest {
|
||||||
self.generation = self.generation.wrapping_add(1);
|
self.generation = self.generation.wrapping_add(1);
|
||||||
self.project_page = None;
|
self.project_page = None;
|
||||||
@@ -1252,6 +1268,31 @@ mod tests {
|
|||||||
assert!(state.needs_search(&second));
|
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]
|
#[test]
|
||||||
fn changing_instance_compatibility_invalidates_results() {
|
fn changing_instance_compatibility_invalidates_results() {
|
||||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||||
|
|||||||
@@ -223,11 +223,25 @@ pub fn render(
|
|||||||
ContentTab::Shaders => shaders_discovery_state.project_page_open(),
|
ContentTab::Shaders => shaders_discovery_state.project_page_open(),
|
||||||
_ => false,
|
_ => 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
|
// keybinds change depending on which tab is active and whether
|
||||||
// the content panel or instances panel has focus
|
// the content panel or instances panel has focus
|
||||||
let kb: Option<&[(&str, &str)]> = if is_focused {
|
let kb: Option<&[(&str, &str)]> = if is_focused {
|
||||||
Some(match (mode, tab) {
|
Some(match (mode, tab) {
|
||||||
|
(ContentMode::Discover, _) if discovery_unavailable => {
|
||||||
|
&[("h/l", " tabs"), ("Tab", " installed")]
|
||||||
|
}
|
||||||
(ContentMode::Discover, _) if discovery_page_open => {
|
(ContentMode::Discover, _) if discovery_page_open => {
|
||||||
&[("j/k", " scroll"), ("g/G", " top/bottom"), ("h", " back")]
|
&[("j/k", " scroll"), ("g/G", " top/bottom"), ("h", " back")]
|
||||||
}
|
}
|
||||||
@@ -347,6 +361,7 @@ pub fn render(
|
|||||||
frame,
|
frame,
|
||||||
content_area,
|
content_area,
|
||||||
mods_discovery_state,
|
mods_discovery_state,
|
||||||
|
instance,
|
||||||
is_focused,
|
is_focused,
|
||||||
"Searching Modrinth...",
|
"Searching Modrinth...",
|
||||||
picker,
|
picker,
|
||||||
@@ -390,6 +405,7 @@ pub fn render(
|
|||||||
frame,
|
frame,
|
||||||
content_area,
|
content_area,
|
||||||
resource_packs_discovery_state,
|
resource_packs_discovery_state,
|
||||||
|
instance,
|
||||||
is_focused,
|
is_focused,
|
||||||
"Searching Modrinth...",
|
"Searching Modrinth...",
|
||||||
picker,
|
picker,
|
||||||
@@ -433,6 +449,7 @@ pub fn render(
|
|||||||
frame,
|
frame,
|
||||||
content_area,
|
content_area,
|
||||||
shaders_discovery_state,
|
shaders_discovery_state,
|
||||||
|
instance,
|
||||||
is_focused,
|
is_focused,
|
||||||
"Searching Modrinth...",
|
"Searching Modrinth...",
|
||||||
picker,
|
picker,
|
||||||
@@ -533,11 +550,19 @@ fn render_discovery(
|
|||||||
frame: &mut Frame,
|
frame: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
state: &mut DiscoveryState,
|
state: &mut DiscoveryState,
|
||||||
|
instance: &crate::instance::InstanceConfig,
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
loading_text: &str,
|
loading_text: &str,
|
||||||
picker: &ratatui_image::picker::Picker,
|
picker: &ratatui_image::picker::Picker,
|
||||||
) {
|
) {
|
||||||
state.set_viewport_rows(area.height);
|
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(page) = state.project_page.as_mut() {
|
||||||
if let Some(error) = page.error.as_deref() {
|
if let Some(error) = page.error.as_deref() {
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
|
|||||||
Reference in new issue
Block a user