fix rdp session ctrl+alt+delete (#7258)
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
ddbd4e79a2
commit
1bc11a207a
@ -186,6 +186,7 @@ pub enum Data {
|
|||||||
MouseMoveTime(i64),
|
MouseMoveTime(i64),
|
||||||
Authorize,
|
Authorize,
|
||||||
Close,
|
Close,
|
||||||
|
#[cfg(windows)]
|
||||||
SAS,
|
SAS,
|
||||||
UserSid(Option<u32>),
|
UserSid(Option<u32>),
|
||||||
OnlineStatus(Option<(i64, bool)>),
|
OnlineStatus(Option<(i64, bool)>),
|
||||||
|
@ -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://docs.microsoft.com/en-us/windows/win32/api/sas/nf-sas-sendsas
|
||||||
// https://www.cnblogs.com/doutu/p/4892726.html
|
// https://www.cnblogs.com/doutu/p/4892726.html
|
||||||
fn send_sas() {
|
pub fn send_sas() {
|
||||||
#[link(name = "sas")]
|
#[link(name = "sas")]
|
||||||
extern "system" {
|
extern "system" {
|
||||||
pub fn SendSAS(AsUser: BOOL);
|
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 {
|
pub fn get_active_username() -> String {
|
||||||
// get_active_user will give console username higher priority
|
// get_active_user will give console username higher priority
|
||||||
if let Some(name) = get_current_session_username() {
|
if let Some(name) = get_current_session_username() {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
use super::rdp_input::client::{RdpInputKeyboard, RdpInputMouse};
|
||||||
use super::*;
|
use super::*;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use crate::common::is_server;
|
use crate::common::is_server;
|
||||||
@ -5,8 +7,6 @@ use crate::input::*;
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use dispatch::Queue;
|
use dispatch::Queue;
|
||||||
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
|
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
use super::rdp_input::client::{RdpInputKeyboard, RdpInputMouse};
|
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
get_time,
|
get_time,
|
||||||
message_proto::{pointer_device_event::Union::TouchEvent, touch_event::Union::ScaleUpdate},
|
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;
|
let mut res = false;
|
||||||
if ck.value() == ControlKey::CtrlAltDel.value() {
|
if ck.value() == ControlKey::CtrlAltDel.value() {
|
||||||
// have to spawn new thread because send_sas is tokio_main, the caller can not be tokio_main.
|
// have to spawn new thread because send_sas is tokio_main, the caller can not be tokio_main.
|
||||||
|
#[cfg(windows)]
|
||||||
std::thread::spawn(|| {
|
std::thread::spawn(|| {
|
||||||
allow_err!(send_sas());
|
allow_err!(send_sas());
|
||||||
});
|
});
|
||||||
@ -1564,10 +1565,15 @@ async fn lock_screen_2() {
|
|||||||
lock_screen().await;
|
lock_screen().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn send_sas() -> ResultType<()> {
|
async fn send_sas() -> ResultType<()> {
|
||||||
|
if crate::platform::is_physical_console_session().unwrap_or(true) {
|
||||||
let mut stream = crate::ipc::connect(1000, crate::POSTFIX_SERVICE).await?;
|
let mut stream = crate::ipc::connect(1000, crate::POSTFIX_SERVICE).await?;
|
||||||
timeout(1000, stream.send(&crate::ipc::Data::SAS)).await??;
|
timeout(1000, stream.send(&crate::ipc::Data::SAS)).await??;
|
||||||
|
} else {
|
||||||
|
crate::platform::send_sas();
|
||||||
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user