mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-20 19:51:04 +03:00
switch sides: linux dbus use uri as para like uni_links
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
/// [Flutter]: handle uni links for linux
|
||||
use dbus::blocking::Connection;
|
||||
use dbus_crossroads::{Crossroads, IfaceBuilder};
|
||||
use hbb_common::{log};
|
||||
use std::{error::Error, fmt, time::Duration};
|
||||
use hbb_common::log;
|
||||
#[cfg(feature = "flutter")]
|
||||
use std::collections::HashMap;
|
||||
use std::{error::Error, fmt, time::Duration};
|
||||
|
||||
const DBUS_NAME: &str = "org.rustdesk.rustdesk";
|
||||
const DBUS_PREFIX: &str = "/dbus";
|
||||
@@ -30,15 +30,16 @@ impl fmt::Display for DbusError {
|
||||
impl Error for DbusError {}
|
||||
|
||||
/// invoke new connection from dbus
|
||||
///
|
||||
///
|
||||
/// [Tips]:
|
||||
/// How to test by CLI:
|
||||
/// - use dbus-send command:
|
||||
/// `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 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 {
|
||||
log::error!("error on call new connection to dbus server");
|
||||
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_ID,),
|
||||
(DBUS_METHOD_RETURN,),
|
||||
move |_, _, (_peer_id,): (String,)| {
|
||||
move |_, _, (_uni_links,): (String,)| {
|
||||
#[cfg(feature = "flutter")]
|
||||
{
|
||||
use crate::flutter::{self, APP_TYPE_MAIN};
|
||||
@@ -79,7 +80,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) {
|
||||
{
|
||||
let data = HashMap::from([
|
||||
("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())) {
|
||||
log::error!("failed to add dbus message to flutter global dbus stream.");
|
||||
|
||||
Reference in New Issue
Block a user