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

@@ -19,7 +19,7 @@ use core_graphics::{
};
use hbb_common::{anyhow::anyhow, bail, log, message_proto::Resolution};
use include_dir::{include_dir, Dir};
use objc::{class, msg_send, sel, sel_impl};
use objc::{class, msg_send, runtime::Object, sel, sel_impl};
use scrap::{libc::c_void, quartz::ffi::*};
use std::path::PathBuf;
@@ -762,3 +762,21 @@ impl WakeLock {
.ok_or(anyhow!("no AwakeHandle"))?
}
}
pub fn send_url_to_system(uni_links: &str) -> Result<(), &'static str> {
unsafe {
let ns_string = NSString::alloc(nil);
let url_str = ns_string.init_str(uni_links);
let url: *mut Object = msg_send![class!(NSURL), URLWithString: url_str];
if url.is_null() {
return Err("Failed to create NSURL");
}
let workspace: *mut Object = msg_send![class!(NSWorkspace), sharedWorkspace];
let success: bool = msg_send![workspace, openURL: url];
if success {
Ok(())
} else {
Err("Failed to open URL")
}
}
}