cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

Fix macOS compile: Enigo not Send, missing Button variants

dami etoile committed c079097
- Move enigo to a dedicated blocking thread with std::sync::mpsc channel
  (Enigo holds NonNull<CGEventSource> on macOS, not Send across .await)
- Remove Button::Back/Forward (not available in enigo on macOS)
commit
c07909718f5c5196430405c70b0beeb3c43cd3f7
parent
8a2aaf0e38d41463390130fe958dabb7f78e5039
author
dami etoile <dami.etoile@gmail.com>
1 file changed, +21 -8
Msrc-tauri/src/commands.rs29+++++++++++++++++++++--------
M src-tauri/src/commands.rs +21 -8
@@ -123,8 +123,6 @@ fn button_from_code(b: u8) -> Button {
123123 match b {124124 2 => Button::Right,125125 3 => Button::Middle,126- 4 => Button::Back,127- 5 => Button::Forward,128126 _ => Button::Left,129127 }130128 }
@@ -473,8 +471,24 @@ async fn handle_input(conn: Connection) -> anyhow::Result<()> {
473471 return Ok(());474472 }475473 476- let mut enigo = Enigo::new(&Settings::default())477- .map_err(|e| anyhow::anyhow!("enigo init: {:?}", e))?;474+ // Enigo is not Send on macOS (holds NonNull<CGEventSource>).475+ // Run it in a dedicated blocking thread, fed via a std channel.476+ let (tx, rx) = std::sync::mpsc::channel::<InputEvent>();477+ std::thread::spawn(move || {478+ let mut enigo = match Enigo::new(&Settings::default()) {479+ Ok(e) => e,480+ Err(e) => {481+ eprintln!("[host] enigo init: {:?}", e);482+ return;483+ }484+ };485+ for event in rx {486+ eprintln!("[host] input: {:?}", event);487+ if let Err(e) = event.apply(&mut enigo) {488+ eprintln!("[host] inject error: {}", e);489+ }490+ }491+ });478492 479493 let mut buf = Vec::new();480494 let mut chunk = [0u8; 1024];
@@ -508,10 +522,7 @@ async fn handle_input(conn: Connection) -> anyhow::Result<()> {
508522 509523 match serde_json::from_str::<InputEvent>(&line_str) {510524 Ok(event) => {511- eprintln!("[host] input: {:?}", event);512- if let Err(e) = event.apply(&mut enigo) {513- eprintln!("[host] inject error: {}", e);514- }525+ let _ = tx.send(event);515526 }516527 Err(e) => {517528 eprintln!("[host] parse error: {} (line: {})", e, line_str);
@@ -520,6 +531,8 @@ async fn handle_input(conn: Connection) -> anyhow::Result<()> {
520531 }521532 }522533 534+ // Drop tx to signal the blocking thread to exit535+ drop(tx);523536 let _ = send.write_all(b"bye\n").await;524537 Ok(())525538 }