diff options
| -rw-r--r-- | TODO.md | 4 | ||||
| -rw-r--r-- | src/audio.rs | 9 | ||||
| -rw-r--r-- | src/config.rs | 18 | ||||
| -rw-r--r-- | src/daemon.rs | 4 |
4 files changed, 29 insertions, 6 deletions
| @@ -2,6 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | ## Completed ✓ | 3 | ## Completed ✓ |
| 4 | 4 | ||
| 5 | - [x] **Dev/release build config separation** - Store config next to binary in dev mode, use XDG in release mode. | ||
| 6 | |||
| 7 | - [x] **Volume without argument returns current volume** - `rsplayer volume` now returns current level. | ||
| 8 | |||
| 5 | - [x] **Fix SampleRate access in audio.rs:104** - `config.sample_rate().0` is invalid because `cpal::SampleRate` is a type alias for `u32`, not a tuple struct. | 9 | - [x] **Fix SampleRate access in audio.rs:104** - `config.sample_rate().0` is invalid because `cpal::SampleRate` is a type alias for `u32`, not a tuple struct. |
| 6 | 10 | ||
| 7 | - [x] **Implement previous track logic** (`src/playback.rs:99`) - Implemented basic previous() that restarts current track if playing/paused. | 11 | - [x] **Implement previous track logic** (`src/playback.rs:99`) - Implemented basic previous() that restarts current track if playing/paused. |
diff --git a/src/audio.rs b/src/audio.rs index 4e26263..93eb8e6 100644 --- a/src/audio.rs +++ b/src/audio.rs | |||
| @@ -18,6 +18,7 @@ pub struct AudioEngine { | |||
| 18 | is_playing: Arc<AtomicBool>, | 18 | is_playing: Arc<AtomicBool>, |
| 19 | current_track: Arc<Mutex<Option<std::path::PathBuf>>>, | 19 | current_track: Arc<Mutex<Option<std::path::PathBuf>>>, |
| 20 | track_ended: Arc<AtomicBool>, | 20 | track_ended: Arc<AtomicBool>, |
| 21 | volume: Arc<Mutex<f32>>, | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | impl AudioEngine { | 24 | impl AudioEngine { |
| @@ -48,6 +49,7 @@ impl AudioEngine { | |||
| 48 | is_playing, | 49 | is_playing, |
| 49 | current_track, | 50 | current_track, |
| 50 | track_ended, | 51 | track_ended, |
| 52 | volume, | ||
| 51 | } | 53 | } |
| 52 | } | 54 | } |
| 53 | 55 | ||
| @@ -75,6 +77,13 @@ impl AudioEngine { | |||
| 75 | let _ = self.command_tx.send(AudioCommand::SetVolume(volume)); | 77 | let _ = self.command_tx.send(AudioCommand::SetVolume(volume)); |
| 76 | } | 78 | } |
| 77 | 79 | ||
| 80 | pub fn get_volume(&self) -> u8 { | ||
| 81 | self.volume | ||
| 82 | .lock() | ||
| 83 | .map(|v| (*v * 100.0) as u8) | ||
| 84 | .unwrap_or(100) | ||
| 85 | } | ||
| 86 | |||
| 78 | pub fn is_playing(&self) -> bool { | 87 | pub fn is_playing(&self) -> bool { |
| 79 | self.is_playing.load(Ordering::SeqCst) | 88 | self.is_playing.load(Ordering::SeqCst) |
| 80 | } | 89 | } |
diff --git a/src/config.rs b/src/config.rs index cda59f4..42573ed 100644 --- a/src/config.rs +++ b/src/config.rs | |||
| @@ -20,13 +20,19 @@ pub struct Config { | |||
| 20 | 20 | ||
| 21 | impl Config { | 21 | impl Config { |
| 22 | pub fn load() -> Result<Self, Box<dyn std::error::Error>> { | 22 | pub fn load() -> Result<Self, Box<dyn std::error::Error>> { |
| 23 | let proj_dirs = ProjectDirs::from("com", "rsplayer", "rsplayer") | 23 | let config_dir = if cfg!(debug_assertions) { |
| 24 | .ok_or("Failed to get project directories")?; | 24 | std::env::current_exe()? |
| 25 | 25 | .parent() | |
| 26 | let config_dir = if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") { | 26 | .map(|p| p.to_path_buf()) |
| 27 | PathBuf::from(xdg).join("rsplayer") | 27 | .unwrap_or_else(|| PathBuf::from(".")) |
| 28 | } else { | 28 | } else { |
| 29 | proj_dirs.config_dir().to_path_buf() | 29 | let proj_dirs = ProjectDirs::from("com", "rsplayer", "rsplayer") |
| 30 | .ok_or("Failed to get project directories")?; | ||
| 31 | if let Ok(xdg) = std::env::var("XDG_CONFIG_HOME") { | ||
| 32 | PathBuf::from(xdg).join("rsplayer") | ||
| 33 | } else { | ||
| 34 | proj_dirs.config_dir().to_path_buf() | ||
| 35 | } | ||
| 30 | }; | 36 | }; |
| 31 | 37 | ||
| 32 | let config_path = config_dir.join("config.toml"); | 38 | let config_path = config_dir.join("config.toml"); |
diff --git a/src/daemon.rs b/src/daemon.rs index b0da698..dab0e5a 100644 --- a/src/daemon.rs +++ b/src/daemon.rs | |||
| @@ -645,6 +645,10 @@ fn process_command( | |||
| 645 | format!("File not found: {}\n", path_str) | 645 | format!("File not found: {}\n", path_str) |
| 646 | } | 646 | } |
| 647 | } | 647 | } |
| 648 | _ if cmd == "volume" => { | ||
| 649 | let vol = audio.get_volume(); | ||
| 650 | format!("Volume: {}\n", vol) | ||
| 651 | } | ||
| 648 | _ if cmd.starts_with("volume ") => { | 652 | _ if cmd.starts_with("volume ") => { |
| 649 | if let Ok(level) = cmd[7..].trim().parse::<u8>() { | 653 | if let Ok(level) = cmd[7..].trim().parse::<u8>() { |
| 650 | audio.set_volume(level as f32 / 100.0); | 654 | audio.set_volume(level as f32 / 100.0); |
