diff --git a/Cargo.toml b/Cargo.toml index 6750d87..b5d53b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ unicode-width = "0.1.5" dbus = { version = "0.6.4", optional = true } rand = "0.6.5" webbrowser = "0.5" +clipboard = "0.5.0" [dependencies.rspotify] git = "https://github.com/samrayleung/rspotify" diff --git a/src/commands.rs b/src/commands.rs index 819fc4f..5265d41 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -6,6 +6,7 @@ use cursive::event::{Event, Key}; use cursive::views::ViewRef; use cursive::Cursive; +use clipboard::{ClipboardContext, ClipboardProvider}; use library::Library; use queue::{Queue, RepeatSetting}; use spotify::Spotify; @@ -197,6 +198,25 @@ impl CommandManager { ); } + { + let queue = queue.clone(); + self.register_command( + "share", + Some(Box::new(move |_, _| { + if let Some(url) = queue + .get_current() + .and_then(|t| t.id) + .map(|id| format!("https://open.spotify.com/track/{}", id)) + { + let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); + ctx.set_contents(url).unwrap(); + } + + Ok(None) + })), + ) + } + { let spotify = spotify.clone(); self.register_command( @@ -284,9 +304,9 @@ impl CommandManager { }); } - pub fn register_keybindings<'a>( + pub fn register_keybindings( this: Arc, - cursive: &'a mut Cursive, + cursive: &mut Cursive, keybindings: Option>, ) { let mut kb = Self::default_keybindings(); @@ -321,6 +341,7 @@ impl CommandManager { kb.insert(",".into(), "seek -500".into()); kb.insert("r".into(), "repeat".into()); kb.insert("z".into(), "shuffle".into()); + kb.insert("m".into(), "share".into()); kb.insert("F1".into(), "focus queue".into()); kb.insert("F2".into(), "focus search".into()); diff --git a/src/main.rs b/src/main.rs index 78c35f4..e9ff401 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ extern crate clap; extern crate crossbeam_channel; #[macro_use] extern crate cursive; +extern crate clipboard; extern crate directories; extern crate failure; extern crate futures;