aboutsummaryrefslogtreecommitdiffstats
path: root/src/daemon.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/daemon.rs54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/daemon.rs b/src/daemon.rs
index 4f95820..eaae64f 100644
--- a/src/daemon.rs
+++ b/src/daemon.rs
@@ -190,7 +190,7 @@ pub fn spawn_try_scrobble_current(
190} 190}
191 191
192pub fn start_daemon() -> Result<(), Box<dyn std::error::Error>> { 192pub fn start_daemon() -> Result<(), Box<dyn std::error::Error>> {
193 let config = Config::load()?; 193 let config = Config::cached()?;
194 let socket_path = Config::get_socket_path(); 194 let socket_path = Config::get_socket_path();
195 let pid_path = get_pid_path(&config); 195 let pid_path = get_pid_path(&config);
196 196
@@ -365,7 +365,7 @@ pub fn start_daemon() -> Result<(), Box<dyn std::error::Error>> {
365 if let Ok(mut s) = scrobble_state.lock() { 365 if let Ok(mut s) = scrobble_state.lock() {
366 s.start(track.clone()); 366 s.start(track.clone());
367 } 367 }
368 let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); 368 let fmt = Config::cached().ok().and_then(|c| c.display_format.clone());
369 notification::notify_track(&track, fmt.as_deref()); 369 notification::notify_track(&track, fmt.as_deref());
370 break; 370 break;
371 } 371 }
@@ -448,7 +448,7 @@ pub fn start_daemon() -> Result<(), Box<dyn std::error::Error>> {
448} 448}
449 449
450pub fn stop_daemon() -> Result<(), Box<dyn std::error::Error>> { 450pub fn stop_daemon() -> Result<(), Box<dyn std::error::Error>> {
451 let config = Config::load()?; 451 let config = Config::cached()?;
452 let pid_path = get_pid_path(&config); 452 let pid_path = get_pid_path(&config);
453 453
454 match check_running_daemon(&pid_path) { 454 match check_running_daemon(&pid_path) {
@@ -708,7 +708,7 @@ enum LoadedLyrics {
708 708
709/// Build the "Now playing" header shown above a track's lyrics. 709/// Build the "Now playing" header shown above a track's lyrics.
710fn lyrics_header(track: &Track) -> String { 710fn lyrics_header(track: &Track) -> String {
711 let name = match Config::load() 711 let name = match Config::cached()
712 .ok() 712 .ok()
713 .and_then(|c| c.display_format.clone()) 713 .and_then(|c| c.display_format.clone())
714 .as_deref() 714 .as_deref()
@@ -1022,7 +1022,7 @@ fn process_command(
1022 "Paused" 1022 "Paused"
1023 }; 1023 };
1024 let track = Track::from_path(track_path); 1024 let track = Track::from_path(track_path);
1025 let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); 1025 let fmt = Config::cached().ok().and_then(|c| c.display_format.clone());
1026 let track_str = match fmt.as_deref() { 1026 let track_str = match fmt.as_deref() {
1027 Some(f) => track.format(f), 1027 Some(f) => track.format(f),
1028 None => track.display_string(0, 1), 1028 None => track.display_string(0, 1),
@@ -1094,7 +1094,7 @@ fn process_command(
1094 "Shutting down\n".to_string() 1094 "Shutting down\n".to_string()
1095 } 1095 }
1096 "reload" | "validate" => { 1096 "reload" | "validate" => {
1097 if let Ok(config) = Config::load() { 1097 if let Ok(config) = Config::cached() {
1098 let temp_scrobbler = Scrobbler::new( 1098 let temp_scrobbler = Scrobbler::new(
1099 config.lastfm_api_key.clone(), 1099 config.lastfm_api_key.clone(),
1100 config.lastfm_api_secret.clone(), 1100 config.lastfm_api_secret.clone(),
@@ -1137,7 +1137,7 @@ fn process_command(
1137 if let Ok(mut s) = scrobble_state.lock() { 1137 if let Ok(mut s) = scrobble_state.lock() {
1138 s.start(track.clone()); 1138 s.start(track.clone());
1139 } 1139 }
1140 let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); 1140 let fmt = Config::cached().ok().and_then(|c| c.display_format.clone());
1141 notification::notify_track(&track, fmt.as_deref()); 1141 notification::notify_track(&track, fmt.as_deref());
1142 "Playing next track\n".to_string() 1142 "Playing next track\n".to_string()
1143 } else { 1143 } else {
@@ -1160,7 +1160,7 @@ fn process_command(
1160 if let Ok(mut s) = scrobble_state.lock() { 1160 if let Ok(mut s) = scrobble_state.lock() {
1161 s.start(track.clone()); 1161 s.start(track.clone());
1162 } 1162 }
1163 let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); 1163 let fmt = Config::cached().ok().and_then(|c| c.display_format.clone());
1164 notification::notify_track(&track, fmt.as_deref()); 1164 notification::notify_track(&track, fmt.as_deref());
1165 "Playing previous track\n".to_string() 1165 "Playing previous track\n".to_string()
1166 } else { 1166 } else {
@@ -1202,7 +1202,7 @@ fn process_command(
1202 "Usage: shuffle [on|off|album|albums]\n".to_string() 1202 "Usage: shuffle [on|off|album|albums]\n".to_string()
1203 }; 1203 };
1204 // Save to config 1204 // Save to config
1205 if let Ok(mut config) = Config::load() { 1205 if let Ok(mut config) = Config::cached() {
1206 if mode_str == "off" || mode_str == "none" { 1206 if mode_str == "off" || mode_str == "none" {
1207 config.shuffle = None; 1207 config.shuffle = None;
1208 } else { 1208 } else {
@@ -1242,7 +1242,7 @@ fn process_command(
1242 let (album_tracks, display_name): (Vec<PathBuf>, String) = if path.is_file() { 1242 let (album_tracks, display_name): (Vec<PathBuf>, String) = if path.is_file() {
1243 let canon = std::fs::canonicalize(&path).unwrap_or_else(|_| path.clone()); 1243 let canon = std::fs::canonicalize(&path).unwrap_or_else(|_| path.clone());
1244 let (artist, album, _, _, _) = crate::database::extract_metadata(&canon); 1244 let (artist, album, _, _, _) = crate::database::extract_metadata(&canon);
1245 let full: Vec<PathBuf> = match Config::load() { 1245 let full: Vec<PathBuf> = match Config::cached() {
1246 Ok(config) => match crate::database::Database::open(&config) { 1246 Ok(config) => match crate::database::Database::open(&config) {
1247 Ok(db) => db 1247 Ok(db) => db
1248 .find_tracks_by_album(&artist, &album) 1248 .find_tracks_by_album(&artist, &album)
@@ -1267,7 +1267,7 @@ fn process_command(
1267 .to_string(); 1267 .to_string();
1268 (rotated, name) 1268 (rotated, name)
1269 } else { 1269 } else {
1270 match Config::load() { 1270 match Config::cached() {
1271 Ok(config) => match crate::database::Database::open(&config) { 1271 Ok(config) => match crate::database::Database::open(&config) {
1272 Ok(db) => { 1272 Ok(db) => {
1273 let tracks = match db.resolve_path(query_str) { 1273 let tracks = match db.resolve_path(query_str) {
@@ -1352,7 +1352,7 @@ fn process_command(
1352 if let Ok(mut s) = scrobble_state.lock() { 1352 if let Ok(mut s) = scrobble_state.lock() {
1353 s.start(track.clone()); 1353 s.start(track.clone());
1354 } 1354 }
1355 let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); 1355 let fmt = Config::cached().ok().and_then(|c| c.display_format.clone());
1356 notification::notify_track(track, fmt.as_deref()); 1356 notification::notify_track(track, fmt.as_deref());
1357 } 1357 }
1358 format!( 1358 format!(
@@ -1464,7 +1464,7 @@ fn process_command(
1464 s.start(track.clone()); 1464 s.start(track.clone());
1465 } 1465 }
1466 let fmt = 1466 let fmt =
1467 Config::load().ok().and_then(|c| c.display_format.clone()); 1467 Config::cached().ok().and_then(|c| c.display_format.clone());
1468 notification::notify_track(track, fmt.as_deref()); 1468 notification::notify_track(track, fmt.as_deref());
1469 } 1469 }
1470 format!("Playing now: {}\n", path_str) 1470 format!("Playing now: {}\n", path_str)
@@ -1486,7 +1486,7 @@ fn process_command(
1486 s.start(track.clone()); 1486 s.start(track.clone());
1487 } 1487 }
1488 let fmt = 1488 let fmt =
1489 Config::load().ok().and_then(|c| c.display_format.clone()); 1489 Config::cached().ok().and_then(|c| c.display_format.clone());
1490 notification::notify_track(track, fmt.as_deref()); 1490 notification::notify_track(track, fmt.as_deref());
1491 } 1491 }
1492 format!("Queued: {}\n", path_str) 1492 format!("Queued: {}\n", path_str)
@@ -1514,8 +1514,9 @@ fn process_command(
1514 if let Ok(mut s) = scrobble_state.lock() { 1514 if let Ok(mut s) = scrobble_state.lock() {
1515 s.start(track.clone()); 1515 s.start(track.clone());
1516 } 1516 }
1517 let fmt = 1517 let fmt = Config::cached()
1518 Config::load().ok().and_then(|c| c.display_format.clone()); 1518 .ok()
1519 .and_then(|c| c.display_format.clone());
1519 notification::notify_track(track, fmt.as_deref()); 1520 notification::notify_track(track, fmt.as_deref());
1520 } 1521 }
1521 format!("Playing now: {}\n", path_str) 1522 format!("Playing now: {}\n", path_str)
@@ -1535,8 +1536,9 @@ fn process_command(
1535 if let Ok(mut s) = scrobble_state.lock() { 1536 if let Ok(mut s) = scrobble_state.lock() {
1536 s.start(track.clone()); 1537 s.start(track.clone());
1537 } 1538 }
1538 let fmt = 1539 let fmt = Config::cached()
1539 Config::load().ok().and_then(|c| c.display_format.clone()); 1540 .ok()
1541 .and_then(|c| c.display_format.clone());
1540 notification::notify_track(&track, fmt.as_deref()); 1542 notification::notify_track(&track, fmt.as_deref());
1541 format!("Playing: {}\n", path_str) 1543 format!("Playing: {}\n", path_str)
1542 } else { 1544 } else {
@@ -1568,7 +1570,7 @@ fn process_command(
1568 if let Ok(mut s) = scrobble_state.lock() { 1570 if let Ok(mut s) = scrobble_state.lock() {
1569 s.start(track.clone()); 1571 s.start(track.clone());
1570 } 1572 }
1571 let fmt = Config::load() 1573 let fmt = Config::cached()
1572 .ok() 1574 .ok()
1573 .and_then(|c| c.display_format.clone()); 1575 .and_then(|c| c.display_format.clone());
1574 notification::notify_track(track, fmt.as_deref()); 1576 notification::notify_track(track, fmt.as_deref());
@@ -1602,7 +1604,7 @@ fn process_command(
1602 if let Ok(mut s) = scrobble_state.lock() { 1604 if let Ok(mut s) = scrobble_state.lock() {
1603 s.start(track.clone()); 1605 s.start(track.clone());
1604 } 1606 }
1605 let fmt = Config::load() 1607 let fmt = Config::cached()
1606 .ok() 1608 .ok()
1607 .and_then(|c| c.display_format.clone()); 1609 .and_then(|c| c.display_format.clone());
1608 notification::notify_track(track, fmt.as_deref()); 1610 notification::notify_track(track, fmt.as_deref());
@@ -1622,7 +1624,7 @@ fn process_command(
1622 _ => format!("Error: No audio files found in '{}'\n", path_str), 1624 _ => format!("Error: No audio files found in '{}'\n", path_str),
1623 } 1625 }
1624 } else { 1626 } else {
1625 match Config::load() { 1627 match Config::cached() {
1626 Ok(config) => match crate::database::Database::open(&config) { 1628 Ok(config) => match crate::database::Database::open(&config) {
1627 Ok(db) => { 1629 Ok(db) => {
1628 // Collect tracks: try hierarchical path first, fallback to search 1630 // Collect tracks: try hierarchical path first, fallback to search
@@ -1666,7 +1668,7 @@ fn process_command(
1666 if let Ok(mut s) = scrobble_state.lock() { 1668 if let Ok(mut s) = scrobble_state.lock() {
1667 s.start(track.clone()); 1669 s.start(track.clone());
1668 } 1670 }
1669 let fmt = Config::load() 1671 let fmt = Config::cached()
1670 .ok() 1672 .ok()
1671 .and_then(|c| c.display_format.clone()); 1673 .and_then(|c| c.display_format.clone());
1672 notification::notify_track(track, fmt.as_deref()); 1674 notification::notify_track(track, fmt.as_deref());
@@ -1710,7 +1712,7 @@ fn process_command(
1710 if let Ok(mut s) = scrobble_state.lock() { 1712 if let Ok(mut s) = scrobble_state.lock() {
1711 s.start(track.clone()); 1713 s.start(track.clone());
1712 } 1714 }
1713 let fmt = Config::load() 1715 let fmt = Config::cached()
1714 .ok() 1716 .ok()
1715 .and_then(|c| c.display_format.clone()); 1717 .and_then(|c| c.display_format.clone());
1716 notification::notify_track( 1718 notification::notify_track(
@@ -1772,7 +1774,7 @@ fn process_command(
1772 let current = audio.get_volume() as i8; 1774 let current = audio.get_volume() as i8;
1773 let new_level = (current + sign * delta).clamp(0, 100) as u8; 1775 let new_level = (current + sign * delta).clamp(0, 100) as u8;
1774 audio.set_volume(new_level as f32 / 100.0); 1776 audio.set_volume(new_level as f32 / 100.0);
1775 if let Ok(mut config) = Config::load() { 1777 if let Ok(mut config) = Config::cached() {
1776 config.volume = Some(new_level); 1778 config.volume = Some(new_level);
1777 let _ = config.save(); 1779 let _ = config.save();
1778 } 1780 }
@@ -1781,7 +1783,7 @@ fn process_command(
1781 // Try absolute value 1783 // Try absolute value
1782 if let Ok(level) = arg.parse::<u8>() { 1784 if let Ok(level) = arg.parse::<u8>() {
1783 audio.set_volume(level as f32 / 100.0); 1785 audio.set_volume(level as f32 / 100.0);
1784 if let Ok(mut config) = Config::load() { 1786 if let Ok(mut config) = Config::cached() {
1785 config.volume = Some(level); 1787 config.volume = Some(level);
1786 let _ = config.save(); 1788 let _ = config.save();
1787 } 1789 }
@@ -1811,7 +1813,7 @@ fn process_command(
1811 q.shuffled_indices().to_vec() 1813 q.shuffled_indices().to_vec()
1812 }; 1814 };
1813 let is_playing = audio.is_playing(); 1815 let is_playing = audio.is_playing();
1814 let fmt = Config::load().ok().and_then(|c| c.display_format.clone()); 1816 let fmt = Config::cached().ok().and_then(|c| c.display_format.clone());
1815 for (display_idx, &track_idx) in indices.iter().enumerate() { 1817 for (display_idx, &track_idx) in indices.iter().enumerate() {
1816 if let Some(track) = q.track_at(track_idx) { 1818 if let Some(track) = q.track_at(track_idx) {
1817 let track_str = match fmt.as_deref() { 1819 let track_str = match fmt.as_deref() {