Add a keybind and shortcut to share the currently playing song
This commit is contained in:
@@ -33,6 +33,7 @@ unicode-width = "0.1.5"
|
|||||||
dbus = { version = "0.6.4", optional = true }
|
dbus = { version = "0.6.4", optional = true }
|
||||||
rand = "0.6.5"
|
rand = "0.6.5"
|
||||||
webbrowser = "0.5"
|
webbrowser = "0.5"
|
||||||
|
clipboard = "0.5.0"
|
||||||
|
|
||||||
[dependencies.rspotify]
|
[dependencies.rspotify]
|
||||||
git = "https://github.com/samrayleung/rspotify"
|
git = "https://github.com/samrayleung/rspotify"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use cursive::event::{Event, Key};
|
|||||||
use cursive::views::ViewRef;
|
use cursive::views::ViewRef;
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
|
|
||||||
|
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||||
use library::Library;
|
use library::Library;
|
||||||
use queue::{Queue, RepeatSetting};
|
use queue::{Queue, RepeatSetting};
|
||||||
use spotify::Spotify;
|
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();
|
let spotify = spotify.clone();
|
||||||
self.register_command(
|
self.register_command(
|
||||||
@@ -284,9 +304,9 @@ impl CommandManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_keybindings<'a>(
|
pub fn register_keybindings(
|
||||||
this: Arc<Self>,
|
this: Arc<Self>,
|
||||||
cursive: &'a mut Cursive,
|
cursive: &mut Cursive,
|
||||||
keybindings: Option<HashMap<String, String>>,
|
keybindings: Option<HashMap<String, String>>,
|
||||||
) {
|
) {
|
||||||
let mut kb = Self::default_keybindings();
|
let mut kb = Self::default_keybindings();
|
||||||
@@ -321,6 +341,7 @@ impl CommandManager {
|
|||||||
kb.insert(",".into(), "seek -500".into());
|
kb.insert(",".into(), "seek -500".into());
|
||||||
kb.insert("r".into(), "repeat".into());
|
kb.insert("r".into(), "repeat".into());
|
||||||
kb.insert("z".into(), "shuffle".into());
|
kb.insert("z".into(), "shuffle".into());
|
||||||
|
kb.insert("m".into(), "share".into());
|
||||||
|
|
||||||
kb.insert("F1".into(), "focus queue".into());
|
kb.insert("F1".into(), "focus queue".into());
|
||||||
kb.insert("F2".into(), "focus search".into());
|
kb.insert("F2".into(), "focus search".into());
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ extern crate clap;
|
|||||||
extern crate crossbeam_channel;
|
extern crate crossbeam_channel;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate cursive;
|
extern crate cursive;
|
||||||
|
extern crate clipboard;
|
||||||
extern crate directories;
|
extern crate directories;
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
|
|||||||
Reference in New Issue
Block a user