Search code examples
swiftrefreshmenubar

Refreshing of Menu Bar View when NSMenu is opened


I am developing an app, that has a custom view in the menu bar. The menu bar extra is a custom NSView that is redrawn every second. When I open the NSMenu of the view, the view freezes and no longer redraws itself. I am using

self.graph.needsDisplay = true

to trigger a redraw.

Is it possible to refresh a NSView in the menu bar when the NSMenu is opened?


Solution

  • turns out it was a duplicate of this topic

    The solution is to add the timer to the RunLoop:

    RunLoop.main.add(timer, forMode: .commonModes)