mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-20 17:13:00 +08:00
fix: unified keyboard check logic in common.rs
This commit is contained in:
parent
70dd3f323e
commit
6fdce63359
@ -1718,14 +1718,14 @@ impl LoginConfigHandler {
|
||||
crate::flutter::push_global_event(crate::flutter::APP_TYPE_MAIN, evt);
|
||||
}
|
||||
if config.keyboard_mode.is_empty() {
|
||||
if is_keyboard_mode_supported(&KeyboardMode::Map, get_version_number(&pi.version)) {
|
||||
if is_keyboard_mode_supported(&KeyboardMode::Map, get_version_number(&pi.version), &pi.platform) {
|
||||
config.keyboard_mode = KeyboardMode::Map.to_string();
|
||||
} else {
|
||||
config.keyboard_mode = KeyboardMode::Legacy.to_string();
|
||||
}
|
||||
} else {
|
||||
let keyboard_modes =
|
||||
crate::get_supported_keyboard_modes(get_version_number(&pi.version));
|
||||
crate::get_supported_keyboard_modes(get_version_number(&pi.version), &pi.platform);
|
||||
let current_mode = &KeyboardMode::from_str(&config.keyboard_mode).unwrap_or_default();
|
||||
if !keyboard_modes.contains(current_mode) {
|
||||
config.keyboard_mode = KeyboardMode::Legacy.to_string();
|
||||
|
@ -977,18 +977,24 @@ pub fn make_privacy_mode_msg(state: back_notification::PrivacyModeState) -> Mess
|
||||
make_privacy_mode_msg_with_details(state, "".to_owned())
|
||||
}
|
||||
|
||||
pub fn is_keyboard_mode_supported(keyboard_mode: &KeyboardMode, version_number: i64) -> bool {
|
||||
pub fn is_keyboard_mode_supported(keyboard_mode: &KeyboardMode, version_number: i64, peer_platform: &str) -> bool {
|
||||
match keyboard_mode {
|
||||
KeyboardMode::Legacy => true,
|
||||
KeyboardMode::Map => version_number >= hbb_common::get_version_number("1.2.0"),
|
||||
KeyboardMode::Map => {
|
||||
if peer_platform.to_lowercase() == crate::PLATFORM_ANDROID.to_lowercase() {
|
||||
false
|
||||
} else {
|
||||
version_number >= hbb_common::get_version_number("1.2.0")
|
||||
}
|
||||
}
|
||||
KeyboardMode::Translate => version_number >= hbb_common::get_version_number("1.2.0"),
|
||||
KeyboardMode::Auto => version_number >= hbb_common::get_version_number("1.2.0"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_supported_keyboard_modes(version: i64) -> Vec<KeyboardMode> {
|
||||
pub fn get_supported_keyboard_modes(version: i64, peer_platform: &str) -> Vec<KeyboardMode> {
|
||||
KeyboardMode::iter()
|
||||
.filter(|&mode| is_keyboard_mode_supported(mode, version))
|
||||
.filter(|&mode| is_keyboard_mode_supported(mode, version, peer_platform))
|
||||
.map(|&mode| mode)
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
@ -392,12 +392,10 @@ 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[..]) {
|
||||
if session.peer_platform() == "Android" && mode == KeyboardMode::Map {
|
||||
return SyncReturn(false);
|
||||
}
|
||||
SyncReturn(is_keyboard_mode_supported(
|
||||
&mode,
|
||||
session.get_peer_version(),
|
||||
&session.peer_platform()
|
||||
))
|
||||
} else {
|
||||
SyncReturn(false)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::input::{MOUSE_BUTTON_LEFT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP, MOUSE_TYPE_WHEEL};
|
||||
use crate::{input::{MOUSE_BUTTON_LEFT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP, MOUSE_TYPE_WHEEL}, common::{is_keyboard_mode_supported, get_supported_keyboard_modes}};
|
||||
use async_trait::async_trait;
|
||||
use bytes::Bytes;
|
||||
use rdev::{Event, EventType::*, KeyCode};
|
||||
@ -214,23 +214,36 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
self.lc.read().unwrap().version.clone()
|
||||
}
|
||||
|
||||
pub fn fallback_keyboard_mode(&self) -> String {
|
||||
let peer_version = self.get_peer_version();
|
||||
let platform = self.peer_platform();
|
||||
|
||||
let supported_modes = get_supported_keyboard_modes(peer_version, &platform);
|
||||
if let Some(mode) = supported_modes.first() {
|
||||
return mode.to_string();
|
||||
} else {
|
||||
if self.get_peer_version() >= get_version_number("1.2.0") {
|
||||
return KeyboardMode::Map.to_string();
|
||||
} else {
|
||||
return KeyboardMode::Legacy.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_keyboard_mode(&self) -> String {
|
||||
let mode = self.lc.read().unwrap().keyboard_mode.clone();
|
||||
if self.peer_platform() == crate::PLATFORM_ANDROID {
|
||||
if mode == "map" {
|
||||
return "translate".to_string();
|
||||
let keyboard_mode = KeyboardMode::from_str(&mode);
|
||||
|
||||
let peer_version = self.get_peer_version();
|
||||
let platform = self.peer_platform();
|
||||
|
||||
// Saved keyboard mode still exists in this version.
|
||||
if let Ok(mode) = keyboard_mode {
|
||||
if is_keyboard_mode_supported(&mode, peer_version, &platform) {
|
||||
return mode.to_string();
|
||||
}
|
||||
}
|
||||
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()
|
||||
}
|
||||
self.fallback_keyboard_mode()
|
||||
}
|
||||
|
||||
pub fn save_keyboard_mode(&self, value: String) {
|
||||
|
Loading…
Reference in New Issue
Block a user