Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add copy_song_url method to app
  • Loading branch information
LennyPenny committed Nov 19, 2019
commit b8a00f4e7e774ac790e23564e4454f1ba1857f32
25 changes: 24 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::config::ClientConfig;
use super::user_config::UserConfig;
use failure::err_msg;
use failure::{err_msg, format_err};
use rspotify::spotify::client::Spotify;
use rspotify::spotify::model::album::{FullAlbum, SavedAlbum, SimplifiedAlbum};
use rspotify::spotify::model::artist::FullArtist;
Expand All @@ -21,6 +21,9 @@ use std::collections::HashSet;
use std::time::Instant;
use tui::layout::Rect;

use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;

pub const LIBRARY_OPTIONS: [&str; 6] = [
"Made For You",
"Recently Played",
Expand Down Expand Up @@ -236,6 +239,7 @@ pub struct App {
pub user: Option<PrivateUser>,
pub album_list_index: usize,
pub artists_list_index: usize,
pub clipboard_context: Option<ClipboardContext>,
}

impl App {
Expand Down Expand Up @@ -297,6 +301,7 @@ impl App {
},
user: None,
instant_since_last_current_playback_poll: Instant::now(),
clipboard_context: None,
}
}

Expand Down Expand Up @@ -648,6 +653,24 @@ impl App {
}
}

pub fn copy_song_url(&mut self) {
let clipboard = match &mut self.clipboard_context {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this could be using an if let?

if let Some(clipboard_context) = &mut self.clipboard_context {
  ...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used an "early return" here to save an indentation level, do you want me to change it?:)

Some(ctx) => ctx,
None => return,
};

if let Some(FullPlayingContext {
item: Some(FullTrack { id: Some(id), .. }),
..
}) = &self.current_playback_context
{
if let Err(e) = clipboard.set_contents(format!("https://open.spotify.com/track/{}", id))
{
self.handle_error(format_err!("failed to get clipboard context: {}", e));
}
}
}

fn set_saved_tracks_to_table(&mut self, saved_track_page: &Page<SavedTrack>) {
self.set_tracks_to_table(
saved_track_page
Expand Down