fix: keyboard, sciter (#9216)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-08-31 19:02:50 +08:00 committed by GitHub
parent e3f6829d02
commit bf390611ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 14 deletions

View File

@ -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,
},
@ -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,
@ -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)
}

View File

@ -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);
@ -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;
}

View File

@ -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>;
}

View File

@ -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();

View File

@ -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);
}