make code less readable
This commit is contained in:
parent
6975148163
commit
8579d5190d
12 changed files with 63 additions and 64 deletions
|
@ -40,7 +40,7 @@ reqwest-middleware = { version = "0.4.0", features = [
|
|||
] }
|
||||
serde = { version = "1.0.214", features = ["derive"] }
|
||||
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 = [
|
||||
"attributes",
|
||||
"std",
|
||||
|
|
|
@ -56,7 +56,7 @@ glib::wrapper! {
|
|||
|
||||
impl Default for Application {
|
||||
fn default() -> Self {
|
||||
glib::Object::builder::<Application>()
|
||||
glib::Object::builder::<Self>()
|
||||
.property("application-id", crate::APP_ID)
|
||||
.property("flags", gio::ApplicationFlags::default())
|
||||
.build()
|
||||
|
|
|
@ -76,7 +76,7 @@ glib::wrapper! {
|
|||
impl Song {
|
||||
pub fn from_child(window: &crate::ui::Window, song: &subsonic::schema::Child) -> Self {
|
||||
let api = window.api();
|
||||
let song: Song = Object::builder()
|
||||
let song: Self = Object::builder()
|
||||
.property("id", &song.id)
|
||||
.property("title", &song.title)
|
||||
.property("artist", &song.artist)
|
||||
|
|
18
src/mpris.rs
18
src/mpris.rs
|
@ -20,8 +20,6 @@ impl Mpris {
|
|||
|
||||
object_server.at("/org/mpris/MediaPlayer2", mpris).await?;
|
||||
|
||||
//let _mpris = object_server.interface::<_, Self>("/org/mpris/MediaPlayer2").await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -43,34 +41,34 @@ impl Mpris {
|
|||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_quit(&self) -> bool {
|
||||
const fn can_quit(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn fullscreen(&self) -> bool {
|
||||
const fn fullscreen(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
// TODO: report that if the argument is just _ the attribute panics
|
||||
// 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)
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_set_fullscreen(&self) -> bool {
|
||||
const fn can_set_fullscreen(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn can_raise(&self) -> bool {
|
||||
const fn can_raise(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn has_track_list(&self) -> bool {
|
||||
const fn has_track_list(&self) -> bool {
|
||||
false // TODO?
|
||||
}
|
||||
|
||||
|
@ -85,12 +83,12 @@ impl Mpris {
|
|||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn supported_uri_schemes(&self) -> Vec<String> {
|
||||
const fn supported_uri_schemes(&self) -> Vec<String> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn supported_mime_types(&self) -> Vec<String> {
|
||||
const fn supported_mime_types(&self) -> Vec<String> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ impl Player {
|
|||
pub async fn new(
|
||||
object_server: &zbus::ObjectServer,
|
||||
playbin: &Window,
|
||||
) -> Result<InterfaceRef<Player>, zbus::Error> {
|
||||
) -> Result<InterfaceRef<Self>, zbus::Error> {
|
||||
let player = Self {
|
||||
window: playbin.downgrade().into(),
|
||||
};
|
||||
|
@ -131,7 +131,7 @@ impl Player {
|
|||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn rate(&self) -> zbus::fdo::Result<f64> {
|
||||
const fn rate(&self) -> zbus::fdo::Result<f64> {
|
||||
Ok(1.0)
|
||||
}
|
||||
|
||||
|
@ -173,6 +173,7 @@ impl Player {
|
|||
(url::Url::from_file_path(path).unwrap().to_string()).into(),
|
||||
);
|
||||
}
|
||||
drop(mpris_art_path);
|
||||
map.insert("xesam:album", song.album().into());
|
||||
// TODO: use the right opensubsonic data
|
||||
map.insert("xesam:artist", vec![song.artist()].into());
|
||||
|
@ -201,12 +202,12 @@ impl Player {
|
|||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn minimum_rate(&self) -> f64 {
|
||||
const fn minimum_rate(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
fn maximum_rate(&self) -> f64 {
|
||||
const fn maximum_rate(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
|
@ -236,7 +237,7 @@ impl Player {
|
|||
}
|
||||
|
||||
#[zbus(property(emits_changed_signal = "const"))]
|
||||
fn can_control(&self) -> bool {
|
||||
const fn can_control(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::fmt;
|
|||
pub struct Error(pub(super) c_int);
|
||||
|
||||
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 {
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ impl Error {
|
|||
.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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ impl SetProperty for i64 {
|
|||
ctx,
|
||||
name,
|
||||
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,
|
||||
name,
|
||||
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 {
|
||||
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(
|
||||
ctx,
|
||||
name,
|
||||
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)
|
||||
}
|
||||
|
@ -124,12 +124,12 @@ impl GetProperty for i64 {
|
|||
|
||||
impl GetProperty for f64 {
|
||||
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(
|
||||
ctx,
|
||||
name,
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ impl Client {
|
|||
.with(http_cache)
|
||||
.build();
|
||||
|
||||
Ok(Client { client, base_url })
|
||||
Ok(Self { client, base_url })
|
||||
}
|
||||
|
||||
async fn send(
|
||||
|
@ -255,12 +255,10 @@ impl Client {
|
|||
}
|
||||
|
||||
pub fn cover_art_url(&self, id: &str, size: Option<u32>) -> url::Url {
|
||||
let endpoint = &["rest", "getCoverArt"];
|
||||
match size {
|
||||
None => self.url(&["rest", "getCoverArt"], &[("id", id)]),
|
||||
Some(size) => self.url(
|
||||
&["rest", "getCoverArt"],
|
||||
&[("id", id), ("size", &size.to_string())],
|
||||
),
|
||||
None => self.url(endpoint, &[("id", id)]),
|
||||
Some(size) => self.url(endpoint, &[("id", id), ("size", &size.to_string())]),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ mod imp {
|
|||
#[gtk::template_callbacks]
|
||||
impl PlayQueue {
|
||||
#[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 {
|
||||
"not-empty"
|
||||
} else {
|
||||
|
|
|
@ -203,5 +203,5 @@ impl Song {
|
|||
song.need_thumbnail(window);
|
||||
}
|
||||
|
||||
pub fn unbind(&self) {}
|
||||
pub const fn unbind(&self) {}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ mod imp {
|
|||
}
|
||||
|
||||
#[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 {
|
||||
"audio-volume-muted"
|
||||
} else {
|
||||
|
@ -150,17 +150,17 @@ mod imp {
|
|||
// updated
|
||||
#[template_callback]
|
||||
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]
|
||||
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]
|
||||
fn song_album(&self, song: Option<&Song>) -> String {
|
||||
song.map(Song::album).unwrap_or("".to_string())
|
||||
song.map(Song::album).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -243,16 +243,17 @@ mod imp {
|
|||
self.time_pos_notify_timeout
|
||||
.replace(Some(glib::timeout_add_local(
|
||||
std::time::Duration::from_millis(100),
|
||||
move || match window.upgrade() {
|
||||
None => glib::ControlFlow::Break,
|
||||
Some(window) => {
|
||||
match window.imp().state.get() {
|
||||
State::Idle | State::FileLoading | State::Seeking => {}
|
||||
State::Active => window.notify("time-pos"),
|
||||
State::FileEnded => {}
|
||||
}
|
||||
glib::ControlFlow::Continue
|
||||
}
|
||||
move || {
|
||||
window
|
||||
.upgrade()
|
||||
.map_or(glib::ControlFlow::Break, move |window| {
|
||||
match window.imp().state.get() {
|
||||
State::Idle | State::FileLoading | State::Seeking => {}
|
||||
State::Active => window.notify("time-pos"),
|
||||
State::FileEnded => {}
|
||||
}
|
||||
glib::ControlFlow::Continue
|
||||
})
|
||||
},
|
||||
)));
|
||||
|
||||
|
@ -522,17 +523,19 @@ mod imp {
|
|||
}
|
||||
|
||||
fn song(&self) -> Option<Song> {
|
||||
match self.obj().playlist_pos().try_into() {
|
||||
Ok(playlist_pos) => Some(
|
||||
self.obj()
|
||||
.playlist_model()
|
||||
.item(playlist_pos)
|
||||
.unwrap()
|
||||
.dynamic_cast()
|
||||
.unwrap(),
|
||||
),
|
||||
Err(_) => None,
|
||||
}
|
||||
self.obj().playlist_pos().try_into().map_or_else(
|
||||
move |_| None,
|
||||
move |playlist_pos| {
|
||||
Some(
|
||||
self.obj()
|
||||
.playlist_model()
|
||||
.item(playlist_pos)
|
||||
.unwrap()
|
||||
.dynamic_cast()
|
||||
.unwrap(),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn buffering_start(&self) {
|
||||
|
@ -541,17 +544,16 @@ mod imp {
|
|||
if let Some(source) = self.buffering_timeout.replace(Some(glib::timeout_add_local(
|
||||
std::time::Duration::from_millis(100),
|
||||
move || {
|
||||
match window.upgrade() {
|
||||
None => glib::ControlFlow::Break,
|
||||
Some(window) => {
|
||||
window
|
||||
.upgrade()
|
||||
.map_or(glib::ControlFlow::Break, move |window| {
|
||||
// 3 second period from gnome hig
|
||||
if started_buffering.elapsed() > std::time::Duration::from_secs(3) {
|
||||
window.imp().playbar.set_show_pulse_bar(true);
|
||||
window.imp().playbar.pulse_bar().pulse();
|
||||
}
|
||||
glib::ControlFlow::Continue
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
))) {
|
||||
source.remove()
|
||||
|
|
Loading…
Reference in a new issue