mirror of
https://github.com/Dummi26/musicdb.git
synced 2025-12-17 13:17:50 +01:00
add some more functions to -mers and add hooks
This commit is contained in:
@@ -80,6 +80,7 @@ pub fn main(
|
||||
connection: TcpStream,
|
||||
get_con: get::Client<TcpStream>,
|
||||
event_sender_arc: Arc<Mutex<Option<UserEventSender<GuiEvent>>>>,
|
||||
after_db_cmd: &Arc<Mutex<Option<Box<dyn FnMut(Command) + Send + Sync + 'static>>>>,
|
||||
) {
|
||||
let config_dir = super::get_config_file_path();
|
||||
let config_file = config_dir.join("config_gui.toml");
|
||||
@@ -262,6 +263,7 @@ pub fn main(
|
||||
#[cfg(feature = "merscfg")]
|
||||
merscfg: crate::merscfg::MersCfg::new(config_dir.join("dynamic_config.mers"), database),
|
||||
},
|
||||
after_db_cmd,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -320,14 +322,18 @@ impl Gui {
|
||||
scroll_pages_multiplier: f64,
|
||||
#[cfg(not(feature = "merscfg"))] gui_config: GuiConfig,
|
||||
#[cfg(feature = "merscfg")] mut gui_config: GuiConfig,
|
||||
#[cfg(feature = "merscfg")] after_db_cmd: &Arc<
|
||||
Mutex<Option<Box<dyn FnMut(Command) + Send + Sync + 'static>>>,
|
||||
>,
|
||||
) -> Self {
|
||||
let (notif_overlay, notif_sender) = NotifOverlay::new();
|
||||
let notif_sender_two = notif_sender.clone();
|
||||
#[cfg(feature = "merscfg")]
|
||||
match gui_config
|
||||
.merscfg
|
||||
.load(Arc::clone(&event_sender), notif_sender.clone())
|
||||
{
|
||||
match gui_config.merscfg.load(
|
||||
Arc::clone(&event_sender),
|
||||
notif_sender.clone(),
|
||||
after_db_cmd,
|
||||
) {
|
||||
Err(e) => {
|
||||
if !matches!(e.kind(), std::io::ErrorKind::NotFound) {
|
||||
eprintln!("Couldn't load merscfg: {e}")
|
||||
|
||||
@@ -105,7 +105,12 @@ fn main() {
|
||||
Arc::new(Mutex::new(None));
|
||||
#[cfg(feature = "speedy2d")]
|
||||
let sender = Arc::clone(&update_gui_sender);
|
||||
#[cfg(any(feature = "mers", feature = "merscfg"))]
|
||||
let mers_after_db_updated_action: Arc<
|
||||
Mutex<Option<Box<dyn FnMut(Command) + Send + Sync + 'static>>>,
|
||||
> = Arc::new(Mutex::new(None));
|
||||
let con_thread = {
|
||||
let mers_after_db_updated_action = Arc::clone(&mers_after_db_updated_action);
|
||||
let mode = mode.clone();
|
||||
let database = Arc::clone(&database);
|
||||
let mut con = con.try_clone().unwrap();
|
||||
@@ -148,7 +153,13 @@ fn main() {
|
||||
if let Some(player) = &mut player {
|
||||
player.handle_command(&update);
|
||||
}
|
||||
database.lock().unwrap().apply_command(update);
|
||||
#[cfg(any(feature = "mers", feature = "merscfg"))]
|
||||
if let Some(action) = &mut *mers_after_db_updated_action.lock().unwrap() {
|
||||
database.lock().unwrap().apply_command(update.clone());
|
||||
action(update);
|
||||
} else {
|
||||
database.lock().unwrap().apply_command(update);
|
||||
}
|
||||
#[cfg(feature = "speedy2d")]
|
||||
if let Some(v) = &*update_gui_sender.lock().unwrap() {
|
||||
v.send_event(GuiEvent::Refresh).unwrap();
|
||||
@@ -175,6 +186,8 @@ fn main() {
|
||||
))
|
||||
.expect("initializing get client connection"),
|
||||
sender,
|
||||
#[cfg(feature = "merscfg")]
|
||||
&mers_after_db_updated_action,
|
||||
)
|
||||
};
|
||||
}
|
||||
@@ -191,6 +204,7 @@ fn main() {
|
||||
mers_lib::prelude_compile::Config::new().bundle_std(),
|
||||
&database,
|
||||
&Arc::new(move |cmd: Command| cmd.to_bytes(&mut *con.lock().unwrap()).unwrap()),
|
||||
&mers_after_db_updated_action,
|
||||
)
|
||||
.infos();
|
||||
let program = mers_lib::prelude_compile::parse(&mut src, &srca)
|
||||
|
||||
@@ -139,13 +139,14 @@ impl MersCfg {
|
||||
notif_sender: Sender<
|
||||
Box<dyn FnOnce(&NotifOverlay) -> (Box<dyn GuiElem>, NotifInfo) + Send>,
|
||||
>,
|
||||
after_db_cmd: &Arc<Mutex<Option<Box<dyn FnMut(Command) + Send + Sync + 'static>>>>,
|
||||
) -> mers_lib::prelude_extend_config::Config {
|
||||
let cmd_es = event_sender.clone();
|
||||
let cmd_ga = self.channel_gui_actions.0.clone();
|
||||
musicdb_mers::add(cfg, db, &Arc::new(move |cmd| {
|
||||
cmd_ga.send(cmd).unwrap();
|
||||
cmd_es.send_event(GuiEvent::RefreshMers).unwrap();
|
||||
}))
|
||||
}), after_db_cmd)
|
||||
.add_var_arc(
|
||||
"is_playing".to_owned(),
|
||||
Arc::clone(&self.var_is_playing),
|
||||
@@ -704,9 +705,10 @@ impl MersCfg {
|
||||
notif_sender: Sender<
|
||||
Box<dyn FnOnce(&NotifOverlay) -> (Box<dyn GuiElem>, NotifInfo) + Send>,
|
||||
>,
|
||||
after_db_cmd: &Arc<Mutex<Option<Box<dyn FnMut(Command) + Send + Sync + 'static>>>>,
|
||||
) -> std::io::Result<Result<Result<(), (String, Option<CheckError>)>, CheckError>> {
|
||||
let src = mers_lib::prelude_compile::Source::new_from_file(self.source_file.clone())?;
|
||||
Ok(self.load2(src, event_sender, notif_sender))
|
||||
Ok(self.load2(src, event_sender, notif_sender, after_db_cmd))
|
||||
}
|
||||
fn load2(
|
||||
&mut self,
|
||||
@@ -715,6 +717,7 @@ impl MersCfg {
|
||||
notif_sender: Sender<
|
||||
Box<dyn FnOnce(&NotifOverlay) -> (Box<dyn GuiElem>, NotifInfo) + Send>,
|
||||
>,
|
||||
after_db_cmd: &Arc<Mutex<Option<Box<dyn FnMut(Command) + Send + Sync + 'static>>>>,
|
||||
) -> Result<Result<(), (String, Option<CheckError>)>, CheckError> {
|
||||
let srca = Arc::new(src.clone());
|
||||
let (mut i1, mut i2, mut i3) = self
|
||||
@@ -723,6 +726,7 @@ impl MersCfg {
|
||||
&self.database,
|
||||
event_sender,
|
||||
notif_sender,
|
||||
after_db_cmd,
|
||||
)
|
||||
.infos();
|
||||
let compiled = mers_lib::prelude_compile::parse(&mut src, &srca)?
|
||||
|
||||
Reference in New Issue
Block a user