Check PWA visibilty

I might be oversharing at this point, but I had connection issue when polling the server while on a mobile device, if the application was in the background. For reason’s I cannot explain. (This is on an iPhone) So I went to my good old pal google and scrounged up a solution.

Here is the wrapper I put on my timer functions that poll the server:

from anvil.js.window import document
from functools import wraps

def check_visibilty(fn):
  def wrapped(*args,**kwargs):
    if document.hidden and get_mobile_flag():
      print("NOT VISIBLE!")
      return fn(*args,**kwargs)
  return wrapped

The get_mobile_flag function was pulled from this beautiful forum :slight_smile:

That’s important because the browser works well when not visible or you’re on a different tab.