gardesk/garbg / c91da3b

Browse files

cli: Delegate next/prev commands to daemon

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
c91da3bb83a5496286f84b8c6b78edee62a17855
Parents
4d4352c
Tree
bfe53bb

1 changed file

StatusFile+-
M garbg/src/main.rs 28 0
garbg/src/main.rsmodified
@@ -464,6 +464,20 @@ fn set_single_wallpaper(
464
 
464
 
465
 /// Advance to the next image in the playlist
465
 /// Advance to the next image in the playlist
466
 fn cmd_next() -> Result<()> {
466
 fn cmd_next() -> Result<()> {
467
+    use garbg::ipc::{is_daemon_running, send_command_blocking};
468
+
469
+    // If daemon is running, delegate to it (preserves pixmap lifetime)
470
+    if is_daemon_running() {
471
+        let response = send_command_blocking(&Command::Next { monitor: None })?;
472
+        if response.success {
473
+            // Daemon handles logging
474
+            return Ok(());
475
+        } else if let Some(err) = response.error {
476
+            anyhow::bail!("Daemon error: {}", err);
477
+        }
478
+    }
479
+
480
+    // Fallback: no daemon running, set directly (pixmap will be freed on exit)
467
     let mut state = PlaylistState::load()?
481
     let mut state = PlaylistState::load()?
468
         .ok_or_else(|| anyhow::anyhow!("No active playlist. Use 'garbg set <directory>' first."))?;
482
         .ok_or_else(|| anyhow::anyhow!("No active playlist. Use 'garbg set <directory>' first."))?;
469
 
483
 
@@ -485,6 +499,20 @@ fn cmd_next() -> Result<()> {
485
 
499
 
486
 /// Go back to the previous image in the playlist
500
 /// Go back to the previous image in the playlist
487
 fn cmd_prev() -> Result<()> {
501
 fn cmd_prev() -> Result<()> {
502
+    use garbg::ipc::{is_daemon_running, send_command_blocking};
503
+
504
+    // If daemon is running, delegate to it (preserves pixmap lifetime)
505
+    if is_daemon_running() {
506
+        let response = send_command_blocking(&Command::Prev { monitor: None })?;
507
+        if response.success {
508
+            // Daemon handles logging
509
+            return Ok(());
510
+        } else if let Some(err) = response.error {
511
+            anyhow::bail!("Daemon error: {}", err);
512
+        }
513
+    }
514
+
515
+    // Fallback: no daemon running, set directly (pixmap will be freed on exit)
488
     let mut state = PlaylistState::load()?
516
     let mut state = PlaylistState::load()?
489
         .ok_or_else(|| anyhow::anyhow!("No active playlist. Use 'garbg set <directory>' first."))?;
517
         .ok_or_else(|| anyhow::anyhow!("No active playlist. Use 'garbg set <directory>' first."))?;
490
 
518