sure ill ship it
This commit is contained in:
parent
67cfcb7696
commit
5790bdce6c
2 changed files with 37 additions and 22 deletions
|
@ -64,6 +64,7 @@ use crate::subsonic;
|
||||||
use adw::{prelude::*, subclass::prelude::*};
|
use adw::{prelude::*, subclass::prelude::*};
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gdk, glib};
|
use gtk::{gdk, glib};
|
||||||
|
use tracing::{event, Level};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct Song(ObjectSubclass<imp::Song>);
|
pub struct Song(ObjectSubclass<imp::Song>);
|
||||||
|
@ -94,11 +95,20 @@ impl Song {
|
||||||
song.imp()
|
song.imp()
|
||||||
.thumbnail_loading
|
.thumbnail_loading
|
||||||
.replace(Some(glib::spawn_future_local(async move {
|
.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
|
.cover_art(&id, Some(50 * scale_factor)) // see pixel-size in
|
||||||
// play_queue_song.blp
|
// play_queue_song.blp
|
||||||
.await
|
.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() {
|
let song = match song_weak.upgrade() {
|
||||||
None => return,
|
None => return,
|
||||||
Some(song) => song,
|
Some(song) => song,
|
||||||
|
|
|
@ -15,7 +15,6 @@ mod imp {
|
||||||
pub(super) enum State {
|
pub(super) enum State {
|
||||||
Idle,
|
Idle,
|
||||||
FileLoading,
|
FileLoading,
|
||||||
FileLoaded, // internal
|
|
||||||
Active,
|
Active,
|
||||||
FileEnded, // internal
|
FileEnded, // internal
|
||||||
Seeking,
|
Seeking,
|
||||||
|
@ -263,7 +262,6 @@ mod imp {
|
||||||
State::Idle | State::FileLoading | State::Seeking => {}
|
State::Idle | State::FileLoading | State::Seeking => {}
|
||||||
State::Active => window.notify("time-pos"),
|
State::Active => window.notify("time-pos"),
|
||||||
State::FileEnded => {}
|
State::FileEnded => {}
|
||||||
other => unreachable!("{other:?}"),
|
|
||||||
}
|
}
|
||||||
glib::ControlFlow::Continue
|
glib::ControlFlow::Continue
|
||||||
}
|
}
|
||||||
|
@ -289,7 +287,6 @@ mod imp {
|
||||||
Event::LogMessage(event) => window.imp().on_log_message(event),
|
Event::LogMessage(event) => window.imp().on_log_message(event),
|
||||||
|
|
||||||
Event::StartFile(_) => window.imp().on_start_file(),
|
Event::StartFile(_) => window.imp().on_start_file(),
|
||||||
Event::FileLoaded => window.imp().on_file_loaded(),
|
|
||||||
Event::PlaybackRestart => window.imp().on_playback_restart(),
|
Event::PlaybackRestart => window.imp().on_playback_restart(),
|
||||||
Event::Seek => window.imp().on_seek(),
|
Event::Seek => window.imp().on_seek(),
|
||||||
Event::EndFile(event) => window.imp().on_end_file(event),
|
Event::EndFile(event) => window.imp().on_end_file(event),
|
||||||
|
@ -411,7 +408,7 @@ mod imp {
|
||||||
let api = self.api.borrow();
|
let api = self.api.borrow();
|
||||||
Rc::clone(api.as_ref().unwrap())
|
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);
|
let song = Song::from_child(&self.obj(), &song, true);
|
||||||
self.mpv
|
self.mpv
|
||||||
.command(["loadfile", &song.stream_url(), "append-play"])
|
.command(["loadfile", &song.stream_url(), "append-play"])
|
||||||
|
@ -676,10 +673,19 @@ mod imp {
|
||||||
.loading_cover_handle
|
.loading_cover_handle
|
||||||
.replace(Some(glib::spawn_future_local(async move {
|
.replace(Some(glib::spawn_future_local(async move {
|
||||||
let api = window.imp().api.borrow().as_ref().unwrap().clone();
|
let api = window.imp().api.borrow().as_ref().unwrap().clone();
|
||||||
let bytes = api
|
let bytes = match api
|
||||||
.cover_art(&song_id, None) // full size
|
.cover_art(&song_id, None) // full size
|
||||||
.await
|
.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() {
|
match window.song() {
|
||||||
Some(song) if song.id() == song_id => {
|
Some(song) if song.id() == song_id => {
|
||||||
|
@ -707,7 +713,18 @@ mod imp {
|
||||||
let mut css = String::new();
|
let mut css = String::new();
|
||||||
css.push_str(":root {");
|
css.push_str(":root {");
|
||||||
let n_colors = palette.len();
|
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}; "));
|
css.push_str(&format!("--background-color-{i}: {color}; "));
|
||||||
}
|
}
|
||||||
for i in n_colors..3 {
|
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) {
|
fn on_seek(&self) {
|
||||||
event!(Level::INFO, "Seek");
|
event!(Level::INFO, "Seek");
|
||||||
|
|
||||||
|
@ -760,7 +766,7 @@ mod imp {
|
||||||
|
|
||||||
fn on_playback_restart(&self) {
|
fn on_playback_restart(&self) {
|
||||||
match self.state.get() {
|
match self.state.get() {
|
||||||
State::FileLoaded => {}
|
State::FileLoading => {}
|
||||||
State::Seeking => {}
|
State::Seeking => {}
|
||||||
|
|
||||||
other => panic!("invalid state transition: PlaybackRestart from {other:?}"),
|
other => panic!("invalid state transition: PlaybackRestart from {other:?}"),
|
||||||
|
@ -783,7 +789,6 @@ mod imp {
|
||||||
match self.state.get() {
|
match self.state.get() {
|
||||||
State::Active => {}
|
State::Active => {}
|
||||||
State::FileLoading => {}
|
State::FileLoading => {}
|
||||||
State::FileLoaded => {}
|
|
||||||
State::Seeking => {}
|
State::Seeking => {}
|
||||||
|
|
||||||
other => panic!("invalid state transition: EndFile from {other:?}"),
|
other => panic!("invalid state transition: EndFile from {other:?}"),
|
||||||
|
|
Loading…
Reference in a new issue