diff --git a/src/ui/window.rs b/src/ui/window.rs index 2ee2278..1dac4f2 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -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, + pub(super) state: Cell, #[template_child] pub(super) playbar: TemplateChild, @@ -760,17 +760,23 @@ impl Window { } pub fn seek(&self, new_position: f64) { - match self - .imp() - .mpv - .command(["seek", &new_position.to_string(), "absolute", "exact"]) - { - Ok(()) => {} - Err(err) => { - event!(Level::INFO, "queuing seek to {new_position}: {err}"); + use imp::State; + + match self.imp().state.get() { + State::Active | State::Seeking => { + self.imp() + .mpv + .command(["seek", &new_position.to_string(), "absolute", "exact"]) + .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:?}"), } }