mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Merge pull request #119 from joerg-krause/say-goodbye
Say goodbye when terminating
This commit is contained in:
commit
6fa4e4d458
4 changed files with 448 additions and 149 deletions
579
Cargo.lock
generated
579
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -44,6 +44,7 @@ url = "~0.5.0"
|
|||
log = "0.3.5"
|
||||
env_logger = "0.3.2"
|
||||
shannon = { git = "https://github.com/plietar/rust-shannon" }
|
||||
simple-signal = "1.0.6"
|
||||
|
||||
vorbis = "~0.0.14"
|
||||
tremor = { git = "https://github.com/plietar/rust-tremor", optional = true }
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -3,6 +3,7 @@ extern crate librespot;
|
|||
extern crate env_logger;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate simple_signal;
|
||||
|
||||
use std::process::exit;
|
||||
use std::thread;
|
||||
|
@ -11,6 +12,8 @@ use std::env;
|
|||
use librespot::spirc::SpircManager;
|
||||
use librespot::main_helper;
|
||||
|
||||
use simple_signal::{Signal, Signals};
|
||||
|
||||
fn usage(program: &str, opts: &getopts::Options) -> String {
|
||||
let brief = format!("Usage: {} [options]", program);
|
||||
format!("{}", opts.usage(&brief))
|
||||
|
@ -44,7 +47,15 @@ fn main() {
|
|||
let player = main_helper::create_player(&session, &matches);
|
||||
|
||||
let spirc = SpircManager::new(session.clone(), player);
|
||||
let spirc_signal = spirc.clone();
|
||||
thread::spawn(move || spirc.run());
|
||||
Signals::set_handler(&[Signal::Int, Signal::Term],
|
||||
move |signals| {
|
||||
println!("Signal received: {:?}. Say goodbye and exit.", signals);
|
||||
spirc_signal.send_goodbye();
|
||||
exit(0);
|
||||
}
|
||||
);
|
||||
|
||||
loop {
|
||||
session.poll();
|
||||
|
|
|
@ -165,6 +165,12 @@ impl SpircManager {
|
|||
.send();
|
||||
}
|
||||
|
||||
pub fn send_goodbye(&self) {
|
||||
let mut internal = self.0.lock().unwrap();
|
||||
CommandSender::new(&mut *internal, MessageType::kMessageTypeGoodbye)
|
||||
.send();
|
||||
}
|
||||
|
||||
pub fn get_queue(&self) -> Vec<SpotifyId> {
|
||||
self.0.lock().unwrap().tracks.clone()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue