Thank you!!!! This issue has been plaguing me for over a year! Utilizing traitCollection.activeAppearance solves the problem!
https://stackoverflow.com/a/75440759/3765792
or simply if you want to grab the active window
UIApplication.shared.windows.filter { $0.isKeyWindow }.first { $0.traitCollection.activeAppearance == .active }