Compare commits

..

3 Commits

Author SHA1 Message Date
arabianq eae455f0b8 change pwsp version to 1.0.2 2025-10-05 23:32:03 +03:00
arabianq e0a55dffa6 update dependencies 2025-10-05 23:31:32 +03:00
arabianq 6a755ad068 use device name instead of node id to get audio device 2025-10-05 23:26:29 +03:00
14 changed files with 131 additions and 139 deletions
Generated
+93 -94
View File
@@ -4,9 +4,9 @@ version = 4
[[package]]
name = "ab_glyph"
version = "0.2.31"
version = "0.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e074464580a518d16a7126262fffaaa47af89d4099d4cb403f8ed938ba12ee7d"
checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2"
dependencies = [
"ab_glyph_rasterizer",
"owned_ttf_parser",
@@ -116,9 +116,9 @@ dependencies = [
[[package]]
name = "anstyle"
version = "1.0.11"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anyhow"
@@ -135,11 +135,11 @@ dependencies = [
"clipboard-win",
"image",
"log",
"objc2 0.6.2",
"objc2-app-kit 0.3.1",
"objc2 0.6.3",
"objc2-app-kit 0.3.2",
"objc2-core-foundation",
"objc2-core-graphics",
"objc2-foundation 0.3.1",
"objc2-foundation 0.3.2",
"parking_lot",
"percent-encoding",
"windows-sys 0.60.2",
@@ -420,11 +420,11 @@ dependencies = [
[[package]]
name = "block2"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "340d2f0bdb2a43c1d3cd40513185b2bd7def0aa1052f956455114bc98f82dcf2"
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
dependencies = [
"objc2 0.6.2",
"objc2 0.6.3",
]
[[package]]
@@ -448,18 +448,18 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
[[package]]
name = "bytemuck"
version = "1.23.2"
version = "1.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677"
checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4"
dependencies = [
"bytemuck_derive",
]
[[package]]
name = "bytemuck_derive"
version = "1.10.1"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f154e572231cb6ba2bd1176980827e3d5dc04cc183a75dea38109fbdd672d29"
checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff"
dependencies = [
"proc-macro2",
"quote",
@@ -506,9 +506,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.39"
version = "1.2.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f"
checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb"
dependencies = [
"find-msvc-tools",
"jobserver",
@@ -842,9 +842,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
dependencies = [
"bitflags 2.9.4",
"block2 0.6.1",
"block2 0.6.2",
"libc",
"objc2 0.6.2",
"objc2 0.6.3",
]
[[package]]
@@ -1179,15 +1179,15 @@ dependencies = [
[[package]]
name = "find-msvc-tools"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959"
checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3"
[[package]]
name = "flate2"
version = "1.1.2"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
checksum = "dc5a4e564e38c699f2880d3fda590bedc2e69f3f84cd48b457bd892ce61d0aa9"
dependencies = [
"crc32fast",
"miniz_oxide",
@@ -1420,10 +1420,10 @@ dependencies = [
"glutin_glx_sys",
"glutin_wgl_sys",
"libloading",
"objc2 0.6.2",
"objc2-app-kit 0.3.1",
"objc2 0.6.3",
"objc2-app-kit 0.3.2",
"objc2-core-foundation",
"objc2-foundation 0.3.1",
"objc2-foundation 0.3.2",
"once_cell",
"raw-window-handle",
"wayland-sys",
@@ -1763,7 +1763,7 @@ checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb"
dependencies = [
"bitflags 2.9.4",
"libc",
"redox_syscall 0.5.17",
"redox_syscall 0.5.18",
]
[[package]]
@@ -1820,11 +1820,10 @@ checksum = "f5e54036fe321fd421e10d732f155734c4e4afd610dd556d9a82833ab3ee0bed"
[[package]]
name = "lock_api"
version = "0.4.13"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"autocfg",
"scopeguard",
]
@@ -1896,9 +1895,9 @@ dependencies = [
[[package]]
name = "moxcms"
version = "0.7.5"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd32fa8935aeadb8a8a6b6b351e40225570a37c43de67690383d87ef170cd08"
checksum = "1cc7d85f3d741164e8972ad355e26ac6e51b20fcae5f911c7da8f2d8bbbb3f33"
dependencies = [
"num-traits",
"pxfm",
@@ -1924,7 +1923,7 @@ dependencies = [
"once_cell",
"rustc-hash 1.1.0",
"strum",
"thiserror 2.0.16",
"thiserror 2.0.17",
"unicode-ident",
]
@@ -2097,9 +2096,9 @@ dependencies = [
[[package]]
name = "objc2"
version = "0.6.2"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "561f357ba7f3a2a61563a186a163d0a3a5247e1089524a3981d49adb775078bc"
checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05"
dependencies = [
"objc2-encode",
]
@@ -2122,31 +2121,31 @@ dependencies = [
[[package]]
name = "objc2-app-kit"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6f29f568bec459b0ddff777cec4fe3fd8666d82d5a40ebd0ff7e66134f89bcc"
checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c"
dependencies = [
"bitflags 2.9.4",
"block2 0.6.1",
"objc2 0.6.2",
"block2 0.6.2",
"objc2 0.6.3",
"objc2-core-foundation",
"objc2-core-graphics",
"objc2-foundation 0.3.1",
"objc2-foundation 0.3.2",
]
[[package]]
name = "objc2-audio-toolbox"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10cbe18d879e20a4aea544f8befe38bcf52255eb63d3f23eca2842f3319e4c07"
checksum = "6948501a91121d6399b79abaa33a8aa4ea7857fe019f341b8c23ad6e81b79b08"
dependencies = [
"bitflags 2.9.4",
"libc",
"objc2 0.6.2",
"objc2 0.6.3",
"objc2-core-audio",
"objc2-core-audio-types",
"objc2-core-foundation",
"objc2-foundation 0.3.1",
"objc2-foundation 0.3.2",
]
[[package]]
@@ -2175,24 +2174,24 @@ dependencies = [
[[package]]
name = "objc2-core-audio"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca44961e888e19313b808f23497073e3f6b3c22bb485056674c8b49f3b025c82"
checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2"
dependencies = [
"dispatch2",
"objc2 0.6.2",
"objc2 0.6.3",
"objc2-core-audio-types",
"objc2-core-foundation",
]
[[package]]
name = "objc2-core-audio-types"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0f1cc99bb07ad2ddb6527ddf83db6a15271bb036b3eb94b801cd44fdc666ee1"
checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c"
dependencies = [
"bitflags 2.9.4",
"objc2 0.6.2",
"objc2 0.6.3",
]
[[package]]
@@ -2209,24 +2208,24 @@ dependencies = [
[[package]]
name = "objc2-core-foundation"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166"
checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536"
dependencies = [
"bitflags 2.9.4",
"dispatch2",
"objc2 0.6.2",
"objc2 0.6.3",
]
[[package]]
name = "objc2-core-graphics"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "989c6c68c13021b5c2d6b71456ebb0f9dc78d752e86a98da7c716f4f9470f5a4"
checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807"
dependencies = [
"bitflags 2.9.4",
"dispatch2",
"objc2 0.6.2",
"objc2 0.6.3",
"objc2-core-foundation",
"objc2-io-surface",
]
@@ -2276,23 +2275,23 @@ dependencies = [
[[package]]
name = "objc2-foundation"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c"
checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272"
dependencies = [
"bitflags 2.9.4",
"objc2 0.6.2",
"objc2 0.6.3",
"objc2-core-foundation",
]
[[package]]
name = "objc2-io-surface"
version = "0.3.1"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7282e9ac92529fa3457ce90ebb15f4ecbc383e8338060960760fa2cf75420c3c"
checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d"
dependencies = [
"bitflags 2.9.4",
"objc2 0.6.2",
"objc2 0.6.3",
"objc2-core-foundation",
]
@@ -2445,9 +2444,9 @@ checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
[[package]]
name = "parking_lot"
version = "0.12.4"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
dependencies = [
"lock_api",
"parking_lot_core",
@@ -2455,15 +2454,15 @@ dependencies = [
[[package]]
name = "parking_lot_core"
version = "0.9.11"
version = "0.9.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.5.17",
"redox_syscall 0.5.18",
"smallvec",
"windows-targets 0.52.6",
"windows-link",
]
[[package]]
@@ -2529,7 +2528,7 @@ dependencies = [
"nix",
"once_cell",
"pipewire-sys",
"thiserror 2.0.16",
"thiserror 2.0.17",
]
[[package]]
@@ -2632,7 +2631,7 @@ checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773"
[[package]]
name = "pwsp"
version = "1.0.1"
version = "1.0.2"
dependencies = [
"async-trait",
"clap",
@@ -2675,9 +2674,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.40"
version = "1.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
dependencies = [
"proc-macro2",
]
@@ -2754,9 +2753,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.17"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
"bitflags 2.9.4",
]
@@ -2769,7 +2768,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
dependencies = [
"getrandom 0.2.16",
"libredox",
"thiserror 2.0.16",
"thiserror 2.0.17",
]
[[package]]
@@ -2814,14 +2813,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef2bee61e6cffa4635c72d7d81a84294e28f0930db0ddcb0f66d10244674ebed"
dependencies = [
"ashpd",
"block2 0.6.1",
"block2 0.6.2",
"dispatch2",
"js-sys",
"log",
"objc2 0.6.2",
"objc2-app-kit 0.3.1",
"objc2 0.6.3",
"objc2-app-kit 0.3.2",
"objc2-core-foundation",
"objc2-foundation 0.3.1",
"objc2-foundation 0.3.2",
"pollster",
"raw-window-handle",
"urlencoding",
@@ -2922,9 +2921,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.227"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80ece43fc6fbed4eb5392ab50c07334d3e577cbf40997ee896fe7af40bba4245"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
"serde_derive",
@@ -2932,18 +2931,18 @@ dependencies = [
[[package]]
name = "serde_core"
version = "1.0.227"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a576275b607a2c86ea29e410193df32bc680303c82f31e275bbfcafe8b33be5"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.227"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51e694923b8824cf0e9b382adf0f60d4e05f348f357b38833a3fa5ed7c2ede04"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
@@ -3389,11 +3388,11 @@ dependencies = [
[[package]]
name = "thiserror"
version = "2.0.16"
version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
dependencies = [
"thiserror-impl 2.0.16",
"thiserror-impl 2.0.17",
]
[[package]]
@@ -3409,9 +3408,9 @@ dependencies = [
[[package]]
name = "thiserror-impl"
version = "2.0.16"
version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
dependencies = [
"proc-macro2",
"quote",
@@ -3893,8 +3892,8 @@ dependencies = [
"jni",
"log",
"ndk-context",
"objc2 0.6.2",
"objc2-foundation 0.3.1",
"objc2 0.6.3",
"objc2-foundation 0.3.2",
"url",
"web-sys",
]
@@ -3954,7 +3953,7 @@ dependencies = [
"raw-window-handle",
"rustc-hash 1.1.0",
"smallvec",
"thiserror 2.0.16",
"thiserror 2.0.17",
"wgpu-core-deps-windows-linux-android",
"wgpu-hal",
"wgpu-types",
@@ -3984,7 +3983,7 @@ dependencies = [
"portable-atomic",
"raw-window-handle",
"renderdoc-sys",
"thiserror 2.0.16",
"thiserror 2.0.17",
"wgpu-types",
]
@@ -3998,7 +3997,7 @@ dependencies = [
"bytemuck",
"js-sys",
"log",
"thiserror 2.0.16",
"thiserror 2.0.17",
"web-sys",
]
+2 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "pwsp"
version = "1.0.1"
version = "1.0.2"
edition = "2024"
authors = ["arabian"]
description = "PWSP lets you play audio files through your microphone. Has both CLI and GUI clients."
@@ -16,7 +16,7 @@ tokio = { version = "1.47.1", features = ["full"] }
futures = { version = "0.3.31", features = ["thread-pool"] }
async-trait = "0.1.89"
serde = { version = "1.0.227", features = ["derive"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
clap = { version = "4.5.48", default-features = false, features = ["std", "suggestions", "help", "usage", "error-context", "derive"] }
+1 -1
View File
@@ -4,7 +4,7 @@
%global cargo_install_lib 0
Name: pwsp
Version: 1.0.1
Version: 1.0.2
Release: %autorelease
Summary: Lets you play audio files through your microphone
+2 -2
View File
@@ -72,7 +72,7 @@ enum SetCommands {
/// Playback position
Position { position: f32 },
/// Input
Input { id: u32 },
Input { name: String },
}
#[tokio::main]
@@ -102,7 +102,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
Commands::Set { parameter } => match parameter {
SetCommands::Volume { volume } => Request::set_volume(volume),
SetCommands::Position { position } => Request::seek(position),
SetCommands::Input { id } => Request::set_input(id),
SetCommands::Input { name } => Request::set_input(&name),
},
};
+3 -3
View File
@@ -287,7 +287,7 @@ impl SoundpadGui {
ui.add_space(5.0);
ui.horizontal_top(|ui| {
// ---------- Microphone selection ----------
let mut mics: Vec<(&u32, &String)> =
let mut mics: Vec<(&String, &String)> =
self.audio_player_state.all_inputs.iter().collect();
mics.sort_by_key(|(k, _)| *k);
@@ -301,8 +301,8 @@ impl SoundpadGui {
.unwrap_or(&String::new()),
)
.show_ui(ui, |ui| {
for (index, device) in mics {
ui.selectable_value(&mut selected_input, index.to_owned(), device);
for (name, nick) in mics {
ui.selectable_value(&mut selected_input, name.to_owned(), nick);
}
});
+3 -3
View File
@@ -92,12 +92,12 @@ impl SoundpadGui {
make_request_sync(Request::play(path.to_str().unwrap())).ok();
}
pub fn set_input(&mut self, id: u32) {
make_request_sync(Request::set_input(id)).ok();
pub fn set_input(&mut self, name: String) {
make_request_sync(Request::set_input(&name)).ok();
if self.config.save_input {
let mut daemon_config = get_daemon_config();
daemon_config.default_input_id = Some(id);
daemon_config.default_input_name = Some(name);
daemon_config.save_to_file().ok();
}
}
+4 -4
View File
@@ -40,8 +40,8 @@ impl AudioPlayer {
let daemon_config = get_daemon_config();
let default_volume = daemon_config.default_volume.unwrap_or(1.0);
let mut default_input_device: Option<AudioDevice> = None;
if let Some(id) = daemon_config.default_input_id
&& let Ok(device) = get_device(id).await
if let Some(name) = daemon_config.default_input_name
&& let Ok(device) = get_device(&name).await
&& device.device_type == DeviceType::Input
{
default_input_device = Some(device);
@@ -224,8 +224,8 @@ impl AudioPlayer {
&self.current_file_path
}
pub async fn set_current_input_device(&mut self, id: u32) -> Result<(), Box<dyn Error>> {
let input_device = get_device(id).await?;
pub async fn set_current_input_device(&mut self, name: &str) -> Result<(), Box<dyn Error>> {
let input_device = get_device(name).await?;
if input_device.device_type != DeviceType::Input {
return Err("Selected device is not an input device".into());
+8 -5
View File
@@ -47,7 +47,7 @@ pub struct GetCurrentInputCommand {}
pub struct GetAllInputsCommand {}
pub struct SetCurrentInputCommand {
pub id: Option<u32>,
pub name: Option<String>,
}
#[async_trait]
@@ -192,7 +192,10 @@ impl Executable for GetCurrentInputCommand {
async fn execute(&self) -> Response {
let audio_player = get_audio_player().await.lock().await;
if let Some(input_device) = &audio_player.current_input_device {
Response::new(true, format!("{} - {}", input_device.id, input_device.nick))
Response::new(
true,
format!("{} - {}", input_device.name, input_device.nick),
)
} else {
Response::new(false, "No input device selected")
}
@@ -209,7 +212,7 @@ impl Executable for GetAllInputsCommand {
continue;
}
let string = format!("{} - {}", device.id, device.nick);
let string = format!("{} - {}", device.name, device.nick);
input_devices_strings.push(string);
}
let response_message = input_devices_strings.join("; ");
@@ -221,9 +224,9 @@ impl Executable for GetAllInputsCommand {
#[async_trait]
impl Executable for SetCurrentInputCommand {
async fn execute(&self) -> Response {
if let Some(id) = self.id {
if let Some(name) = &self.name {
let mut audio_player = get_audio_player().await.lock().await;
match audio_player.set_current_input_device(id).await {
match audio_player.set_current_input_device(name).await {
Ok(_) => Response::new(true, "Input device was set"),
Err(err) => Response::new(false, err.to_string()),
}
+1 -1
View File
@@ -4,7 +4,7 @@ use std::{collections::HashSet, error::Error, fs, path::PathBuf};
#[derive(Default, Clone, Serialize, Deserialize)]
pub struct DaemonConfig {
pub default_input_id: Option<u32>,
pub default_input_name: Option<String>,
pub default_volume: Option<f32>,
}
+2 -2
View File
@@ -34,6 +34,6 @@ pub struct AudioPlayerState {
pub new_position: Option<f32>,
pub duration: f32,
pub current_input: u32,
pub all_inputs: HashMap<u32, String>,
pub current_input: String,
pub all_inputs: HashMap<String, String>,
}
+2 -2
View File
@@ -80,8 +80,8 @@ impl Request {
Request::new("seek", vec![("position", &position.to_string())])
}
pub fn set_input(id: u32) -> Self {
Request::new("set_input", vec![("input_id", &id.to_string())])
pub fn set_input(name: &str) -> Self {
Request::new("set_input", vec![("input_name", name)])
}
}
+2 -7
View File
@@ -44,13 +44,8 @@ pub fn parse_command(request: &Request) -> Option<Box<dyn Executable + Send>> {
"get_input" => Some(Box::new(GetCurrentInputCommand {})),
"get_inputs" => Some(Box::new(GetAllInputsCommand {})),
"set_input" => {
let id = request
.args
.get("input_id")
.unwrap_or(&String::new())
.parse::<u32>()
.ok();
Some(Box::new(SetCurrentInputCommand { id }))
let name = Some(request.args.get("input_name").unwrap_or(&String::new())).cloned();
Some(Box::new(SetCurrentInputCommand { name }))
}
_ => None,
}
+6 -11
View File
@@ -96,10 +96,8 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
.collect::<Vec<&str>>()
.first()
.unwrap()
.to_string()
.parse::<u32>()
.unwrap_or_default(),
false => 0,
.to_string(),
false => String::new(),
};
let all_inputs = match all_inputs_res.status {
true => all_inputs_res
@@ -111,14 +109,11 @@ pub fn start_app_state_thread(audio_player_state_shared: Arc<Mutex<AudioPlayerSt
if entry.is_empty() {
return None;
}
entry.split_once(" - ").and_then(|(k, v)| {
k.trim()
.parse::<u32>()
.ok()
.map(|key| (key, v.trim().to_string()))
})
entry
.split_once(" - ")
.map(|(k, v)| (k.trim().to_string(), v.trim().to_string()))
})
.collect(),
.collect::<HashMap<String, String>>(),
false => HashMap::new(),
};
+2 -2
View File
@@ -199,12 +199,12 @@ pub async fn get_all_devices() -> Result<(Vec<AudioDevice>, Vec<AudioDevice>), B
}
}
pub async fn get_device(node_id: u32) -> Result<AudioDevice, Box<dyn Error>> {
pub async fn get_device(device_name: &str) -> Result<AudioDevice, Box<dyn Error>> {
let (mut input_devices, output_devices) = get_all_devices().await?;
input_devices.extend(output_devices);
for device in input_devices {
if device.id == node_id {
if device.name == device_name {
return Ok(device);
}
}