mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +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"
|
log = "0.3.5"
|
||||||
env_logger = "0.3.2"
|
env_logger = "0.3.2"
|
||||||
shannon = { git = "https://github.com/plietar/rust-shannon" }
|
shannon = { git = "https://github.com/plietar/rust-shannon" }
|
||||||
|
simple-signal = "1.0.6"
|
||||||
|
|
||||||
vorbis = "~0.0.14"
|
vorbis = "~0.0.14"
|
||||||
tremor = { git = "https://github.com/plietar/rust-tremor", optional = true }
|
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;
|
extern crate env_logger;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
extern crate simple_signal;
|
||||||
|
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
@ -11,6 +12,8 @@ use std::env;
|
||||||
use librespot::spirc::SpircManager;
|
use librespot::spirc::SpircManager;
|
||||||
use librespot::main_helper;
|
use librespot::main_helper;
|
||||||
|
|
||||||
|
use simple_signal::{Signal, Signals};
|
||||||
|
|
||||||
fn usage(program: &str, opts: &getopts::Options) -> String {
|
fn usage(program: &str, opts: &getopts::Options) -> String {
|
||||||
let brief = format!("Usage: {} [options]", program);
|
let brief = format!("Usage: {} [options]", program);
|
||||||
format!("{}", opts.usage(&brief))
|
format!("{}", opts.usage(&brief))
|
||||||
|
@ -44,7 +47,15 @@ fn main() {
|
||||||
let player = main_helper::create_player(&session, &matches);
|
let player = main_helper::create_player(&session, &matches);
|
||||||
|
|
||||||
let spirc = SpircManager::new(session.clone(), player);
|
let spirc = SpircManager::new(session.clone(), player);
|
||||||
|
let spirc_signal = spirc.clone();
|
||||||
thread::spawn(move || spirc.run());
|
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 {
|
loop {
|
||||||
session.poll();
|
session.poll();
|
||||||
|
|
|
@ -165,6 +165,12 @@ impl SpircManager {
|
||||||
.send();
|
.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> {
|
pub fn get_queue(&self) -> Vec<SpotifyId> {
|
||||||
self.0.lock().unwrap().tracks.clone()
|
self.0.lock().unwrap().tracks.clone()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue