1use aethermap_common::{
7 ipc_client, AnalogCalibrationConfig, DeviceCapabilities, DeviceInfo, LayerConfigInfo,
8 LayerMode, LedPattern, LedZone, MacroEntry, Request, Response,
9};
10use std::collections::HashMap;
11use std::path::PathBuf;
12
13pub struct GuiIpcClient {
15 socket_path: PathBuf,
16}
17
18impl GuiIpcClient {
19 pub fn new(socket_path: PathBuf) -> Self {
21 Self { socket_path }
22 }
23
24 pub async fn connect(&self) -> Result<(), String> {
26 match ipc_client::is_daemon_running(Some(&self.socket_path)).await {
27 true => Ok(()),
28 false => Err("Daemon is not running".to_string()),
29 }
30 }
31
32 pub async fn get_devices(&self) -> Result<Vec<DeviceInfo>, String> {
34 let request = Request::GetDevices;
35 match ipc_client::send_to_path(&request, &self.socket_path).await {
36 Ok(Response::Devices(devices)) => Ok(devices),
37 Ok(_) => Err("Unexpected response".to_string()),
38 Err(e) => Err(format!("Failed to get devices: {}", e)),
39 }
40 }
41
42 pub async fn list_macros(&self) -> Result<Vec<MacroEntry>, String> {
44 let request = Request::ListMacros;
45 match ipc_client::send_to_path(&request, &self.socket_path).await {
46 Ok(Response::Macros(macros)) => Ok(macros),
47 Ok(_) => Err("Unexpected response".to_string()),
48 Err(e) => Err(format!("Failed to list macros: {}", e)),
49 }
50 }
51
52 pub async fn start_recording_macro(
54 &self,
55 device_path: &str,
56 name: &str,
57 capture_mouse: bool,
58 ) -> Result<(), String> {
59 let request = Request::RecordMacro {
60 device_path: device_path.to_string(),
61 name: name.to_string(),
62 capture_mouse,
63 };
64 match ipc_client::send_to_path(&request, &self.socket_path).await {
65 Ok(Response::RecordingStarted { .. }) => Ok(()),
66 Ok(_) => Err("Unexpected response".to_string()),
67 Err(e) => Err(format!("Failed to start recording: {}", e)),
68 }
69 }
70
71 pub async fn stop_recording_macro(&self) -> Result<MacroEntry, String> {
73 let request = Request::StopRecording;
74 match ipc_client::send_to_path(&request, &self.socket_path).await {
75 Ok(Response::RecordingStopped { macro_entry }) => Ok(macro_entry),
76 Ok(_) => Err("Unexpected response".to_string()),
77 Err(e) => Err(format!("Failed to stop recording: {}", e)),
78 }
79 }
80
81 pub async fn delete_macro(&self, name: &str) -> Result<(), String> {
83 let request = Request::DeleteMacro {
84 name: name.to_string(),
85 };
86 match ipc_client::send_to_path(&request, &self.socket_path).await {
87 Ok(Response::Ack) => Ok(()),
88 Ok(_) => Err("Unexpected response".to_string()),
89 Err(e) => Err(format!("Failed to delete macro: {}", e)),
90 }
91 }
92
93 pub async fn test_macro(&self, name: &str) -> Result<(), String> {
95 let request = Request::TestMacro {
96 name: name.to_string(),
97 };
98 match ipc_client::send_to_path(&request, &self.socket_path).await {
99 Ok(Response::Ack) => Ok(()),
100 Ok(_) => Err("Unexpected response".to_string()),
101 Err(e) => Err(format!("Failed to test macro: {}", e)),
102 }
103 }
104
105 pub async fn save_profile(&self, name: &str) -> Result<(String, usize), String> {
107 let request = Request::SaveProfile {
108 name: name.to_string(),
109 };
110 match ipc_client::send_to_path(&request, &self.socket_path).await {
111 Ok(Response::ProfileSaved { name, macros_count }) => Ok((name, macros_count)),
112 Ok(_) => Err("Unexpected response".to_string()),
113 Err(e) => Err(format!("Failed to save profile: {}", e)),
114 }
115 }
116
117 pub async fn load_profile(&self, name: &str) -> Result<(String, usize), String> {
119 let request = Request::LoadProfile {
120 name: name.to_string(),
121 };
122 match ipc_client::send_to_path(&request, &self.socket_path).await {
123 Ok(Response::ProfileLoaded { name, macros_count }) => Ok((name, macros_count)),
124 Ok(_) => Err("Unexpected response".to_string()),
125 Err(e) => Err(format!("Failed to load profile: {}", e)),
126 }
127 }
128
129 pub async fn grab_device(&self, device_path: &str) -> Result<(), String> {
131 let request = Request::GrabDevice {
132 device_path: device_path.to_string(),
133 };
134 match ipc_client::send_to_path(&request, &self.socket_path).await {
135 Ok(Response::Ack) => Ok(()),
136 Ok(_) => Err("Unexpected response".to_string()),
137 Err(e) => Err(format!("Failed to grab device: {}", e)),
138 }
139 }
140
141 pub async fn ungrab_device(&self, device_path: &str) -> Result<(), String> {
143 let request = Request::UngrabDevice {
144 device_path: device_path.to_string(),
145 };
146 match ipc_client::send_to_path(&request, &self.socket_path).await {
147 Ok(Response::Ack) => Ok(()),
148 Ok(_) => Err("Unexpected response".to_string()),
149 Err(e) => Err(format!("Failed to ungrab device: {}", e)),
150 }
151 }
152
153 pub async fn get_device_profiles(&self, device_id: String) -> Result<Vec<String>, String> {
164 let request = Request::GetDeviceProfiles { device_id };
165
166 match ipc_client::send_to_path(&request, &self.socket_path).await {
167 Ok(Response::DeviceProfiles { profiles, .. }) => Ok(profiles),
168 Ok(Response::Error(msg)) => Err(msg),
169 Ok(_) => Err("Unexpected response".to_string()),
170 Err(e) => Err(format!("Failed to get device profiles: {}", e)),
171 }
172 }
173
174 pub async fn activate_profile(
186 &self,
187 device_id: String,
188 profile_name: String,
189 ) -> Result<(), String> {
190 let request = Request::ActivateProfile {
191 device_id,
192 profile_name,
193 };
194
195 match ipc_client::send_to_path(&request, &self.socket_path).await {
196 Ok(Response::ProfileActivated { .. }) => Ok(()),
197 Ok(Response::Error(msg)) => Err(msg),
198 Ok(_) => Err("Unexpected response".to_string()),
199 Err(e) => Err(format!("Failed to activate profile: {}", e)),
200 }
201 }
202
203 pub async fn deactivate_profile(&self, device_id: String) -> Result<(), String> {
214 let request = Request::DeactivateProfile { device_id };
215
216 match ipc_client::send_to_path(&request, &self.socket_path).await {
217 Ok(Response::ProfileDeactivated { .. }) => Ok(()),
218 Ok(Response::Error(msg)) => Err(msg),
219 Ok(_) => Err("Unexpected response".to_string()),
220 Err(e) => Err(format!("Failed to deactivate profile: {}", e)),
221 }
222 }
223
224 pub async fn get_active_profile(&self, device_id: String) -> Result<Option<String>, String> {
235 let request = Request::GetActiveProfile { device_id };
236
237 match ipc_client::send_to_path(&request, &self.socket_path).await {
238 Ok(Response::ActiveProfile { profile_name, .. }) => Ok(profile_name),
239 Ok(Response::Error(msg)) => Err(msg),
240 Ok(_) => Err("Unexpected response".to_string()),
241 Err(e) => Err(format!("Failed to get active profile: {}", e)),
242 }
243 }
244
245 pub async fn get_active_remaps(
256 &self,
257 device_path: &str,
258 ) -> Result<Option<(String, Vec<aethermap_common::RemapEntry>)>, String> {
259 let request = Request::GetActiveRemaps {
260 device_path: device_path.to_string(),
261 };
262
263 match ipc_client::send_to_path(&request, &self.socket_path).await {
264 Ok(Response::ActiveRemaps {
265 profile_name,
266 remaps,
267 ..
268 }) => {
269 if let Some(name) = profile_name {
270 Ok(Some((name, remaps)))
271 } else {
272 Ok(None)
273 }
274 }
275 Ok(Response::Error(msg)) => Err(msg),
276 Ok(_) => Err("Unexpected response".to_string()),
277 Err(e) => Err(format!("Failed to get active remaps: {}", e)),
278 }
279 }
280
281 pub async fn list_remap_profiles(
292 &self,
293 device_path: &str,
294 ) -> Result<Vec<aethermap_common::RemapProfileInfo>, String> {
295 let request = Request::ListRemapProfiles {
296 device_path: device_path.to_string(),
297 };
298
299 match ipc_client::send_to_path(&request, &self.socket_path).await {
300 Ok(Response::RemapProfiles { profiles, .. }) => Ok(profiles),
301 Ok(Response::Error(msg)) => Err(msg),
302 Ok(_) => Err("Unexpected response".to_string()),
303 Err(e) => Err(format!("Failed to list remap profiles: {}", e)),
304 }
305 }
306
307 pub async fn activate_remap_profile(
319 &self,
320 device_path: &str,
321 profile_name: &str,
322 ) -> Result<(), String> {
323 let request = Request::ActivateRemapProfile {
324 device_path: device_path.to_string(),
325 profile_name: profile_name.to_string(),
326 };
327
328 match ipc_client::send_to_path(&request, &self.socket_path).await {
329 Ok(Response::RemapProfileActivated { .. }) => Ok(()),
330 Ok(Response::Error(msg)) => Err(msg),
331 Ok(_) => Err("Unexpected response".to_string()),
332 Err(e) => Err(format!("Failed to activate remap profile: {}", e)),
333 }
334 }
335
336 pub async fn deactivate_remap_profile(&self, device_path: &str) -> Result<(), String> {
347 let request = Request::DeactivateRemapProfile {
348 device_path: device_path.to_string(),
349 };
350
351 match ipc_client::send_to_path(&request, &self.socket_path).await {
352 Ok(Response::RemapProfileDeactivated { .. }) => Ok(()),
353 Ok(Response::Error(msg)) => Err(msg),
354 Ok(_) => Err("Unexpected response".to_string()),
355 Err(e) => Err(format!("Failed to deactivate remap profile: {}", e)),
356 }
357 }
358
359 pub async fn get_device_capabilities(
370 &self,
371 device_path: &str,
372 ) -> Result<DeviceCapabilities, String> {
373 let request = Request::GetDeviceCapabilities {
374 device_path: device_path.to_string(),
375 };
376
377 match ipc_client::send_to_path(&request, &self.socket_path).await {
378 Ok(Response::DeviceCapabilities { capabilities, .. }) => Ok(capabilities),
379 Ok(Response::Error(msg)) => Err(msg),
380 Ok(_) => Err("Unexpected response".to_string()),
381 Err(e) => Err(format!("Failed to get device capabilities: {}", e)),
382 }
383 }
384
385 pub async fn get_active_layer(&self, device_id: &str) -> Result<Option<usize>, String> {
396 let request = Request::GetActiveLayer {
397 device_id: device_id.to_string(),
398 };
399
400 match ipc_client::send_to_path(&request, &self.socket_path).await {
401 Ok(Response::ActiveLayer { layer_id, .. }) => Ok(Some(layer_id)),
402 Ok(Response::Error(msg)) => Err(msg),
403 Ok(_) => Err("Unexpected response".to_string()),
404 Err(e) => Err(format!("Failed to get active layer: {}", e)),
405 }
406 }
407
408 pub async fn set_layer_config(
422 &self,
423 device_id: &str,
424 layer_id: usize,
425 name: String,
426 mode: LayerMode,
427 ) -> Result<(), String> {
428 let config = LayerConfigInfo {
429 layer_id,
430 name: name.clone(),
431 mode,
432 remap_count: 0, led_color: (0, 0, 255), led_zone: None, };
436
437 let request = Request::SetLayerConfig {
438 device_id: device_id.to_string(),
439 layer_id,
440 config,
441 };
442
443 match ipc_client::send_to_path(&request, &self.socket_path).await {
444 Ok(Response::LayerConfigured { .. }) => Ok(()),
445 Ok(Response::Error(msg)) => Err(msg),
446 Ok(_) => Err("Unexpected response".to_string()),
447 Err(e) => Err(format!("Failed to set layer config: {}", e)),
448 }
449 }
450
451 pub async fn activate_layer(
464 &self,
465 device_id: &str,
466 layer_id: usize,
467 mode: LayerMode,
468 ) -> Result<(), String> {
469 let request = Request::ActivateLayer {
470 device_id: device_id.to_string(),
471 layer_id,
472 mode,
473 };
474
475 match ipc_client::send_to_path(&request, &self.socket_path).await {
476 Ok(Response::LayerConfigured { .. }) => Ok(()),
477 Ok(Response::Error(msg)) => Err(msg),
478 Ok(_) => Err("Unexpected response".to_string()),
479 Err(e) => Err(format!("Failed to activate layer: {}", e)),
480 }
481 }
482
483 pub async fn list_layers(&self, device_id: &str) -> Result<Vec<LayerConfigInfo>, String> {
494 let request = Request::ListLayers {
495 device_id: device_id.to_string(),
496 };
497
498 match ipc_client::send_to_path(&request, &self.socket_path).await {
499 Ok(Response::LayerList { layers, .. }) => Ok(layers),
500 Ok(Response::Error(msg)) => Err(msg),
501 Ok(_) => Err("Unexpected response".to_string()),
502 Err(e) => Err(format!("Failed to list layers: {}", e)),
503 }
504 }
505
506 pub async fn set_analog_dpad_mode(&self, device_id: &str, mode: &str) -> Result<(), String> {
518 let request = Request::SetAnalogDpadMode {
519 device_id: device_id.to_string(),
520 mode: mode.to_string(),
521 };
522
523 match ipc_client::send_to_path(&request, &self.socket_path).await {
524 Ok(Response::AnalogDpadModeSet { .. }) => Ok(()),
525 Ok(Response::Error(msg)) => Err(msg),
526 Ok(_) => Err("Unexpected response".to_string()),
527 Err(e) => Err(format!("Failed to set D-pad mode: {}", e)),
528 }
529 }
530
531 pub async fn get_analog_dpad_mode(&self, device_id: &str) -> Result<String, String> {
542 let request = Request::GetAnalogDpadMode {
543 device_id: device_id.to_string(),
544 };
545
546 match ipc_client::send_to_path(&request, &self.socket_path).await {
547 Ok(Response::AnalogDpadMode { mode, .. }) => Ok(mode),
548 Ok(Response::Error(msg)) => Err(msg),
549 Ok(_) => Err("Unexpected response".to_string()),
550 Err(e) => Err(format!("Failed to get D-pad mode: {}", e)),
551 }
552 }
553
554 pub async fn set_analog_deadzone_xy(
567 &self,
568 device_id: &str,
569 x_percentage: u8,
570 y_percentage: u8,
571 ) -> Result<(), String> {
572 let request = Request::SetAnalogDeadzoneXY {
573 device_id: device_id.to_string(),
574 x_percentage,
575 y_percentage,
576 };
577
578 match ipc_client::send_to_path(&request, &self.socket_path).await {
579 Ok(Response::AnalogDeadzoneXYSet { .. }) => Ok(()),
580 Ok(Response::Error(msg)) => Err(msg),
581 Ok(_) => Err("Unexpected response".to_string()),
582 Err(e) => Err(format!("Failed to set per-axis deadzone: {}", e)),
583 }
584 }
585
586 pub async fn get_analog_deadzone_xy(&self, device_id: &str) -> Result<(u8, u8), String> {
597 let request = Request::GetAnalogDeadzoneXY {
598 device_id: device_id.to_string(),
599 };
600
601 match ipc_client::send_to_path(&request, &self.socket_path).await {
602 Ok(Response::AnalogDeadzoneXY {
603 x_percentage,
604 y_percentage,
605 ..
606 }) => Ok((x_percentage, y_percentage)),
607 Ok(Response::Error(msg)) => Err(msg),
608 Ok(_) => Err("Unexpected response".to_string()),
609 Err(e) => Err(format!("Failed to get per-axis deadzone: {}", e)),
610 }
611 }
612
613 pub async fn set_analog_outer_deadzone_xy(
626 &self,
627 device_id: &str,
628 x_percentage: u8,
629 y_percentage: u8,
630 ) -> Result<(), String> {
631 let request = Request::SetAnalogOuterDeadzoneXY {
632 device_id: device_id.to_string(),
633 x_percentage,
634 y_percentage,
635 };
636
637 match ipc_client::send_to_path(&request, &self.socket_path).await {
638 Ok(Response::AnalogOuterDeadzoneXYSet { .. }) => Ok(()),
639 Ok(Response::Error(msg)) => Err(msg),
640 Ok(_) => Err("Unexpected response".to_string()),
641 Err(e) => Err(format!("Failed to set per-axis outer deadzone: {}", e)),
642 }
643 }
644
645 pub async fn get_analog_outer_deadzone_xy(&self, device_id: &str) -> Result<(u8, u8), String> {
656 let request = Request::GetAnalogOuterDeadzoneXY {
657 device_id: device_id.to_string(),
658 };
659
660 match ipc_client::send_to_path(&request, &self.socket_path).await {
661 Ok(Response::AnalogOuterDeadzoneXY {
662 x_percentage,
663 y_percentage,
664 ..
665 }) => Ok((x_percentage, y_percentage)),
666 Ok(Response::Error(msg)) => Err(msg),
667 Ok(_) => Err("Unexpected response".to_string()),
668 Err(e) => Err(format!("Failed to get per-axis outer deadzone: {}", e)),
669 }
670 }
671
672 pub async fn set_led_color(
687 &self,
688 device_id: &str,
689 zone: LedZone,
690 red: u8,
691 green: u8,
692 blue: u8,
693 ) -> Result<(), String> {
694 let request = Request::SetLedColor {
695 device_id: device_id.to_string(),
696 zone,
697 red,
698 green,
699 blue,
700 };
701
702 match ipc_client::send_to_path(&request, &self.socket_path).await {
703 Ok(Response::LedColorSet { .. }) => Ok(()),
704 Ok(Response::Error(msg)) => Err(msg),
705 Ok(_) => Err("Unexpected response".to_string()),
706 Err(e) => Err(format!("Failed to set LED color: {}", e)),
707 }
708 }
709
710 pub async fn get_led_color(
722 &self,
723 device_id: &str,
724 zone: LedZone,
725 ) -> Result<Option<(u8, u8, u8)>, String> {
726 let request = Request::GetLedColor {
727 device_id: device_id.to_string(),
728 zone,
729 };
730
731 match ipc_client::send_to_path(&request, &self.socket_path).await {
732 Ok(Response::LedColor { color, .. }) => Ok(color),
733 Ok(Response::Error(msg)) => Err(msg),
734 Ok(_) => Err("Unexpected response".to_string()),
735 Err(e) => Err(format!("Failed to get LED color: {}", e)),
736 }
737 }
738
739 pub async fn get_all_led_colors(
750 &self,
751 device_id: &str,
752 ) -> Result<HashMap<LedZone, (u8, u8, u8)>, String> {
753 let request = Request::GetAllLedColors {
754 device_id: device_id.to_string(),
755 };
756
757 match ipc_client::send_to_path(&request, &self.socket_path).await {
758 Ok(Response::AllLedColors { colors, .. }) => Ok(colors),
759 Ok(Response::Error(msg)) => Err(msg),
760 Ok(_) => Err("Unexpected response".to_string()),
761 Err(e) => Err(format!("Failed to get all LED colors: {}", e)),
762 }
763 }
764
765 pub async fn set_led_brightness(
778 &self,
779 device_id: &str,
780 zone: Option<LedZone>,
781 brightness: u8,
782 ) -> Result<(), String> {
783 let request = Request::SetLedBrightness {
784 device_id: device_id.to_string(),
785 zone,
786 brightness,
787 };
788
789 match ipc_client::send_to_path(&request, &self.socket_path).await {
790 Ok(Response::LedBrightnessSet { .. }) => Ok(()),
791 Ok(Response::Error(msg)) => Err(msg),
792 Ok(_) => Err("Unexpected response".to_string()),
793 Err(e) => Err(format!("Failed to set LED brightness: {}", e)),
794 }
795 }
796
797 pub async fn get_led_brightness(
809 &self,
810 device_id: &str,
811 zone: Option<LedZone>,
812 ) -> Result<u8, String> {
813 let request = Request::GetLedBrightness {
814 device_id: device_id.to_string(),
815 zone,
816 };
817
818 match ipc_client::send_to_path(&request, &self.socket_path).await {
819 Ok(Response::LedBrightness { brightness, .. }) => Ok(brightness),
820 Ok(Response::Error(msg)) => Err(msg),
821 Ok(_) => Err("Unexpected response".to_string()),
822 Err(e) => Err(format!("Failed to get LED brightness: {}", e)),
823 }
824 }
825
826 pub async fn set_led_pattern(
838 &self,
839 device_id: &str,
840 pattern: LedPattern,
841 ) -> Result<(), String> {
842 let request = Request::SetLedPattern {
843 device_id: device_id.to_string(),
844 pattern,
845 };
846
847 match ipc_client::send_to_path(&request, &self.socket_path).await {
848 Ok(Response::LedPatternSet { .. }) => Ok(()),
849 Ok(Response::Error(msg)) => Err(msg),
850 Ok(_) => Err("Unexpected response".to_string()),
851 Err(e) => Err(format!("Failed to set LED pattern: {}", e)),
852 }
853 }
854
855 pub async fn get_led_pattern(&self, device_id: &str) -> Result<LedPattern, String> {
866 let request = Request::GetLedPattern {
867 device_id: device_id.to_string(),
868 };
869
870 match ipc_client::send_to_path(&request, &self.socket_path).await {
871 Ok(Response::LedPattern { pattern, .. }) => Ok(pattern),
872 Ok(Response::Error(msg)) => Err(msg),
873 Ok(_) => Err("Unexpected response".to_string()),
874 Err(e) => Err(format!("Failed to get LED pattern: {}", e)),
875 }
876 }
877
878 pub async fn send_focus_change(
890 &self,
891 app_id: String,
892 window_title: Option<String>,
893 ) -> Result<(), String> {
894 let request = Request::FocusChanged {
895 app_id,
896 window_title,
897 };
898 match ipc_client::send_to_path(&request, &self.socket_path).await {
899 Ok(Response::FocusChangedAck { .. }) => Ok(()),
900 Ok(Response::Error(e)) => Err(e),
901 Ok(other) => Err(format!("Unexpected response: {:?}", other)),
902 Err(e) => Err(format!("Failed to send focus change: {}", e)),
903 }
904 }
905
906 pub async fn get_analog_calibration(
918 &self,
919 device_id: &str,
920 layer_id: usize,
921 ) -> Result<AnalogCalibrationConfig, String> {
922 let request = Request::GetAnalogCalibration {
923 device_id: device_id.to_string(),
924 layer_id,
925 };
926
927 match ipc_client::send_to_path(&request, &self.socket_path).await {
928 Ok(Response::AnalogCalibration {
929 calibration: Some(cal),
930 ..
931 }) => Ok(cal),
932 Ok(Response::AnalogCalibration {
933 calibration: None, ..
934 }) => {
935 Ok(AnalogCalibrationConfig::default())
937 }
938 Ok(Response::Error(msg)) => Err(msg),
939 Ok(_) => Err("Unexpected response".to_string()),
940 Err(e) => Err(format!("Failed to get analog calibration: {}", e)),
941 }
942 }
943
944 pub async fn set_analog_calibration(
957 &self,
958 device_id: &str,
959 layer_id: usize,
960 calibration: AnalogCalibrationConfig,
961 ) -> Result<(), String> {
962 let request = Request::SetAnalogCalibration {
963 device_id: device_id.to_string(),
964 layer_id,
965 calibration,
966 };
967
968 match ipc_client::send_to_path(&request, &self.socket_path).await {
969 Ok(Response::AnalogCalibrationAck) => Ok(()),
970 Ok(Response::Error(msg)) => Err(msg),
971 Ok(_) => Err("Unexpected response".to_string()),
972 Err(e) => Err(format!("Failed to set analog calibration: {}", e)),
973 }
974 }
975
976 pub async fn subscribe_analog_input(&self, device_id: &str) -> Result<(), String> {
987 let request = Request::SubscribeAnalogInput {
988 device_id: device_id.to_string(),
989 };
990
991 match ipc_client::send_to_path(&request, &self.socket_path).await {
992 Ok(Response::AnalogInputSubscribed) => Ok(()),
993 Ok(Response::Error(msg)) => Err(msg),
994 Ok(_) => Err("Unexpected response".to_string()),
995 Err(e) => Err(format!("Failed to subscribe to analog input: {}", e)),
996 }
997 }
998
999 pub async fn unsubscribe_analog_input(&self, device_id: &str) -> Result<(), String> {
1010 let request = Request::UnsubscribeAnalogInput {
1011 device_id: device_id.to_string(),
1012 };
1013
1014 match ipc_client::send_to_path(&request, &self.socket_path).await {
1015 Ok(Response::Ack) => Ok(()),
1016 Ok(Response::Error(msg)) => Err(msg),
1017 Ok(_) => Err("Unexpected response".to_string()),
1018 Err(e) => Err(format!("Failed to unsubscribe from analog input: {}", e)),
1019 }
1020 }
1021
1022 pub async fn get_macro_settings(&self) -> Result<aethermap_common::MacroSettings, String> {
1024 let request = Request::GetMacroSettings;
1025 match ipc_client::send_to_path(&request, &self.socket_path).await {
1026 Ok(Response::MacroSettings(settings)) => Ok(settings),
1027 Ok(Response::Error(msg)) => Err(msg),
1028 Ok(_) => Err("Unexpected response".to_string()),
1029 Err(e) => Err(format!("Failed to get macro settings: {}", e)),
1030 }
1031 }
1032
1033 pub async fn set_macro_settings(
1035 &self,
1036 settings: aethermap_common::MacroSettings,
1037 ) -> Result<(), String> {
1038 let request = Request::SetMacroSettings(settings);
1039 match ipc_client::send_to_path(&request, &self.socket_path).await {
1040 Ok(Response::Ack) => Ok(()),
1041 Ok(Response::Error(msg)) => Err(msg),
1042 Ok(_) => Err("Unexpected response".to_string()),
1043 Err(e) => Err(format!("Failed to set macro settings: {}", e)),
1044 }
1045 }
1046}
1047
1048pub type IpcClient = GuiIpcClient;