1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-04 02:09:26 +02:00

Say goodbye when terminating

When librespot is terminated while a session is active it will now send
a goodbye message, so that the Spotify client unregisters the device
from its list.

Closes: #114
This commit is contained in:
Jörg Krause 2016-09-20 20:59:41 +02:00
parent b153de93d1
commit c1e570f48d
4 changed files with 35 additions and 0 deletions

View file

@ -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();