From 8df1e4297700cd0d16da05ac5cb488fafe6fff8a Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 29 Apr 2022 10:40:00 +0800 Subject: [PATCH] hide icon after initialization before close is useless --- src/ui/macos.rs | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/src/ui/macos.rs b/src/ui/macos.rs index 4a633b4c5..559a6c558 100644 --- a/src/ui/macos.rs +++ b/src/ui/macos.rs @@ -42,9 +42,7 @@ impl DelegateState { } } -lazy_static::lazy_static! { - static ref START_TM: std::sync::Mutex = std::sync::Mutex::new(std::time::Instant::now()); -} +static mut FIRST_TIME: bool = true; impl AppHandler for Rc { fn command(&mut self, cmd: u32) { @@ -55,12 +53,11 @@ impl AppHandler for Rc { let _ = self.call_function("awake", &make_args![]); let _ = self.call_function("showSettings", &make_args![]); } else if cmd == AWAKE { - if START_TM.lock().unwrap().elapsed().as_millis() < 1000 { - hbb_common::log::debug!( - "First click on docker icon {:?}", - START_TM.lock().unwrap().elapsed() - ); - return; + unsafe { + if std::env::args().nth(1) == Some("--server".to_owned()) && FIRST_TIME { + FIRST_TIME = false; + return; + } } let _ = self.call_function("awake", &make_args![]); } @@ -69,7 +66,6 @@ impl AppHandler for Rc { // https://github.com/xi-editor/druid/blob/master/druid-shell/src/platform/mac/application.rs unsafe fn set_delegate(handler: Option>) { - *START_TM.lock().unwrap() = std::time::Instant::now(); let mut decl = ClassDecl::new("AppDelegate", class!(NSObject)).expect("App Delegate definition failed"); decl.add_ivar::<*mut c_void>(APP_HANDLER_IVAR); @@ -136,37 +132,22 @@ extern "C" fn application_should_handle_open_untitled_file( YES } -extern "C" fn application_should_handle_reopen( - _this: &mut Object, - _: Sel, - _sender: id, -) -> BOOL { +extern "C" fn application_should_handle_reopen(_this: &mut Object, _: Sel, _sender: id) -> BOOL { hbb_common::log::debug!("reopen"); YES } -extern "C" fn application_did_become_active ( - _this: &mut Object, - _: Sel, - _sender: id, -) -> BOOL { +extern "C" fn application_did_become_active(_this: &mut Object, _: Sel, _sender: id) -> BOOL { hbb_common::log::debug!("active"); YES } -extern "C" fn application_did_become_unhide ( - _this: &mut Object, - _: Sel, - _sender: id, -) -> BOOL { +extern "C" fn application_did_become_unhide(_this: &mut Object, _: Sel, _sender: id) -> BOOL { hbb_common::log::debug!("unhide"); YES } extern "C" fn application_will_terminate(_this: &mut Object, _: Sel, _sender: id) -> BOOL { - if std::env::args().len() == 1 || std::env::args().nth(1) == Some("--server".to_owned()) { - hide_dock(); - } YES }