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 = { 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",
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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)
|
||||||
|
|
18
src/mpris.rs
18
src/mpris.rs
|
@ -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![]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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())],
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -203,5 +203,5 @@ impl Song {
|
||||||
song.need_thumbnail(window);
|
song.need_thumbnail(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unbind(&self) {}
|
pub const fn unbind(&self) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
.map_or(glib::ControlFlow::Break, move |window| {
|
||||||
match window.imp().state.get() {
|
match window.imp().state.get() {
|
||||||
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 => {}
|
||||||
}
|
}
|
||||||
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,
|
||||||
|
move |playlist_pos| {
|
||||||
|
Some(
|
||||||
self.obj()
|
self.obj()
|
||||||
.playlist_model()
|
.playlist_model()
|
||||||
.item(playlist_pos)
|
.item(playlist_pos)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.dynamic_cast()
|
.dynamic_cast()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
),
|
)
|
||||||
Err(_) => None,
|
},
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
|
|
Loading…
Reference in a new issue