Update gtk-rs crates

This commit is contained in:
Elias Projahn 2021-05-07 23:49:05 +02:00
parent df6e2e86c7
commit 7d7343ea8c
63 changed files with 3499 additions and 908 deletions

View file

@ -21,6 +21,4 @@ pub enum Error {
Other(String),
}
pub type Result<T> = std::result::Result<T, Error>;

View file

@ -20,9 +20,15 @@ impl Backend {
/// Set the path to the music library folder and start a database thread in the background.
pub async fn set_music_library_path(&self, path: PathBuf) -> Result<()> {
if let Err(err) = self.settings.set_string("music-library-path", path.to_str().unwrap()) {
warn!("The music library path could not be saved using GSettings. It will most likely \
not be available at the next startup. Error message: {}", err);
if let Err(err) = self
.settings
.set_string("music-library-path", path.to_str().unwrap())
{
warn!(
"The music library path could not be saved using GSettings. It will most likely \
not be available at the next startup. Error message: {}",
err
);
}
self.set_music_library_path_priv(path).await

View file

@ -1,7 +1,7 @@
use crate::{Error, Result};
use musicus_database::Track;
use glib::clone;
use gstreamer_player::prelude::*;
use musicus_database::Track;
use std::cell::{Cell, RefCell};
use std::path::PathBuf;
use std::rc::Rc;
@ -101,9 +101,11 @@ impl Player {
#[cfg(target_os = "linux")]
{
result.mpris.connect_play_pause(clone!(@weak result => move || {
result.play_pause();
}));
result
.mpris
.connect_play_pause(clone!(@weak result => move || {
result.play_pause();
}));
result.mpris.connect_play(clone!(@weak result => move || {
if !result.is_playing() {
@ -117,9 +119,11 @@ impl Player {
}
}));
result.mpris.connect_previous(clone!(@weak result => move || {
let _ = result.previous();
}));
result
.mpris
.connect_previous(clone!(@weak result => move || {
let _ = result.previous();
}));
result.mpris.connect_next(clone!(@weak result => move || {
let _ = result.next();
@ -246,10 +250,9 @@ impl Player {
}
pub fn previous(&self) -> Result<()> {
let mut current_track = self
.current_track
.get()
.ok_or(Error::Other(String::from("Player tried to access non existant current track.")))?;
let mut current_track = self.current_track.get().ok_or(Error::Other(String::from(
"Player tried to access non existant current track.",
)))?;
if current_track > 0 {
current_track -= 1;
@ -270,10 +273,9 @@ impl Player {
}
pub fn next(&self) -> Result<()> {
let mut current_track = self
.current_track
.get()
.ok_or(Error::Other(String::from("Player tried to access non existant current track.")))?;
let mut current_track = self.current_track.get().ok_or(Error::Other(String::from(
"Player tried to access non existant current track.",
)))?;
let playlist = self.playlist.borrow();
@ -289,11 +291,17 @@ impl Player {
pub fn set_track(&self, current_track: usize) -> Result<()> {
let track = &self.playlist.borrow()[current_track];
let path = self.music_library_path.join(track.path.clone())
.into_os_string().into_string().unwrap();
let path = self
.music_library_path
.join(track.path.clone())
.into_os_string()
.into_string()
.unwrap();
let uri = glib::filename_to_uri(&path, None)
.or(Err(Error::Other(format!("Failed to create URI from path: {}", path))))?;
let uri = glib::filename_to_uri(&path, None).or(Err(Error::Other(format!(
"Failed to create URI from path: {}",
path
))))?;
self.player.set_uri(&uri);

View file

@ -1,6 +1,6 @@
use crate::{Backend, Error, Result};
use musicus_client::LoginData;
use futures_channel::oneshot;
use musicus_client::LoginData;
use secret_service::{Collection, EncryptionType, SecretService};
use std::collections::HashMap;
use std::thread;
@ -35,14 +35,18 @@ impl Backend {
let items = collection.get_all_items()?;
let key = "musicus-login-data";
let item = items.iter().find(|item| item.get_label().unwrap_or_default() == key);
let item = items
.iter()
.find(|item| item.get_label().unwrap_or_default() == key);
Ok(match item {
Some(item) => {
let username = item
.get_attributes()?
.get("username")
.ok_or(Error::Other("Missing username in SecretService attributes."))?
.ok_or(Error::Other(
"Missing username in SecretService attributes.",
))?
.to_owned();
let password = std::str::from_utf8(&item.get_secret()?)?.to_owned();
@ -63,7 +67,13 @@ impl Backend {
let mut attributes = HashMap::new();
attributes.insert("username", data.username.as_str());
collection.create_item(key, attributes, data.password.as_bytes(), true, "text/plain")?;
collection.create_item(
key,
attributes,
data.password.as_bytes(),
true,
"text/plain",
)?;
Ok(())
}