applicationShouldOpenUntitledFile

This commit is contained in:
rustdesk 2023-01-20 01:25:15 +08:00
parent 3e63df1d59
commit aac12c2b21
6 changed files with 47 additions and 26 deletions

View File

@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "rustdesk.app"
BuildableName = "RustDesk.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
@ -31,7 +31,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "rustdesk.app"
BuildableName = "RustDesk.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
@ -54,7 +54,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "rustdesk.app"
BuildableName = "RustDesk.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
@ -71,7 +71,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "rustdesk.app"
BuildableName = "RustDesk.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>

View File

@ -7,4 +7,9 @@ class AppDelegate: FlutterAppDelegate {
dummy_method_to_enforce_bundling()
return true
}
override func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
handle_applicationShouldOpenUntitledFile();
return true
}
}

View File

@ -699,6 +699,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
password_strength:
dependency: "direct main"
description:
name: password_strength
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
path:
dependency: "direct main"
description:

View File

@ -39,6 +39,15 @@ pub extern "C" fn rustdesk_core_main() -> bool {
false
}
#[cfg(target_os = "macos")]
#[no_mangle]
pub extern "C" fn handle_applicationShouldOpenUntitledFile() {
hbb_common::log::debug!("icon clicked on finder");
if std::env::args().nth(1) == Some("--server".to_owned()) {
crate::platform::macos::check_main_window();
}
}
#[cfg(windows)]
#[no_mangle]
pub extern "C" fn rustdesk_core_main_args(args_len: *mut c_int) -> *mut *mut c_char {

View File

@ -556,3 +556,23 @@ pub fn hide_dock() {
NSApp().setActivationPolicy_(NSApplicationActivationPolicyAccessory);
}
}
pub fn check_main_window() {
use sysinfo::{ProcessExt, System, SystemExt};
let mut sys = System::new();
sys.refresh_processes();
let app = format!("/Applications/{}.app", crate::get_app_name());
let my_uid = sys
.process((std::process::id() as i32).into())
.map(|x| x.user_id())
.unwrap_or_default();
for (_, p) in sys.processes().iter() {
if p.cmd().len() == 1 && p.user_id() == my_uid && p.cmd()[0].contains(&app) {
return;
}
}
std::process::Command::new("open")
.args(["-n", &app])
.status()
.ok();
}

View File

@ -127,7 +127,7 @@ extern "C" fn application_should_handle_open_untitled_file(
}
hbb_common::log::debug!("icon clicked on finder");
if std::env::args().nth(1) == Some("--server".to_owned()) {
check_main_window();
crate::platform::macos::check_main_window();
}
let inner: *mut c_void = *this.get_ivar(APP_HANDLER_IVAR);
let inner = &mut *(inner as *mut DelegateState);
@ -233,24 +233,4 @@ pub fn make_tray() {
set_delegate(None);
}
crate::tray::make_tray();
}
pub fn check_main_window() {
use sysinfo::{ProcessExt, System, SystemExt};
let mut sys = System::new();
sys.refresh_processes();
let app = format!("/Applications/{}.app", crate::get_app_name());
let my_uid = sys
.process((std::process::id() as i32).into())
.map(|x| x.user_id())
.unwrap_or_default();
for (_, p) in sys.processes().iter() {
if p.cmd().len() == 1 && p.user_id() == my_uid && p.cmd()[0].contains(&app) {
return;
}
}
std::process::Command::new("open")
.args(["-n", &app])
.status()
.ok();
}
}