diff --git a/src/flutter.rs b/src/flutter.rs index 2bb7a9faf..788a9f540 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -324,6 +324,8 @@ impl InvokeUiSession for FlutterHandler { ); } + fn on_connected(&self, _conn_type: ConnType) {} + fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool) { let has_retry = if retry { "true" } else { "" }; self.push_event( diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 0c90c3131..ddfaad06d 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -17,8 +17,6 @@ use hbb_common::{ use crate::flutter::{self, SESSIONS}; use crate::ui_interface::{self, *}; -#[cfg(not(any(target_os = "android", target_os = "ios")))] -use crate::keyboard::CUR_SESSION; use crate::{ client::file_trait::FileManager, flutter::{make_fd_to_json, session_add, session_start_}, @@ -293,7 +291,7 @@ 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 { - *CUR_SESSION.lock().unwrap() = Some(session.clone()); + crate::keyboard::set_cur_session(session.clone()); session.enter(); } else { session.leave(); diff --git a/src/keyboard.rs b/src/keyboard.rs index f0c14a1e9..eb39301f3 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -8,29 +8,31 @@ use crate::ui::remote::SciterHandler; use crate::ui_session_interface::Session; use hbb_common::{log, message_proto::*}; use rdev::{Event, EventType, Key}; -use std::collections::{HashMap, HashSet}; -use std::sync::atomic::AtomicBool; -#[cfg(any(target_os = "windows", target_os = "macos"))] -use std::sync::atomic::Ordering; -use std::sync::{mpsc, Arc, Mutex}; -use std::thread; -use std::time::SystemTime; +use std::{ + collections::{HashMap, HashSet}, + sync::{ + atomic::{AtomicBool, Ordering}, + mpsc, Arc, Mutex, + }, + thread, + time::SystemTime, +}; static mut IS_ALT_GR: bool = false; -pub static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false); +static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false); lazy_static::lazy_static! { - pub static ref GRAB_SENDER: Arc>>> = Default::default(); + static ref GRAB_SENDER: Arc>>> = Default::default(); } #[cfg(feature = "flutter")] lazy_static::lazy_static! { - pub static ref CUR_SESSION: Arc>>> = Default::default(); + static ref CUR_SESSION: Arc>>> = Default::default(); } #[cfg(not(feature = "flutter"))] lazy_static::lazy_static! { - pub static ref CUR_SESSION: Arc>>> = Default::default(); + static ref CUR_SESSION: Arc>>> = Default::default(); } lazy_static::lazy_static! { @@ -47,7 +49,10 @@ lazy_static::lazy_static! { m.insert(Key::MetaRight, false); Mutex::new(m) }; +} +pub fn set_cur_session(session: Session) { + *CUR_SESSION.lock().unwrap() = Some(session); } pub mod client { diff --git a/src/ui.rs b/src/ui.rs index e282d19c4..921c137ec 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -124,12 +124,15 @@ pub fn start(args: &mut [String]) { let args: Vec = iter.map(|x| x.clone()).collect(); frame.set_title(&id); frame.register_behavior("native-remote", move || { - Box::new(remote::SciterSession::new( + let handler = remote::SciterSession::new( cmd.clone(), id.clone(), pass.clone(), args.clone(), - )) + ); + let inner = handler.inner(); + crate::keyboard::set_cur_session(inner); + Box::new(handler) }); page = "remote.html"; } else { diff --git a/src/ui/remote.rs b/src/ui/remote.rs index 3d209a71c..29b1a9eee 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -231,6 +231,17 @@ impl InvokeUiSession for SciterHandler { self.call("updatePi", &make_args!(pi_sciter)); } + fn on_connected(&self, conn_type: ConnType) { + match conn_type { + ConnType::RDP => {}, + ConnType::PORT_FORWARD => {}, + ConnType::FILE_TRANSFER => {}, + ConnType::DEFAULT_CONN => { + crate::keyboard::client::start_grab_loop(); + }, + } + } + fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool) { self.call2( "msgbox_retry", @@ -434,6 +445,10 @@ impl SciterSession { Self(session) } + pub fn inner(&self) -> Session { + self.0.clone() + } + fn get_custom_image_quality(&mut self) -> Value { let mut v = Value::array(0); for x in self.lc.read().unwrap().custom_image_quality.iter() { diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 6bdf88b11..e594ac94b 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -5,6 +5,7 @@ use crate::client::{ QualityStatus, KEY_MAP, }; use crate::common::GrabState; +use crate::keyboard; use crate::{client::Data, client::Interface}; use async_trait::async_trait; use hbb_common::config::{Config, LocalConfig, PeerConfig}; @@ -12,12 +13,11 @@ use hbb_common::rendezvous_proto::ConnType; use hbb_common::tokio::{self, sync::mpsc}; use hbb_common::{allow_err, message_proto::*}; use hbb_common::{fs, get_version_number, log, Stream}; +use rdev::{Event, EventType::*}; use std::collections::HashMap; use std::ops::{Deref, DerefMut}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex, RwLock}; -use crate::keyboard; -use rdev::{Event, EventType::*}; pub static IS_IN: AtomicBool = AtomicBool::new(false); #[derive(Clone, Default)] @@ -580,6 +580,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default { fn set_display(&self, x: i32, y: i32, w: i32, h: i32, cursor_embeded: bool); fn switch_display(&self, display: &SwitchDisplay); fn set_peer_info(&self, peer_info: &PeerInfo); // flutter + fn on_connected(&self, conn_type: ConnType); fn update_privacy_mode(&self); fn set_permission(&self, name: &str, value: bool); fn close_success(&self); @@ -712,6 +713,7 @@ impl Interface for Session { "", ); } + self.on_connected(self.lc.read().unwrap().conn_type); #[cfg(windows)] { let mut path = std::env::temp_dir();