mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-06-12 21:53:14 +08:00
Merge pull request #6333 from 21pages/cm
close all connections if cm exit unexpected, and allow retry
This commit is contained in:
commit
fd3cb1b0eb
@ -1319,7 +1319,7 @@ class _DisplayState extends State<_Display> {
|
|||||||
otherRow('Zoom cursor', 'zoom-cursor'),
|
otherRow('Zoom cursor', 'zoom-cursor'),
|
||||||
otherRow('Show quality monitor', 'show_quality_monitor'),
|
otherRow('Show quality monitor', 'show_quality_monitor'),
|
||||||
otherRow('Mute', 'disable_audio'),
|
otherRow('Mute', 'disable_audio'),
|
||||||
otherRow('Allow file copy and paste', 'enable_file_transfer'),
|
otherRow('Enable file copy and paste', 'enable_file_transfer'),
|
||||||
otherRow('Disable clipboard', 'disable_clipboard'),
|
otherRow('Disable clipboard', 'disable_clipboard'),
|
||||||
otherRow('Lock after session end', 'lock_after_session_end'),
|
otherRow('Lock after session end', 'lock_after_session_end'),
|
||||||
otherRow('Privacy mode', 'privacy_mode'),
|
otherRow('Privacy mode', 'privacy_mode'),
|
||||||
|
@ -91,7 +91,7 @@ Future<void> main(List<String> args) async {
|
|||||||
debugPrint("--cm started");
|
debugPrint("--cm started");
|
||||||
desktopType = DesktopType.cm;
|
desktopType = DesktopType.cm;
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
runConnectionManagerScreen(args.contains('--hide'));
|
runConnectionManagerScreen();
|
||||||
} else if (args.contains('--install')) {
|
} else if (args.contains('--install')) {
|
||||||
runInstallPage();
|
runInstallPage();
|
||||||
} else {
|
} else {
|
||||||
@ -225,13 +225,14 @@ void runMultiWindow(
|
|||||||
WindowController.fromWindowId(kWindowId!).show();
|
WindowController.fromWindowId(kWindowId!).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runConnectionManagerScreen(bool hide) async {
|
void runConnectionManagerScreen() async {
|
||||||
await initEnv(kAppTypeConnectionManager);
|
await initEnv(kAppTypeConnectionManager);
|
||||||
_runApp(
|
_runApp(
|
||||||
'',
|
'',
|
||||||
const DesktopServerPage(),
|
const DesktopServerPage(),
|
||||||
MyTheme.currentThemeMode(),
|
MyTheme.currentThemeMode(),
|
||||||
);
|
);
|
||||||
|
final hide = await bind.cmGetConfig(name: "hide_cm") == 'true';
|
||||||
gFFI.serverModel.hideCm = hide;
|
gFFI.serverModel.hideCm = hide;
|
||||||
if (hide) {
|
if (hide) {
|
||||||
await hideCmWindow(isStartup: true);
|
await hideCmWindow(isStartup: true);
|
||||||
|
@ -79,10 +79,12 @@ class ServerModel with ChangeNotifier {
|
|||||||
|
|
||||||
setVerificationMethod(String method) async {
|
setVerificationMethod(String method) async {
|
||||||
await bind.mainSetOption(key: "verification-method", value: method);
|
await bind.mainSetOption(key: "verification-method", value: method);
|
||||||
|
/*
|
||||||
if (method != kUsePermanentPassword) {
|
if (method != kUsePermanentPassword) {
|
||||||
await bind.mainSetOption(
|
await bind.mainSetOption(
|
||||||
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
|
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
String get temporaryPasswordLength {
|
String get temporaryPasswordLength {
|
||||||
@ -99,10 +101,12 @@ class ServerModel with ChangeNotifier {
|
|||||||
|
|
||||||
setApproveMode(String mode) async {
|
setApproveMode(String mode) async {
|
||||||
await bind.mainSetOption(key: 'approve-mode', value: mode);
|
await bind.mainSetOption(key: 'approve-mode', value: mode);
|
||||||
|
/*
|
||||||
if (mode != 'password') {
|
if (mode != 'password') {
|
||||||
await bind.mainSetOption(
|
await bind.mainSetOption(
|
||||||
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
|
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditingController get serverId => _serverId;
|
TextEditingController get serverId => _serverId;
|
||||||
|
@ -395,7 +395,7 @@ pub fn session_is_keyboard_mode_supported(session_id: SessionID, mode: String) -
|
|||||||
SyncReturn(is_keyboard_mode_supported(
|
SyncReturn(is_keyboard_mode_supported(
|
||||||
&mode,
|
&mode,
|
||||||
session.get_peer_version(),
|
session.get_peer_version(),
|
||||||
&session.peer_platform()
|
&session.peer_platform(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
SyncReturn(false)
|
SyncReturn(false)
|
||||||
@ -1529,6 +1529,21 @@ pub fn cm_switch_back(conn_id: i32) {
|
|||||||
crate::ui_cm_interface::switch_back(conn_id);
|
crate::ui_cm_interface::switch_back(conn_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cm_get_config(name: String) -> String {
|
||||||
|
#[cfg(not(target_os = "ios"))]
|
||||||
|
{
|
||||||
|
if let Ok(Some(v)) = crate::ipc::get_config(&name) {
|
||||||
|
v
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "ios")]
|
||||||
|
{
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main_get_build_date() -> String {
|
pub fn main_get_build_date() -> String {
|
||||||
crate::BUILD_DATE.to_string()
|
crate::BUILD_DATE.to_string()
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,7 @@ pub enum Data {
|
|||||||
FileTransferLog((String, String)),
|
FileTransferLog((String, String)),
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
ControlledSessionCount(usize),
|
ControlledSessionCount(usize),
|
||||||
|
CmErr(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
@ -407,6 +408,12 @@ async fn handle(data: Data, stream: &mut Connection) {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
} else if name == "hide_cm" {
|
||||||
|
value = if crate::hbbs_http::sync::is_pro() {
|
||||||
|
Some(hbb_common::password_security::hide_cm().to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
value = None;
|
value = None;
|
||||||
}
|
}
|
||||||
@ -698,7 +705,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn get_config(name: &str) -> ResultType<Option<String>> {
|
pub async fn get_config(name: &str) -> ResultType<Option<String>> {
|
||||||
get_config_async(name, 1_000).await
|
get_config_async(name, 1_000).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ use super::{input_service::*, *};
|
|||||||
use crate::clipboard_file::*;
|
use crate::clipboard_file::*;
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
use crate::common::update_clipboard;
|
use crate::common::update_clipboard;
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
use crate::keyboard::client::map_key_to_control_key;
|
||||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||||
use crate::platform::linux_desktop_manager;
|
use crate::platform::linux_desktop_manager;
|
||||||
@ -24,6 +26,8 @@ use cidr_utils::cidr::IpCidr;
|
|||||||
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
#[cfg(all(target_os = "linux", feature = "linux_headless"))]
|
||||||
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
#[cfg(not(any(feature = "flatpak", feature = "appimage")))]
|
||||||
use hbb_common::platform::linux::run_cmds;
|
use hbb_common::platform::linux::run_cmds;
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
use hbb_common::protobuf::EnumOrUnknown;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
config::Config,
|
config::Config,
|
||||||
fs,
|
fs,
|
||||||
@ -38,12 +42,10 @@ use hbb_common::{
|
|||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
time::{self, Duration, Instant, Interval},
|
time::{self, Duration, Instant, Interval},
|
||||||
},
|
},
|
||||||
tokio_util::codec::{BytesCodec, Framed}, protobuf::EnumOrUnknown,
|
tokio_util::codec::{BytesCodec, Framed},
|
||||||
};
|
};
|
||||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
use scrap::android::{call_main_service_pointer_input, call_main_service_key_event};
|
use scrap::android::{call_main_service_key_event, call_main_service_pointer_input};
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
use crate::keyboard::client::map_key_to_control_key;
|
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use serde_json::{json, value::Value};
|
use serde_json::{json, value::Value};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
@ -439,6 +441,13 @@ impl Connection {
|
|||||||
conn.on_close("connection manager", true).await;
|
conn.on_close("connection manager", true).await;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
ipc::Data::CmErr(e) => {
|
||||||
|
if e != "expected" {
|
||||||
|
// cm closed before connection
|
||||||
|
conn.on_close(&format!("connection manager error: {}", e), false).await;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
ipc::Data::ChatMessage{text} => {
|
ipc::Data::ChatMessage{text} => {
|
||||||
let mut misc = Misc::new();
|
let mut misc = Misc::new();
|
||||||
misc.set_chat_message(ChatMessage {
|
misc.set_chat_message(ChatMessage {
|
||||||
@ -816,7 +825,11 @@ impl Connection {
|
|||||||
Some(data) = rx_from_cm.recv() => {
|
Some(data) = rx_from_cm.recv() => {
|
||||||
match data {
|
match data {
|
||||||
ipc::Data::Close => {
|
ipc::Data::Close => {
|
||||||
bail!("Close requested from selection manager");
|
bail!("Close requested from connection manager");
|
||||||
|
}
|
||||||
|
ipc::Data::CmErr(e) => {
|
||||||
|
log::error!("Connection manager error: {e}");
|
||||||
|
bail!("{e}");
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -1383,15 +1396,15 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_recent_session(&mut self) -> bool {
|
fn is_recent_session(&mut self) -> bool {
|
||||||
|
SESSIONS
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.retain(|_, s| s.last_recv_time.lock().unwrap().elapsed() < SESSION_TIMEOUT);
|
||||||
let session = SESSIONS
|
let session = SESSIONS
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get(&self.lr.my_id)
|
.get(&self.lr.my_id)
|
||||||
.map(|s| s.to_owned());
|
.map(|s| s.to_owned());
|
||||||
SESSIONS
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.retain(|_, s| s.last_recv_time.lock().unwrap().elapsed() < SESSION_TIMEOUT);
|
|
||||||
// last_recv_time is a mutex variable shared with connection, can be updated lively.
|
// last_recv_time is a mutex variable shared with connection, can be updated lively.
|
||||||
if let Some(session) = session {
|
if let Some(session) = session {
|
||||||
if session.name == self.lr.my_name
|
if session.name == self.lr.my_name
|
||||||
@ -1461,6 +1474,7 @@ impl Connection {
|
|||||||
fn try_start_cm_ipc(&mut self) {
|
fn try_start_cm_ipc(&mut self) {
|
||||||
if let Some(p) = self.start_cm_ipc_para.take() {
|
if let Some(p) = self.start_cm_ipc_para.take() {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
let tx_from_cm_clone = p.tx_from_cm.clone();
|
||||||
if let Err(err) = start_ipc(
|
if let Err(err) = start_ipc(
|
||||||
p.rx_to_cm,
|
p.rx_to_cm,
|
||||||
p.tx_from_cm,
|
p.tx_from_cm,
|
||||||
@ -1470,6 +1484,7 @@ impl Connection {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
log::error!("ipc to connection manager exit: {}", err);
|
log::error!("ipc to connection manager exit: {}", err);
|
||||||
|
allow_err!(tx_from_cm_clone.send(Data::CmErr(err.to_string())));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
#[cfg(all(windows, feature = "flutter"))]
|
#[cfg(all(windows, feature = "flutter"))]
|
||||||
@ -2777,9 +2792,6 @@ async fn start_ipc(
|
|||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
let mut args = vec!["--cm"];
|
let mut args = vec!["--cm"];
|
||||||
if crate::hbbs_http::sync::is_pro() && password::hide_cm() {
|
|
||||||
args.push("--hide");
|
|
||||||
}
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
let mut user = None;
|
let mut user = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user