Skip to main content

Posts

Showing posts with the label SwiftUI

macOS Menu Bar Apps: SwiftUI Popovers and WindowManagement APIs

  Building a "Status Bar Only" application (agent app) on macOS seems deceptively simple: set a flag in   Info.plist , use a   MenuBarExtra , and you are done. However, as soon as you attempt to add complex interactivity—text inputs, intricate state management, or custom window sizing—the abstraction leaks. You encounter the classic "Agent App" lifecycle problems: The popover doesn't automatically close when clicking the desktop. Text fields refuse to accept focus because the app never officially "activates." MenuBarExtra  in  .window  style lacks fine-grained control over positioning relative to the screen edge. To build a production-grade utility that feels like native macOS Control Center modules, we must bypass the  MenuBarExtra  wrapper and orchestrate  NSStatusItem ,  NSPopover , and the  NSApplication  activation policy manually. The Root Cause: Application Activation Policy The core issue lies in how macOS treats applic...