Identify front window in document-based Mac app

I have a document-based Mac app using the SwiftUI life-cycle.

It works well except that I cannot work out how to tell which window is frontmost.

So if I have a menu item that operates on a document, how can I apply it to the document in the frontmost window?

Any approach using notifications or passthrough subjects gets applied to all open windows.

I think that the focusable modifiers are supposed to deal with this, but they do not appear to work.
Identify front window in document-based Mac app
 
 
Q