From aac12c2b21be369354a5df3e5074cfe96284863f Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 20 Jan 2023 01:25:15 +0800 Subject: [PATCH] applicationShouldOpenUntitledFile --- .../xcshareddata/xcschemes/Runner.xcscheme | 8 +++---- flutter/macos/Runner/AppDelegate.swift | 5 ++++ flutter/pubspec.lock | 7 ++++++ src/flutter.rs | 9 +++++++ src/platform/macos.rs | 20 ++++++++++++++++ src/ui/macos.rs | 24 ++----------------- 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/flutter/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/flutter/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 898fbe4e7..9c428a004 100644 --- a/flutter/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/flutter/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -15,7 +15,7 @@ @@ -31,7 +31,7 @@ @@ -54,7 +54,7 @@ @@ -71,7 +71,7 @@ diff --git a/flutter/macos/Runner/AppDelegate.swift b/flutter/macos/Runner/AppDelegate.swift index 156e0c79b..46622746d 100644 --- a/flutter/macos/Runner/AppDelegate.swift +++ b/flutter/macos/Runner/AppDelegate.swift @@ -7,4 +7,9 @@ class AppDelegate: FlutterAppDelegate { dummy_method_to_enforce_bundling() return true } + + override func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool { + handle_applicationShouldOpenUntitledFile(); + return true + } } diff --git a/flutter/pubspec.lock b/flutter/pubspec.lock index 228817422..ef57f375c 100644 --- a/flutter/pubspec.lock +++ b/flutter/pubspec.lock @@ -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: diff --git a/src/flutter.rs b/src/flutter.rs index 3036ca9b3..1369b5646 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -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 { diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 165470cac..c7dbd9b73 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -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(); +} diff --git a/src/ui/macos.rs b/src/ui/macos.rs index 835fd87b0..7daef8eab 100644 --- a/src/ui/macos.rs +++ b/src/ui/macos.rs @@ -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(); -} +} \ No newline at end of file