macos support uni command "rustdesk rustdesk://xxxx" without mainwindow (#7534)

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2024-03-27 13:42:50 +08:00
committed by GitHub
parent d7137990b9
commit 50fbf8833b
3 changed files with 46 additions and 19 deletions

View File

@@ -31,6 +31,12 @@ fn is_empty_uni_link(arg: &str) -> bool {
arg[prefix.len()..].chars().all(|c| c == '/')
}
#[inline]
fn is_valid_non_empty_uni_link(arg: &str) -> bool {
let prefix = crate::get_uri_prefix();
arg.starts_with(&prefix) && arg[prefix.len()..].chars().any(|c| c != '/')
}
/// shared by flutter and sciter main function
///
/// [Note]
@@ -64,8 +70,9 @@ pub fn core_main() -> Option<Vec<String>> {
.contains(&arg.as_str())
{
_is_flutter_invoke_new_connection = true;
}
if arg == "--elevate" {
} else if i == 1 && is_valid_non_empty_uni_link(&arg) {
return handle_uni_links(arg);
} else if arg == "--elevate" {
_is_elevate = true;
} else if arg == "--run-as-system" {
_is_run_as_system = true;
@@ -104,7 +111,7 @@ pub fn core_main() -> Option<Vec<String>> {
}
#[cfg(feature = "flutter")]
if _is_flutter_invoke_new_connection {
return core_main_invoke_new_connection(std::env::args());
return handle_uni_links(cmd_to_uni_link(std::env::args()));
}
let click_setup = cfg!(windows) && args.is_empty() && crate::common::is_setup(&arg_exe);
if click_setup && !config::is_disable_installation() {
@@ -511,14 +518,8 @@ fn import_config(path: &str) {
}
}
/// invoke a new connection
///
/// [Note]
/// this is for invoke new connection from dbus.
/// If it returns [`None`], then the process will terminate, and flutter gui will not be started.
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
#[cfg(feature = "flutter")]
fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<String>> {
fn cmd_to_uni_link(mut args: std::env::Args) -> String {
let mut authority = None;
let mut id = None;
let mut param_array = vec![];
@@ -565,6 +566,17 @@ fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<Strin
);
}
}
return uni_links;
}
/// invoke a new connection
///
/// [Note]
/// this is for invoke new connection.
/// If it returns [`None`], then the process will terminate, and flutter gui will not be started.
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
#[cfg(feature = "flutter")]
fn handle_uni_links(uni_links: String) -> Option<Vec<String>> {
if uni_links.is_empty() {
return None;
}
@@ -586,7 +598,9 @@ fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<Strin
}
#[cfg(target_os = "macos")]
{
return if let Err(_) = crate::ipc::send_url_scheme(uni_links) {
return if let Err(_) = crate::ipc::send_url_scheme(uni_links.clone()) {
let res = crate::platform::send_url_to_system(&uni_links); // if exit, can't invoke this url successfully
println!("open_url result: {res:?}");
Some(Vec::new())
} else {
None