refactor set_peer_info
This commit is contained in:
parent
41a53e4983
commit
2891c1b148
@ -325,6 +325,7 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
if (evt['is_file_transfer'] == "true") {
|
||||
// TODO is file transfer
|
||||
parent.target?.fileModel.onReady();
|
||||
} else {
|
||||
_pi.displays = [];
|
||||
|
@ -1278,13 +1278,13 @@ impl LoginConfigHandler {
|
||||
///
|
||||
/// * `username` - The name of the peer.
|
||||
/// * `pi` - The peer info.
|
||||
pub fn handle_peer_info(&mut self, username: String, pi: PeerInfo) {
|
||||
pub fn handle_peer_info(&mut self, pi: PeerInfo) {
|
||||
if !pi.version.is_empty() {
|
||||
self.version = hbb_common::get_version_number(&pi.version);
|
||||
}
|
||||
self.features = pi.features.into_option();
|
||||
let serde = PeerInfoSerde {
|
||||
username,
|
||||
username: pi.username.clone(),
|
||||
hostname: pi.hostname.clone(),
|
||||
platform: pi.platform.clone(),
|
||||
};
|
||||
|
@ -1,24 +1,13 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{
|
||||
Arc, RwLock,
|
||||
},
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer};
|
||||
|
||||
use hbb_common::{
|
||||
bail,
|
||||
config::{LocalConfig},
|
||||
message_proto::*,
|
||||
ResultType,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ui_session_interface::{io_loop, InvokeUi, Session},
|
||||
};
|
||||
|
||||
use hbb_common::{bail, config::LocalConfig, message_proto::*, ResultType};
|
||||
|
||||
use crate::ui_session_interface::{io_loop, InvokeUi, Session};
|
||||
|
||||
use crate::{client::*, flutter_ffi::EventToUI};
|
||||
|
||||
@ -97,10 +86,6 @@ impl InvokeUi for FlutterHandler {
|
||||
self.push_event("permission", vec![(name, &value.to_string())]);
|
||||
}
|
||||
|
||||
fn update_pi(&self, pi: PeerInfo) {
|
||||
// todo!()
|
||||
}
|
||||
|
||||
fn close_success(&self) {
|
||||
// todo!()
|
||||
}
|
||||
@ -204,29 +189,27 @@ impl InvokeUi for FlutterHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_peer_info(
|
||||
&self,
|
||||
username: &str,
|
||||
hostname: &str,
|
||||
platform: &str,
|
||||
sas_enabled: bool,
|
||||
displays: &Vec<HashMap<&str, i32>>,
|
||||
version: &str,
|
||||
current_display: usize,
|
||||
is_file_transfer: bool,
|
||||
) {
|
||||
let displays = serde_json::ser::to_string(displays).unwrap_or("".to_owned());
|
||||
fn set_peer_info(&self, pi: &PeerInfo) {
|
||||
let mut displays = Vec::new();
|
||||
for ref d in pi.displays.iter() {
|
||||
let mut h: HashMap<&str, i32> = Default::default();
|
||||
h.insert("x", d.x);
|
||||
h.insert("y", d.y);
|
||||
h.insert("width", d.width);
|
||||
h.insert("height", d.height);
|
||||
displays.push(h);
|
||||
}
|
||||
let displays = serde_json::ser::to_string(&displays).unwrap_or("".to_owned());
|
||||
self.push_event(
|
||||
"peer_info",
|
||||
vec![
|
||||
("username", username),
|
||||
("hostname", hostname),
|
||||
("platform", platform),
|
||||
("sas_enabled", &sas_enabled.to_string()),
|
||||
("username", &pi.username),
|
||||
("hostname", &pi.hostname),
|
||||
("platform", &pi.platform),
|
||||
("sas_enabled", &pi.sas_enabled.to_string()),
|
||||
("displays", &displays),
|
||||
("version", &version),
|
||||
("current_display", ¤t_display.to_string()),
|
||||
("is_file_transfer", &is_file_transfer.to_string()),
|
||||
("version", &pi.version),
|
||||
("current_display", &pi.current_display.to_string()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ impl InvokeUi for SciterHandler {
|
||||
|
||||
fn set_display(&self, x: i32, y: i32, w: i32, h: i32) {
|
||||
self.call("setDisplay", &make_args!(x, y, w, h));
|
||||
// https://sciter.com/forums/topic/color_spaceiyuv-crash
|
||||
// Nothing spectacular in decoder – done on CPU side.
|
||||
// So if you can do BGRA translation on your side – the better.
|
||||
// BGRA is used as internal image format so it will not require additional transformations.
|
||||
VIDEO.lock().unwrap().as_mut().map(|v| {
|
||||
v.stop_streaming().ok();
|
||||
let ok = v.start_streaming((w, h), COLOR_SPACE::Rgb32, None);
|
||||
@ -111,8 +115,6 @@ impl InvokeUi for SciterHandler {
|
||||
self.call2("setPermission", &make_args!(name, value));
|
||||
}
|
||||
|
||||
fn update_pi(&self, pi: PeerInfo) {} // TODO dup flutter
|
||||
|
||||
fn close_success(&self) {
|
||||
self.call2("closeSuccess", &make_args!());
|
||||
}
|
||||
@ -202,17 +204,25 @@ impl InvokeUi for SciterHandler {
|
||||
.map(|v| v.render_frame(data).ok());
|
||||
}
|
||||
|
||||
fn set_peer_info(
|
||||
&self,
|
||||
username: &str,
|
||||
hostname: &str,
|
||||
platform: &str,
|
||||
sas_enabled: bool,
|
||||
displays: &Vec<HashMap<&str, i32>>,
|
||||
version: &str,
|
||||
current_display: usize,
|
||||
is_file_transfer: bool,
|
||||
) {
|
||||
fn set_peer_info(&self, pi: &PeerInfo) {
|
||||
let mut pi_sciter = Value::map();
|
||||
pi_sciter.set_item("username", pi.username.clone());
|
||||
pi_sciter.set_item("hostname", pi.hostname.clone());
|
||||
pi_sciter.set_item("platform", pi.platform.clone());
|
||||
pi_sciter.set_item("sas_enabled", pi.sas_enabled);
|
||||
|
||||
let mut displays = Value::array(0);
|
||||
for ref d in pi.displays.iter() {
|
||||
let mut display = Value::map();
|
||||
display.set_item("x", d.x);
|
||||
display.set_item("y", d.y);
|
||||
display.set_item("width", d.width);
|
||||
display.set_item("height", d.height);
|
||||
displays.push(display);
|
||||
}
|
||||
pi_sciter.set_item("displays", displays);
|
||||
pi_sciter.set_item("current_display", pi.current_display);
|
||||
self.call("updatePi", &make_args!(pi_sciter));
|
||||
}
|
||||
|
||||
fn msgbox(&self, msgtype: &str, title: &str, text: &str, retry: bool) {
|
||||
|
@ -532,20 +532,9 @@ pub trait InvokeUi: Send + Sync + Clone + 'static + Sized + Default {
|
||||
fn set_cursor_position(&self, cp: CursorPosition);
|
||||
fn set_display(&self, x: i32, y: i32, w: i32, h: i32);
|
||||
fn switch_display(&self, display: &SwitchDisplay);
|
||||
fn set_peer_info(
|
||||
&self,
|
||||
username: &str,
|
||||
hostname: &str,
|
||||
platform: &str,
|
||||
sas_enabled: bool,
|
||||
displays: &Vec<HashMap<&str, i32>>,
|
||||
version: &str,
|
||||
current_display: usize,
|
||||
is_file_transfer: bool,
|
||||
); // flutter
|
||||
fn set_peer_info(&self, peer_info: &PeerInfo); // flutter
|
||||
fn update_privacy_mode(&self);
|
||||
fn set_permission(&self, name: &str, value: bool);
|
||||
fn update_pi(&self, pi: PeerInfo);
|
||||
fn close_success(&self);
|
||||
fn update_quality_status(&self, qs: QualityStatus);
|
||||
fn set_connection_type(&self, is_secured: bool, direct: bool);
|
||||
@ -623,20 +612,11 @@ impl<T: InvokeUi> Interface for Session<T> {
|
||||
self.lc.write().unwrap().handle_login_error(err, self)
|
||||
}
|
||||
|
||||
fn handle_peer_info(&mut self, pi: PeerInfo) {
|
||||
let mut lc = self.lc.write().unwrap();
|
||||
|
||||
// let mut pi_sciter = Value::map();
|
||||
let username = lc.get_username(&pi);
|
||||
|
||||
// flutter
|
||||
let mut displays = Vec::new();
|
||||
let mut current_index = pi.current_display as usize;
|
||||
|
||||
// pi_sciter.set_item("username", username.clone());
|
||||
// pi_sciter.set_item("hostname", pi.hostname.clone());
|
||||
// pi_sciter.set_item("platform", pi.platform.clone());
|
||||
// pi_sciter.set_item("sas_enabled", pi.sas_enabled);
|
||||
fn handle_peer_info(&mut self, mut pi: PeerInfo) {
|
||||
pi.username = self.lc.read().unwrap().get_username(&pi);
|
||||
if pi.current_display as usize >= pi.displays.len() {
|
||||
pi.current_display = 0;
|
||||
}
|
||||
if get_version_number(&pi.version) < get_version_number("1.1.10") {
|
||||
self.set_permission("restart", false);
|
||||
}
|
||||
@ -647,73 +627,22 @@ impl<T: InvokeUi> Interface for Session<T> {
|
||||
}
|
||||
} else if !self.is_port_forward() {
|
||||
if pi.displays.is_empty() {
|
||||
lc.handle_peer_info(username, pi);
|
||||
self.lc.write().unwrap().handle_peer_info(pi);
|
||||
self.update_privacy_mode();
|
||||
self.msgbox("error", "Remote Error", "No Display");
|
||||
return;
|
||||
}
|
||||
// let mut displays = Value::array(0);
|
||||
// for ref d in pi.displays.iter() {
|
||||
// let mut display = Value::map();
|
||||
// display.set_item("x", d.x);
|
||||
// display.set_item("y", d.y);
|
||||
// display.set_item("width", d.width);
|
||||
// display.set_item("height", d.height);
|
||||
// displays.push(display);
|
||||
// }
|
||||
// pi_sciter.set_item("displays", displays);
|
||||
|
||||
// flutter
|
||||
for ref d in pi.displays.iter() {
|
||||
let mut h: HashMap<&str, i32> = Default::default();
|
||||
h.insert("x", d.x);
|
||||
h.insert("y", d.y);
|
||||
h.insert("width", d.width);
|
||||
h.insert("height", d.height);
|
||||
displays.push(h);
|
||||
}
|
||||
if current_index >= pi.displays.len() {
|
||||
current_index = 0;
|
||||
}
|
||||
|
||||
if current_index >= pi.displays.len() {
|
||||
current_index = 0;
|
||||
}
|
||||
// pi_sciter.set_item("current_display", current as i32);
|
||||
let current = &pi.displays[current_index];
|
||||
self.set_display(current.x, current.y, current.width, current.height);
|
||||
|
||||
self.set_peer_info(
|
||||
&username,
|
||||
&pi.hostname,
|
||||
&pi.platform,
|
||||
pi.sas_enabled,
|
||||
&displays,
|
||||
&pi.version,
|
||||
current_index,
|
||||
lc.is_file_transfer,
|
||||
);
|
||||
|
||||
// https://sciter.com/forums/topic/color_spaceiyuv-crash
|
||||
// Nothing spectacular in decoder – done on CPU side.
|
||||
// So if you can do BGRA translation on your side – the better.
|
||||
// BGRA is used as internal image format so it will not require additional transformations.
|
||||
// VIDEO.lock().unwrap().as_mut().map(|v| {
|
||||
// let ok = v.start_streaming(
|
||||
// (current.width as _, current.height as _),
|
||||
// COLOR_SPACE::Rgb32,
|
||||
// None,
|
||||
// );
|
||||
// log::info!("[video] initialized: {:?}", ok);
|
||||
// });
|
||||
let p = lc.should_auto_login();
|
||||
let p = self.lc.read().unwrap().should_auto_login();
|
||||
if !p.is_empty() {
|
||||
input_os_password(p, true, self.clone());
|
||||
}
|
||||
let current = &pi.displays[pi.current_display as usize];
|
||||
self.set_display(current.x, current.y, current.width, current.height);
|
||||
}
|
||||
lc.handle_peer_info(username, pi);
|
||||
self.update_privacy_mode();
|
||||
// self.update_pi(pi);
|
||||
self.set_peer_info(&pi);
|
||||
self.lc.write().unwrap().handle_peer_info(pi);
|
||||
|
||||
if self.is_file_transfer() {
|
||||
self.close_success();
|
||||
} else if !self.is_port_forward() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user