From 5790bdce6c30a11c21c974e5070b99477b71d436 Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 13 Nov 2024 23:33:19 +0100 Subject: [PATCH] sure ill ship it --- src/model/song.rs | 14 ++++++++++++-- src/ui/window.rs | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/model/song.rs b/src/model/song.rs index ad340bc..8ec818d 100644 --- a/src/model/song.rs +++ b/src/model/song.rs @@ -64,6 +64,7 @@ use crate::subsonic; use adw::{prelude::*, subclass::prelude::*}; use glib::Object; use gtk::{gdk, glib}; +use tracing::{event, Level}; glib::wrapper! { pub struct Song(ObjectSubclass); @@ -94,11 +95,20 @@ impl Song { song.imp() .thumbnail_loading .replace(Some(glib::spawn_future_local(async move { - let bytes = api + let bytes = match api .cover_art(&id, Some(50 * scale_factor)) // see pixel-size in // play_queue_song.blp .await - .unwrap(); + { + Ok(bytes) => bytes, + Err(err) => { + event!( + Level::ERROR, + "could not fetch thumbnail for song {id}: {err}" + ); + return; + } + }; let song = match song_weak.upgrade() { None => return, Some(song) => song, diff --git a/src/ui/window.rs b/src/ui/window.rs index 15765cb..0021e7b 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -15,7 +15,6 @@ mod imp { pub(super) enum State { Idle, FileLoading, - FileLoaded, // internal Active, FileEnded, // internal Seeking, @@ -263,7 +262,6 @@ mod imp { State::Idle | State::FileLoading | State::Seeking => {} State::Active => window.notify("time-pos"), State::FileEnded => {} - other => unreachable!("{other:?}"), } glib::ControlFlow::Continue } @@ -289,7 +287,6 @@ mod imp { Event::LogMessage(event) => window.imp().on_log_message(event), Event::StartFile(_) => window.imp().on_start_file(), - Event::FileLoaded => window.imp().on_file_loaded(), Event::PlaybackRestart => window.imp().on_playback_restart(), Event::Seek => window.imp().on_seek(), Event::EndFile(event) => window.imp().on_end_file(event), @@ -411,7 +408,7 @@ mod imp { let api = self.api.borrow(); Rc::clone(api.as_ref().unwrap()) }; - for song in api.random_songs(10).await.unwrap().into_iter() { + for song in api.random_songs(500).await.unwrap().into_iter() { let song = Song::from_child(&self.obj(), &song, true); self.mpv .command(["loadfile", &song.stream_url(), "append-play"]) @@ -676,10 +673,19 @@ mod imp { .loading_cover_handle .replace(Some(glib::spawn_future_local(async move { let api = window.imp().api.borrow().as_ref().unwrap().clone(); - let bytes = api + let bytes = match api .cover_art(&song_id, None) // full size .await - .expect("could not load cover art for song {song_id}"); + { + Ok(bytes) => bytes, + Err(err) => { + event!( + Level::ERROR, + "could not fetch cover art for song {song_id}: {err}" + ); + return; + } + }; match window.song() { Some(song) if song.id() == song_id => { @@ -707,7 +713,18 @@ mod imp { let mut css = String::new(); css.push_str(":root {"); let n_colors = palette.len(); - for (i, color) in palette.into_iter().enumerate() { + for (i, color) in palette + .into_iter() + .map(|c| { + gdk::RGBA::new( + c.r as f32 / 255.0, + c.g as f32 / 255.0, + c.b as f32 / 255.0, + 1.0, + ) + }) + .enumerate() + { css.push_str(&format!("--background-color-{i}: {color}; ")); } for i in n_colors..3 { @@ -732,17 +749,6 @@ mod imp { } } - fn on_file_loaded(&self) { - match self.state.get() { - State::FileLoading => {} - - other => panic!("invalid state transition: FileLoaded from {other:?}"), - } - self.state.set(State::FileLoaded); - - event!(Level::INFO, "FileLoaded"); - } - fn on_seek(&self) { event!(Level::INFO, "Seek"); @@ -760,7 +766,7 @@ mod imp { fn on_playback_restart(&self) { match self.state.get() { - State::FileLoaded => {} + State::FileLoading => {} State::Seeking => {} other => panic!("invalid state transition: PlaybackRestart from {other:?}"), @@ -783,7 +789,6 @@ mod imp { match self.state.get() { State::Active => {} State::FileLoading => {} - State::FileLoaded => {} State::Seeking => {} other => panic!("invalid state transition: EndFile from {other:?}"),