Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup code, fix build #215

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ jobs:
- name: Build ${{ matrix.target }}
uses: actions-rs/cargo@v1
env:
PKG_CONFIG_ALLOW_CROSS: 1
SQLITE3_STATIC: true
PKG_CONFIG_ALL_STATIC: true
DATABASE_URL: "sqlite:///tmp/data.db"
with:
use-cross: true
command: build
args: --bin hifi-rs --release --target=${{ matrix.target }}
- name: Tar hifi-rs-${{ matrix.target }}.tar.gz
Expand Down
6 changes: 3 additions & 3 deletions hifirs/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ pub async fn run() -> Result<(), Error> {
} => {
let client =
qobuz::make_client(cli.username.as_deref(), cli.password.as_deref()).await?;
let results = client.search_all(query, limit.unwrap_or_default()).await?;
let results = client.search_all(&query, limit.unwrap_or_default()).await?;

output!(results, output_format);

Expand All @@ -334,7 +334,7 @@ pub async fn run() -> Result<(), Error> {
} => {
let client =
qobuz::make_client(cli.username.as_deref(), cli.password.as_deref()).await?;
let results = client.search_albums(query.clone(), limit).await?;
let results = client.search_albums(&query, limit).await?;

output!(results, output_format);

Expand All @@ -347,7 +347,7 @@ pub async fn run() -> Result<(), Error> {
} => {
let client =
qobuz::make_client(cli.username.as_deref(), cli.password.as_deref()).await?;
let results = client.search_artists(query.clone(), limit).await?;
let results = client.search_artists(&query, limit).await?;

output!(results, output_format);

Expand Down
2 changes: 1 addition & 1 deletion hifirs/src/cursive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ pub async fn receive_notifications() {
set_current_track(s, first.1, list.list_type());
}

entity_title.set_content(playlist.title.clone());
entity_title.set_content(&playlist.title);
total_tracks.set_content(format!("{:03}", list.total()));
}

Expand Down
6 changes: 3 additions & 3 deletions hifirs/src/mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ pub async fn receive_notifications(conn: Connection) {
let tracks = list
.cursive_list()
.iter()
.map(|t| t.0.clone())
.collect::<Vec<String>>();
.map(|t| t.0)
.collect::<Vec<&str>>();

MprisTrackList::track_list_replaced(
list_ref.signal_context(),
Expand Down Expand Up @@ -397,7 +397,7 @@ impl MprisTrackList {
#[dbus_interface(signal, name = "TrackListReplaced")]
pub async fn track_list_replaced(
#[zbus(signal_context)] ctxt: &SignalContext<'_>,
tracks: Vec<String>,
tracks: Vec<&str>,
current: &str,
) -> zbus::Result<()>;

Expand Down
12 changes: 6 additions & 6 deletions hifirs/src/player/queue/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl PlayerState {
debug!("setting up album to play");

if let Some(album) = self.service.album(album_id.as_str()).await {
let mut tracklist = TrackListValue::new(Some(album.tracks.clone()));
let mut tracklist = TrackListValue::new(Some(&album.tracks));
tracklist.set_album(album);
tracklist.set_list_type(TrackListType::Album);
tracklist.set_track_status(1, TrackStatus::Playing);
Expand Down Expand Up @@ -105,7 +105,7 @@ impl PlayerState {
let mut queue = BTreeMap::new();
queue.entry(track.position).or_insert_with(|| track.clone());

let mut tracklist = TrackListValue::new(Some(queue));
let mut tracklist = TrackListValue::new(Some(&queue));
tracklist.set_list_type(TrackListType::Track);

self.replace_list(tracklist.clone());
Expand All @@ -123,7 +123,7 @@ impl PlayerState {
debug!("setting up playlist to play");

if let Some(playlist) = self.service.playlist(playlist_id).await {
let mut tracklist = TrackListValue::new(Some(playlist.tracks.clone()));
let mut tracklist = TrackListValue::new(Some(&playlist.tracks));

tracklist.set_playlist(playlist);
tracklist.set_list_type(TrackListType::Playlist);
Expand Down Expand Up @@ -332,7 +332,7 @@ impl PlayerState {
match entity_type {
TrackListType::Album => {
if let Some(album) = self.service.album(&last_state.playback_entity_id).await {
self.replace_list(TrackListValue::new(Some(album.tracks.clone())));
self.replace_list(TrackListValue::new(Some(&album.tracks)));
self.tracklist.set_list_type(TrackListType::Album);
self.tracklist.set_album(album);

Expand All @@ -355,7 +355,7 @@ impl PlayerState {
)
.await
{
self.replace_list(TrackListValue::new(Some(playlist.tracks.clone())));
self.replace_list(TrackListValue::new(Some(&playlist.tracks)));
self.tracklist.set_list_type(TrackListType::Playlist);
self.tracklist.set_playlist(playlist);

Expand All @@ -379,7 +379,7 @@ impl PlayerState {
let mut queue = BTreeMap::new();
queue.entry(track.position).or_insert_with(|| track);

let mut tracklist = TrackListValue::new(Some(queue));
let mut tracklist = TrackListValue::new(Some(&queue));
tracklist.set_list_type(TrackListType::Track);

self.replace_list(tracklist);
Expand Down
16 changes: 5 additions & 11 deletions hifirs/src/player/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,9 @@ pub struct TrackListValue {

impl TrackListValue {
#[instrument]
pub fn new(queue: Option<BTreeMap<u32, Track>>) -> TrackListValue {
let queue = if let Some(q) = queue {
q
} else {
BTreeMap::new()
};

pub fn new(queue: Option<&BTreeMap<u32, Track>>) -> TrackListValue {
TrackListValue {
queue,
queue: queue.unwrap_or(&BTreeMap::new()).clone(),
album: None,
playlist: None,
list_type: TrackListType::Unknown,
Expand Down Expand Up @@ -194,10 +188,10 @@ impl TrackListValue {
.find(|&track| track.status == TrackStatus::Playing)
}

pub fn cursive_list(&self) -> Vec<(String, i32)> {
pub fn cursive_list(&self) -> Vec<(&str, i32)> {
self.queue
.values()
.map(|i| (i.title.clone(), i.id as i32))
.collect::<Vec<(String, i32)>>()
.map(|i| (i.title.as_str(), i.id as i32))
.collect::<Vec<(&str, i32)>>()
}
}
6 changes: 6 additions & 0 deletions hifirs/src/qobuz/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ impl From<QobuzAlbum> for Album {
}
}
}

impl From<&QobuzAlbum> for Album {
fn from(value: &QobuzAlbum) -> Self {
value.clone().into()
}
}
2 changes: 1 addition & 1 deletion hifirs/src/qobuz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl MusicService for QobuzClient {
}

async fn search(&self, query: &str) -> Option<SearchResults> {
match self.search_all(query.to_string(), 100).await {
match self.search_all(query, 100).await {
Ok(results) => Some(results.into()),
Err(_) => None,
}
Expand Down
8 changes: 7 additions & 1 deletion hifirs/src/qobuz/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hifirs_qobuz_api::client::track::Track as QobuzTrack;
impl From<QobuzTrack> for Track {
fn from(value: QobuzTrack) -> Self {
let album = value.album.as_ref().map(|a| {
let album: Album = a.clone().into();
let album: Album = a.into();

album
});
Expand Down Expand Up @@ -47,3 +47,9 @@ impl From<QobuzTrack> for Track {
}
}
}

impl From<&QobuzTrack> for Track {
fn from(value: &QobuzTrack) -> Self {
value.clone().into()
}
}
6 changes: 3 additions & 3 deletions hifirs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ impl CursiveFormat for Album {
style = style.combine(Effect::Dim).combine(Effect::Strikethrough);
}

let mut title = StyledString::styled(self.title.clone(), style.combine(Effect::Bold));
let mut title = StyledString::styled(self.title.as_str(), style.combine(Effect::Bold));

title.append_styled(" by ", style);
title.append_styled(self.artist.name.clone(), style);
title.append_styled(self.artist.name.as_str(), style);
title.append_styled(" ", style);

title.append_styled(self.release_year.to_string(), style.combine(Effect::Dim));
Expand Down Expand Up @@ -189,6 +189,6 @@ pub struct Playlist {

impl CursiveFormat for Artist {
fn list_item(&self) -> StyledString {
StyledString::plain(self.name.clone())
StyledString::plain(self.name.as_str())
}
}
8 changes: 4 additions & 4 deletions hifirs/src/sql/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub async fn init() {
url.push("hifi-rs");

if !url.exists() {
std::fs::create_dir_all(url.clone()).expect("failed to create database directory");
std::fs::create_dir_all(&url).expect("failed to create database directory");
}

url.push("data.db");
Expand Down Expand Up @@ -85,7 +85,7 @@ pub async fn set_password(password: String) {
}
}

pub async fn set_user_token(token: String) {
pub async fn set_user_token(token: &String) {
if let Ok(mut conn) = acquire!() {
query!(
r#"
Expand All @@ -99,7 +99,7 @@ pub async fn set_user_token(token: String) {
}
}

pub async fn set_app_id(id: String) {
pub async fn set_app_id(id: &String) {
if let Ok(mut conn) = acquire!() {
query!(
r#"
Expand All @@ -113,7 +113,7 @@ pub async fn set_app_id(id: String) {
}
}

pub async fn set_active_secret(secret: String) {
pub async fn set_active_secret(secret: &String) {
if let Ok(mut conn) = acquire!() {
query!(
r#"
Expand Down
4 changes: 2 additions & 2 deletions playlist-sync/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub async fn run() -> Result<(), Error> {
if let (Some(isrc), Some(track_position)) =
(existing_track.isrc, existing_track.position)
{
let results = qobuz.search(isrc.to_lowercase()).await;
let results = qobuz.search(&isrc.to_lowercase()).await;
if !results.is_empty() {
if let Some(found) = results.get(0) {
qobuz
Expand Down Expand Up @@ -147,7 +147,7 @@ pub async fn run() -> Result<(), Error> {

for missing in missing_tracks {
if let Some(isrc) = missing.track.external_ids.get("isrc") {
let results = qobuz.search(isrc.to_lowercase()).await;
let results = qobuz.search(&isrc.to_lowercase()).await;
if !results.is_empty() {
if let Some(found) = results.get(0) {
qobuz
Expand Down
4 changes: 2 additions & 2 deletions playlist-sync/src/qobuz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ impl<'q> Qobuz<'q> {
Ok(QobuzPlaylist(playlist))
}

pub async fn search(&self, query: String) -> Vec<Track> {
pub async fn search(&self, query: &str) -> Vec<Track> {
self.progress.set_message(format!("{query} searching"));
let results = self.client.search_all(query.clone(), 100).await.unwrap();
let results = self.client.search_all(query, 100).await.unwrap();

if results.tracks.items.is_empty() {
self.progress.set_message(format!("{query} not found"));
Expand Down
Loading
Loading