Skip to content

Commit

Permalink
fix: keyboard, sciter (rustdesk#9216)
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <[email protected]>
  • Loading branch information
fufesou authored Aug 31, 2024
1 parent e3f6829 commit bf39061
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
14 changes: 2 additions & 12 deletions src/flutter_ffi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
client::file_trait::FileManager,
common::{is_keyboard_mode_supported, make_fd_to_json},
common::make_fd_to_json,
flutter::{
self, session_add, session_add_existed, session_start_, sessions, try_sync_peer_option,
},
Expand All @@ -19,13 +19,11 @@ use hbb_common::allow_err;
use hbb_common::{
config::{self, LocalConfig, PeerConfig, PeerInfoSerde},
fs, lazy_static, log,
message_proto::KeyboardMode,
rendezvous_proto::ConnType,
ResultType,
};
use std::{
collections::HashMap,
str::FromStr,
sync::{
atomic::{AtomicI32, Ordering},
Arc,
Expand Down Expand Up @@ -447,15 +445,7 @@ pub fn session_get_custom_image_quality(session_id: SessionID) -> Option<Vec<i32

pub fn session_is_keyboard_mode_supported(session_id: SessionID, mode: String) -> SyncReturn<bool> {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
if let Ok(mode) = KeyboardMode::from_str(&mode[..]) {
SyncReturn(is_keyboard_mode_supported(
&mode,
session.get_peer_version(),
&session.peer_platform(),
))
} else {
SyncReturn(false)
}
SyncReturn(session.is_keyboard_mode_supported(mode))
} else {
SyncReturn(false)
}
Expand Down
2 changes: 2 additions & 0 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const OS_LOWER_ANDROID: &str = "android";
#[cfg(any(target_os = "windows", target_os = "macos"))]
static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false);

#[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
static IS_RDEV_ENABLED: AtomicBool = AtomicBool::new(false);

Expand Down Expand Up @@ -71,6 +72,7 @@ pub mod client {

#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn change_grab_status(state: GrabState, keyboard_mode: &str) {
#[cfg(feature = "flutter")]
if !IS_RDEV_ENABLED.load(Ordering::SeqCst) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/ui/header.tis
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ class Header: Reactor.Component {
}

function renderKeyboardPop(){
const is_map_mode_supported = handler.is_keyboard_mode_supported("map");
const is_translate_mode_supported = handler.is_keyboard_mode_supported("translate");
return <popup>
<menu.context #keyboard-options>
<li #legacy><span>{svg_checkmark}</span>{translate('Legacy mode')}</li>
<li #map><span>{svg_checkmark}</span>{translate('Map mode')}</li>
<li #legacy><span>{svg_checkmark}</span>{translate('Legacy mode')}</li>
{ is_map_mode_supported && <li #map><span>{svg_checkmark}</span>{translate('Map mode')}</li> }
{ is_translate_mode_supported && <li #translate><span>{svg_checkmark}</span>{translate('Translate mode')}</li> }
</menu>
</popup>;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ impl sciter::EventHandler for SciterSession {
fn peer_platform();
fn set_write_override(i32, i32, bool, bool, bool);
fn get_keyboard_mode();
fn is_keyboard_mode_supported(String);
fn save_keyboard_mode(String);
fn alternative_codecs();
fn change_prefer_codec();
Expand Down
12 changes: 12 additions & 0 deletions src/ui_session_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ impl<T: InvokeUiSession> Session<T> {
self.fallback_keyboard_mode()
}

pub fn is_keyboard_mode_supported(&self, mode: String) -> bool {
if let Ok(mode) = KeyboardMode::from_str(&mode[..]) {
crate::common::is_keyboard_mode_supported(
&mode,
self.get_peer_version(),
&self.peer_platform(),
)
} else {
false
}
}

pub fn save_keyboard_mode(&self, value: String) {
self.lc.write().unwrap().save_keyboard_mode(value);
}
Expand Down

0 comments on commit bf39061

Please sign in to comment.