Forum > LCL

TTrayIcon.PopupMenu.OnPopup on MacOS

(1/2) > >>

CCRDude:
OS: macOS Ventura 13.0
Lazarus: 2.2 with FPC 3.2.2, Revision "unknown", x86_64-darwin-cocoa

I'm writing a small tool to handle a bunch of day-to-day stuff from a menubar icon (like auto-reconnecting a VPN or user-mounting through sshfs).
This menubar icon (TTrayIcon) has PopupMenu assigned listing VPN connections with captions indicating their state.

Usually I would now create a OnPopup event for the PopupMenu and update item captions based on their state. But OnPopup doesn't fire when the menubar icon is clicked. Neither does OnMeasureItem.
As a workaround, I would use the OnMouseDown or OnClick handlers of the TTrayIcon, but they don't get fired.

Aside from using a timer and updating regularly when it's not required (and my status updates are querying command line tools, which is much overhead to repeatedly do here), can you suggest any other events that may work here?

howardpc:
You could try Application.OnIdle to avoid introducing a timer.

CCRDude:
That wouldn't avoid the "updating regularly when it's not required" though ;)

(at some point, that will be required for the auto-reconnect, but only for those entries that need to auto-reconnect)

howardpc:
If you have an algorithm for determining when it's not required, you can disable the handler for those cases, and re-enable it when the algorithm tells it to get going again.

CCRDude:
Well, it's updating the UI when the menu opens, the "algorithm" is clear, see my initial post.

--- Quote ---Usually I would now create a OnPopup event for the PopupMenu and update item captions based on their state.
--- End quote ---

An alternative would be a system event telling me a VPN state has changed. I don't know any, do you?
(and then, a second for when a volume has been mounted or unmounted)

Navigation

[0] Message Index

[#] Next page

Go to full version