Merge pull request #2880 from fufesou/fix/keyboard_cur_session
fix cur session
This commit is contained in:
		
						commit
						8f8019b45b
					
				| @ -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"; | pub(super) const APP_TYPE_DESKTOP_PORT_FORWARD: &str = "port forward"; | ||||||
| 
 | 
 | ||||||
| lazy_static::lazy_static! { | 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 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
 |     pub static ref GLOBAL_EVENT_STREAM: RwLock<HashMap<String, StreamSink<String>>> = Default::default(); // rust to dart event channel
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -319,7 +319,6 @@ pub fn session_enter_or_leave(id: String, enter: bool) { | |||||||
|     #[cfg(not(any(target_os = "android", target_os = "ios")))] |     #[cfg(not(any(target_os = "android", target_os = "ios")))] | ||||||
|     if let Some(session) = SESSIONS.read().unwrap().get(&id) { |     if let Some(session) = SESSIONS.read().unwrap().get(&id) { | ||||||
|         if enter { |         if enter { | ||||||
|             crate::keyboard::set_cur_session(session.clone()); |  | ||||||
|             session.enter(); |             session.enter(); | ||||||
|         } else { |         } else { | ||||||
|             session.leave(); |             session.leave(); | ||||||
|  | |||||||
| @ -2,10 +2,9 @@ | |||||||
| use crate::client::get_key_state; | use crate::client::get_key_state; | ||||||
| use crate::common::GrabState; | use crate::common::GrabState; | ||||||
| #[cfg(feature = "flutter")] | #[cfg(feature = "flutter")] | ||||||
| use crate::flutter::FlutterHandler; | use crate::flutter::{CUR_SESSION_ID, SESSIONS}; | ||||||
| #[cfg(not(any(feature = "flutter", feature = "cli")))] | #[cfg(not(any(feature = "flutter", feature = "cli")))] | ||||||
| use crate::ui::remote::SciterHandler; | use crate::ui::CUR_SESSION; | ||||||
| use crate::ui_session_interface::Session; |  | ||||||
| use hbb_common::{log, message_proto::*}; | use hbb_common::{log, message_proto::*}; | ||||||
| use rdev::{Event, EventType, Key}; | use rdev::{Event, EventType, Key}; | ||||||
| #[cfg(any(target_os = "windows", target_os = "macos"))] | #[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"))] | #[cfg(any(target_os = "windows", target_os = "macos"))] | ||||||
| static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false); | 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! { | lazy_static::lazy_static! { | ||||||
|     static ref TO_RELEASE: Arc<Mutex<HashSet<Key>>> = Arc::new(Mutex::new(HashSet::<Key>::new())); |     static ref TO_RELEASE: Arc<Mutex<HashSet<Key>>> = Arc::new(Mutex::new(HashSet::<Key>::new())); | ||||||
|     static ref MODIFIERS_STATE: Mutex<HashMap<Key, bool>> = { |     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 { | pub mod client { | ||||||
|     use super::*; |     use super::*; | ||||||
| 
 | 
 | ||||||
|     pub fn get_keyboard_mode() -> String { |     pub fn get_keyboard_mode() -> String { | ||||||
|         #[cfg(not(feature = "cli"))] |         #[cfg(not(any(feature = "flutter", feature = "cli")))] | ||||||
|         if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() { |         if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() { | ||||||
|             return handler.get_keyboard_mode(); |             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() |         "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(); |         let mut key_event = KeyEvent::new(); | ||||||
|         key_event.set_control_key(ControlKey::LockScreen); |         key_event.set_control_key(ControlKey::LockScreen); | ||||||
|         key_event.down = true; |         key_event.down = true; | ||||||
|         key_event.mode = KeyboardMode::Legacy.into(); |         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(); |         let mut key_event = KeyEvent::new(); | ||||||
|         if get_peer_platform() == "Windows" { |         if get_peer_platform() == "Windows" { | ||||||
|             key_event.set_control_key(ControlKey::CtrlAltDel); |             key_event.set_control_key(ControlKey::CtrlAltDel); | ||||||
| @ -183,7 +175,12 @@ pub mod client { | |||||||
|             key_event.press = true; |             key_event.press = true; | ||||||
|         } |         } | ||||||
|         key_event.mode = KeyboardMode::Legacy.into(); |         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 { |     for key in to_release { | ||||||
|         let event_type = EventType::KeyRelease(key); |         let event_type = EventType::KeyRelease(key); | ||||||
|         let event = event_type_to_event(event_type); |         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); |         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) { | pub fn send_key_event(key_event: &KeyEvent) { | ||||||
|     #[cfg(not(feature = "cli"))] |     #[cfg(not(any(feature = "flutter", feature = "cli")))] | ||||||
|     if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() { |     if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() { | ||||||
|         handler.send_key_event(key_event); |         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 { | pub fn get_peer_platform() -> String { | ||||||
|     #[cfg(not(feature = "cli"))] |     #[cfg(not(any(feature = "flutter", feature = "cli")))] | ||||||
|     if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() { |     if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() { | ||||||
|         return handler.peer_platform(); |         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() |     "Windows".to_string() | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								src/ui.rs
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/ui.rs
									
									
									
									
									
								
							| @ -13,9 +13,9 @@ use hbb_common::{ | |||||||
|     log, |     log, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use crate::common::get_app_name; | #[cfg(not(any(feature = "flutter", feature = "cli")))] | ||||||
| use crate::ipc; | use crate::ui_session_interface::Session; | ||||||
| use crate::ui_interface::*; | use crate::{common::get_app_name, ipc, ui_interface::*}; | ||||||
| 
 | 
 | ||||||
| mod cm; | mod cm; | ||||||
| #[cfg(feature = "inline")] | #[cfg(feature = "inline")] | ||||||
| @ -35,6 +35,11 @@ lazy_static::lazy_static! { | |||||||
|     static ref STUPID_VALUES: Mutex<Vec<Arc<Vec<Value>>>> = Default::default(); |     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; | struct UIHostHandler; | ||||||
| 
 | 
 | ||||||
| pub fn start(args: &mut [String]) { | pub fn start(args: &mut [String]) { | ||||||
| @ -119,9 +124,10 @@ pub fn start(args: &mut [String]) { | |||||||
|         frame.register_behavior("native-remote", move || { |         frame.register_behavior("native-remote", move || { | ||||||
|             let handler = |             let handler = | ||||||
|                 remote::SciterSession::new(cmd.clone(), id.clone(), pass.clone(), args.clone()); |                 remote::SciterSession::new(cmd.clone(), id.clone(), pass.clone(), args.clone()); | ||||||
|             #[cfg(not(feature = "flutter"))] |             #[cfg(not(any(feature = "flutter", feature = "cli")))] | ||||||
|             crate::keyboard::set_cur_session(handler.inner()); |             { | ||||||
| 
 |                 *CUR_SESSION.lock().unwrap() = Some(handler.inner()); | ||||||
|  |             } | ||||||
|             Box::new(handler) |             Box::new(handler) | ||||||
|         }); |         }); | ||||||
|         page = "remote.html"; |         page = "remote.html"; | ||||||
|  | |||||||
| @ -577,6 +577,7 @@ pub fn is_installed_daemon(_prompt: bool) -> bool { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[inline] | #[inline] | ||||||
|  | #[cfg(feature = "flutter")] | ||||||
| pub fn is_can_input_monitoring(_prompt: bool) -> bool { | pub fn is_can_input_monitoring(_prompt: bool) -> bool { | ||||||
|     #[cfg(target_os = "macos")] |     #[cfg(target_os = "macos")] | ||||||
|     return crate::platform::macos::is_can_input_monitoring(_prompt); |     return crate::platform::macos::is_can_input_monitoring(_prompt); | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ use crate::client::{ | |||||||
|     input_os_password, load_config, send_mouse, start_video_audio_threads, FileManager, Key, |     input_os_password, load_config, send_mouse, start_video_audio_threads, FileManager, Key, | ||||||
|     LoginConfigHandler, QualityStatus, KEY_MAP, |     LoginConfigHandler, QualityStatus, KEY_MAP, | ||||||
| }; | }; | ||||||
| use crate::common::{self, is_keyboard_mode_supported, GrabState}; | use crate::common::{self, GrabState}; | ||||||
| use crate::keyboard; | use crate::keyboard; | ||||||
| use crate::{client::Data, client::Interface}; | use crate::{client::Data, client::Interface}; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| @ -780,10 +780,10 @@ impl<T: InvokeUiSession> Interface for Session<T> { | |||||||
| 
 | 
 | ||||||
| impl<T: InvokeUiSession> Session<T> { | impl<T: InvokeUiSession> Session<T> { | ||||||
|     pub fn lock_screen(&self) { |     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) { |     pub fn ctrl_alt_del(&self) { | ||||||
|         crate::keyboard::client::ctrl_alt_del(); |         self.send_key_event(&crate::keyboard::client::event_ctrl_alt_del()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user