fix sync displays info && select monitor menu

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-02-17 13:32:17 +08:00
parent 5b58e957f6
commit 302499d1e0
14 changed files with 234 additions and 108 deletions

View File

@@ -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();
}

View File

@@ -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()?)