fix, RwLock, remove nested read calls

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-09-17 13:01:27 +08:00
parent a1e1f5aab6
commit ae3efa1151
4 changed files with 69 additions and 87 deletions

View File

@@ -168,7 +168,17 @@ impl<T: InvokeUiSession> Session<T> {
}
pub fn get_keyboard_mode(&self) -> String {
self.lc.read().unwrap().keyboard_mode.clone()
let mode = self.lc.read().unwrap().keyboard_mode.clone();
if ["map", "translate", "legacy"].contains(&(&mode as &str)) {
mode
} else {
if self.get_peer_version() > hbb_common::get_version_number("1.2.0") {
"map"
} else {
"legacy"
}
.to_string()
}
}
pub fn save_keyboard_mode(&mut self, value: String) {
@@ -562,28 +572,15 @@ impl<T: InvokeUiSession> Session<T> {
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn enter(&self) {
#[cfg(target_os = "windows")]
{
match &self.lc.read().unwrap().keyboard_mode as _ {
"legacy" => rdev::set_get_key_unicode(true),
"translate" => rdev::set_get_key_unicode(true),
_ => {}
}
}
pub fn enter(&self, keyboard_mode: &str) {
IS_IN.store(true, Ordering::SeqCst);
keyboard::client::change_grab_status(GrabState::Run);
keyboard::client::change_grab_status(GrabState::Run, keyboard_mode);
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn leave(&self) {
#[cfg(target_os = "windows")]
{
rdev::set_get_key_unicode(false);
}
pub fn leave(&self, keyboard_mode: &str) {
IS_IN.store(false, Ordering::SeqCst);
keyboard::client::change_grab_status(GrabState::Wait);
keyboard::client::change_grab_status(GrabState::Wait, keyboard_mode);
}
// flutter only TODO new input
@@ -631,6 +628,7 @@ impl<T: InvokeUiSession> Session<T> {
#[cfg(not(any(target_os = "ios")))]
pub fn handle_flutter_key_event(
&self,
keyboard_mode: &str,
_name: &str,
platform_code: i32,
position_code: i32,
@@ -663,7 +661,7 @@ impl<T: InvokeUiSession> Session<T> {
#[cfg(any(target_os = "windows", target_os = "macos"))]
extra_data: 0,
};
keyboard::client::process_event(&event, Some(lock_modes));
keyboard::client::process_event(keyboard_mode, &event, Some(lock_modes));
}
// flutter only TODO new input