From 3672d6f43ea8293f57981c31892c4ec92999f26c Mon Sep 17 00:00:00 2001 From: arabian Date: Fri, 2 Jan 2026 02:10:58 +0300 Subject: [PATCH] feat: now pwsp-daemon main loop is separated into commands_loop and player_loop --- src/bin/daemon.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/bin/daemon.rs b/src/bin/daemon.rs index 329c499..5492e6a 100644 --- a/src/bin/daemon.rs +++ b/src/bin/daemon.rs @@ -1,5 +1,8 @@ use pwsp::{ - types::socket::{Request, Response}, + types::{ + audio_player::PlayerState, + socket::{Request, Response}, + }, utils::{ commands::parse_command, daemon::{ @@ -9,10 +12,11 @@ use pwsp::{ pipewire::create_virtual_mic, }, }; -use std::{error::Error, fs}; +use std::{error::Error, fs, time::Duration}; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::UnixListener, + time::sleep, }; #[tokio::main] @@ -44,6 +48,32 @@ async fn main() -> Result<(), Box> { socket_path.to_str().unwrap_or_default() ); + let commands_loop_handle = tokio::spawn(async { + commands_loop(listener).await.ok(); + }); + + let player_loop_handle = tokio::spawn(async { + player_loop().await; + }); + + loop { + if commands_loop_handle.is_finished() { + eprint!("Commands loop was finished, stopping program..."); + player_loop_handle.abort(); + break; + } + + if player_loop_handle.is_finished() { + eprint!("Audio Player loop was finished, stopping program..."); + commands_loop_handle.abort(); + break; + } + } + + Ok(()) +} + +async fn commands_loop(listener: UnixListener) -> Result<(), Box> { loop { let (mut stream, _addr) = listener.accept().await?; @@ -94,3 +124,7 @@ async fn main() -> Result<(), Box> { }); } } + +async fn player_loop() { + loop {} +}