switch sides: linux dbus use uri as para like uni_links

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-01-18 13:54:56 +08:00
parent c25796e44d
commit b7844d1175
8 changed files with 45 additions and 38 deletions

View File

@ -1261,23 +1261,28 @@ StreamSubscription? listenUniLinks() {
/// Returns true if we successfully handle the startup arguments. /// Returns true if we successfully handle the startup arguments.
bool checkArguments() { bool checkArguments() {
// bootArgs:[--connect, 362587269, --switch_uuid, e3d531cc-5dce-41e0-bd06-5d4a2b1eec05]
// check connect args // check connect args
final connectIndex = bootArgs.indexOf("--connect"); final connectIndex = bootArgs.indexOf("--connect");
if (connectIndex == -1) { if (connectIndex == -1) {
return false; return false;
} }
String? arg = String? id =
bootArgs.length < connectIndex + 1 ? null : bootArgs[connectIndex + 1]; bootArgs.length < connectIndex + 1 ? null : bootArgs[connectIndex + 1];
if (arg != null) { final switchUuidIndex = bootArgs.indexOf("--switch_uuid");
if (arg.startsWith(kUniLinksPrefix)) { String? switchUuid = bootArgs.length < switchUuidIndex + 1
return parseRustdeskUri(arg); ? null
: bootArgs[switchUuidIndex + 1];
if (id != null) {
if (id.startsWith(kUniLinksPrefix)) {
return parseRustdeskUri(id);
} else { } else {
// remove "--connect xxx" in the `bootArgs` array // remove "--connect xxx" in the `bootArgs` array
bootArgs.removeAt(connectIndex); bootArgs.removeAt(connectIndex);
bootArgs.removeAt(connectIndex); bootArgs.removeAt(connectIndex);
// fallback to peer id // fallback to peer id
Future.delayed(Duration.zero, () { Future.delayed(Duration.zero, () {
rustDeskWinManager.newRemoteDesktop(arg); rustDeskWinManager.newRemoteDesktop(id, switch_uuid: switchUuid);
}); });
return true; return true;
} }

View File

@ -544,7 +544,7 @@ void setPasswordDialog() async {
final p1 = TextEditingController(text: pw); final p1 = TextEditingController(text: pw);
var errMsg0 = ""; var errMsg0 = "";
var errMsg1 = ""; var errMsg1 = "";
final RxString rxPass = p0.text.obs; final RxString rxPass = pw.trim().obs;
final rules = [ final rules = [
DigitValidationRule(), DigitValidationRule(),
UppercaseValidationRule(), UppercaseValidationRule(),
@ -603,7 +603,7 @@ void setPasswordDialog() async {
controller: p0, controller: p0,
focusNode: FocusNode()..requestFocus(), focusNode: FocusNode()..requestFocus(),
onChanged: (value) { onChanged: (value) {
rxPass.value = value; rxPass.value = value.trim();
}, },
), ),
), ),

View File

@ -184,13 +184,9 @@ class FfiModel with ChangeNotifier {
} else if (name == 'update_privacy_mode') { } else if (name == 'update_privacy_mode') {
updatePrivacyMode(evt, peerId); updatePrivacyMode(evt, peerId);
} else if (name == 'new_connection') { } else if (name == 'new_connection') {
var arg = evt['peer_id'].toString(); var uni_links = evt['uni_links'].toString();
if (arg.startsWith(kUniLinksPrefix)) { if (uni_links.startsWith(kUniLinksPrefix)) {
parseRustdeskUri(arg); parseRustdeskUri(uni_links);
} else {
Future.delayed(Duration.zero, () {
rustDeskWinManager.newRemoteDesktop(arg);
});
} }
} else if (name == 'alias') { } else if (name == 'alias') {
handleAliasChanged(evt); handleAliasChanged(evt);

View File

@ -305,11 +305,20 @@ fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<Strin
} }
} }
let switch_uuid = switch_uuid.map_or("".to_string(), |p| format!("switch_uuid={}", p));
let params = vec![switch_uuid].join("&");
let params_flag = if params.is_empty() { "" } else { "?" };
#[allow(unused)]
let uni_links = format!(
"rustdesk://connection/new/{}{}{}",
peer_id, params_flag, params
);
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
use crate::dbus::invoke_new_connection; use crate::dbus::invoke_new_connection;
match invoke_new_connection(peer_id) { match invoke_new_connection(uni_links) {
Ok(()) => { Ok(()) => {
return None; return None;
} }
@ -322,14 +331,7 @@ fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<Strin
} }
#[cfg(windows)] #[cfg(windows)]
{ {
let switch_uuid = switch_uuid.map_or("".to_string(), |p| format!("switch_uuid={}", p));
let params = vec![switch_uuid].join("&");
let params_flag = if params.is_empty() { "" } else { "?" };
use winapi::um::winuser::WM_USER; use winapi::um::winuser::WM_USER;
let uni_links = format!(
"rustdesk://connection/new/{}{}{}",
peer_id, params_flag, params
);
let res = crate::platform::send_message_to_hnwd( let res = crate::platform::send_message_to_hnwd(
"FLUTTER_RUNNER_WIN32_WINDOW", "FLUTTER_RUNNER_WIN32_WINDOW",
"RustDesk", "RustDesk",

View File

@ -1,6 +1,5 @@
use crate::ui_session_interface::{io_loop, InvokeUiSession, Session}; use crate::ui_session_interface::{io_loop, InvokeUiSession, Session};
use crate::{client::*, flutter_ffi::EventToUI}; use crate::{client::*, flutter_ffi::EventToUI};
use bytes::Bytes;
use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer}; use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer};
use hbb_common::{ use hbb_common::{
bail, config::LocalConfig, get_version_number, message_proto::*, rendezvous_proto::ConnType, bail, config::LocalConfig, get_version_number, message_proto::*, rendezvous_proto::ConnType,

View File

@ -784,12 +784,14 @@ extern "C" fn breakdown_signal_handler(sig: i32) {
sig, sig,
stack.join("\n").to_string() stack.join("\n").to_string()
); );
system_message( if !info.is_empty() {
"RustDesk", system_message(
&format!("Got signal {} and exit.{}", sig, info), "RustDesk",
true, &format!("Got signal {} and exit.{}", sig, info),
) true,
.ok(); )
.ok();
}
std::process::exit(0); std::process::exit(0);
} }

View File

@ -102,6 +102,7 @@ pub struct Connection {
last_recv_time: Arc<Mutex<Instant>>, last_recv_time: Arc<Mutex<Instant>>,
chat_unanswered: bool, chat_unanswered: bool,
close_manually: bool, close_manually: bool,
#[allow(unused)]
elevation_requested: bool, elevation_requested: bool,
from_switch: bool, from_switch: bool,
} }
@ -1547,7 +1548,7 @@ impl Connection {
self.send(msg).await; self.send(msg).await;
} }
} }
Some(elevation_request::Union::Logon(r)) => { Some(elevation_request::Union::Logon(_r)) => {
#[cfg(windows)] #[cfg(windows)]
{ {
let mut err = "No need to elevate".to_string(); let mut err = "No need to elevate".to_string();
@ -1556,7 +1557,8 @@ impl Connection {
{ {
use crate::portable_service::client; use crate::portable_service::client;
err = client::start_portable_service(client::StartPara::Logon( err = client::start_portable_service(client::StartPara::Logon(
r.username, r.password, _r.username,
_r.password,
)) ))
.err() .err()
.map_or("".to_string(), |e| e.to_string()); .map_or("".to_string(), |e| e.to_string());

View File

@ -5,10 +5,10 @@
/// [Flutter]: handle uni links for linux /// [Flutter]: handle uni links for linux
use dbus::blocking::Connection; use dbus::blocking::Connection;
use dbus_crossroads::{Crossroads, IfaceBuilder}; use dbus_crossroads::{Crossroads, IfaceBuilder};
use hbb_common::{log}; use hbb_common::log;
use std::{error::Error, fmt, time::Duration};
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
use std::collections::HashMap; use std::collections::HashMap;
use std::{error::Error, fmt, time::Duration};
const DBUS_NAME: &str = "org.rustdesk.rustdesk"; const DBUS_NAME: &str = "org.rustdesk.rustdesk";
const DBUS_PREFIX: &str = "/dbus"; const DBUS_PREFIX: &str = "/dbus";
@ -30,15 +30,16 @@ impl fmt::Display for DbusError {
impl Error for DbusError {} impl Error for DbusError {}
/// invoke new connection from dbus /// invoke new connection from dbus
/// ///
/// [Tips]: /// [Tips]:
/// How to test by CLI: /// How to test by CLI:
/// - use dbus-send command: /// - use dbus-send command:
/// `dbus-send --session --print-reply --dest=org.rustdesk.rustdesk /dbus org.rustdesk.rustdesk.NewConnection string:'PEER_ID'` /// `dbus-send --session --print-reply --dest=org.rustdesk.rustdesk /dbus org.rustdesk.rustdesk.NewConnection string:'PEER_ID'`
pub fn invoke_new_connection(peer_id: String) -> Result<(), Box<dyn Error>> { pub fn invoke_new_connection(uni_links: String) -> Result<(), Box<dyn Error>> {
let conn = Connection::new_session()?; let conn = Connection::new_session()?;
let proxy = conn.with_proxy(DBUS_NAME, DBUS_PREFIX, DBUS_TIMEOUT); let proxy = conn.with_proxy(DBUS_NAME, DBUS_PREFIX, DBUS_TIMEOUT);
let (ret,): (String,) = proxy.method_call(DBUS_NAME, DBUS_METHOD_NEW_CONNECTION, (peer_id,))?; let (ret,): (String,) =
proxy.method_call(DBUS_NAME, DBUS_METHOD_NEW_CONNECTION, (uni_links,))?;
if ret != DBUS_METHOD_RETURN_SUCCESS { if ret != DBUS_METHOD_RETURN_SUCCESS {
log::error!("error on call new connection to dbus server"); log::error!("error on call new connection to dbus server");
return Err(Box::new(DbusError("not success".to_string()))); return Err(Box::new(DbusError("not success".to_string())));
@ -67,7 +68,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) {
DBUS_METHOD_NEW_CONNECTION, DBUS_METHOD_NEW_CONNECTION,
(DBUS_METHOD_NEW_CONNECTION_ID,), (DBUS_METHOD_NEW_CONNECTION_ID,),
(DBUS_METHOD_RETURN,), (DBUS_METHOD_RETURN,),
move |_, _, (_peer_id,): (String,)| { move |_, _, (_uni_links,): (String,)| {
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
{ {
use crate::flutter::{self, APP_TYPE_MAIN}; use crate::flutter::{self, APP_TYPE_MAIN};
@ -79,7 +80,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) {
{ {
let data = HashMap::from([ let data = HashMap::from([
("name", "new_connection"), ("name", "new_connection"),
("peer_id", _peer_id.as_str()) ("uni_links", _uni_links.as_str()),
]); ]);
if !stream.add(serde_json::ser::to_string(&data).unwrap_or("".to_string())) { if !stream.add(serde_json::ser::to_string(&data).unwrap_or("".to_string())) {
log::error!("failed to add dbus message to flutter global dbus stream."); log::error!("failed to add dbus message to flutter global dbus stream.");