mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-16 13:05:47 +00:00
Refactor get led state
This commit is contained in:
@@ -330,7 +330,6 @@ impl<T: InvokeUi> Session<T> {
|
||||
if get_key_state(enigo::Key::NumLock) {
|
||||
key_event.modifiers.push(ControlKey::NumLock.into());
|
||||
}
|
||||
log::info!("{:?}", get_key_state(enigo::Key::NumLock));
|
||||
|
||||
self.send_key_event(key_event, KeyboardMode::Map);
|
||||
}
|
||||
@@ -416,20 +415,11 @@ impl<T: InvokeUi> Session<T> {
|
||||
{
|
||||
key_event.modifiers.push(ControlKey::Meta.into());
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
if get_led_state(enigo::Key::CapsLock){
|
||||
key_event.modifiers.push(ControlKey::CapsLock.into());
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
|
||||
if get_key_state(enigo::Key::CapsLock) {
|
||||
key_event.modifiers.push(ControlKey::CapsLock.into());
|
||||
}
|
||||
if self.peer_platform() != "Mac OS" {
|
||||
#[cfg(target_os = "linux")]
|
||||
if get_led_state(enigo::Key::NumLock){
|
||||
key_event.modifiers.push(ControlKey::NumLock.into());
|
||||
}
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
if get_key_state(enigo::Key::NumLock) {
|
||||
key_event.modifiers.push(ControlKey::NumLock.into());
|
||||
}
|
||||
@@ -1371,29 +1361,4 @@ async fn start_one_port_forward<T: InvokeUi>(
|
||||
async fn send_note(url: String, id: String, conn_id: i32, note: String) {
|
||||
let body = serde_json::json!({ "id": id, "Id": conn_id, "note": note });
|
||||
allow_err!(crate::post_request(url, body.to_string(), "").await);
|
||||
}
|
||||
|
||||
fn get_led_state(key: enigo::Key) -> bool{
|
||||
let led_file = match key{
|
||||
enigo::Key::CapsLock => {
|
||||
"/sys/class/leds/input1::capslock/brightness"
|
||||
}
|
||||
enigo::Key::NumLock => {
|
||||
"/sys/class/leds/input1::numlock/brightness"
|
||||
}
|
||||
_ => {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
let status = if let Ok(mut file) = std::fs::File::open(&led_file) {
|
||||
let mut content = String::new();
|
||||
file.read_to_string(&mut content).ok();
|
||||
let status = content.trim_end().to_string().parse::<i32>().unwrap_or(0);
|
||||
status
|
||||
}else{
|
||||
0
|
||||
};
|
||||
log::info!("get led state: {}", status);
|
||||
status == 1
|
||||
}
|
||||
Reference in New Issue
Block a user