From 224a7ff3dc2c59686d10ea89bd83978f9ba05694 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Mon, 4 Nov 2024 13:29:10 +0100 Subject: [PATCH] sanity check --- src/ui/window.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/ui/window.rs b/src/ui/window.rs index 358e815..a376aff 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -25,8 +25,8 @@ mod imp { #[property(get, set, nullable)] playing_cover_art: RefCell>, - #[property(get, set, nullable)] - song: RefCell>, + #[property(type = Option, get = Self::song, nullable)] + _song: (), pub(super) setup: crate::ui::Setup, @@ -70,7 +70,7 @@ mod imp { play_queue: Default::default(), can_click_shuffle_all: Cell::new(false), playing_cover_art: Default::default(), - song: Default::default(), + _song: (), setup: Default::default(), api: Default::default(), mpv, @@ -139,14 +139,14 @@ mod imp { }, Event::StartFile(_) => { - let song: PlaybinSong = window - .playlist_model() - .item(window.playlist_pos() as u32) - .unwrap() - .dynamic_cast() - .unwrap(); - window.set_song(Some(&song)); + window.notify("song"); // TODO: load cover art + + // sanity check + assert_eq!( + window.song().unwrap().stream_url(), + window.imp().mpv.get_property::("path").unwrap() + ); } Event::Hook(event) => match event.reply_userdata { @@ -298,6 +298,21 @@ mod imp { } .unwrap() } + + fn song(&self) -> Option { + if self.obj().playlist_pos() < 0 { + None + } else { + Some( + self.obj() + .playlist_model() + .item(self.obj().playlist_pos() as u32) + .unwrap() + .dynamic_cast() + .unwrap(), + ) + } + } } impl Drop for Window {