This commit is contained in:
Erica Z 2024-11-10 17:25:53 +01:00
parent 1d9318eb92
commit e72a690be2

View file

@ -12,12 +12,12 @@ mod imp {
use zbus::object_server::InterfaceRef;
#[derive(Debug, Copy, Clone)]
enum State {
pub(super) enum State {
Idle,
FileLoading,
FileLoaded,
FileLoaded, // internal?
Active,
FileEnded,
FileEnded, // internal?
Seeking,
}
@ -25,7 +25,7 @@ mod imp {
#[template(resource = "/eu/callcc/audrey/window.ui")]
#[properties(wrapper_type = super::Window)]
pub struct Window {
state: Cell<State>,
pub(super) state: Cell<State>,
#[template_child]
pub(super) playbar: TemplateChild<crate::ui::Playbar>,
@ -760,17 +760,23 @@ impl Window {
}
pub fn seek(&self, new_position: f64) {
match self
.imp()
use imp::State;
match self.imp().state.get() {
State::Active | State::Seeking => {
self.imp()
.mpv
.command(["seek", &new_position.to_string(), "absolute", "exact"])
{
Ok(()) => {}
Err(err) => {
event!(Level::INFO, "queuing seek to {new_position}: {err}");
.unwrap();
}
State::FileLoading => {
event!(Level::INFO, "queuing seek to {new_position}");
self.imp().queued_seek.set(Some(new_position));
self.notify("time-pos");
}
other => panic!("can not seek when in state {other:?}"),
}
}