feat(tui): integrate import wizard into layout event loop
This commit is contained in:
1 parent
8a9d6f9941
commit
5914e68b69
1 file changed
+44
@@ -1,3 +1,4 @@
|
||||
use super::widgets::popups::import_modpack;
|
||||
use super::widgets::popups::new_instance;
|
||||
use super::{
|
||||
widgets::{self, profiles, WidgetKey},
|
||||
@@ -66,6 +67,7 @@ pub enum FocusedArea {
|
||||
Overview,
|
||||
OverviewExpanded,
|
||||
Popup,
|
||||
ImportPopup,
|
||||
ErrorPopup,
|
||||
ConfirmDelete,
|
||||
}
|
||||
@@ -131,6 +133,10 @@ impl App {
|
||||
self.spawn_create(params);
|
||||
}
|
||||
|
||||
if let Some(result) = import_modpack::take_result() {
|
||||
self.spawn_import(result);
|
||||
}
|
||||
|
||||
self.dismiss_expired_errors();
|
||||
|
||||
self.drain_pending_instances();
|
||||
@@ -253,6 +259,11 @@ impl App {
|
||||
new_instance::render(frame, area, self.focused);
|
||||
}
|
||||
|
||||
if self.profiles_state.show_import_popup {
|
||||
let area = import_modpack::popup_rect(frame.area());
|
||||
import_modpack::render(frame, area, self.focused);
|
||||
}
|
||||
|
||||
if self.focused == FocusedArea::ConfirmDelete {
|
||||
let name = confirm_popup::pending_delete_name();
|
||||
if !name.is_empty() {
|
||||
@@ -416,6 +427,9 @@ impl App {
|
||||
FocusedArea::Popup => {
|
||||
new_instance::handle_key(&key_event, &mut self.profiles_state);
|
||||
}
|
||||
FocusedArea::ImportPopup => {
|
||||
import_modpack::handle_key(&key_event, &mut self.profiles_state);
|
||||
}
|
||||
_ => {
|
||||
if self.focused == FocusedArea::Profiles && self.profiles_state.renaming.is_some() {
|
||||
match key_event.code {
|
||||
@@ -567,6 +581,12 @@ impl App {
|
||||
self.focused = FocusedArea::Profiles;
|
||||
}
|
||||
|
||||
if self.profiles_state.wants_import_popup() {
|
||||
self.focused = FocusedArea::ImportPopup;
|
||||
} else if self.focused == FocusedArea::ImportPopup {
|
||||
self.focused = FocusedArea::Profiles;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -604,6 +624,30 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_import(&self, result: import_modpack::ImportResult) {
|
||||
let instances_dir = self.instance_manager.instances_dir.clone();
|
||||
let meta_dir = crate::config::SETTINGS.paths.resolve_meta_dir();
|
||||
let pending_instances = PENDING_INSTANCES.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let manager = InstanceManager::new(instances_dir, meta_dir);
|
||||
match crate::instance::import::execute_import(&result.summary, &manager).await {
|
||||
Ok(config) => match pending_instances.lock() {
|
||||
Ok(mut pending) => {
|
||||
pending.push(config);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Pending instance queue lock poisoned: {}", e);
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::error!("Import failed: {}", e);
|
||||
crate::tui::progress::clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn run_editor(terminal: &mut ratatui::DefaultTerminal, path: &std::path::Path) {
|
||||
use ratatui::crossterm::{
|
||||
terminal::{
|
||||
|
||||
Reference in new issue
Block a user