macOS: set activation policy by default if app is not bundled (#3961)
This commit is contained in:
parent
59b1eb5410
commit
f6b20852bf
1 changed files with 16 additions and 5 deletions
|
|
@ -5,7 +5,7 @@ use std::sync::atomic::Ordering as AtomicOrdering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy};
|
use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSRunningApplication};
|
||||||
use objc2_foundation::{MainThreadMarker, NSNotification};
|
use objc2_foundation::{MainThreadMarker, NSNotification};
|
||||||
|
|
||||||
use super::super::event_handler::EventHandler;
|
use super::super::event_handler::EventHandler;
|
||||||
|
|
@ -113,10 +113,21 @@ impl AppState {
|
||||||
// We need to delay setting the activation policy and activating the app
|
// We need to delay setting the activation policy and activating the app
|
||||||
// until `applicationDidFinishLaunching` has been called. Otherwise the
|
// until `applicationDidFinishLaunching` has been called. Otherwise the
|
||||||
// menu bar is initially unresponsive on macOS 10.15.
|
// menu bar is initially unresponsive on macOS 10.15.
|
||||||
// If no activation policy is explicitly provided, do not set it at all
|
if let Some(activation_policy) = self.activation_policy {
|
||||||
// to allow the package manifest to define behavior via LSUIElement.
|
app.setActivationPolicy(activation_policy);
|
||||||
if self.activation_policy.is_some() {
|
} else {
|
||||||
app.setActivationPolicy(self.activation_policy.unwrap());
|
// 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)]
|
#[allow(deprecated)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue