From 941b7a365bd45a3362a1b4f35197afd4e4227b9e Mon Sep 17 00:00:00 2001 From: Asura Date: Sun, 11 Dec 2022 06:22:24 -0800 Subject: [PATCH] opt: catch error of grab --- Cargo.lock | 28 +++------------------------- Cargo.toml | 2 +- src/keyboard.rs | 14 ++++++++------ 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 237369d2c..07d95ac50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1533,7 +1533,7 @@ dependencies = [ "log", "objc", "pkg-config", - "rdev 0.5.0-2 (git+https://github.com/asur4s/rdev)", + "rdev", "serde 1.0.147", "serde_derive", "tfc", @@ -4229,29 +4229,7 @@ dependencies = [ [[package]] name = "rdev" version = "0.5.0-2" -source = "git+https://github.com/asur4s/rdev#4051761e7ccf434a443b8e9592c23160c9cace56" -dependencies = [ - "cocoa", - "core-foundation 0.9.3", - "core-foundation-sys 0.8.3", - "core-graphics 0.22.3", - "enum-map", - "epoll", - "inotify", - "lazy_static", - "libc", - "mio 0.8.5", - "strum 0.24.1", - "strum_macros 0.24.3", - "widestring 1.0.2", - "winapi 0.3.9", - "x11 2.20.0", -] - -[[package]] -name = "rdev" -version = "0.5.0-2" -source = "git+https://github.com/rustdesk/rdev#25c29f61bfdf5d8ec50f0a8a7743bc1d85eb2c04" +source = "git+https://github.com/asur4s/rdev#3d6d413a9b2ab703edc22071acea31826b0efce3" dependencies = [ "cocoa", "core-foundation 0.9.3", @@ -4540,7 +4518,7 @@ dependencies = [ "num_cpus", "objc", "parity-tokio-ipc", - "rdev 0.5.0-2 (git+https://github.com/rustdesk/rdev)", + "rdev", "repng", "reqwest", "rpassword 7.1.0", diff --git a/Cargo.toml b/Cargo.toml index a783b1abe..cbf384a38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ default-net = "0.11.0" wol-rs = "0.9.1" flutter_rust_bridge = { git = "https://github.com/SoLongAndThanksForAllThePizza/flutter_rust_bridge", optional = true } errno = "0.2.8" -rdev = { git = "https://github.com/rustdesk/rdev" } +rdev = { git = "https://github.com/asur4s/rdev" } url = { version = "2.1", features = ["serde"] } reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features=false } diff --git a/src/keyboard.rs b/src/keyboard.rs index d4a51c0f3..b2e19ac73 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -7,7 +7,7 @@ use crate::flutter::FlutterHandler; use crate::ui::remote::SciterHandler; use crate::ui_session_interface::Session; use hbb_common::{log, message_proto::*}; -use rdev::{Event, EventType, Key}; +use rdev::{Event, EventType, Key, GrabError}; use std::{ collections::{HashMap, HashSet}, sync::{ @@ -79,7 +79,7 @@ pub mod client { KEYBOARD_HOOKED.swap(true, Ordering::SeqCst); #[cfg(target_os = "linux")] - rdev::enable_grab().ok(); + rdev::enable_grab(); } GrabState::Wait => { release_remote_keys(); @@ -88,11 +88,11 @@ pub mod client { KEYBOARD_HOOKED.swap(false, Ordering::SeqCst); #[cfg(target_os = "linux")] - rdev::disable_grab().ok(); + rdev::disable_grab(); } GrabState::Exit => { #[cfg(target_os = "linux")] - rdev::exit_grab_listen().ok(); + rdev::exit_grab_listen(); } } } @@ -214,7 +214,7 @@ pub fn start_grab_loop() { }); #[cfg(target_os = "linux")] - rdev::start_grab_listen(move |event: Event| match event.event_type { + if let Err(err) = rdev::start_grab_listen(move |event: Event| match event.event_type { EventType::KeyPress(key) | EventType::KeyRelease(key) => { if let Key::Unknown(keycode) = key { log::error!("rdev get unknown key, keycode is : {:?}", keycode); @@ -224,7 +224,9 @@ pub fn start_grab_loop() { None } _ => Some(event), - }); + }) { + log::error!("Failed to init rdev grab thread: {:?}", err); + }; } pub fn is_long_press(event: &Event) -> bool {