Compare commits

..

2 commits

Author SHA1 Message Date
daff4e7dbd move sanity check 2024-11-04 13:54:30 +01:00
f18c413457 mpv logging 2024-11-04 13:52:33 +01:00
3 changed files with 31 additions and 15 deletions

View file

@ -48,7 +48,7 @@ pub struct LogMessageEvent {
pub prefix: String, pub prefix: String,
pub level: String, pub level: String,
pub text: String, pub text: String,
//log_level: i32, pub log_level: u32,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View file

@ -188,6 +188,7 @@ impl Handle {
text: unsafe { CStr::from_ptr(data.text) } text: unsafe { CStr::from_ptr(data.text) }
.to_string_lossy() .to_string_lossy()
.into(), .into(),
log_level: data.log_level,
})) }))
} }

View file

@ -150,12 +150,6 @@ mod imp {
Event::StartFile(_) => { Event::StartFile(_) => {
window.notify("song"); window.notify("song");
// TODO: load cover art // TODO: load cover art
// sanity check
assert_eq!(
window.song().unwrap().stream_url(),
window.imp().mpv.get_property::<String>("path").unwrap()
);
} }
Event::Hook(event) => match event.reply_userdata { Event::Hook(event) => match event.reply_userdata {
@ -169,6 +163,21 @@ mod imp {
_ => unreachable!(), _ => unreachable!(),
}, },
Event::LogMessage(event) => {
// TODO: levels etc
if event.log_level < 30 {
event!(target: "mpv", Level::ERROR, "[{}] {}", event.prefix, event.text.trim());
} else if event.log_level < 40 {
event!(target: "mpv", Level::WARN, "[{}] {}", event.prefix, event.text.trim());
} else if event.log_level < 50 {
event!(target: "mpv", Level::INFO, "[{}] {}", event.prefix, event.text.trim());
} else if event.log_level < 70 {
event!(target: "mpv", Level::DEBUG, "[{}] {}", event.prefix, event.text.trim());
} else {
event!(target: "mpv", Level::TRACE, "[{}] {}", event.prefix, event.text.trim());
};
}
_ => event!(Level::DEBUG, "unhandled {event:?}"), _ => event!(Level::DEBUG, "unhandled {event:?}"),
} }
} }
@ -317,14 +326,20 @@ mod imp {
if self.obj().playlist_pos() < 0 { if self.obj().playlist_pos() < 0 {
None None
} else { } else {
Some( let song: PlaybinSong = self
self.obj() .obj()
.playlist_model() .playlist_model()
.item(self.obj().playlist_pos() as u32) .item(self.obj().playlist_pos() as u32)
.unwrap() .unwrap()
.dynamic_cast() .dynamic_cast()
.unwrap(), .unwrap();
)
// sanity check
assert_eq!(
song.stream_url(),
self.mpv.get_property::<String>("path").unwrap()
);
Some(song)
} }
} }
} }