Merge pull request #2880 from fufesou/fix/keyboard_cur_session

fix cur session
This commit is contained in:
RustDesk 2023-01-21 07:58:30 +08:00 committed by GitHub
commit 8f8019b45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 47 deletions

View File

@ -23,7 +23,7 @@ pub(super) const APP_TYPE_DESKTOP_FILE_TRANSFER: &str = "file transfer";
pub(super) const APP_TYPE_DESKTOP_PORT_FORWARD: &str = "port forward";
lazy_static::lazy_static! {
static ref CUR_SESSION_ID: RwLock<String> = Default::default();
pub static ref CUR_SESSION_ID: RwLock<String> = Default::default();
pub static ref SESSIONS: RwLock<HashMap<String, Session<FlutterHandler>>> = Default::default();
pub static ref GLOBAL_EVENT_STREAM: RwLock<HashMap<String, StreamSink<String>>> = Default::default(); // rust to dart event channel
}

View File

@ -319,7 +319,6 @@ pub fn session_enter_or_leave(id: String, enter: bool) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
if enter {
crate::keyboard::set_cur_session(session.clone());
session.enter();
} else {
session.leave();

View File

@ -2,10 +2,9 @@
use crate::client::get_key_state;
use crate::common::GrabState;
#[cfg(feature = "flutter")]
use crate::flutter::FlutterHandler;
use crate::flutter::{CUR_SESSION_ID, SESSIONS};
#[cfg(not(any(feature = "flutter", feature = "cli")))]
use crate::ui::remote::SciterHandler;
use crate::ui_session_interface::Session;
use crate::ui::CUR_SESSION;
use hbb_common::{log, message_proto::*};
use rdev::{Event, EventType, Key};
#[cfg(any(target_os = "windows", target_os = "macos"))]
@ -22,16 +21,6 @@ static mut IS_ALT_GR: bool = false;
#[cfg(any(target_os = "windows", target_os = "macos"))]
static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false);
#[cfg(feature = "flutter")]
lazy_static::lazy_static! {
static ref CUR_SESSION: Arc<Mutex<Option<Session<FlutterHandler>>>> = Default::default();
}
#[cfg(not(any(feature = "flutter", feature = "cli")))]
lazy_static::lazy_static! {
static ref CUR_SESSION: Arc<Mutex<Option<Session<SciterHandler>>>> = Default::default();
}
lazy_static::lazy_static! {
static ref TO_RELEASE: Arc<Mutex<HashSet<Key>>> = Arc::new(Mutex::new(HashSet::<Key>::new()));
static ref MODIFIERS_STATE: Mutex<HashMap<Key, bool>> = {
@ -48,23 +37,21 @@ lazy_static::lazy_static! {
};
}
#[cfg(feature = "flutter")]
pub fn set_cur_session(session: Session<FlutterHandler>) {
*CUR_SESSION.lock().unwrap() = Some(session);
}
#[cfg(not(any(feature = "flutter", feature = "cli")))]
pub fn set_cur_session(session: Session<SciterHandler>) {
*CUR_SESSION.lock().unwrap() = Some(session);
}
pub mod client {
use super::*;
pub fn get_keyboard_mode() -> String {
#[cfg(not(feature = "cli"))]
if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() {
return handler.get_keyboard_mode();
#[cfg(not(any(feature = "flutter", feature = "cli")))]
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
return session.get_keyboard_mode();
}
#[cfg(feature = "flutter")]
if let Some(session) = SESSIONS
.read()
.unwrap()
.get(&*CUR_SESSION_ID.read().unwrap())
{
return session.get_keyboard_mode();
}
"legacy".to_string()
}
@ -164,15 +151,20 @@ pub mod client {
}
}
pub fn lock_screen() {
pub fn event_lock_screen() -> KeyEvent {
let mut key_event = KeyEvent::new();
key_event.set_control_key(ControlKey::LockScreen);
key_event.down = true;
key_event.mode = KeyboardMode::Legacy.into();
send_key_event(&key_event);
key_event
}
pub fn ctrl_alt_del() {
#[inline]
pub fn lock_screen() {
send_key_event(&event_lock_screen());
}
pub fn event_ctrl_alt_del() -> KeyEvent {
let mut key_event = KeyEvent::new();
if get_peer_platform() == "Windows" {
key_event.set_control_key(ControlKey::CtrlAltDel);
@ -183,7 +175,12 @@ pub mod client {
key_event.press = true;
}
key_event.mode = KeyboardMode::Legacy.into();
send_key_event(&key_event);
key_event
}
#[inline]
pub fn ctrl_alt_del() {
send_key_event(&event_ctrl_alt_del());
}
}
@ -254,6 +251,8 @@ pub fn release_remote_keys() {
for key in to_release {
let event_type = EventType::KeyRelease(key);
let event = event_type_to_event(event_type);
// to-do: BUG
// Release events should be sent to the corresponding sessions, instead of current session.
client::process_event(&event, None);
}
}
@ -382,16 +381,32 @@ pub fn event_type_to_event(event_type: EventType) -> Event {
}
pub fn send_key_event(key_event: &KeyEvent) {
#[cfg(not(feature = "cli"))]
if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() {
handler.send_key_event(key_event);
#[cfg(not(any(feature = "flutter", feature = "cli")))]
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
session.send_key_event(key_event);
}
#[cfg(feature = "flutter")]
if let Some(session) = SESSIONS
.read()
.unwrap()
.get(&*CUR_SESSION_ID.read().unwrap())
{
session.send_key_event(key_event);
}
}
pub fn get_peer_platform() -> String {
#[cfg(not(feature = "cli"))]
if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() {
return handler.peer_platform();
#[cfg(not(any(feature = "flutter", feature = "cli")))]
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
return session.peer_platform();
}
#[cfg(feature = "flutter")]
if let Some(session) = SESSIONS
.read()
.unwrap()
.get(&*CUR_SESSION_ID.read().unwrap())
{
return session.peer_platform();
}
"Windows".to_string()
}

View File

@ -13,9 +13,9 @@ use hbb_common::{
log,
};
use crate::common::get_app_name;
use crate::ipc;
use crate::ui_interface::*;
#[cfg(not(any(feature = "flutter", feature = "cli")))]
use crate::ui_session_interface::Session;
use crate::{common::get_app_name, ipc, ui_interface::*};
mod cm;
#[cfg(feature = "inline")]
@ -35,6 +35,11 @@ lazy_static::lazy_static! {
static ref STUPID_VALUES: Mutex<Vec<Arc<Vec<Value>>>> = Default::default();
}
#[cfg(not(any(feature = "flutter", feature = "cli")))]
lazy_static::lazy_static! {
pub static ref CUR_SESSION: Arc<Mutex<Option<Session<remote::SciterHandler>>>> = Default::default();
}
struct UIHostHandler;
pub fn start(args: &mut [String]) {
@ -119,9 +124,10 @@ pub fn start(args: &mut [String]) {
frame.register_behavior("native-remote", move || {
let handler =
remote::SciterSession::new(cmd.clone(), id.clone(), pass.clone(), args.clone());
#[cfg(not(feature = "flutter"))]
crate::keyboard::set_cur_session(handler.inner());
#[cfg(not(any(feature = "flutter", feature = "cli")))]
{
*CUR_SESSION.lock().unwrap() = Some(handler.inner());
}
Box::new(handler)
});
page = "remote.html";

View File

@ -577,6 +577,7 @@ pub fn is_installed_daemon(_prompt: bool) -> bool {
}
#[inline]
#[cfg(feature = "flutter")]
pub fn is_can_input_monitoring(_prompt: bool) -> bool {
#[cfg(target_os = "macos")]
return crate::platform::macos::is_can_input_monitoring(_prompt);

View File

@ -4,7 +4,7 @@ use crate::client::{
input_os_password, load_config, send_mouse, start_video_audio_threads, FileManager, Key,
LoginConfigHandler, QualityStatus, KEY_MAP,
};
use crate::common::{self, is_keyboard_mode_supported, GrabState};
use crate::common::{self, GrabState};
use crate::keyboard;
use crate::{client::Data, client::Interface};
use async_trait::async_trait;
@ -780,10 +780,10 @@ impl<T: InvokeUiSession> Interface for Session<T> {
impl<T: InvokeUiSession> Session<T> {
pub fn lock_screen(&self) {
crate::keyboard::client::lock_screen();
self.send_key_event(&crate::keyboard::client::event_lock_screen());
}
pub fn ctrl_alt_del(&self) {
crate::keyboard::client::ctrl_alt_del();
self.send_key_event(&crate::keyboard::client::event_ctrl_alt_del());
}
}