refactor app/jack init

This commit is contained in:
🪞👃🪞 2024-07-10 13:15:53 +03:00
parent 117f4d5363
commit 23d9910399
7 changed files with 166 additions and 80 deletions

View file

@ -65,24 +65,22 @@ pub use crate::{submod, pubmod, render, handle, process, phrase, keymap, ports};
// Reexport JACK proto-lib:
pub use crate::jack::*;
impl<T: Render + Handle + Send + Sync + Sized + 'static> Run for T {}
pub trait Run: Render + Handle + Send + Sync + Sized + 'static {
fn run (self, init: Option<impl FnOnce(Arc<RwLock<Self>>)->Usually<()>>) -> Usually<()> {
let app = Arc::new(RwLock::new(self));
let exited = Arc::new(AtomicBool::new(false));
let _input_thread = input_thread(&exited, &app);
terminal_setup()?;
panic_hook_setup();
let main_thread = main_thread(&exited, &app)?;
if let Some(init) = init {
init(app)?;
}
main_thread.join().unwrap();
terminal_teardown()?;
Ok(())
}
pub fn run <T> (state: Arc<RwLock<T>>) -> Usually<Arc<RwLock<T>>>
where T: Render + Handle + Send + Sync + Sized + 'static
{
let exited = Arc::new(AtomicBool::new(false));
let _input_thread = input_thread(&exited, &state);
terminal_setup()?;
panic_hook_setup();
let main_thread = main_thread(&exited, &state)?;
main_thread.join().unwrap();
terminal_teardown()?;
Ok(state)
}
pub trait Run: Render + Handle + Send + Sync + Sized + 'static {
fn run (self) -> Usually<Arc<RwLock<Self>>> { run(Arc::new(RwLock::new(self))) }
}
impl<T: Render + Handle + Send + Sync + Sized + 'static> Run for T {}
/// Set up panic hook
pub fn panic_hook_setup () {