fix rdp session ctrl+alt+delete (#7258)

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2024-02-26 13:22:21 +08:00 committed by GitHub
parent ddbd4e79a2
commit 1bc11a207a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 5 deletions

View File

@ -186,6 +186,7 @@ pub enum Data {
MouseMoveTime(i64),
Authorize,
Close,
#[cfg(windows)]
SAS,
UserSid(Option<u32>),
OnlineStatus(Option<(i64, bool)>),

View File

@ -675,7 +675,7 @@ async fn send_close_async(postfix: &str) -> ResultType<()> {
// https://docs.microsoft.com/en-us/windows/win32/api/sas/nf-sas-sendsas
// https://www.cnblogs.com/doutu/p/4892726.html
fn send_sas() {
pub fn send_sas() {
#[link(name = "sas")]
extern "system" {
pub fn SendSAS(AsUser: BOOL);
@ -744,6 +744,17 @@ pub fn get_current_process_session_id() -> Option<u32> {
}
}
pub fn is_physical_console_session() -> Option<bool> {
if let Some(sid) = get_current_process_session_id() {
let physical_console_session_id = unsafe { get_current_session(TRUE) };
if physical_console_session_id == u32::MAX {
return None;
}
return Some(physical_console_session_id == sid);
}
None
}
pub fn get_active_username() -> String {
// get_active_user will give console username higher priority
if let Some(name) = get_current_session_username() {

View File

@ -1,3 +1,5 @@
#[cfg(target_os = "linux")]
use super::rdp_input::client::{RdpInputKeyboard, RdpInputMouse};
use super::*;
#[cfg(target_os = "macos")]
use crate::common::is_server;
@ -5,8 +7,6 @@ use crate::input::*;
#[cfg(target_os = "macos")]
use dispatch::Queue;
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
#[cfg(target_os = "linux")]
use super::rdp_input::client::{RdpInputKeyboard, RdpInputMouse};
use hbb_common::{
get_time,
message_proto::{pointer_device_event::Union::TouchEvent, touch_event::Union::ScaleUpdate},
@ -1316,6 +1316,7 @@ fn is_function_key(ck: &EnumOrUnknown<ControlKey>) -> bool {
let mut res = false;
if ck.value() == ControlKey::CtrlAltDel.value() {
// have to spawn new thread because send_sas is tokio_main, the caller can not be tokio_main.
#[cfg(windows)]
std::thread::spawn(|| {
allow_err!(send_sas());
});
@ -1564,10 +1565,15 @@ async fn lock_screen_2() {
lock_screen().await;
}
#[cfg(windows)]
#[tokio::main(flavor = "current_thread")]
async fn send_sas() -> ResultType<()> {
let mut stream = crate::ipc::connect(1000, crate::POSTFIX_SERVICE).await?;
timeout(1000, stream.send(&crate::ipc::Data::SAS)).await??;
if crate::platform::is_physical_console_session().unwrap_or(true) {
let mut stream = crate::ipc::connect(1000, crate::POSTFIX_SERVICE).await?;
timeout(1000, stream.send(&crate::ipc::Data::SAS)).await??;
} else {
crate::platform::send_sas();
};
Ok(())
}