diff --git a/Cargo.lock b/Cargo.lock index c4fd31ea7..fe2fb18e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5876,7 +5876,7 @@ dependencies = [ [[package]] name = "tao" version = "0.18.1" -source = "git+https://github.com/tauri-apps/tao?branch=muda#0c1417884161d165b8852fbf11be5492edef9fe7" +source = "git+https://github.com/Kingtous/tao?branch=muda#dea701661a182cf2d944d5d05b5d299c78079871" dependencies = [ "bitflags", "cairo-rs", @@ -5921,7 +5921,7 @@ dependencies = [ [[package]] name = "tao-macros" version = "0.1.1" -source = "git+https://github.com/tauri-apps/tao?branch=muda#0c1417884161d165b8852fbf11be5492edef9fe7" +source = "git+https://github.com/Kingtous/tao?branch=muda#dea701661a182cf2d944d5d05b5d299c78079871" dependencies = [ "proc-macro2 1.0.54", "quote 1.0.26", diff --git a/Cargo.toml b/Cargo.toml index 0200e0fee..d924b4616 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,7 +113,7 @@ objc_id = "0.1" [target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies] tray-icon = "0.4" -tao = { git = "https://github.com/tauri-apps/tao", branch = "muda" } +tao = { git = "https://github.com/Kingtous/tao", branch = "muda" } image = "0.24" [target.'cfg(target_os = "linux")'.dependencies] diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index d64f2cde5..dafd75e1f 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1581,7 +1581,13 @@ bool checkArguments() { /// Returns true if we successfully handle the uri provided. /// [Functions] /// 1. New Connection: rustdesk://connection/new/your_peer_id +/// 2. Bring the main window to the top: empty uriPath bool parseRustdeskUri(String uriPath) { + // If we invoke uri with blank path, we just bring the main window to tht top. + if (uriPath.isEmpty) { + window_on_top(null); + return true; + } final uri = Uri.tryParse(uriPath); if (uri == null) { debugPrint("uri is not valid: $uriPath"); diff --git a/flutter/lib/models/native_model.dart b/flutter/lib/models/native_model.dart index 2b99e1823..6da8dda27 100644 --- a/flutter/lib/models/native_model.dart +++ b/flutter/lib/models/native_model.dart @@ -173,13 +173,10 @@ class PlatformFFI { if (Platform.isLinux) { // Start a dbus service, no need to await _ffiBind.mainStartDbusServer(); + _ffiBind.mainStartPa(); } else if (Platform.isMacOS && isMain) { - Future.wait([ - // Start dbus service. - _ffiBind.mainStartDbusServer(), - // Start local audio pulseaudio server. - _ffiBind.mainStartPa() - ]); + // Start ipc service for uri links. + _ffiBind.mainStartIpcUrlServer(); } _startListenEvent(_ffiBind); // global event try { diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs index 55e80599a..5b3ded04c 100644 --- a/libs/hbb_common/src/config.rs +++ b/libs/hbb_common/src/config.rs @@ -969,13 +969,20 @@ impl PeerConfig { fn path(id: &str) -> PathBuf { //If the id contains invalid chars, encode it - let forbidden_paths = Regex::new(r".*[<>:/\\|\?\*].*").unwrap(); - let id_encoded = if forbidden_paths.is_match(id) { - "base64_".to_string() + base64::encode(id, base64::Variant::Original).as_str() + let forbidden_paths = Regex::new(r".*[<>:/\\|\?\*].*"); + let path: PathBuf; + if let Ok(forbidden_paths) = forbidden_paths { + let id_encoded = if forbidden_paths.is_match(id) { + "base64_".to_string() + base64::encode(id, base64::Variant::Original).as_str() + } else { + id.to_string() + }; + path = [PEERS, id_encoded.as_str()].iter().collect(); } else { - id.to_string() - }; - let path: PathBuf = [PEERS, id_encoded.as_str()].iter().collect(); + log::warn!("Regex create failed: {:?}", forbidden_paths.err()); + // fallback for failing to create this regex. + path = [PEERS, id.replace(":", "_").as_str()].iter().collect(); + } Config::with_extension(Config::path(path)) } diff --git a/src/platform/delegate.rs b/src/platform/delegate.rs index 01855536e..1612b33bd 100644 --- a/src/platform/delegate.rs +++ b/src/platform/delegate.rs @@ -6,7 +6,7 @@ use cocoa::{ base::{id, nil, YES}, foundation::{NSAutoreleasePool, NSString}, }; -use objc::runtime::Class; +use objc::runtime::{Class, NO}; use objc::{ class, declare::ClassDecl, @@ -107,7 +107,7 @@ pub unsafe fn set_delegate(handler: Option>) { ); decl.add_method( sel!(handleEvent:withReplyEvent:), - handle_apple_event as extern "C" fn(&Object, Sel, u64, u64), + handle_apple_event as extern "C" fn(&Object, Sel, u64, u64) -> BOOL, ); let decl = decl.register(); let delegate: id = msg_send![decl, alloc]; @@ -183,11 +183,27 @@ extern "C" fn handle_menu_item(this: &mut Object, _: Sel, item: id) { } } -extern "C" fn handle_apple_event(_this: &Object, _cmd: Sel, event: u64, _reply: u64) { +#[no_mangle] +extern "C" fn handle_apple_event(_this: &Object, _cmd: Sel, event: u64, _reply: u64) -> BOOL { let event = event as *mut Object; let url = fruitbasket::parse_url_event(event); log::debug!("an event was received: {}", url); std::thread::spawn(move || crate::handle_url_scheme(url)); + YES +} + +// Customize the service opening logic. +#[no_mangle] +fn service_should_handle_reopen( + obj: &Object, + sel: Sel, + sender: id, + has_visible_windows: BOOL, + ) -> BOOL { + log::debug!("Invoking the main rustdesk process"); + std::thread::spawn(move || crate::handle_url_scheme("".to_string())); + // Prevent default logic. + NO } unsafe fn make_menu_item(title: &str, key: &str, tag: u32) -> *mut Object { diff --git a/src/server.rs b/src/server.rs index 6a0371757..b6cbdac44 100644 --- a/src/server.rs +++ b/src/server.rs @@ -454,7 +454,7 @@ pub async fn start_ipc_url_server() { let mut m = HashMap::new(); m.insert("name", "on_url_scheme_received"); m.insert("url", url.as_str()); - let event = serde_json::to_string(&m).unwrap(); + let event = serde_json::to_string(&m).unwrap_or("".to_owned()); match crate::flutter::push_global_event(crate::flutter::APP_TYPE_MAIN, event) { None => log::warn!("No main window app found!"), Some(..) => {} diff --git a/src/tray.rs b/src/tray.rs index 38ed9b0cb..617ec2c93 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -131,10 +131,6 @@ pub fn make_tray() -> hbb_common::ResultType<()> { let event_loop = EventLoopBuilder::new().build(); - unsafe { - crate::platform::delegate::set_delegate(None); - } - let tray_menu = Menu::new(); let quit_i = MenuItem::new(crate::client::translate("Exit".to_owned()), true, None); tray_menu.append_items(&[&quit_i]);