Detecting focus of another window

Hi. I’m wanting to make an Electron app to add extra buttons to the Touch Bar for Roblox Studio. I was wondering if there was a way to detect a new window focusing so I can add Touch Bar buttons when Roblox Studio is in focus.