Give the menu-bar hint popover an explicit size so it actually shows
NSPopover measures its content when show() is called, and a container sized only by Auto Layout constraints has no frame to report yet, so show() failed silently and the hint never appeared. The label and container now carry explicit frames, and the view controller states its preferredContentSize. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79395ef9d6
commit
a740b53627
1 file changed
+12
-8
@@ -442,25 +442,29 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, LiveSt
|
|||||||
guard !MenuBarHintShown.value, let button = statusItem.button else { return }
|
guard !MenuBarHintShown.value, let button = statusItem.button else { return }
|
||||||
MenuBarHintShown.value = true
|
MenuBarHintShown.value = true
|
||||||
|
|
||||||
|
// Sized with an explicit frame rather than Auto Layout constraints
|
||||||
|
// alone: NSPopover computes its window size synchronously from
|
||||||
|
// contentViewController.view at the moment show() is called, and a
|
||||||
|
// container with no frame of its own — only constraints pinning a
|
||||||
|
// child to its edges — has nothing to report yet, so show() silently
|
||||||
|
// fails (isShown comes back false, nothing appears).
|
||||||
let label = NSTextField(wrappingLabelWithString: "Claude isn't running — click here to start a profile.")
|
let label = NSTextField(wrappingLabelWithString: "Claude isn't running — click here to start a profile.")
|
||||||
label.font = .systemFont(ofSize: 13)
|
label.font = .systemFont(ofSize: 13)
|
||||||
label.isEditable = false
|
label.isEditable = false
|
||||||
label.isBordered = false
|
label.isBordered = false
|
||||||
label.drawsBackground = false
|
label.drawsBackground = false
|
||||||
label.preferredMaxLayoutWidth = 200
|
label.preferredMaxLayoutWidth = 200
|
||||||
|
label.frame = NSRect(x: 14, y: 12, width: 200, height: 40)
|
||||||
|
label.sizeToFit()
|
||||||
|
label.frame.origin = NSPoint(x: 14, y: 12)
|
||||||
|
|
||||||
let container = NSView()
|
let containerSize = NSSize(width: label.frame.width + 28, height: label.frame.height + 24)
|
||||||
|
let container = NSView(frame: NSRect(origin: .zero, size: containerSize))
|
||||||
container.addSubview(label)
|
container.addSubview(label)
|
||||||
label.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
label.topAnchor.constraint(equalTo: container.topAnchor, constant: 12),
|
|
||||||
label.bottomAnchor.constraint(equalTo: container.bottomAnchor, constant: -12),
|
|
||||||
label.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 14),
|
|
||||||
label.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -14),
|
|
||||||
])
|
|
||||||
|
|
||||||
let viewController = NSViewController()
|
let viewController = NSViewController()
|
||||||
viewController.view = container
|
viewController.view = container
|
||||||
|
viewController.preferredContentSize = containerSize
|
||||||
|
|
||||||
let popover = NSPopover()
|
let popover = NSPopover()
|
||||||
popover.contentViewController = viewController
|
popover.contentViewController = viewController
|
||||||
|
|||||||
Reference in new issue
Block a user