feat: add error popup system, progress bar, and log overlay
This commit is contained in:
1 parent
252fe8e44a
commit
96b6f4e0e9
4 files changed
+244
-24
No files matched your search
@@ -0,0 +1,71 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct ProgressState {
|
||||
/// Current main action text, e.g. "Downloading 1.20.1..."
|
||||
pub current_action: Option<String>,
|
||||
/// (bytes_downloaded, total_bytes). total = 0 means unknown size.
|
||||
pub progress: Option<(u64, u64)>,
|
||||
/// Detail text shown below main action, e.g. "libraries/net/minecraft/client.jar"
|
||||
pub sub_action: Option<String>,
|
||||
}
|
||||
|
||||
pub static PROGRESS: Lazy<Arc<Mutex<ProgressState>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(ProgressState::default())));
|
||||
|
||||
pub fn set_action(text: impl Into<String>) {
|
||||
let text = text.into();
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.current_action = Some(text.clone());
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
crate::tui::log_buffer::push_log(crate::tui::log_buffer::LogEntry {
|
||||
level: tracing::Level::INFO,
|
||||
message: text,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn set_progress(current: u64, total: u64) {
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.progress = Some((current, total));
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_sub_action(text: impl Into<String>) {
|
||||
let text = text.into();
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.sub_action = Some(text.clone());
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
crate::tui::log_buffer::push_log(crate::tui::log_buffer::LogEntry {
|
||||
level: tracing::Level::INFO,
|
||||
message: format!(" {}", text),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn clear() {
|
||||
match PROGRESS.lock() {
|
||||
Ok(mut state) => {
|
||||
state.current_action = None;
|
||||
state.progress = None;
|
||||
state.sub_action = None;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Progress lock poisoned: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user