refactor: clarify content and tui ownership
This commit is contained in:
1 parent
078afe4b9d
commit
15d76c18a0
32 files changed
+893
-1144
No files matched your search
+3
-3
@@ -112,15 +112,15 @@ impl App {
|
||||
instances_state,
|
||||
mods_state,
|
||||
mods_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::net::modrinth::DiscoveryKind::Mod,
|
||||
crate::instance::ContentKind::Mod,
|
||||
),
|
||||
resource_packs_state,
|
||||
resource_packs_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::net::modrinth::DiscoveryKind::ResourcePack,
|
||||
crate::instance::ContentKind::ResourcePack,
|
||||
),
|
||||
shaders_state,
|
||||
shaders_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::net::modrinth::DiscoveryKind::Shader,
|
||||
crate::instance::ContentKind::Shader,
|
||||
),
|
||||
worlds_state: widgets::content::list::ContentListState::default(),
|
||||
logs_state: widgets::logs_viewer::LogsState::default(),
|
||||
|
||||
+23
-48
@@ -34,45 +34,29 @@ impl App {
|
||||
// get scanned/loaded on separate tokio tasks
|
||||
self.drain_pending_instances();
|
||||
self.drain_pending_last_played();
|
||||
let local_streamed = self.mods_state.drain_pending();
|
||||
let mods_update = self.mods_state.drain_watcher();
|
||||
self.mods_state.drain_provider_icons();
|
||||
self.mods_state.request_image_loads(&self.picker);
|
||||
self.mods_state.drain_image_loads(&self.picker);
|
||||
self.mods_discovery_state.drain_pending();
|
||||
self.mods_discovery_state.list.drain_pending();
|
||||
self.mods_discovery_state
|
||||
.list
|
||||
.request_image_loads(&self.picker);
|
||||
self.mods_discovery_state
|
||||
.list
|
||||
.drain_image_loads(&self.picker);
|
||||
let local_streamed = self.resource_packs_state.drain_pending() || local_streamed;
|
||||
let resource_packs_update = self.resource_packs_state.drain_watcher();
|
||||
self.resource_packs_state.drain_provider_icons();
|
||||
self.resource_packs_state.request_image_loads(&self.picker);
|
||||
self.resource_packs_state.drain_image_loads(&self.picker);
|
||||
self.resource_packs_discovery_state.drain_pending();
|
||||
self.resource_packs_discovery_state.list.drain_pending();
|
||||
self.resource_packs_discovery_state
|
||||
.list
|
||||
.request_image_loads(&self.picker);
|
||||
self.resource_packs_discovery_state
|
||||
.list
|
||||
.drain_image_loads(&self.picker);
|
||||
let local_streamed = self.shaders_state.drain_pending() || local_streamed;
|
||||
let shaders_update = self.shaders_state.drain_watcher();
|
||||
self.shaders_state.drain_provider_icons();
|
||||
self.shaders_state.request_image_loads(&self.picker);
|
||||
self.shaders_state.drain_image_loads(&self.picker);
|
||||
self.shaders_discovery_state.drain_pending();
|
||||
self.shaders_discovery_state.list.drain_pending();
|
||||
self.shaders_discovery_state
|
||||
.list
|
||||
.request_image_loads(&self.picker);
|
||||
self.shaders_discovery_state
|
||||
.list
|
||||
.drain_image_loads(&self.picker);
|
||||
let mut local_streamed = false;
|
||||
let mut content_changed = false;
|
||||
let mut toggles = Vec::new();
|
||||
for (local, discovery) in [
|
||||
(&mut self.mods_state, &mut self.mods_discovery_state),
|
||||
(
|
||||
&mut self.resource_packs_state,
|
||||
&mut self.resource_packs_discovery_state,
|
||||
),
|
||||
(&mut self.shaders_state, &mut self.shaders_discovery_state),
|
||||
] {
|
||||
local_streamed |= local.drain_pending();
|
||||
let update = local.drain_watcher();
|
||||
content_changed |= update.requires_reconcile;
|
||||
toggles.extend(update.toggles);
|
||||
local.drain_provider_icons();
|
||||
local.request_image_loads(&self.picker);
|
||||
local.drain_image_loads(&self.picker);
|
||||
discovery.drain_pending();
|
||||
discovery.list.drain_pending();
|
||||
discovery.list.request_image_loads(&self.picker);
|
||||
discovery.list.drain_image_loads(&self.picker);
|
||||
}
|
||||
self.worlds_state.drain_pending();
|
||||
self.worlds_state.drain_watcher();
|
||||
self.worlds_state.request_image_loads(&self.picker);
|
||||
@@ -84,15 +68,6 @@ impl App {
|
||||
self.screenshots_state.drain_pending_entries();
|
||||
self.screenshots_state.request_visible_loads();
|
||||
self.create_screenshot_protocols();
|
||||
let mut content_changed = mods_update.requires_reconcile
|
||||
|| resource_packs_update.requires_reconcile
|
||||
|| shaders_update.requires_reconcile;
|
||||
let toggles = mods_update
|
||||
.toggles
|
||||
.into_iter()
|
||||
.chain(resource_packs_update.toggles)
|
||||
.chain(shaders_update.toggles)
|
||||
.collect::<Vec<_>>();
|
||||
if !toggles.is_empty() {
|
||||
content_changed |= self.persist_content_toggles(&toggles);
|
||||
}
|
||||
|
||||
+29
-96
@@ -32,18 +32,9 @@ impl App {
|
||||
{
|
||||
return;
|
||||
}
|
||||
let link = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => self
|
||||
.mods_discovery_state
|
||||
.project_link_at(event.column, event.row),
|
||||
widgets::content::ContentTab::ResourcePacks => self
|
||||
.resource_packs_discovery_state
|
||||
.project_link_at(event.column, event.row),
|
||||
widgets::content::ContentTab::Shaders => self
|
||||
.shaders_discovery_state
|
||||
.project_link_at(event.column, event.row),
|
||||
_ => None,
|
||||
};
|
||||
let link = self
|
||||
.active_discovery_state_mut()
|
||||
.and_then(|state| state.project_link_at(event.column, event.row));
|
||||
if let Some(link) = link
|
||||
&& let Err(error) = open::that_detached(link)
|
||||
{
|
||||
@@ -232,24 +223,16 @@ impl App {
|
||||
if self.focused == FocusedArea::Content
|
||||
&& self.content_mode == widgets::content::ContentMode::Discover
|
||||
{
|
||||
let (search_active, popup_open, project_page_open) = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => (
|
||||
self.mods_discovery_state.search.active,
|
||||
self.mods_discovery_state.version_popup.is_some(),
|
||||
self.mods_discovery_state.project_page_open(),
|
||||
),
|
||||
widgets::content::ContentTab::ResourcePacks => (
|
||||
self.resource_packs_discovery_state.search.active,
|
||||
self.resource_packs_discovery_state.version_popup.is_some(),
|
||||
self.resource_packs_discovery_state.project_page_open(),
|
||||
),
|
||||
widgets::content::ContentTab::Shaders => (
|
||||
self.shaders_discovery_state.search.active,
|
||||
self.shaders_discovery_state.version_popup.is_some(),
|
||||
self.shaders_discovery_state.project_page_open(),
|
||||
),
|
||||
_ => (false, false, false),
|
||||
};
|
||||
let (search_active, popup_open, project_page_open) = self
|
||||
.active_discovery_state_mut()
|
||||
.map(|state| {
|
||||
(
|
||||
state.search.active,
|
||||
state.version_popup.is_some(),
|
||||
state.project_page_open(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if !search_active
|
||||
&& !popup_open
|
||||
&& !project_page_open
|
||||
@@ -292,23 +275,9 @@ impl App {
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let handled = {
|
||||
let state = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => Some(&mut self.mods_discovery_state),
|
||||
widgets::content::ContentTab::ResourcePacks => {
|
||||
Some(&mut self.resource_packs_discovery_state)
|
||||
}
|
||||
widgets::content::ContentTab::Shaders => {
|
||||
Some(&mut self.shaders_discovery_state)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(state) = state {
|
||||
widgets::content::discovery::handle_key(&key_event, state)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
};
|
||||
let handled = self
|
||||
.active_discovery_state_mut()
|
||||
.is_some_and(|state| widgets::content::discovery::handle_key(&key_event, state));
|
||||
if handled {
|
||||
if matches!(
|
||||
key_event.code,
|
||||
@@ -726,7 +695,7 @@ impl App {
|
||||
Some(provider) => match provider
|
||||
.compatible_versions(
|
||||
&request.project_id,
|
||||
discovery_content_kind(kind),
|
||||
kind,
|
||||
&instance.game_version,
|
||||
instance.loader,
|
||||
)
|
||||
@@ -875,18 +844,11 @@ impl App {
|
||||
let Some(instance) = self.instances_state.selected_instance().cloned() else {
|
||||
return;
|
||||
};
|
||||
let kind = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => crate::net::modrinth::DiscoveryKind::Mod,
|
||||
widgets::content::ContentTab::ResourcePacks => {
|
||||
crate::net::modrinth::DiscoveryKind::ResourcePack
|
||||
}
|
||||
widgets::content::ContentTab::Shaders => crate::net::modrinth::DiscoveryKind::Shader,
|
||||
_ => return,
|
||||
let Some(state) = self.active_discovery_state_mut() else {
|
||||
return;
|
||||
};
|
||||
let Some(request) = self
|
||||
.active_discovery_state_mut()
|
||||
.and_then(widgets::content::DiscoveryState::begin_install)
|
||||
else {
|
||||
let kind = state.kind;
|
||||
let Some(request) = state.begin_install() else {
|
||||
return;
|
||||
};
|
||||
let destination = self
|
||||
@@ -894,23 +856,12 @@ impl App {
|
||||
.instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join(match kind {
|
||||
crate::net::modrinth::DiscoveryKind::Mod => "mods",
|
||||
crate::net::modrinth::DiscoveryKind::ResourcePack => "resourcepacks",
|
||||
crate::net::modrinth::DiscoveryKind::Shader => "shaderpacks",
|
||||
});
|
||||
.join(kind.directory());
|
||||
let instance_paths = crate::storage::InstancePaths::new(
|
||||
self.instance_manager.instances_dir.join(&instance.name),
|
||||
);
|
||||
let manifest_path = instance_paths.content_manifest();
|
||||
let minecraft_dir = instance_paths.minecraft();
|
||||
let content_kind = match kind {
|
||||
crate::net::modrinth::DiscoveryKind::Mod => crate::instance::ContentKind::Mod,
|
||||
crate::net::modrinth::DiscoveryKind::ResourcePack => {
|
||||
crate::instance::ContentKind::ResourcePack
|
||||
}
|
||||
crate::net::modrinth::DiscoveryKind::Shader => crate::instance::ContentKind::Shader,
|
||||
};
|
||||
tokio::spawn(async move {
|
||||
let action = if request.installed_path.is_some() {
|
||||
format!("Changing {} version", request.project_title)
|
||||
@@ -949,7 +900,7 @@ impl App {
|
||||
let fingerprint = crate::instance::content::manifest::fingerprint(&path)?;
|
||||
let record = crate::instance::ContentFileRecord {
|
||||
relative_path,
|
||||
kind: content_kind,
|
||||
kind,
|
||||
enabled: !path
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
@@ -1023,11 +974,8 @@ impl App {
|
||||
.minecraft();
|
||||
let icon_cache = crate::storage::MetadataPaths::new(&self.instance_manager.meta_dir)
|
||||
.provider_icons("modrinth");
|
||||
let state = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => &mut self.mods_discovery_state,
|
||||
widgets::content::ContentTab::ResourcePacks => &mut self.resource_packs_discovery_state,
|
||||
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
||||
_ => return,
|
||||
let Some(state) = self.active_discovery_state_mut() else {
|
||||
return;
|
||||
};
|
||||
if state.unavailable_message(&instance).is_some() {
|
||||
state.set_unavailable(&instance);
|
||||
@@ -1062,11 +1010,8 @@ impl App {
|
||||
.minecraft();
|
||||
let icon_cache = crate::storage::MetadataPaths::new(&self.instance_manager.meta_dir)
|
||||
.provider_icons("modrinth");
|
||||
let state = match self.content_tab {
|
||||
widgets::content::ContentTab::Mods => &mut self.mods_discovery_state,
|
||||
widgets::content::ContentTab::ResourcePacks => &mut self.resource_packs_discovery_state,
|
||||
widgets::content::ContentTab::Shaders => &mut self.shaders_discovery_state,
|
||||
_ => return,
|
||||
let Some(state) = self.active_discovery_state_mut() else {
|
||||
return;
|
||||
};
|
||||
if state.unavailable_message(&instance).is_some() {
|
||||
state.set_unavailable(&instance);
|
||||
@@ -1090,7 +1035,7 @@ impl App {
|
||||
|
||||
fn spawn_discovery_request(
|
||||
instance: crate::instance::InstanceConfig,
|
||||
kind: crate::net::modrinth::DiscoveryKind,
|
||||
kind: crate::instance::ContentKind,
|
||||
query: String,
|
||||
manifest: Option<crate::instance::ContentManifest>,
|
||||
minecraft_dir: std::path::PathBuf,
|
||||
@@ -1113,7 +1058,7 @@ impl App {
|
||||
Some(provider) => {
|
||||
provider
|
||||
.search(
|
||||
discovery_content_kind(kind),
|
||||
kind,
|
||||
&query,
|
||||
&instance,
|
||||
offset,
|
||||
@@ -1282,18 +1227,6 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn discovery_content_kind(
|
||||
kind: crate::net::modrinth::DiscoveryKind,
|
||||
) -> crate::instance::ContentKind {
|
||||
match kind {
|
||||
crate::net::modrinth::DiscoveryKind::Mod => crate::instance::ContentKind::Mod,
|
||||
crate::net::modrinth::DiscoveryKind::ResourcePack => {
|
||||
crate::instance::ContentKind::ResourcePack
|
||||
}
|
||||
crate::net::modrinth::DiscoveryKind::Shader => crate::instance::ContentKind::Shader,
|
||||
}
|
||||
}
|
||||
|
||||
fn delete_content_path(path: &std::path::Path) -> std::io::Result<()> {
|
||||
match std::fs::metadata(path) {
|
||||
Ok(meta) if meta.is_dir() => std::fs::remove_dir_all(path),
|
||||
|
||||
@@ -57,15 +57,15 @@ impl UiHarness {
|
||||
instances_state: widgets::instances::State::default(),
|
||||
mods_state: widgets::content::ContentListState::default(),
|
||||
mods_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::net::modrinth::DiscoveryKind::Mod,
|
||||
crate::instance::ContentKind::Mod,
|
||||
),
|
||||
resource_packs_state: widgets::content::ContentListState::default(),
|
||||
resource_packs_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::net::modrinth::DiscoveryKind::ResourcePack,
|
||||
crate::instance::ContentKind::ResourcePack,
|
||||
),
|
||||
shaders_state: widgets::content::ContentListState::default(),
|
||||
shaders_discovery_state: widgets::content::DiscoveryState::new(
|
||||
crate::net::modrinth::DiscoveryKind::Shader,
|
||||
crate::instance::ContentKind::Shader,
|
||||
),
|
||||
worlds_state: widgets::content::ContentListState::default(),
|
||||
screenshots_state: {
|
||||
|
||||
@@ -72,7 +72,7 @@ fn install_and_change_version_popups_only_differ_in_title() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state
|
||||
.list
|
||||
.entries
|
||||
@@ -104,7 +104,7 @@ fn compatible_versions_populate_the_open_popup() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(project, None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let request = state.begin_versions().unwrap();
|
||||
@@ -136,7 +136,7 @@ fn project_page_loads_for_the_selected_discovery_entry() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(project, None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
|
||||
@@ -174,7 +174,7 @@ fn project_page_loads_for_the_selected_discovery_entry() {
|
||||
|
||||
#[test]
|
||||
fn project_page_navigation_is_bounded_and_can_go_back() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.project_page = Some(ProjectPageState {
|
||||
request_id: 1,
|
||||
project_id: "project".to_owned(),
|
||||
@@ -215,7 +215,7 @@ fn confirmation_can_return_to_version_selection() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(project, None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let request = state.begin_versions().unwrap();
|
||||
@@ -252,7 +252,7 @@ fn discovery_delete_only_clears_the_matching_installed_badge() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state
|
||||
.list
|
||||
.entries
|
||||
@@ -295,7 +295,7 @@ fn successful_install_marks_the_project_and_closes_the_popup() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(project, None));
|
||||
state.list.list_state.selected = Some(0);
|
||||
let versions_request = state.begin_versions().unwrap();
|
||||
@@ -350,7 +350,7 @@ fn installed_labels_follow_exact_manifest_projects() {
|
||||
icon_url: None,
|
||||
icon_bytes: None,
|
||||
};
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(project, None));
|
||||
|
||||
let mut manifest = crate::instance::ContentManifest::default();
|
||||
@@ -392,7 +392,7 @@ fn installed_labels_follow_exact_manifest_projects() {
|
||||
|
||||
#[test]
|
||||
fn changing_instance_invalidates_results() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let first = instance("one", "1.21.1");
|
||||
let second = instance("two", "1.21.1");
|
||||
let _request = state.begin_search(&first);
|
||||
@@ -403,7 +403,7 @@ fn changing_instance_invalidates_results() {
|
||||
|
||||
#[test]
|
||||
fn unavailable_vanilla_discovery_clears_cached_results() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.list.entries.push(project_entry(
|
||||
DiscoveryProject {
|
||||
id: "cached".to_owned(),
|
||||
@@ -418,6 +418,10 @@ fn unavailable_vanilla_discovery_clears_cached_results() {
|
||||
));
|
||||
let mut vanilla = instance("vanilla", "1.21.1");
|
||||
vanilla.loader = ModLoader::Vanilla;
|
||||
assert_eq!(
|
||||
state.unavailable_message(&vanilla),
|
||||
Some("Vanilla does not support mods.")
|
||||
);
|
||||
|
||||
state.set_unavailable(&vanilla);
|
||||
|
||||
@@ -428,7 +432,7 @@ fn unavailable_vanilla_discovery_clears_cached_results() {
|
||||
|
||||
#[test]
|
||||
fn changing_instance_compatibility_invalidates_results() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let original = instance("one", "1.21.1");
|
||||
let mut other_version = original.clone();
|
||||
other_version.game_version = "1.20.1".to_owned();
|
||||
@@ -442,7 +446,7 @@ fn changing_instance_compatibility_invalidates_results() {
|
||||
|
||||
#[test]
|
||||
fn stale_search_result_is_ignored() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let instance = instance("one", "1.21.1");
|
||||
let old = state.begin_search(&instance);
|
||||
let _new = state.begin_search(&instance);
|
||||
@@ -464,7 +468,7 @@ fn stale_search_result_is_ignored() {
|
||||
|
||||
#[test]
|
||||
fn next_page_prefetches_before_selection_reaches_the_end() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.set_viewport_rows(30);
|
||||
let instance = instance("one", "1.21.1");
|
||||
let first = state.begin_search(&instance);
|
||||
@@ -502,7 +506,7 @@ fn next_page_prefetches_before_selection_reaches_the_end() {
|
||||
|
||||
#[test]
|
||||
fn large_page_fills_a_tall_viewport_without_another_request() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
state.set_viewport_rows(90);
|
||||
let first = state.begin_search(&instance("one", "1.21.1"));
|
||||
for index in 0..PAGE_SIZE {
|
||||
@@ -536,7 +540,7 @@ fn large_page_fills_a_tall_viewport_without_another_request() {
|
||||
|
||||
#[test]
|
||||
fn typing_keeps_loaded_results_until_remote_search_is_due() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let request = state.begin_search(&instance("one", "1.21.1"));
|
||||
for title in ["Sodium", "Lithium"] {
|
||||
assert!(request.stream.send(project_entry(
|
||||
@@ -574,7 +578,7 @@ fn typing_keeps_loaded_results_until_remote_search_is_due() {
|
||||
|
||||
#[test]
|
||||
fn search_refresh_keeps_rows_until_the_diff_arrives() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let instance = instance("one", "1.21.1");
|
||||
let initial = state.begin_search(&instance);
|
||||
for title in ["Sodium", "Lithium"] {
|
||||
@@ -606,7 +610,7 @@ fn search_refresh_keeps_rows_until_the_diff_arrives() {
|
||||
|
||||
#[test]
|
||||
fn pagination_continues_across_multiple_pages() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let instance = instance("one", "1.21.1");
|
||||
let first = state.begin_search(&instance);
|
||||
for index in 0..PAGE_SIZE {
|
||||
@@ -670,7 +674,7 @@ fn pagination_continues_across_multiple_pages() {
|
||||
|
||||
#[test]
|
||||
fn permanent_pagination_failure_stops_without_discarding_loaded_entries() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let first = state.begin_search(&instance("one", "1.21.1"));
|
||||
for index in 0..PAGE_SIZE {
|
||||
assert!(first.stream.upsert(project_entry(
|
||||
@@ -717,7 +721,7 @@ fn permanent_pagination_failure_stops_without_discarding_loaded_entries() {
|
||||
|
||||
#[test]
|
||||
fn transient_pagination_failure_retries_the_same_offset_after_a_delay() {
|
||||
let mut state = DiscoveryState::new(DiscoveryKind::Mod);
|
||||
let mut state = DiscoveryState::new(ContentKind::Mod);
|
||||
let first = state.begin_search(&instance("one", "1.21.1"));
|
||||
DiscoveryState::push_result(
|
||||
&first.pending,
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::instance::content::mods::ContentEntry;
|
||||
use crate::instance::ContentEntry;
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
@@ -38,6 +38,27 @@ fn entry(name: &str) -> ContentEntry {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggling_a_selected_entry_renames_and_updates_it() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let path = temp.path().join("example.jar");
|
||||
std::fs::write(&path, b"mod").unwrap();
|
||||
let mut content = entry("Example");
|
||||
content.path = path.clone();
|
||||
let mut state = ContentListState::default();
|
||||
state.entries.push(content);
|
||||
state.list_state.selected = Some(0);
|
||||
|
||||
state.toggle_selected();
|
||||
|
||||
assert!(!path.exists());
|
||||
assert_eq!(
|
||||
state.entries[0].path,
|
||||
temp.path().join("example.jar.disabled")
|
||||
);
|
||||
assert!(!state.entries[0].enabled);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_watcher_ignores_file_access_events() {
|
||||
assert_eq!(
|
||||
@@ -295,14 +316,14 @@ fn source_refresh_reconciles_without_rebuilding_unchanged_entries() {
|
||||
fn provider_icons_are_requested_only_for_visible_missing_icons() {
|
||||
let mut state = ContentListState::default();
|
||||
let mut visible = entry("Visible");
|
||||
visible.icon_lines = Some(crate::instance::content::mods::fallback_icon());
|
||||
visible.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
visible.provider_project = Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "visible-project".to_owned(),
|
||||
version_id: "version".to_owned(),
|
||||
});
|
||||
let mut offscreen = entry("Offscreen");
|
||||
offscreen.icon_lines = Some(crate::instance::content::mods::fallback_icon());
|
||||
offscreen.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
offscreen.provider_project = Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "offscreen-project".to_owned(),
|
||||
@@ -322,7 +343,7 @@ fn embedded_icons_do_not_request_provider_fallbacks() {
|
||||
let mut state = ContentListState::default();
|
||||
let mut visible = entry("Visible");
|
||||
visible.icon_bytes = Some(vec![1, 2, 3]);
|
||||
visible.icon_lines = Some(crate::instance::content::mods::fallback_icon());
|
||||
visible.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
visible.provider_project = Some(crate::instance::ProviderProject {
|
||||
provider: "modrinth".to_owned(),
|
||||
project_id: "visible-project".to_owned(),
|
||||
|
||||
@@ -3,9 +3,8 @@ use std::sync::{Arc, Mutex};
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
|
||||
use crate::instance::content::mods::ContentEntry;
|
||||
use crate::instance::{InstanceConfig, ModLoader};
|
||||
use crate::net::modrinth::{DiscoveryKind, DiscoveryProject, VersionInfo};
|
||||
use crate::instance::{ContentEntry, ContentKind, InstanceConfig, ModLoader};
|
||||
use crate::net::modrinth::{DiscoveryProject, VersionInfo};
|
||||
|
||||
use super::list::{ContentListState, ContentStream};
|
||||
|
||||
@@ -159,7 +158,7 @@ pub enum DiscoveryActionResult {
|
||||
pub(crate) type PendingActions = Arc<Mutex<Vec<DiscoveryActionResult>>>;
|
||||
|
||||
pub struct DiscoveryState {
|
||||
pub kind: DiscoveryKind,
|
||||
pub kind: ContentKind,
|
||||
pub list: ContentListState,
|
||||
pub search: crate::tui::widgets::search::SearchState,
|
||||
pub total_hits: usize,
|
||||
@@ -184,7 +183,7 @@ pub struct DiscoveryState {
|
||||
}
|
||||
|
||||
impl DiscoveryState {
|
||||
pub fn new(kind: DiscoveryKind) -> Self {
|
||||
pub fn new(kind: ContentKind) -> Self {
|
||||
Self {
|
||||
kind,
|
||||
list: ContentListState::default(),
|
||||
@@ -859,7 +858,7 @@ pub(crate) fn project_entry(
|
||||
provider_icon,
|
||||
provider_description: false,
|
||||
path: PathBuf::from(project.id),
|
||||
icon_lines: Some(crate::instance::content::mods::fallback_icon()),
|
||||
icon_lines: Some(crate::instance::content::fallback_icon()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use ratatui_image::{CropOptions, Resize, StatefulImage, protocol::StatefulProtoc
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
use crate::config::theme::THEME;
|
||||
use crate::instance::content::mods::{ContentEntry, IconCell};
|
||||
use crate::instance::content::{ContentEntry, IconCell};
|
||||
|
||||
type ScanOneFn = fn(&Path, &str, bool) -> ContentEntry;
|
||||
static PROVIDER_ICON_SLOTS: LazyLock<Arc<tokio::sync::Semaphore>> =
|
||||
@@ -249,7 +249,7 @@ impl ContentListState {
|
||||
if entry.provider_project.take().is_some() {
|
||||
if entry.provider_icon {
|
||||
entry.icon_bytes = None;
|
||||
entry.icon_lines = Some(crate::instance::content::mods::fallback_icon());
|
||||
entry.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
entry.provider_icon = false;
|
||||
invalidated_icons.push(entry.file_stem.clone());
|
||||
}
|
||||
@@ -268,7 +268,7 @@ impl ContentListState {
|
||||
if entry.provider_project != project {
|
||||
if entry.provider_icon {
|
||||
entry.icon_bytes = None;
|
||||
entry.icon_lines = Some(crate::instance::content::mods::fallback_icon());
|
||||
entry.icon_lines = Some(crate::instance::content::fallback_icon());
|
||||
entry.provider_icon = false;
|
||||
invalidated_icons.push(entry.file_stem.clone());
|
||||
}
|
||||
@@ -524,18 +524,18 @@ impl ContentListState {
|
||||
return PendingContentImage {
|
||||
file_stem,
|
||||
path,
|
||||
icon_lines: crate::instance::content::mods::fallback_icon(),
|
||||
icon_lines: crate::instance::content::fallback_icon(),
|
||||
image: None,
|
||||
};
|
||||
};
|
||||
let icon_lines = if use_quadrants {
|
||||
crate::instance::content::mods::make_icon_quadrants_from_image(
|
||||
crate::instance::content::make_icon_quadrants_from_image(
|
||||
&image,
|
||||
columns,
|
||||
rows as u16,
|
||||
)
|
||||
} else {
|
||||
crate::instance::content::mods::make_icon_pixels_from_image(
|
||||
crate::instance::content::make_icon_pixels_from_image(
|
||||
&image,
|
||||
columns,
|
||||
rows as u16,
|
||||
@@ -1161,37 +1161,18 @@ impl ContentListState {
|
||||
let Some(entry) = self.entries.get(index) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let new_path = if entry.enabled {
|
||||
let fname = match entry.path.file_name().and_then(|n| n.to_str()) {
|
||||
Some(n) => n,
|
||||
None => return,
|
||||
};
|
||||
let mut p = entry.path.clone();
|
||||
p.set_file_name(format!("{fname}.disabled"));
|
||||
p
|
||||
} else {
|
||||
let fname = match entry.path.file_name().and_then(|n| n.to_str()) {
|
||||
Some(n) => n,
|
||||
None => return,
|
||||
};
|
||||
let mut p = entry.path.clone();
|
||||
p.set_file_name(fname.trim_end_matches(".disabled"));
|
||||
p
|
||||
};
|
||||
|
||||
match std::fs::rename(&entry.path, &new_path) {
|
||||
Ok(()) => {
|
||||
match crate::instance::content::toggle_entry_path(entry) {
|
||||
Ok(Some(new_path)) => {
|
||||
let entry = &mut self.entries[index];
|
||||
entry.enabled = !entry.enabled;
|
||||
entry.path = new_path;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"Failed to toggle '{}' from {} to {}: {}",
|
||||
"Failed to toggle '{}' at {}: {}",
|
||||
entry.file_stem,
|
||||
entry.path.display(),
|
||||
new_path.display(),
|
||||
e
|
||||
);
|
||||
}
|
||||
@@ -1329,42 +1310,18 @@ async fn load_provider_metadata(
|
||||
}
|
||||
|
||||
pub fn handle_key_no_toggle(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
||||
if handle_search_keys(key_event, state) {
|
||||
return true;
|
||||
}
|
||||
let filtered = state.filtered_indices();
|
||||
let count = filtered.len();
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Char('j') | KeyCode::Down => {
|
||||
if count == 0 {
|
||||
return true;
|
||||
}
|
||||
let current = state.list_state.selected.unwrap_or(0);
|
||||
state.list_state.selected = Some((current + 1).min(count - 1));
|
||||
state.update_scrollbar();
|
||||
true
|
||||
}
|
||||
KeyCode::Char('k') | KeyCode::Up => {
|
||||
let current = state.list_state.selected.unwrap_or(0);
|
||||
state.list_state.selected = Some(current.saturating_sub(1));
|
||||
state.update_scrollbar();
|
||||
true
|
||||
}
|
||||
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
|
||||
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i))
|
||||
&& let Some(dir) = state.entries[real_idx].path.parent()
|
||||
&& let Err(e) = open::that_detached(dir)
|
||||
{
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
handle_key_inner(key_event, state, false)
|
||||
}
|
||||
|
||||
pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
||||
handle_key_inner(key_event, state, true)
|
||||
}
|
||||
|
||||
fn handle_key_inner(
|
||||
key_event: &KeyEvent,
|
||||
state: &mut ContentListState,
|
||||
toggle_on_enter: bool,
|
||||
) -> bool {
|
||||
if handle_search_keys(key_event, state) {
|
||||
return true;
|
||||
}
|
||||
@@ -1396,7 +1353,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
KeyCode::Enter if toggle_on_enter => {
|
||||
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
|
||||
state.list_state.selected = Some(real_idx);
|
||||
state.toggle_selected();
|
||||
@@ -1998,7 +1955,7 @@ fn ellipsize(text: &str, max_width: usize) -> String {
|
||||
}
|
||||
|
||||
fn protocol_icon_columns(
|
||||
entry: &crate::instance::content::mods::ContentEntry,
|
||||
entry: &crate::instance::ContentEntry,
|
||||
picker: &ratatui_image::picker::Picker,
|
||||
) -> u16 {
|
||||
let rows = entry.icon_lines.as_ref().map_or(3, Vec::len) as u16;
|
||||
@@ -2124,7 +2081,7 @@ fn diff_event_paths(
|
||||
fn watcher_diff(
|
||||
toggled: Vec<(String, bool, std::path::PathBuf)>,
|
||||
removed: Vec<String>,
|
||||
added: Vec<crate::instance::content::mods::ContentEntry>,
|
||||
added: Vec<crate::instance::ContentEntry>,
|
||||
) -> Option<WatcherDiff> {
|
||||
if toggled.is_empty() && removed.is_empty() && added.is_empty() {
|
||||
None
|
||||
|
||||
+113
-132
@@ -17,6 +17,17 @@ use crate::tui::widgets::content::{ContentMode, DiscoveryState};
|
||||
|
||||
use crate::tui::widgets::styled_title;
|
||||
|
||||
type ContentScanner = fn(&std::path::Path, &str, bool) -> crate::instance::ContentEntry;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct DownloadableTab {
|
||||
directory: &'static str,
|
||||
extension: &'static str,
|
||||
scanner: ContentScanner,
|
||||
loading_text: &'static str,
|
||||
empty_text: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ContentTab {
|
||||
#[default]
|
||||
@@ -79,6 +90,33 @@ impl ContentTab {
|
||||
pub fn previous_for_mode(self, mode: ContentMode) -> Self {
|
||||
cycle_tab(self, visible_tabs(mode), false)
|
||||
}
|
||||
|
||||
fn downloadable(self) -> Option<DownloadableTab> {
|
||||
match self {
|
||||
Self::Mods => Some(DownloadableTab {
|
||||
directory: "mods",
|
||||
extension: ".jar",
|
||||
scanner: crate::instance::scan_one_mod,
|
||||
loading_text: "Loading mods...",
|
||||
empty_text: "No mods installed.",
|
||||
}),
|
||||
Self::ResourcePacks => Some(DownloadableTab {
|
||||
directory: "resourcepacks",
|
||||
extension: ".zip",
|
||||
scanner: crate::instance::scan_one_resource_pack,
|
||||
loading_text: "Loading resource packs...",
|
||||
empty_text: "No resource packs installed.",
|
||||
}),
|
||||
Self::Shaders => Some(DownloadableTab {
|
||||
directory: "shaderpacks",
|
||||
extension: ".zip",
|
||||
scanner: crate::instance::scan_one_shader,
|
||||
loading_text: "Loading shaders...",
|
||||
empty_text: "No shaders installed.",
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visible_tabs(mode: ContentMode) -> &'static [ContentTab] {
|
||||
@@ -340,140 +378,31 @@ pub fn render(
|
||||
content_area =
|
||||
crate::tui::widgets::popups::render_keybind_overflow(frame, content_area, &keybind_lines);
|
||||
|
||||
let downloadable_state = match tab {
|
||||
ContentTab::Mods => Some((mods_state, mods_discovery_state)),
|
||||
ContentTab::ResourcePacks => Some((resource_packs_state, resource_packs_discovery_state)),
|
||||
ContentTab::Shaders => Some((shaders_state, shaders_discovery_state)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((state, discovery_state)) = downloadable_state {
|
||||
render_downloadable(
|
||||
frame,
|
||||
content_area,
|
||||
instance,
|
||||
state,
|
||||
discovery_state,
|
||||
tab.downloadable().expect("downloadable tab config"),
|
||||
mode,
|
||||
is_focused,
|
||||
instances_dir,
|
||||
picker,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// lazy-load: only scan when switching to an instance that hasn't been loaded yet
|
||||
match tab {
|
||||
ContentTab::Mods => {
|
||||
if let Some(instance) = instance {
|
||||
if mods_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("mods");
|
||||
mods_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_mod,
|
||||
".jar",
|
||||
);
|
||||
mods_state.watch_dir(content_dir);
|
||||
}
|
||||
if mode == ContentMode::Discover {
|
||||
render_discovery(
|
||||
frame,
|
||||
content_area,
|
||||
mods_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
);
|
||||
} else {
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
mods_state,
|
||||
is_focused,
|
||||
"Loading mods...",
|
||||
"No mods installed.",
|
||||
picker,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
ContentTab::ResourcePacks => {
|
||||
if let Some(instance) = instance {
|
||||
if resource_packs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("resourcepacks");
|
||||
resource_packs_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_resource_pack,
|
||||
".zip",
|
||||
);
|
||||
resource_packs_state.watch_dir(content_dir);
|
||||
}
|
||||
if mode == ContentMode::Discover {
|
||||
render_discovery(
|
||||
frame,
|
||||
content_area,
|
||||
resource_packs_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
);
|
||||
} else {
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
resource_packs_state,
|
||||
is_focused,
|
||||
"Loading resource packs...",
|
||||
"No resource packs installed.",
|
||||
picker,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
ContentTab::Shaders => {
|
||||
if let Some(instance) = instance {
|
||||
if shaders_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join("shaderpacks");
|
||||
shaders_state.start_load(
|
||||
&content_dir,
|
||||
&instance.name,
|
||||
crate::instance::scan_one_shader,
|
||||
".zip",
|
||||
);
|
||||
shaders_state.watch_dir(content_dir);
|
||||
}
|
||||
if mode == ContentMode::Discover {
|
||||
render_discovery(
|
||||
frame,
|
||||
content_area,
|
||||
shaders_discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
);
|
||||
} else {
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
shaders_state,
|
||||
is_focused,
|
||||
"Loading shaders...",
|
||||
"No shaders installed.",
|
||||
picker,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
ContentTab::Mods | ContentTab::ResourcePacks | ContentTab::Shaders => unreachable!(),
|
||||
ContentTab::Logs => {
|
||||
if let Some(instance) = instance {
|
||||
if logs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
@@ -547,6 +476,58 @@ pub fn render(
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn render_downloadable(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
instance: Option<&crate::instance::InstanceConfig>,
|
||||
state: &mut super::list::ContentListState,
|
||||
discovery_state: &mut DiscoveryState,
|
||||
tab: DownloadableTab,
|
||||
mode: ContentMode,
|
||||
is_focused: bool,
|
||||
instances_dir: &std::path::Path,
|
||||
picker: &ratatui_image::picker::Picker,
|
||||
) {
|
||||
let Some(instance) = instance else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.as_ref().text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
};
|
||||
if state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
let content_dir = instances_dir
|
||||
.join(&instance.name)
|
||||
.join(crate::storage::MINECRAFT_DIR_NAME)
|
||||
.join(tab.directory);
|
||||
state.start_load(&content_dir, &instance.name, tab.scanner, tab.extension);
|
||||
state.watch_dir(content_dir);
|
||||
}
|
||||
if mode == ContentMode::Discover {
|
||||
render_discovery(
|
||||
frame,
|
||||
area,
|
||||
discovery_state,
|
||||
instance,
|
||||
is_focused,
|
||||
"Searching Modrinth...",
|
||||
picker,
|
||||
);
|
||||
} else {
|
||||
super::list::render(
|
||||
frame,
|
||||
area,
|
||||
state,
|
||||
is_focused,
|
||||
tab.loading_text,
|
||||
tab.empty_text,
|
||||
picker,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_discovery(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
|
||||
@@ -25,7 +25,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::config::settings::ImageProtocol;
|
||||
use crate::config::theme::THEME;
|
||||
use crate::instance::content::mods::{
|
||||
use crate::instance::content::{
|
||||
IconCell, fallback_icon, make_icon_pixels_from_image, make_icon_quadrants_from_image,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// rendering for the modpack import wizard. same pattern as new_instance:
|
||||
// snapshot the state, pick the right step renderer, done.
|
||||
|
||||
use super::super::LoadState;
|
||||
use super::super::base::PopupFrame;
|
||||
use super::super::new_instance::LoadState;
|
||||
use super::state::{IMPORT_STATE, ImportStep, ImportWizardState};
|
||||
use crate::config::theme::THEME;
|
||||
use crate::tui::app::FocusedArea;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// (.mrpack, mmc/prism zips). remote packs go through version selection,
|
||||
// local files skip straight to the confirm step.
|
||||
|
||||
use super::super::new_instance::LoadState;
|
||||
use super::super::LoadState;
|
||||
use crate::instance::import::{ImportInput, ImportSummary, parse_import_input};
|
||||
use crate::net::modrinth::{self, VersionInfo};
|
||||
use crate::tui::widgets::instances;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum LoadState<T> {
|
||||
#[default]
|
||||
Idle,
|
||||
Loading,
|
||||
Loaded(T),
|
||||
Error(String),
|
||||
}
|
||||
@@ -5,8 +5,11 @@ pub mod base;
|
||||
pub mod confirm;
|
||||
pub mod error;
|
||||
pub mod import_modpack;
|
||||
mod load_state;
|
||||
pub mod new_instance;
|
||||
|
||||
pub use load_state::LoadState;
|
||||
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::{Alignment, Constraint, Layout, Rect},
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
mod render;
|
||||
mod state;
|
||||
|
||||
pub use super::LoadState;
|
||||
pub(crate) use render::render_select_list;
|
||||
pub use render::{popup_rect, render};
|
||||
pub use state::{LoadState, WizardParams, WizardState, WizardStep, handle_key, take_result};
|
||||
pub use state::{WizardParams, WizardState, WizardStep, handle_key, take_result};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn reset_for_test() {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// rendering for the new instance wizard. each step gets its own render fn
|
||||
// and the popup resizes itself based on which step is active.
|
||||
|
||||
use super::super::LoadState;
|
||||
use super::state::{
|
||||
LoadState, WIZARD_STATE, WizardState, WizardStep, clamp_loader_version_index,
|
||||
clamp_version_index, ensure_loader_versions_loaded, ensure_versions_loaded, visible_versions,
|
||||
WIZARD_STATE, WizardState, WizardStep, clamp_loader_version_index, clamp_version_index,
|
||||
ensure_loader_versions_loaded, ensure_versions_loaded, visible_versions,
|
||||
};
|
||||
use crate::config::theme::THEME;
|
||||
use crate::instance::models::ModLoader;
|
||||
|
||||
@@ -12,6 +12,8 @@ use std::sync::LazyLock;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tui_prompts::{FocusState, State as PromptState, TextState};
|
||||
|
||||
use super::super::LoadState;
|
||||
|
||||
pub(crate) static WIZARD_STATE: LazyLock<Arc<Mutex<WizardState>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(WizardState::default())));
|
||||
// populated on confirm, consumed by the main event loop to actually create the instance
|
||||
@@ -36,15 +38,6 @@ pub enum WizardStep {
|
||||
Confirm,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum LoadState<T> {
|
||||
#[default]
|
||||
Idle,
|
||||
Loading,
|
||||
Loaded(T),
|
||||
Error(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WizardState {
|
||||
pub step: WizardStep,
|
||||
|
||||
Reference in new issue
Block a user