From bf390611ab1c44c3492d329ae949ebed15ce3b60 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Sat, 31 Aug 2024 19:02:50 +0800 Subject: [PATCH] fix: keyboard, sciter (#9216) Signed-off-by: fufesou --- src/flutter_ffi.rs | 14 ++------------ src/keyboard.rs | 2 ++ src/ui/header.tis | 7 +++++-- src/ui/remote.rs | 1 + src/ui_session_interface.rs | 12 ++++++++++++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 48efda3af..8cc475316 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -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 SyncReturn { 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) } diff --git a/src/keyboard.rs b/src/keyboard.rs index 6b4b0988f..e9bff5d81 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -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; } diff --git a/src/ui/header.tis b/src/ui/header.tis index c4e765280..e99d398aa 100644 --- a/src/ui/header.tis +++ b/src/ui/header.tis @@ -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 -
  • {svg_checkmark}{translate('Legacy mode')}
  • -
  • {svg_checkmark}{translate('Map mode')}
  • +
  • {svg_checkmark}{translate('Legacy mode')}
  • + { is_map_mode_supported &&
  • {svg_checkmark}{translate('Map mode')}
  • } + { is_translate_mode_supported &&
  • {svg_checkmark}{translate('Translate mode')}
  • }
    ; } diff --git a/src/ui/remote.rs b/src/ui/remote.rs index 0ad84e8ed..baf9d1f64 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -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(); diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 6686e5419..ce28b78d8 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -252,6 +252,18 @@ impl Session { 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); }