mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
fix sync displays info && select monitor menu
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -1253,6 +1253,14 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(message::Union::PeerInfo(pi)) => {
|
||||
match pi.conn_id {
|
||||
crate::SYNC_PEER_INFO_DISPLAYS => {
|
||||
self.handler.set_displays(&pi.displays);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ pub type NotifyMessageBox = fn(String, String, String, String) -> dyn Future<Out
|
||||
pub const CLIPBOARD_NAME: &'static str = "clipboard";
|
||||
pub const CLIPBOARD_INTERVAL: u64 = 333;
|
||||
|
||||
pub const SYNC_PEER_INFO_DISPLAYS: i32 = 1;
|
||||
|
||||
// the executable name of the portable version
|
||||
pub const PORTABLE_APPNAME_RUNTIME_ENV_KEY: &str = "RUSTDESK_APPNAME";
|
||||
|
||||
|
||||
@@ -142,6 +142,20 @@ impl FlutterHandler {
|
||||
}
|
||||
*stream_lock = None;
|
||||
}
|
||||
|
||||
fn make_displays_msg(displays: &Vec<DisplayInfo>) -> String {
|
||||
let mut msg_vec = Vec::new();
|
||||
for ref d in 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);
|
||||
h.insert("cursor_embedded", if d.cursor_embedded { 1 } else { 0 });
|
||||
msg_vec.push(h);
|
||||
}
|
||||
serde_json::ser::to_string(&msg_vec).unwrap_or("".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl InvokeUiSession for FlutterHandler {
|
||||
@@ -316,17 +330,7 @@ impl InvokeUiSession for FlutterHandler {
|
||||
}
|
||||
|
||||
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);
|
||||
h.insert("cursor_embedded", if d.cursor_embedded { 1 } else { 0 });
|
||||
displays.push(h);
|
||||
}
|
||||
let displays = serde_json::ser::to_string(&displays).unwrap_or("".to_owned());
|
||||
let displays = Self::make_displays_msg(&pi.displays);
|
||||
let mut features: HashMap<&str, i32> = Default::default();
|
||||
for ref f in pi.features.iter() {
|
||||
features.insert("privacy_mode", if f.privacy_mode { 1 } else { 0 });
|
||||
@@ -351,6 +355,13 @@ impl InvokeUiSession for FlutterHandler {
|
||||
);
|
||||
}
|
||||
|
||||
fn set_displays(&self, displays: &Vec<DisplayInfo>) {
|
||||
self.push_event(
|
||||
"sync_peer_info",
|
||||
vec![("displays", &Self::make_displays_msg(displays))],
|
||||
);
|
||||
}
|
||||
|
||||
fn on_connected(&self, _conn_type: ConnType) {}
|
||||
|
||||
fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool) {
|
||||
|
||||
@@ -6,7 +6,10 @@ use crate::common::update_clipboard;
|
||||
#[cfg(windows)]
|
||||
use crate::portable_service::client as portable_client;
|
||||
use crate::{
|
||||
client::{start_audio_thread, LatencyController, MediaData, MediaSender, new_voice_call_request, new_voice_call_response},
|
||||
client::{
|
||||
new_voice_call_request, new_voice_call_response, start_audio_thread, LatencyController,
|
||||
MediaData, MediaSender,
|
||||
},
|
||||
common::{get_default_sound_input, set_sound_input},
|
||||
video_service,
|
||||
};
|
||||
@@ -672,15 +675,15 @@ impl Connection {
|
||||
.collect();
|
||||
if !whitelist.is_empty()
|
||||
&& whitelist
|
||||
.iter()
|
||||
.filter(|x| x == &"0.0.0.0")
|
||||
.next()
|
||||
.is_none()
|
||||
.iter()
|
||||
.filter(|x| x == &"0.0.0.0")
|
||||
.next()
|
||||
.is_none()
|
||||
&& whitelist
|
||||
.iter()
|
||||
.filter(|x| IpCidr::from_str(x).map_or(false, |y| y.contains(addr.ip())))
|
||||
.next()
|
||||
.is_none()
|
||||
.iter()
|
||||
.filter(|x| IpCidr::from_str(x).map_or(false, |y| y.contains(addr.ip())))
|
||||
.next()
|
||||
.is_none()
|
||||
{
|
||||
self.send_login_error("Your ip is blocked by the peer")
|
||||
.await;
|
||||
@@ -806,7 +809,7 @@ impl Connection {
|
||||
};
|
||||
self.post_conn_audit(json!({"peer": self.peer_info, "type": conn_type}));
|
||||
#[allow(unused_mut)]
|
||||
let mut username = crate::platform::get_active_username();
|
||||
let mut username = crate::platform::get_active_username();
|
||||
let mut res = LoginResponse::new();
|
||||
let mut pi = PeerInfo {
|
||||
username: username.clone(),
|
||||
@@ -833,7 +836,7 @@ impl Connection {
|
||||
h265,
|
||||
..Default::default()
|
||||
})
|
||||
.into();
|
||||
.into();
|
||||
}
|
||||
|
||||
if self.port_forward_socket.is_some() {
|
||||
@@ -877,7 +880,7 @@ impl Connection {
|
||||
privacy_mode: video_service::is_privacy_mode_supported(),
|
||||
..Default::default()
|
||||
})
|
||||
.into();
|
||||
.into();
|
||||
|
||||
let mut sub_service = false;
|
||||
if self.file_transfer.is_some() {
|
||||
@@ -893,10 +896,11 @@ impl Connection {
|
||||
res.set_error(format!("{}", err));
|
||||
}
|
||||
Ok((current, displays)) => {
|
||||
pi.displays = displays.into();
|
||||
pi.displays = displays.clone();
|
||||
pi.current_display = current as _;
|
||||
res.set_peer_info(pi);
|
||||
sub_service = true;
|
||||
*super::video_service::LAST_SYNC_DISPLAYS.write().unwrap() = displays;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1160,7 +1164,7 @@ impl Connection {
|
||||
"Failed to access remote {}, please make sure if it is open",
|
||||
addr
|
||||
))
|
||||
.await;
|
||||
.await;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1324,12 +1328,12 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
Some(message::Union::Clipboard(cb)) =>
|
||||
{
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.clipboard {
|
||||
update_clipboard(cb, None);
|
||||
}
|
||||
{
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.clipboard {
|
||||
update_clipboard(cb, None);
|
||||
}
|
||||
}
|
||||
Some(message::Union::Cliprdr(_clip)) => {
|
||||
if self.file_transfer_enabled() {
|
||||
#[cfg(windows)]
|
||||
@@ -1512,15 +1516,15 @@ impl Connection {
|
||||
}
|
||||
|
||||
Some(misc::Union::RestartRemoteDevice(_)) =>
|
||||
{
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.restart {
|
||||
match system_shutdown::reboot() {
|
||||
Ok(_) => log::info!("Restart by the peer"),
|
||||
Err(e) => log::error!("Failed to restart:{}", e),
|
||||
}
|
||||
{
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.restart {
|
||||
match system_shutdown::reboot() {
|
||||
Ok(_) => log::info!("Restart by the peer"),
|
||||
Err(e) => log::error!("Failed to restart:{}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(misc::Union::ElevationRequest(r)) => match r.union {
|
||||
Some(elevation_request::Union::Direct(_)) => {
|
||||
#[cfg(windows)]
|
||||
@@ -1530,8 +1534,8 @@ impl Connection {
|
||||
err = portable_client::start_portable_service(
|
||||
portable_client::StartPara::Direct,
|
||||
)
|
||||
.err()
|
||||
.map_or("".to_string(), |e| e.to_string());
|
||||
.err()
|
||||
.map_or("".to_string(), |e| e.to_string());
|
||||
}
|
||||
self.portable.elevation_requested = err.is_empty();
|
||||
let mut misc = Misc::new();
|
||||
@@ -1549,8 +1553,8 @@ impl Connection {
|
||||
err = portable_client::start_portable_service(
|
||||
portable_client::StartPara::Logon(_r.username, _r.password),
|
||||
)
|
||||
.err()
|
||||
.map_or("".to_string(), |e| e.to_string());
|
||||
.err()
|
||||
.map_or("".to_string(), |e| e.to_string());
|
||||
}
|
||||
self.portable.elevation_requested = err.is_empty();
|
||||
let mut misc = Misc::new();
|
||||
@@ -1571,7 +1575,11 @@ impl Connection {
|
||||
// No video frame will be sent here, so we need to disable latency controller, or audio check may fail.
|
||||
latency_controller.lock().unwrap().set_audio_only(true);
|
||||
self.audio_sender = Some(start_audio_thread(Some(latency_controller)));
|
||||
allow_err!(self.audio_sender.as_ref().unwrap().send(MediaData::AudioFormat(format)));
|
||||
allow_err!(self
|
||||
.audio_sender
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.send(MediaData::AudioFormat(format)));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "flutter")]
|
||||
@@ -1583,7 +1591,7 @@ impl Connection {
|
||||
"--switch_uuid",
|
||||
uuid.to_string().as_ref(),
|
||||
])
|
||||
.ok();
|
||||
.ok();
|
||||
self.send_close_reason_no_retry("Closed as expected").await;
|
||||
self.on_close("switch sides", false).await;
|
||||
return false;
|
||||
@@ -1596,7 +1604,9 @@ impl Connection {
|
||||
if let Some(sender) = &self.audio_sender {
|
||||
allow_err!(sender.send(MediaData::AudioFrame(frame)));
|
||||
} else {
|
||||
log::warn!("Processing audio frame without the voice call audio sender.");
|
||||
log::warn!(
|
||||
"Processing audio frame without the voice call audio sender."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1646,7 +1656,9 @@ impl Connection {
|
||||
|
||||
pub async fn close_voice_call(&mut self) {
|
||||
// Restore to the prior audio device.
|
||||
if let Some(sound_input) = std::mem::replace(&mut self.audio_input_device_before_voice_call, None) {
|
||||
if let Some(sound_input) =
|
||||
std::mem::replace(&mut self.audio_input_device_before_voice_call, None)
|
||||
{
|
||||
set_sound_input(sound_input);
|
||||
}
|
||||
// Notify the connection manager that the voice call has been closed.
|
||||
@@ -1821,13 +1833,13 @@ impl Connection {
|
||||
lock_screen().await;
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
let data = if self.chat_unanswered {
|
||||
let data = if self.chat_unanswered {
|
||||
ipc::Data::Disconnected
|
||||
} else {
|
||||
ipc::Data::Close
|
||||
};
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
let data = ipc::Data::Close;
|
||||
let data = ipc::Data::Close;
|
||||
self.tx_to_cm.send(data).ok();
|
||||
self.port_forward_socket.take();
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ lazy_static::lazy_static! {
|
||||
pub static ref VIDEO_QOS: Arc<Mutex<VideoQoS>> = Default::default();
|
||||
pub static ref IS_UAC_RUNNING: Arc<Mutex<bool>> = Default::default();
|
||||
pub static ref IS_FOREGROUND_WINDOW_ELEVATED: Arc<Mutex<bool>> = Default::default();
|
||||
pub static ref LAST_SYNC_DISPLAYS: Arc<RwLock<Vec<DisplayInfo>>> = Default::default();
|
||||
}
|
||||
|
||||
fn is_capturer_mag_supported() -> bool {
|
||||
@@ -407,6 +408,43 @@ fn get_capturer(use_yuv: bool, portable_service_running: bool) -> ResultType<Cap
|
||||
})
|
||||
}
|
||||
|
||||
fn check_displays_new() -> Option<Vec<Display>> {
|
||||
let displays = try_get_displays().ok()?;
|
||||
let last_sync_displays = &*LAST_SYNC_DISPLAYS.read().unwrap();
|
||||
|
||||
if displays.len() != last_sync_displays.len() {
|
||||
Some(displays)
|
||||
} else {
|
||||
for i in 0..displays.len() {
|
||||
if displays[i].height() != (last_sync_displays[i].height as usize) {
|
||||
return Some(displays);
|
||||
}
|
||||
if displays[i].width() != (last_sync_displays[i].width as usize) {
|
||||
return Some(displays);
|
||||
}
|
||||
if displays[i].origin() != (last_sync_displays[i].x, last_sync_displays[i].y) {
|
||||
return Some(displays);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn check_displays_changed() -> Option<Message> {
|
||||
let displays = check_displays_new()?;
|
||||
let (current, displays) = get_displays_2(&displays);
|
||||
let mut pi = PeerInfo {
|
||||
conn_id: crate::SYNC_PEER_INFO_DISPLAYS,
|
||||
..Default::default()
|
||||
};
|
||||
pi.displays = displays.clone();
|
||||
pi.current_display = current as _;
|
||||
let mut msg_out = Message::new();
|
||||
msg_out.set_peer_info(pi);
|
||||
*LAST_SYNC_DISPLAYS.write().unwrap() = displays;
|
||||
Some(msg_out)
|
||||
}
|
||||
|
||||
fn run(sp: GenericService) -> ResultType<()> {
|
||||
#[cfg(windows)]
|
||||
ensure_close_virtual_device()?;
|
||||
@@ -529,6 +567,11 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
let now = time::Instant::now();
|
||||
if last_check_displays.elapsed().as_millis() > 1000 {
|
||||
last_check_displays = now;
|
||||
|
||||
if let Some(msg_out) = check_displays_changed() {
|
||||
sp.send(msg_out);
|
||||
}
|
||||
|
||||
if c.ndisplay != get_display_num() {
|
||||
log::info!("Displays changed");
|
||||
*SWITCH.lock().unwrap() = true;
|
||||
@@ -798,11 +841,7 @@ fn get_display_num() -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(d) = try_get_displays() {
|
||||
d.len()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
LAST_SYNC_DISPLAYS.read().unwrap().len()
|
||||
}
|
||||
|
||||
pub(super) fn get_displays_2(all: &Vec<Display>) -> (usize, Vec<DisplayInfo>) {
|
||||
@@ -861,6 +900,7 @@ pub async fn switch_display(i: i32) {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn refresh() {
|
||||
#[cfg(target_os = "android")]
|
||||
Display::refresh_size();
|
||||
@@ -888,10 +928,12 @@ fn get_primary() -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn switch_to_primary() {
|
||||
switch_display(get_primary() as _).await;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(windows))]
|
||||
fn try_get_displays() -> ResultType<Vec<Display>> {
|
||||
Ok(Display::all()?)
|
||||
|
||||
@@ -480,6 +480,14 @@ handler.updatePi = function(v) {
|
||||
}
|
||||
}
|
||||
|
||||
handler.updateDisplays = function(v) {
|
||||
pi.displays = v;
|
||||
header.update();
|
||||
if (is_port_forward) {
|
||||
view.windowState = View.WINDOW_MINIMIZED;
|
||||
}
|
||||
}
|
||||
|
||||
function updatePrivacyMode() {
|
||||
var el = $(li#privacy-mode);
|
||||
if (el) {
|
||||
|
||||
@@ -53,6 +53,20 @@ impl SciterHandler {
|
||||
allow_err!(e.call_method(func, &super::value_crash_workaround(args)[..]));
|
||||
}
|
||||
}
|
||||
|
||||
fn make_displays_array(displays: &Vec<DisplayInfo>) -> Value {
|
||||
let mut displays_value = Value::array(0);
|
||||
for d in 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);
|
||||
display.set_item("cursor_embedded", d.cursor_embedded);
|
||||
displays_value.push(display);
|
||||
}
|
||||
displays_value
|
||||
}
|
||||
}
|
||||
|
||||
impl InvokeUiSession for SciterHandler {
|
||||
@@ -215,22 +229,18 @@ impl InvokeUiSession for SciterHandler {
|
||||
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);
|
||||
display.set_item("cursor_embedded", d.cursor_embedded);
|
||||
displays.push(display);
|
||||
}
|
||||
pi_sciter.set_item("displays", displays);
|
||||
pi_sciter.set_item("displays", Self::make_displays_array(&pi.displays));
|
||||
pi_sciter.set_item("current_display", pi.current_display);
|
||||
self.call("updatePi", &make_args!(pi_sciter));
|
||||
}
|
||||
|
||||
fn set_displays(&self, displays: &Vec<DisplayInfo>) {
|
||||
self.call(
|
||||
"updateDisplays",
|
||||
&make_args!(Self::make_displays_array(displays)),
|
||||
);
|
||||
}
|
||||
|
||||
fn on_connected(&self, conn_type: ConnType) {
|
||||
match conn_type {
|
||||
ConnType::RDP => {}
|
||||
|
||||
@@ -761,6 +761,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
|
||||
fn set_display(&self, x: i32, y: i32, w: i32, h: i32, cursor_embedded: bool);
|
||||
fn switch_display(&self, display: &SwitchDisplay);
|
||||
fn set_peer_info(&self, peer_info: &PeerInfo); // flutter
|
||||
fn set_displays(&self, displays: &Vec<DisplayInfo>);
|
||||
fn on_connected(&self, conn_type: ConnType);
|
||||
fn update_privacy_mode(&self);
|
||||
fn set_permission(&self, name: &str, value: bool);
|
||||
|
||||
Reference in New Issue
Block a user