New app lifecycle and undoManager

Currently I have my AppDelegate be an NSWindowDelegate so that I can make windowWillReturnUndoManager return the undoManager of my viewContext. This makes undo/redo work in sync with any NSManagedObject changes.

Is this functionality possible with the new app lifecycle (@mainApp and Scene)? There is an undoManager in Environment, but you can't set it yourself, and there's no clue as to how it is set by the framework. It seems to work automatically if for example a TextField is first responder, but it does not work for my own custom view that is an NSResponder with an undoManager behind an NSViewRepresentable.
New app lifecycle and undoManager
 
 
Q