make code less readable

This commit is contained in:
psykose 2024-11-23 22:39:12 +01:00
parent 6975148163
commit 8579d5190d
Signed by: psykose
SSH key fingerprint: SHA256:pRMVjV3kRB6zl+wNx+sV8KoMnPqQAW6v8dNCxsCGZv8
12 changed files with 63 additions and 64 deletions

View file

@ -40,7 +40,7 @@ reqwest-middleware = { version = "0.4.0", features = [
] } ] }
serde = { version = "1.0.214", features = ["derive"] } serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.133" serde_json = "1.0.133"
tokio = { version = "1", features = ["parking_lot", "rt-multi-thread"] } tokio = { version = "1", features = ["parking_lot", "rt-multi-thread", "sync"] }
tracing = { version = "0.1.40", default-features = false, features = [ tracing = { version = "0.1.40", default-features = false, features = [
"attributes", "attributes",
"std", "std",

View file

@ -56,7 +56,7 @@ glib::wrapper! {
impl Default for Application { impl Default for Application {
fn default() -> Self { fn default() -> Self {
glib::Object::builder::<Application>() glib::Object::builder::<Self>()
.property("application-id", crate::APP_ID) .property("application-id", crate::APP_ID)
.property("flags", gio::ApplicationFlags::default()) .property("flags", gio::ApplicationFlags::default())
.build() .build()

View file

@ -76,7 +76,7 @@ glib::wrapper! {
impl Song { impl Song {
pub fn from_child(window: &crate::ui::Window, song: &subsonic::schema::Child) -> Self { pub fn from_child(window: &crate::ui::Window, song: &subsonic::schema::Child) -> Self {
let api = window.api(); let api = window.api();
let song: Song = Object::builder() let song: Self = Object::builder()
.property("id", &song.id) .property("id", &song.id)
.property("title", &song.title) .property("title", &song.title)
.property("artist", &song.artist) .property("artist", &song.artist)

View file

@ -20,8 +20,6 @@ impl Mpris {
object_server.at("/org/mpris/MediaPlayer2", mpris).await?; object_server.at("/org/mpris/MediaPlayer2", mpris).await?;
//let _mpris = object_server.interface::<_, Self>("/org/mpris/MediaPlayer2").await?;
Ok(()) Ok(())
} }
} }
@ -43,34 +41,34 @@ impl Mpris {
} }
#[zbus(property)] #[zbus(property)]
fn can_quit(&self) -> bool { const fn can_quit(&self) -> bool {
true true
} }
#[zbus(property)] #[zbus(property)]
fn fullscreen(&self) -> bool { const fn fullscreen(&self) -> bool {
false false
} }
#[zbus(property)] #[zbus(property)]
// TODO: report that if the argument is just _ the attribute panics // TODO: report that if the argument is just _ the attribute panics
// TODO: why can't this return zbus::fdo::Result?? // TODO: why can't this return zbus::fdo::Result??
fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> { const fn set_fullscreen(&self, _fullscreen: bool) -> zbus::Result<()> {
Err(zbus::Error::Unsupported) Err(zbus::Error::Unsupported)
} }
#[zbus(property)] #[zbus(property)]
fn can_set_fullscreen(&self) -> bool { const fn can_set_fullscreen(&self) -> bool {
false false
} }
#[zbus(property)] #[zbus(property)]
fn can_raise(&self) -> bool { const fn can_raise(&self) -> bool {
true true
} }
#[zbus(property)] #[zbus(property)]
fn has_track_list(&self) -> bool { const fn has_track_list(&self) -> bool {
false // TODO? false // TODO?
} }
@ -85,12 +83,12 @@ impl Mpris {
} }
#[zbus(property)] #[zbus(property)]
fn supported_uri_schemes(&self) -> Vec<String> { const fn supported_uri_schemes(&self) -> Vec<String> {
vec![] vec![]
} }
#[zbus(property)] #[zbus(property)]
fn supported_mime_types(&self) -> Vec<String> { const fn supported_mime_types(&self) -> Vec<String> {
vec![] vec![]
} }
} }

View file

@ -16,7 +16,7 @@ impl Player {
pub async fn new( pub async fn new(
object_server: &zbus::ObjectServer, object_server: &zbus::ObjectServer,
playbin: &Window, playbin: &Window,
) -> Result<InterfaceRef<Player>, zbus::Error> { ) -> Result<InterfaceRef<Self>, zbus::Error> {
let player = Self { let player = Self {
window: playbin.downgrade().into(), window: playbin.downgrade().into(),
}; };
@ -131,7 +131,7 @@ impl Player {
} }
#[zbus(property)] #[zbus(property)]
fn rate(&self) -> zbus::fdo::Result<f64> { const fn rate(&self) -> zbus::fdo::Result<f64> {
Ok(1.0) Ok(1.0)
} }
@ -173,6 +173,7 @@ impl Player {
(url::Url::from_file_path(path).unwrap().to_string()).into(), (url::Url::from_file_path(path).unwrap().to_string()).into(),
); );
} }
drop(mpris_art_path);
map.insert("xesam:album", song.album().into()); map.insert("xesam:album", song.album().into());
// TODO: use the right opensubsonic data // TODO: use the right opensubsonic data
map.insert("xesam:artist", vec![song.artist()].into()); map.insert("xesam:artist", vec![song.artist()].into());
@ -201,12 +202,12 @@ impl Player {
} }
#[zbus(property)] #[zbus(property)]
fn minimum_rate(&self) -> f64 { const fn minimum_rate(&self) -> f64 {
1.0 1.0
} }
#[zbus(property)] #[zbus(property)]
fn maximum_rate(&self) -> f64 { const fn maximum_rate(&self) -> f64 {
1.0 1.0
} }
@ -236,7 +237,7 @@ impl Player {
} }
#[zbus(property(emits_changed_signal = "const"))] #[zbus(property(emits_changed_signal = "const"))]
fn can_control(&self) -> bool { const fn can_control(&self) -> bool {
true true
} }
} }

View file

@ -6,7 +6,7 @@ use std::fmt;
pub struct Error(pub(super) c_int); pub struct Error(pub(super) c_int);
impl Error { impl Error {
pub(super) fn from_return_code(rc: c_int) -> Result<(), Self> { pub(super) const fn from_return_code(rc: c_int) -> Result<(), Self> {
if rc == 0 { if rc == 0 {
Ok(()) Ok(())
} else { } else {
@ -20,7 +20,7 @@ impl Error {
.unwrap() .unwrap()
} }
pub fn is_property_unavailable(self) -> bool { pub const fn is_property_unavailable(self) -> bool {
self.0 == ffi::mpv_error_MPV_ERROR_PROPERTY_UNAVAILABLE self.0 == ffi::mpv_error_MPV_ERROR_PROPERTY_UNAVAILABLE
} }
} }

View file

@ -66,7 +66,7 @@ impl SetProperty for i64 {
ctx, ctx,
name, name,
ffi::mpv_format_MPV_FORMAT_INT64, ffi::mpv_format_MPV_FORMAT_INT64,
std::ptr::from_ref::<i64>(&self) as *mut c_void, std::ptr::from_ref::<Self>(&self) as *mut c_void,
)) ))
} }
} }
@ -81,7 +81,7 @@ impl SetProperty for f64 {
ctx, ctx,
name, name,
ffi::mpv_format_MPV_FORMAT_DOUBLE, ffi::mpv_format_MPV_FORMAT_DOUBLE,
std::ptr::from_ref::<f64>(&self) as *mut c_void, std::ptr::from_ref::<Self>(&self) as *mut c_void,
)) ))
} }
} }
@ -111,12 +111,12 @@ impl GetProperty for bool {
impl GetProperty for i64 { impl GetProperty for i64 {
unsafe fn get_property(ctx: *mut ffi::mpv_handle, name: *const c_char) -> Result<Self, Error> { unsafe fn get_property(ctx: *mut ffi::mpv_handle, name: *const c_char) -> Result<Self, Error> {
let mut value: i64 = -1; let mut value: Self = -1;
Error::from_return_code(ffi::mpv_get_property( Error::from_return_code(ffi::mpv_get_property(
ctx, ctx,
name, name,
ffi::mpv_format_MPV_FORMAT_INT64, ffi::mpv_format_MPV_FORMAT_INT64,
std::ptr::from_mut::<i64>(&mut value) as *mut c_void, std::ptr::from_mut::<Self>(&mut value) as *mut c_void,
))?; ))?;
Ok(value) Ok(value)
} }
@ -124,12 +124,12 @@ impl GetProperty for i64 {
impl GetProperty for f64 { impl GetProperty for f64 {
unsafe fn get_property(ctx: *mut ffi::mpv_handle, name: *const c_char) -> Result<Self, Error> { unsafe fn get_property(ctx: *mut ffi::mpv_handle, name: *const c_char) -> Result<Self, Error> {
let mut value: f64 = 0.0; let mut value: Self = 0.0;
Error::from_return_code(ffi::mpv_get_property( Error::from_return_code(ffi::mpv_get_property(
ctx, ctx,
name, name,
ffi::mpv_format_MPV_FORMAT_DOUBLE, ffi::mpv_format_MPV_FORMAT_DOUBLE,
std::ptr::from_mut::<f64>(&mut value) as *mut c_void, std::ptr::from_mut::<Self>(&mut value) as *mut c_void,
))?; ))?;
Ok(value) Ok(value)
} }

View file

@ -146,7 +146,7 @@ impl Client {
.with(http_cache) .with(http_cache)
.build(); .build();
Ok(Client { client, base_url }) Ok(Self { client, base_url })
} }
async fn send( async fn send(
@ -255,12 +255,10 @@ impl Client {
} }
pub fn cover_art_url(&self, id: &str, size: Option<u32>) -> url::Url { pub fn cover_art_url(&self, id: &str, size: Option<u32>) -> url::Url {
let endpoint = &["rest", "getCoverArt"];
match size { match size {
None => self.url(&["rest", "getCoverArt"], &[("id", id)]), None => self.url(endpoint, &[("id", id)]),
Some(size) => self.url( Some(size) => self.url(endpoint, &[("id", id), ("size", &size.to_string())]),
&["rest", "getCoverArt"],
&[("id", id), ("size", &size.to_string())],
),
} }
} }

View file

@ -50,7 +50,7 @@ mod imp {
#[gtk::template_callbacks] #[gtk::template_callbacks]
impl PlayQueue { impl PlayQueue {
#[template_callback] #[template_callback]
fn visible_child_name(&self, n_items: u32) -> &'static str { const fn visible_child_name(&self, n_items: u32) -> &'static str {
if n_items > 0 { if n_items > 0 {
"not-empty" "not-empty"
} else { } else {

View file

@ -203,5 +203,5 @@ impl Song {
song.need_thumbnail(window); song.need_thumbnail(window);
} }
pub fn unbind(&self) {} pub const fn unbind(&self) {}
} }

View file

@ -76,7 +76,7 @@ mod imp {
} }
#[template_callback] #[template_callback]
fn mute_button_icon_name(&self, mute: bool) -> &'static str { const fn mute_button_icon_name(&self, mute: bool) -> &'static str {
if mute { if mute {
"audio-volume-muted" "audio-volume-muted"
} else { } else {
@ -150,17 +150,17 @@ mod imp {
// updated // updated
#[template_callback] #[template_callback]
fn song_title(&self, song: Option<&Song>) -> String { fn song_title(&self, song: Option<&Song>) -> String {
song.map(Song::title).unwrap_or("".to_string()) song.map(Song::title).unwrap_or_default()
} }
#[template_callback] #[template_callback]
fn song_artist(&self, song: Option<&Song>) -> String { fn song_artist(&self, song: Option<&Song>) -> String {
song.map(Song::artist).unwrap_or("".to_string()) song.map(Song::artist).unwrap_or_default()
} }
#[template_callback] #[template_callback]
fn song_album(&self, song: Option<&Song>) -> String { fn song_album(&self, song: Option<&Song>) -> String {
song.map(Song::album).unwrap_or("".to_string()) song.map(Song::album).unwrap_or_default()
} }
} }

View file

@ -243,16 +243,17 @@ mod imp {
self.time_pos_notify_timeout self.time_pos_notify_timeout
.replace(Some(glib::timeout_add_local( .replace(Some(glib::timeout_add_local(
std::time::Duration::from_millis(100), std::time::Duration::from_millis(100),
move || match window.upgrade() { move || {
None => glib::ControlFlow::Break, window
Some(window) => { .upgrade()
match window.imp().state.get() { .map_or(glib::ControlFlow::Break, move |window| {
State::Idle | State::FileLoading | State::Seeking => {} match window.imp().state.get() {
State::Active => window.notify("time-pos"), State::Idle | State::FileLoading | State::Seeking => {}
State::FileEnded => {} State::Active => window.notify("time-pos"),
} State::FileEnded => {}
glib::ControlFlow::Continue }
} glib::ControlFlow::Continue
})
}, },
))); )));
@ -522,17 +523,19 @@ mod imp {
} }
fn song(&self) -> Option<Song> { fn song(&self) -> Option<Song> {
match self.obj().playlist_pos().try_into() { self.obj().playlist_pos().try_into().map_or_else(
Ok(playlist_pos) => Some( move |_| None,
self.obj() move |playlist_pos| {
.playlist_model() Some(
.item(playlist_pos) self.obj()
.unwrap() .playlist_model()
.dynamic_cast() .item(playlist_pos)
.unwrap(), .unwrap()
), .dynamic_cast()
Err(_) => None, .unwrap(),
} )
},
)
} }
fn buffering_start(&self) { fn buffering_start(&self) {
@ -541,17 +544,16 @@ mod imp {
if let Some(source) = self.buffering_timeout.replace(Some(glib::timeout_add_local( if let Some(source) = self.buffering_timeout.replace(Some(glib::timeout_add_local(
std::time::Duration::from_millis(100), std::time::Duration::from_millis(100),
move || { move || {
match window.upgrade() { window
None => glib::ControlFlow::Break, .upgrade()
Some(window) => { .map_or(glib::ControlFlow::Break, move |window| {
// 3 second period from gnome hig // 3 second period from gnome hig
if started_buffering.elapsed() > std::time::Duration::from_secs(3) { if started_buffering.elapsed() > std::time::Duration::from_secs(3) {
window.imp().playbar.set_show_pulse_bar(true); window.imp().playbar.set_show_pulse_bar(true);
window.imp().playbar.pulse_bar().pulse(); window.imp().playbar.pulse_bar().pulse();
} }
glib::ControlFlow::Continue glib::ControlFlow::Continue
} })
}
}, },
))) { ))) {
source.remove() source.remove()