diff --git a/src/main.rs b/src/main.rs index ea0e337..a269ec4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ pub use playbin_song::Song as PlaybinSong; pub mod subsonic; pub mod playbin; -pub type Playbin = playbin::Playbin; +pub use playbin::Playbin; mod signal; pub use signal::{Signal, SignalEmitter, SignalHandler}; diff --git a/src/playbin.rs b/src/playbin.rs index d6dcdaa..4e32b93 100644 --- a/src/playbin.rs +++ b/src/playbin.rs @@ -1,25 +1,14 @@ use crate::mpv; use crate::signal::{Signal, SignalEmitter}; use crate::Event; +use crate::PlaybinSong as Song; use event_listener::EventListener; use std::cell::{Ref, RefCell}; use tracing::{event, span, Level}; -use url::Url; -pub trait PlaybinEntry { - fn url(&self) -> Url; -} - -impl PlaybinEntry for Url { - fn url(&self) -> Url { - self.clone() - } -} - -// E: generic entry type -pub struct Playbin { +pub struct Playbin { mpv: mpv::Handle, - entries: RefCell>, + entries: RefCell>, sender: async_broadcast::Sender, @@ -29,10 +18,7 @@ pub struct Playbin { file_started: SignalEmitter, } -impl Playbin -where - E: PlaybinEntry, -{ +impl Playbin { pub fn new(sender: async_broadcast::Sender) -> Self { let mpv = mpv::Handle::new(); mpv.set_property("audio-client-name", "audrey").unwrap(); @@ -116,14 +102,14 @@ where .unwrap(); } - pub fn entries(&self) -> Ref<'_, [E]> { + pub fn entries(&self) -> Ref<'_, [Song]> { Ref::map(self.entries.borrow(), Vec::as_ref) } - pub fn push_entry(&self, entry: E) { + pub fn push_entry(&self, entry: Song) { let mut entries = self.entries.borrow_mut(); self.mpv - .command(["loadfile", entry.url().as_str(), "append-play"]) + .command(["loadfile", &entry.stream_url(), "append-play"]) .unwrap(); let index = entries.len(); entries.push(entry); @@ -134,10 +120,10 @@ where .unwrap(); } - pub fn insert_entry(&self, index: usize, entry: E) { + pub fn insert_entry(&self, index: usize, entry: Song) { let mut entries = self.entries.borrow_mut(); self.mpv - .command(["loadfile", entry.url().as_str(), "insert-at-play"]) + .command(["loadfile", &entry.stream_url(), "insert-at-play"]) .unwrap(); entries.insert(index, entry); @@ -246,8 +232,8 @@ where // sanity check assert_eq!( - self.entries()[self.current_entry().unwrap()].url().as_str(), - &self.mpv.get_property::("path").unwrap() + self.entries()[self.current_entry().unwrap()].stream_url(), + self.mpv.get_property::("path").unwrap() ); } @@ -268,7 +254,7 @@ where } } -impl Drop for Playbin { +impl Drop for Playbin { fn drop(&mut self) { event!(Level::DEBUG, "dropping Playbin2"); self.mpv.command(["quit"]).unwrap(); diff --git a/src/playbin_song.rs b/src/playbin_song.rs index f6a94a0..63b9318 100644 --- a/src/playbin_song.rs +++ b/src/playbin_song.rs @@ -73,9 +73,3 @@ impl Song { .build() } } - -impl crate::playbin::PlaybinEntry for Song { - fn url(&self) -> url::Url { - url::Url::parse(&self.stream_url()).unwrap() - } -} diff --git a/src/ui/play_queue/song.rs b/src/ui/play_queue/song.rs index e281aaa..97a81f8 100644 --- a/src/ui/play_queue/song.rs +++ b/src/ui/play_queue/song.rs @@ -163,7 +163,6 @@ mod imp { } } -use crate::PlaybinSong; use adw::prelude::*; use glib::Object; use gtk::glib; diff --git a/src/ui/window.rs b/src/ui/window.rs index 8dea634..a41c83c 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -32,7 +32,7 @@ mod imp { pub(super) playbin: Rc, pub(super) api: RefCell>>, - pub(super) sender: async_broadcast::Sender, + pub(super) _sender: async_broadcast::Sender, pub(super) inactive_receiver: async_broadcast::InactiveReceiver, } @@ -49,7 +49,7 @@ mod imp { setup: Default::default(), playbin: Rc::new(Playbin::new(sender.clone())), api: Default::default(), - sender, + _sender: sender, inactive_receiver: receiver.deactivate(), } }