opt: map mode hide when unsupported

This commit is contained in:
asur4s 2022-12-26 02:30:25 -08:00
parent 85620b73a7
commit a3769ca8e9
2 changed files with 37 additions and 4 deletions

View File

@ -1185,10 +1185,25 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
final keyboardMenu = [
MenuEntryRadios<String>(
text: translate('Ratio'),
optionsGetter: () => [
MenuEntryRadioOption(text: translate('Legacy mode'), value: 'legacy'),
MenuEntryRadioOption(text: translate('Map mode'), value: 'map'),
],
optionsGetter: () {
List<MenuEntryRadioOption> list = [];
List<String> modes = ["legacy"];
if (bind.sessionIsKeyboardModeSupported(id: widget.id, mode: "map")) {
modes.add("map");
}
for (String mode in modes) {
if (mode == "legacy") {
list.add(MenuEntryRadioOption(
text: translate('Legacy mode'), value: 'legacy'));
} else if (mode == "map") {
list.add(MenuEntryRadioOption(
text: translate('Map mode'), value: 'map'));
}
}
return list;
},
curOptionGetter: () async {
return await bind.sessionGetKeyboardMode(id: widget.id) ?? "legacy";
},

View File

@ -7,11 +7,14 @@ use std::{
use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer};
use serde_json::json;
use crate::common::is_keyboard_mode_supported;
use hbb_common::message_proto::KeyboardMode;
use hbb_common::ResultType;
use hbb_common::{
config::{self, LocalConfig, PeerConfig, ONLINE},
fs, log,
};
use std::str::FromStr;
// use crate::hbbs_http::account::AuthResult;
@ -245,6 +248,21 @@ pub fn session_get_custom_image_quality(id: String) -> Option<Vec<i32>> {
}
}
pub fn session_is_keyboard_mode_supported(id: String, mode: String) -> SyncReturn<bool> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
if let Ok(mode) = KeyboardMode::from_str(&mode[..]) {
SyncReturn(is_keyboard_mode_supported(
&mode,
session.get_peer_version(),
))
} else {
SyncReturn(false)
}
} else {
SyncReturn(false)
}
}
pub fn session_set_custom_image_quality(id: String, value: i32) {
if let Some(session) = SESSIONS.write().unwrap().get_mut(&id) {
session.save_custom_image_quality(value);