Help with writing a widget for BTT

I want to make sure I get it right but if a Widget is not marked not visible like so:

The code is not going to be ran by BTT in background right?

Also is it okay to run the below code every 1 second? I want to emulate menu bar reactivity but am afraid I will burn the battery this way. I feel like ideally it would not have to be me querying to ask what keyboard layout I have every 1 second but BTT reacting on keyboard layout switching and making the call only then, if that's possible.