I'm trying to fade in a popover on the docktile of my app. The whole thing should work like this: when a user clicks on the Dock icon, a popover appears above the Dock icon. The DockTile that belongs to the app is determined with NSApplication.shared.dockTile and I can also catch the click on the DockTile with applicationShouldHandleReopen. The view needed to display a popup is an NSImage which represents the ContentView of the DockTile.
import Cocoa
import Foundation
let applicationDelegate = NSApplication.shared.delegate as! AppDelegate
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let appDockTile = NSApplication.shared.dockTile
let popover = NSPopover()
func applicationDidFinishLaunching(_ aNotification: Notification) {
let dockIcon = NSImage(named: "AppIcon")
appDockTile.contentView = NSImageView(image: dockIcon!)
appDockTile.display()
popover.behavior = .transient
popover.resignFirstResponder()
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
popover.show(relativeTo: appDockTile.contentView!.bounds, of: appDockTile.contentView!, preferredEdge: NSRectEdge.minY)
return false
}
}
However, the NSPopover is not displayed and raizes always the following error message:
[NSPopover showRelativeToRect:ofView:preferredEdge:]: view has no window. You must supply a view in a window.
A popup can apparently only be displayed with reference to a view on a NSWindow. This would also be understandable if an NSPopover could not be displayed without problems at an NSStatusBarButton - and similar to a DockTile there is nothing to be seen of an NSWindow.
Does anyone have an idea or tip on how to display a popover to a DockTile or is that really not possible?