KeyWindow Swift Compiler Warning

What’s the most elegant way to fix my issue with “keyWindow” which has been depreciated.

Google “keyWindow deprecated”, typically the Apple Docs will tell you what replaced it

I did google and bunch of very different methods came up. Having difficulty trying to fix it without have to redo the whole logic.