diff --git a/src/platform_impl/apple/appkit/app_state.rs b/src/platform_impl/apple/appkit/app_state.rs index c2f107ee8c..9ff1e95720 100644 --- a/src/platform_impl/apple/appkit/app_state.rs +++ b/src/platform_impl/apple/appkit/app_state.rs @@ -5,7 +5,7 @@ use std::sync::atomic::Ordering as AtomicOrdering; use std::sync::Arc; use std::time::Instant; -use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy}; +use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSRunningApplication}; use objc2_foundation::{MainThreadMarker, NSNotification}; use super::super::event_handler::EventHandler; @@ -113,10 +113,21 @@ impl AppState { // We need to delay setting the activation policy and activating the app // until `applicationDidFinishLaunching` has been called. Otherwise the // menu bar is initially unresponsive on macOS 10.15. - // If no activation policy is explicitly provided, do not set it at all - // to allow the package manifest to define behavior via LSUIElement. - if self.activation_policy.is_some() { - app.setActivationPolicy(self.activation_policy.unwrap()); + if let Some(activation_policy) = self.activation_policy { + app.setActivationPolicy(activation_policy); + } else { + // If no activation policy is explicitly provided, and the application + // is bundled, do not set the activation policy at all, to allow the + // package manifest to define the behavior via LSUIElement. + // + // See: + // - https://github.com/rust-windowing/winit/issues/261 + // - https://github.com/rust-windowing/winit/issues/3958 + let is_bundled = + unsafe { NSRunningApplication::currentApplication().bundleIdentifier().is_some() }; + if !is_bundled { + app.setActivationPolicy(NSApplicationActivationPolicy::Regular); + } } #[allow(deprecated)]