aboutsummaryrefslogtreecommitdiffstats
path: root/src/daemon.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/daemon.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/daemon.rs b/src/daemon.rs
index 0921e11..cca9b11 100644
--- a/src/daemon.rs
+++ b/src/daemon.rs
@@ -1,5 +1,6 @@
1use crate::audio::AudioEngine; 1use crate::audio::AudioEngine;
2use crate::config::Config; 2use crate::config::Config;
3use crate::notification;
3use crate::queue::{Queue, ShuffleMode, Track}; 4use crate::queue::{Queue, ShuffleMode, Track};
4use std::io::{Read, Write}; 5use std::io::{Read, Write};
5use std::os::unix::net::{UnixListener, UnixStream}; 6use std::os::unix::net::{UnixListener, UnixStream};
@@ -97,12 +98,15 @@ pub fn start_daemon() -> Result<(), Box<dyn std::error::Error>> {
97 { 98 {
98 let original_position = q.position(); 99 let original_position = q.position();
99 let mut started = false; 100 let mut started = false;
101 let mut had_next = false;
100 let max_trials = 4usize; 102 let max_trials = 4usize;
101 for _ in 0..max_trials { 103 for _ in 0..max_trials {
102 if let Some(next_track) = q.next() { 104 if let Some(next_track) = q.next() {
105 had_next = true;
103 audio_engine.play(next_track.clone()); 106 audio_engine.play(next_track.clone());
104 if wait_for_start(&audio_engine, &next_track, 500) { 107 if wait_for_start(&audio_engine, &next_track, 500) {
105 started = true; 108 started = true;
109 notification::notify_track(&Track::from_path(next_track));
106 break; 110 break;
107 } 111 }
108 } else { 112 } else {
@@ -112,6 +116,11 @@ pub fn start_daemon() -> Result<(), Box<dyn std::error::Error>> {
112 if !started { 116 if !started {
113 q.set_position(original_position); 117 q.set_position(original_position);
114 audio_engine.stop(); 118 audio_engine.stop();
119 if had_next {
120 notification::notify_error("Playback failed");
121 } else {
122 notification::notify_queue_ended();
123 }
115 } 124 }
116 } 125 }
117 126
@@ -286,10 +295,12 @@ fn process_command(
286 "next" => { 295 "next" => {
287 if let Ok(mut q) = queue.lock() { 296 if let Ok(mut q) = queue.lock() {
288 if let Some(next_track) = q.next() { 297 if let Some(next_track) = q.next() {
289 audio.play(next_track); 298 audio.play(next_track.clone());
299 notification::notify_track(&Track::from_path(next_track));
290 "Playing next track\n".to_string() 300 "Playing next track\n".to_string()
291 } else { 301 } else {
292 audio.stop(); 302 audio.stop();
303 notification::notify_queue_ended();
293 "Queue empty, stopped\n".to_string() 304 "Queue empty, stopped\n".to_string()
294 } 305 }
295 } else { 306 } else {
@@ -299,7 +310,8 @@ fn process_command(
299 "previous" => { 310 "previous" => {
300 if let Ok(mut q) = queue.lock() { 311 if let Ok(mut q) = queue.lock() {
301 if let Some(prev_track) = q.previous() { 312 if let Some(prev_track) = q.previous() {
302 audio.play(prev_track); 313 audio.play(prev_track.clone());
314 notification::notify_track(&Track::from_path(prev_track));
303 "Playing previous track\n".to_string() 315 "Playing previous track\n".to_string()
304 } else { 316 } else {
305 "No previous track\n".to_string() 317 "No previous track\n".to_string()
@@ -378,6 +390,7 @@ fn process_command(
378 } 390 }
379 if let Some(track) = q.track_at(q.position()) { 391 if let Some(track) = q.track_at(q.position()) {
380 audio.play(track.path.clone()); 392 audio.play(track.path.clone());
393 notification::notify_track(track);
381 } 394 }
382 format!("Playing now: {}\n", path_str) 395 format!("Playing now: {}\n", path_str)
383 } 396 }
@@ -389,7 +402,9 @@ fn process_command(
389 let was_playing = audio.is_playing(); 402 let was_playing = audio.is_playing();
390 q.add_track(path.clone()); 403 q.add_track(path.clone());
391 if !was_playing { 404 if !was_playing {
405 let track = Track::from_path(path.clone());
392 audio.play(path); 406 audio.play(path);
407 notification::notify_track(&track);
393 format!("Playing: {}\n", path_str) 408 format!("Playing: {}\n", path_str)
394 } else { 409 } else {
395 format!("Queued: {}\n", path_str) 410 format!("Queued: {}\n", path_str)
@@ -415,6 +430,7 @@ fn process_command(
415 } 430 }
416 if let Some(track) = q.track_at(q.position()) { 431 if let Some(track) = q.track_at(q.position()) {
417 audio.play(track.path.clone()); 432 audio.play(track.path.clone());
433 notification::notify_track(track);
418 } 434 }
419 format!( 435 format!(
420 "Playing now: {} tracks from {}\n", 436 "Playing now: {} tracks from {}\n",
@@ -439,7 +455,9 @@ fn process_command(
439 if !audio.is_playing() 455 if !audio.is_playing()
440 && let Some(track) = files.first() 456 && let Some(track) = files.first()
441 { 457 {
442 audio.play(track.clone()); 458 let track = Track::from_path(track.clone());
459 audio.play(track.path.clone());
460 notification::notify_track(&track);
443 } 461 }
444 format!("Queued {} tracks from: {}\n", files.len(), path_str) 462 format!("Queued {} tracks from: {}\n", files.len(), path_str)
445 } 463 }