[HELP] Detecting if FiveM client is in the backrgound/on tray

Hello!

I was trying to figure out how i could detect if the fivem client is in the background/on tray/not focused.

The problem is that, i have a script that uses nui for sound play, and those sounds doesn’t stop even if the fivem “loses focus”.

Is there a way to detect that?

pause on focus loss ? but it is a setting so most of users disable it.
so you can fix the users who has it enabled with this native

IsPauseMenuActive()

Well, it would count as a half solution because not every player has it enabled, and i dont want to stop these sounds in the menu.