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