2024-08-23 11:22:09 +00:00
|
|
|
use context::prelude::*;
|
|
|
|
|
|
|
|
use std::{sync::Arc, thread};
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
pub struct LoadingScreen;
|
|
|
|
|
|
|
|
impl LoadingScreen {
|
|
|
|
pub fn load<T, R, L, G>(
|
|
|
|
context: &Arc<Context>,
|
|
|
|
gui: Option<Arc<G>>,
|
|
|
|
loader: L,
|
|
|
|
on_ready: R,
|
|
|
|
) -> Result<()>
|
|
|
|
where
|
|
|
|
R: Fn(T) -> Result<()> + Send + Sync + 'static,
|
|
|
|
T: Send + Sync + 'static,
|
|
|
|
L: FnOnce() -> T + Send + Sync + 'static,
|
|
|
|
G: TopLevelGui + TopGui + Send + Sync + 'static,
|
|
|
|
{
|
|
|
|
if let Some(gui) = &gui {
|
|
|
|
gui.enable()?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let context = context.clone();
|
|
|
|
|
|
|
|
thread::spawn(move || {
|
|
|
|
let result = loader();
|
|
|
|
if let Some(gui) = &gui {
|
|
|
|
gui.disable().unwrap();
|
|
|
|
}
|
|
|
|
|
2025-02-26 13:51:44 +00:00
|
|
|
todo!();
|
|
|
|
// context.push_event(move || (on_ready)(result));
|
2024-08-23 11:22:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|