mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-28 06:21:23 +00:00
feat(daemon): implementet get full-state command
This commit is contained in:
@@ -34,6 +34,15 @@ pub struct TrackInfo {
|
||||
pub paused: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FullState {
|
||||
pub state: PlayerState,
|
||||
pub tracks: Vec<TrackInfo>,
|
||||
pub volume: f32,
|
||||
pub current_input: String,
|
||||
pub all_inputs: HashMap<String, String>,
|
||||
}
|
||||
|
||||
pub struct PlayingSound {
|
||||
pub id: u32,
|
||||
pub sink: Sink,
|
||||
|
||||
+41
-2
@@ -1,12 +1,15 @@
|
||||
use crate::{
|
||||
types::{audio_player::PlayerState, socket::Response},
|
||||
types::{
|
||||
audio_player::{FullState, PlayerState},
|
||||
socket::Response,
|
||||
},
|
||||
utils::{
|
||||
daemon::get_audio_player,
|
||||
pipewire::{get_all_devices, get_device},
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
#[async_trait]
|
||||
pub trait Executable {
|
||||
@@ -79,6 +82,8 @@ pub struct ToggleLoopCommand {
|
||||
pub id: Option<u32>,
|
||||
}
|
||||
|
||||
pub struct GetFullStateCommand {}
|
||||
|
||||
#[async_trait]
|
||||
impl Executable for PingCommand {
|
||||
async fn execute(&self) -> Response {
|
||||
@@ -341,3 +346,37 @@ impl Executable for ToggleLoopCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Executable for GetFullStateCommand {
|
||||
async fn execute(&self) -> Response {
|
||||
let (input_devices, _output_devices) = get_all_devices().await.unwrap();
|
||||
let mut all_inputs = HashMap::new();
|
||||
let mut current_input_nick = String::new();
|
||||
|
||||
let audio_player = get_audio_player().await.lock().await;
|
||||
for device in input_devices {
|
||||
if device.name == "pwsp-virtual-mic" {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(current_input_name) = &audio_player.input_device_name {
|
||||
if device.name == *current_input_name {
|
||||
current_input_nick = format!("{} - {}", device.name, device.nick);
|
||||
}
|
||||
}
|
||||
|
||||
all_inputs.insert(device.name, device.nick);
|
||||
}
|
||||
|
||||
let full_state = FullState {
|
||||
state: audio_player.get_state(),
|
||||
tracks: audio_player.get_tracks(),
|
||||
volume: audio_player.volume,
|
||||
current_input: current_input_nick,
|
||||
all_inputs,
|
||||
};
|
||||
|
||||
Response::new(true, serde_json::to_string(&full_state).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +155,10 @@ impl Request {
|
||||
}
|
||||
Request::new("toggle_loop", args)
|
||||
}
|
||||
|
||||
pub fn get_full_state() -> Self {
|
||||
Request::new("get_full_state", vec![])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user