This commit is contained in:
Mark
2024-12-19 18:52:56 +01:00
parent 85c79a21e1
commit d3a1facba0
20 changed files with 544 additions and 231 deletions

View File

@@ -362,90 +362,124 @@ impl Gui {
}
Ok(Ok(Ok(()))) => eprintln!("Info: using merscfg"),
}
database.lock().unwrap().update_endpoints.push(
musicdb_lib::data::database::UpdateEndpoint::Custom(Box::new(move |cmd| {
match &cmd.action {
Action::Resume
| Action::Pause
| Action::Stop
| Action::Save
| Action::InitComplete => {}
Action::NextSong
| Action::QueueUpdate(..)
| Action::QueueAdd(..)
| Action::QueueInsert(..)
| Action::QueueRemove(..)
| Action::QueueMove(..)
| Action::QueueMoveInto(..)
| Action::QueueGoto(..)
| Action::QueueShuffle(..)
| Action::QueueSetShuffle(..)
| Action::QueueUnshuffle(..) => {
if let Some(s) = &*event_sender_arc.lock().unwrap() {
_ = s.send_event(GuiEvent::UpdatedQueue);
{
let mut db = database.lock().unwrap();
let udepid = db.update_endpoints_id;
db.update_endpoints_id += 1;
db.update_endpoints.push((
udepid,
musicdb_lib::data::database::UpdateEndpoint::Custom(Box::new(
move |cmd| match &cmd.action {
Action::Resume
| Action::Pause
| Action::Stop
| Action::Save
| Action::InitComplete => {}
Action::NextSong
| Action::QueueUpdate(..)
| Action::QueueAdd(..)
| Action::QueueInsert(..)
| Action::QueueRemove(..)
| Action::QueueMove(..)
| Action::QueueMoveInto(..)
| Action::QueueGoto(..)
| Action::QueueShuffle(..)
| Action::QueueSetShuffle(..)
| Action::QueueUnshuffle(..) => {
if let Some(s) = &*event_sender_arc.lock().unwrap() {
_ = s.send_event(GuiEvent::UpdatedQueue);
}
}
}
Action::SyncDatabase(..)
| Action::AddSong(_)
| Action::AddAlbum(_)
| Action::AddArtist(_)
| Action::AddCover(_)
| Action::ModifySong(_)
| Action::ModifyAlbum(_)
| Action::ModifyArtist(_)
| Action::RemoveSong(_)
| Action::RemoveAlbum(_)
| Action::RemoveArtist(_)
| Action::TagSongFlagSet(..)
| Action::TagSongFlagUnset(..)
| Action::TagAlbumFlagSet(..)
| Action::TagAlbumFlagUnset(..)
| Action::TagArtistFlagSet(..)
| Action::TagArtistFlagUnset(..)
| Action::TagSongPropertySet(..)
| Action::TagSongPropertyUnset(..)
| Action::TagAlbumPropertySet(..)
| Action::TagAlbumPropertyUnset(..)
| Action::TagArtistPropertySet(..)
| Action::TagArtistPropertyUnset(..)
| Action::SetSongDuration(..) => {
if let Some(s) = &*event_sender_arc.lock().unwrap() {
_ = s.send_event(GuiEvent::UpdatedLibrary);
Action::SyncDatabase(..)
| Action::AddSong(_, _)
| Action::AddAlbum(_, _)
| Action::AddArtist(_, _)
| Action::AddCover(_, _)
| Action::ModifySong(_, _)
| Action::ModifyAlbum(_, _)
| Action::ModifyArtist(_, _)
| Action::RemoveSong(_)
| Action::RemoveAlbum(_)
| Action::RemoveArtist(_)
| Action::TagSongFlagSet(..)
| Action::TagSongFlagUnset(..)
| Action::TagAlbumFlagSet(..)
| Action::TagAlbumFlagUnset(..)
| Action::TagArtistFlagSet(..)
| Action::TagArtistFlagUnset(..)
| Action::TagSongPropertySet(..)
| Action::TagSongPropertyUnset(..)
| Action::TagAlbumPropertySet(..)
| Action::TagAlbumPropertyUnset(..)
| Action::TagArtistPropertySet(..)
| Action::TagArtistPropertyUnset(..)
| Action::SetSongDuration(..) => {
if let Some(s) = &*event_sender_arc.lock().unwrap() {
_ = s.send_event(GuiEvent::UpdatedLibrary);
}
}
}
Action::ErrorInfo(t, d) => {
let (t, d) = (t.clone(), d.clone());
notif_sender_two
.send(Box::new(move |_| {
(
Box::new(Panel::with_background(
GuiElemCfg::default(),
[Label::new(
Action::ErrorInfo(t, d) => {
let (t, d) = (t.clone(), d.clone());
notif_sender_two
.send(Box::new(move |_| {
(
Box::new(Panel::with_background(
GuiElemCfg::default(),
if t.is_empty() {
format!("Server message\n{d}")
} else {
format!("Server error ({t})\n{d}")
},
Color::WHITE,
None,
Vec2::new(0.5, 0.5),
)],
Color::from_rgba(0.0, 0.0, 0.0, 0.8),
)),
if t.is_empty() {
NotifInfo::new(Duration::from_secs(2))
} else {
NotifInfo::new(Duration::from_secs(5))
.with_highlight(Color::RED)
},
)
}))
.unwrap();
}
}
})),
);
[Label::new(
GuiElemCfg::default(),
if t.is_empty() {
format!("Server message\n{d}")
} else {
format!("Server error ({t})\n{d}")
},
Color::WHITE,
None,
Vec2::new(0.5, 0.5),
)],
Color::from_rgba(0.0, 0.0, 0.0, 0.8),
)),
if t.is_empty() {
NotifInfo::new(Duration::from_secs(2))
} else {
NotifInfo::new(Duration::from_secs(5))
.with_highlight(Color::RED)
},
)
}))
.unwrap();
}
Action::Denied(req) => {
let req = *req;
notif_sender_two
.send(Box::new(move |_| {
(
Box::new(Panel::with_background(
GuiElemCfg::default(),
[Label::new(
GuiElemCfg::default(),
format!(
"server denied {}",
if req.is_some() {
"request, maybe desynced"
} else {
"action, likely desynced"
},
),
Color::WHITE,
None,
Vec2::new(0.5, 0.5),
)],
Color::from_rgba(0.0, 0.0, 0.0, 0.8),
)),
NotifInfo::new(Duration::from_secs(1)),
)
}))
.unwrap();
}
},
)),
));
}
let no_animations = false;
Gui {
event_sender,
@@ -1307,16 +1341,10 @@ impl Gui {
}
}
GuiAction::SendToServer(action) => {
let command = self.database.lock().unwrap().seq.pack(action);
#[cfg(debug_assertions)]
eprintln!("[DEBUG] Sending command to server: {action:?}");
if let Err(e) = self
.database
.lock()
.unwrap()
.seq
.pack(action)
.to_bytes(&mut self.connection)
{
eprintln!("[DEBUG] Sending command to server: {command:?}");
if let Err(e) = command.to_bytes(&mut self.connection) {
eprintln!("Error sending command to server: {e}");
}
}