Skip to content

Commit

Permalink
macOS: set activation policy by default if app is not bundled (#3961)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns authored Nov 18, 2024
1 parent 59b1eb5 commit f6b2085
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/platform_impl/apple/appkit/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit f6b2085

Please sign in to comment.