I have a multiple window Mac Catalyst app. I'm using a NSToolbar and the menu bar via UIMenuBuilder.
I noticed after changing windows the menu bar isn't always validating properly. For example my app implements "Undo" and "redo". So I can reproduce the issue using these steps:
- Perform an action that can be undone.
- Open a new window. This new window has its own undo manager.
- In the Menu bar select Edit -> Undo
- Undo validates even though the current window has nothing on its local undo stack. If invoked undo is performed on the inactive window which definitely seems wrong.
The same thing sometimes happens in reverse (that is, undo doesn't validate when it should after switching windows). This also happens with other actions after switching windows.
Sometimes I can get the actions to validate by hitting the Tab key to move focus then shift tabbing back, which seems to force proper lookup in the responder chain (but sometimes that doesn't work).
It seems that Catalyst is losing track of the real active window/window scene for some reason and is validating actions on the wrong window scene.
Anyone experience this and know where I could be going wrong and/or know of a possible workaround?
I tried subclassing UIApplication and implementing the methods there (and then forwarding them to the active UIWindowScene). However this doesn't work, the wrong window scene has its activationState set to UISceneActivationStateForegroundActive when the problem occurs.