refactor handle_applicationShouldOpenUntitledFile
This commit is contained in:
parent
4f25b03a10
commit
fcd1f9b4a3
@ -42,11 +42,7 @@ pub extern "C" fn rustdesk_core_main() -> bool {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn handle_applicationShouldOpenUntitledFile() {
|
pub extern "C" fn handle_applicationShouldOpenUntitledFile() {
|
||||||
hbb_common::log::debug!("icon clicked on finder");
|
crate::platform::macos::handle_applicationShouldOpenUntitledFile();
|
||||||
let x = std::env::args().nth(1).unwrap_or_default();
|
|
||||||
if x == "--server" || x == "--cm" {
|
|
||||||
crate::platform::macos::check_main_window();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -557,7 +557,7 @@ pub fn hide_dock() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_main_window() {
|
fn check_main_window() -> bool {
|
||||||
use sysinfo::{ProcessExt, System, SystemExt};
|
use sysinfo::{ProcessExt, System, SystemExt};
|
||||||
let mut sys = System::new();
|
let mut sys = System::new();
|
||||||
sys.refresh_processes();
|
sys.refresh_processes();
|
||||||
@ -568,11 +568,22 @@ pub fn check_main_window() {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
for (_, p) in sys.processes().iter() {
|
for (_, p) in sys.processes().iter() {
|
||||||
if p.cmd().len() == 1 && p.user_id() == my_uid && p.cmd()[0].contains(&app) {
|
if p.cmd().len() == 1 && p.user_id() == my_uid && p.cmd()[0].contains(&app) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::process::Command::new("open")
|
std::process::Command::new("open")
|
||||||
.args(["-n", &app])
|
.args(["-n", &app])
|
||||||
.status()
|
.status()
|
||||||
.ok();
|
.ok();
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_applicationShouldOpenUntitledFile() {
|
||||||
|
hbb_common::log::debug!("icon clicked on finder");
|
||||||
|
let x = std::env::args().nth(1).unwrap_or_default();
|
||||||
|
if x == "--server" || x == "--cm" {
|
||||||
|
if crate::platform::macos::check_main_window() {
|
||||||
|
crate::ipc::send_url_scheme("rustdesk:".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,15 @@ use cocoa::{
|
|||||||
base::{id, nil, YES},
|
base::{id, nil, YES},
|
||||||
foundation::{NSAutoreleasePool, NSString},
|
foundation::{NSAutoreleasePool, NSString},
|
||||||
};
|
};
|
||||||
|
use objc::runtime::Class;
|
||||||
use objc::{
|
use objc::{
|
||||||
class,
|
class,
|
||||||
declare::ClassDecl,
|
declare::ClassDecl,
|
||||||
msg_send,
|
msg_send,
|
||||||
runtime::{BOOL, Object, Sel},
|
runtime::{Object, Sel, BOOL},
|
||||||
sel, sel_impl,
|
sel, sel_impl,
|
||||||
};
|
};
|
||||||
use objc::runtime::Class;
|
use sciter::{make_args, Host};
|
||||||
use sciter::{Host, make_args};
|
|
||||||
|
|
||||||
use hbb_common::log;
|
use hbb_common::log;
|
||||||
|
|
||||||
@ -102,7 +102,10 @@ unsafe fn set_delegate(handler: Option<Box<dyn AppHandler>>) {
|
|||||||
sel!(handleMenuItem:),
|
sel!(handleMenuItem:),
|
||||||
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
);
|
);
|
||||||
decl.add_method(sel!(handleEvent:withReplyEvent:), handle_apple_event as extern fn(&Object, Sel, u64, u64));
|
decl.add_method(
|
||||||
|
sel!(handleEvent:withReplyEvent:),
|
||||||
|
handle_apple_event as extern "C" fn(&Object, Sel, u64, u64),
|
||||||
|
);
|
||||||
let decl = decl.register();
|
let decl = decl.register();
|
||||||
let delegate: id = msg_send![decl, alloc];
|
let delegate: id = msg_send![decl, alloc];
|
||||||
let () = msg_send![delegate, init];
|
let () = msg_send![delegate, init];
|
||||||
@ -138,10 +141,7 @@ extern "C" fn application_should_handle_open_untitled_file(
|
|||||||
if !LAUNCHED {
|
if !LAUNCHED {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
log::debug!("icon clicked on finder");
|
crate::platform::macos::handle_applicationShouldOpenUntitledFile();
|
||||||
if std::env::args().nth(1) == Some("--server".to_owned()) {
|
|
||||||
crate::platform::macos::check_main_window();
|
|
||||||
}
|
|
||||||
let inner: *mut c_void = *this.get_ivar(APP_HANDLER_IVAR);
|
let inner: *mut c_void = *this.get_ivar(APP_HANDLER_IVAR);
|
||||||
let inner = &mut *(inner as *mut DelegateState);
|
let inner = &mut *(inner as *mut DelegateState);
|
||||||
(*inner).command(AWAKE);
|
(*inner).command(AWAKE);
|
||||||
@ -191,7 +191,7 @@ pub fn handle_url_scheme(url: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern fn handle_apple_event(_this: &Object, _cmd: Sel, event: u64, _reply: u64) {
|
extern "C" fn handle_apple_event(_this: &Object, _cmd: Sel, event: u64, _reply: u64) {
|
||||||
let event = event as *mut Object;
|
let event = event as *mut Object;
|
||||||
let url = fruitbasket::parse_url_event(event);
|
let url = fruitbasket::parse_url_event(event);
|
||||||
log::debug!("an event was received: {}", url);
|
log::debug!("an event was received: {}", url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user