Refact/options (#9318)

* refact options

Signed-off-by: fufesou <linlong1266@gmail.com>

* Remove unused msg

Signed-off-by: fufesou <linlong1266@gmail.com>

* web, toggle virtual display

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-09-10 23:54:59 +08:00 committed by GitHub
parent 519539ed0a
commit 9380f33d7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 14 additions and 49 deletions

View File

@ -1718,7 +1718,9 @@ class _KeyboardMenu extends StatelessWidget {
if (value == null) return;
await bind.sessionToggleOption(
sessionId: ffi.sessionId, value: kOptionToggleViewOnly);
ffiModel.setViewOnly(id, value);
final viewOnly = await bind.sessionGetToggleOption(
sessionId: ffi.sessionId, arg: kOptionToggleViewOnly);
ffiModel.setViewOnly(id, viewOnly ?? value);
}
: null,
ffi: ffi,

View File

@ -795,7 +795,7 @@ class FfiModel with ChangeNotifier {
isRefreshing = false;
}
Map<String, dynamic> features = json.decode(evt['features']);
_pi.features.privacyMode = features['privacy_mode'] == 1;
_pi.features.privacyMode = features['privacy_mode'] == true;
if (!isCache) {
handleResolutions(peerId, evt["resolutions"]);
}

View File

@ -196,8 +196,8 @@ class RustdeskImpl {
required bool on,
dynamic hint}) {
return Future(() => js.context.callMethod('setByName', [
'option:toggle',
jsonEncode({implKey, on})
'toggle_privacy_mode',
jsonEncode({'impl_key': implKey, 'on': on})
]));
}
@ -1204,8 +1204,10 @@ class RustdeskImpl {
required int index,
required bool on,
dynamic hint}) {
// TODO
throw UnimplementedError();
return Future(() => js.context.callMethod('setByName', [
'toggle_virtual_display',
jsonEncode({'index': index, 'on': on})
]));
}
Future<void> mainSetHomeDir({required String home, dynamic hint}) {

View File

@ -316,7 +316,7 @@ impl ToString for CodecFormat {
CodecFormat::AV1 => "AV1".into(),
CodecFormat::H264 => "H264".into(),
CodecFormat::H265 => "H265".into(),
CodecFormat::Unknown => "Unknow".into(),
CodecFormat::Unknown => "Unknown".into(),
}
}
}

View File

@ -1800,28 +1800,6 @@ impl LoginConfigHandler {
)
}
pub fn get_option_message_after_login(&self) -> Option<OptionMessage> {
if self.conn_type.eq(&ConnType::FILE_TRANSFER)
|| self.conn_type.eq(&ConnType::PORT_FORWARD)
|| self.conn_type.eq(&ConnType::RDP)
{
return None;
}
let mut n = 0;
let mut msg = OptionMessage::new();
if self.version < hbb_common::get_version_number("1.2.4") {
if self.get_toggle_option("privacy-mode") {
msg.privacy_mode = BoolOption::Yes.into();
n += 1;
}
}
if n > 0 {
Some(msg)
} else {
None
}
}
/// Parse the image quality option.
/// Return [`ImageQuality`] if the option is valid, otherwise return `None`.
///

View File

@ -958,22 +958,6 @@ impl<T: InvokeUiSession> Remote<T> {
true
}
async fn send_opts_after_login(&self, peer: &mut Stream) {
if let Some(opts) = self
.handler
.lc
.read()
.unwrap()
.get_option_message_after_login()
{
let mut misc = Misc::new();
misc.set_option(opts);
let mut msg_out = Message::new();
msg_out.set_misc(misc);
allow_err!(peer.send(&msg_out).await);
}
}
async fn send_toggle_virtual_display_msg(&self, peer: &mut Stream) {
if !self.peer_info.is_support_virtual_display() {
return;
@ -1135,7 +1119,6 @@ impl<T: InvokeUiSession> Remote<T> {
self.first_frame = true;
self.handler.close_success();
self.handler.adapt_size();
self.send_opts_after_login(peer).await;
self.send_toggle_virtual_display_msg(peer).await;
self.send_toggle_privacy_mode_msg(peer).await;
}

View File

@ -802,13 +802,13 @@ impl InvokeUiSession for FlutterHandler {
fn set_peer_info(&self, pi: &PeerInfo) {
let displays = Self::make_displays_msg(&pi.displays);
let mut features: HashMap<&str, i32> = Default::default();
let mut features: HashMap<&str, bool> = Default::default();
for ref f in pi.features.iter() {
features.insert("privacy_mode", if f.privacy_mode { 1 } else { 0 });
features.insert("privacy_mode", f.privacy_mode);
}
// compatible with 1.1.9
if get_version_number(&pi.version) < get_version_number("1.2.0") {
features.insert("privacy_mode", 0);
features.insert("privacy_mode", false);
}
let features = serde_json::ser::to_string(&features).unwrap_or("".to_owned());
let resolutions = serialize_resolutions(&pi.resolutions.resolutions);