From 38b6c5e16ead9e9dd925e8012ddff36445fe6f34 Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Tue, 3 Sep 2024 09:51:42 +0800 Subject: [PATCH] Revert "feat(dock): try to setup macos dock handler" This reverts commit be4d56211eb93fb864c2638093cd2c980b05f668. --- backend/tauri/src/utils/dock.rs | 51 ++---------------------------- backend/tauri/src/utils/resolve.rs | 2 -- 2 files changed, 3 insertions(+), 50 deletions(-) diff --git a/backend/tauri/src/utils/dock.rs b/backend/tauri/src/utils/dock.rs index bedc5bda63..f4e925a814 100644 --- a/backend/tauri/src/utils/dock.rs +++ b/backend/tauri/src/utils/dock.rs @@ -3,17 +3,9 @@ pub mod macos { extern crate cocoa; extern crate objc; - use cocoa::{ - appkit::{NSApp, NSApplication, NSApplicationActivationPolicy, NSWindow}, - base::{id, nil, BOOL, NO, YES}, - }; - use objc::{ - class, - declare::ClassDecl, - msg_send, - runtime::{Object, Sel}, - sel, sel_impl, - }; + use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicy}; + use objc::runtime::YES; + pub unsafe fn show_dock_icon() { let app = NSApp(); app.setActivationPolicy_( @@ -28,41 +20,4 @@ pub mod macos { NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory, ); } - - pub fn setup_dock_click_handler() { - unsafe { - let app = NSApp(); - let superclass = class!(NSObject); - let mut decl = ClassDecl::new("AppDelegate", superclass).unwrap(); - decl.add_method( - sel!(applicationShouldHandleReopen:hasVisibleWindows:), - reopen_handler as extern "C" fn(&mut Object, Sel, id, BOOL) -> BOOL, - ); - decl.register(); - let delegate: id = msg_send![class!(AppDelegate), new]; - app.setDelegate_(delegate); - } - } - - extern "C" fn reopen_handler(_: &mut Object, _: Sel, _: id, has_visible_windows: BOOL) -> BOOL { - unsafe { - let app = NSApp(); - let current_policy: NSApplicationActivationPolicy = msg_send![app, activationPolicy]; - if current_policy - == NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory - { - if has_visible_windows == NO { - // resolve crate window - let handle = crate::core::handle::Handle::global(); - let app_handle = handle.app_handle.lock(); - if let Some(app_handle) = app_handle.as_ref() { - crate::utils::resolve::create_window(app_handle); - } - } - NO - } else { - YES - } - } - } } diff --git a/backend/tauri/src/utils/resolve.rs b/backend/tauri/src/utils/resolve.rs index ec6c18ca5d..1fc68092f2 100644 --- a/backend/tauri/src/utils/resolve.rs +++ b/backend/tauri/src/utils/resolve.rs @@ -85,8 +85,6 @@ pub fn find_unused_port() -> Result { pub fn resolve_setup(app: &mut App) { #[cfg(target_os = "macos")] app.set_activation_policy(tauri::ActivationPolicy::Accessory); - #[cfg(target_os = "macos")] - crate::utils::dock::macos::setup_dock_click_handler(); app.listen_global("react_app_mounted", move |_| { tracing::debug!("Frontend React App is mounted, reset open window counter"); reset_window_open_counter();