From 3fbd5e351e83e31a579f61d7b2603999221e4d3d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 28 Feb 2018 10:46:24 -0800 Subject: [PATCH] Add user agent check to frontend (#955) * Add user agent check to frontend * Remove auto generated comment. --- public/__init__.py | 25 ++++++++++++++++++++++++- setup.py | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/public/__init__.py b/public/__init__.py index c7603274c2..1b30218204 100644 --- a/public/__init__.py +++ b/public/__init__.py @@ -1,8 +1,31 @@ -"""AUTO-GENERATED. DO NOT MODIFY""" +"""Frontend for Home Assistant.""" import os +from user_agents import parse + +FAMILY_MIN_VERSION = { + 'Chrome': 54, # Object.values + 'Chrome Mobile': 54, + 'Firefox': 47, # Object.values + 'Firefox Mobile': 47, + 'Opera': 41, # Object.values + 'Edge': 14, # Array.prototype.includes added in 14 + 'Safari': 10, # Many features not supported by 9 +} def where(): """Return path to the frontend.""" return os.path.dirname(__file__) + +def version(useragent): + """Get the version for given user agent.""" + useragent = parse(useragent) + + # on iOS every browser is a Safari which we support from version 11. + if useragent.os.family == 'iOS': + # Was >= 10, temp setting it to 12 to work around issue #11387 + return useragent.os.version[0] >= 12 + + version = FAMILY_MIN_VERSION.get(useragent.browser.family) + return version and useragent.browser.version[0] >= version diff --git a/setup.py b/setup.py index f2080e190a..8625208770 100644 --- a/setup.py +++ b/setup.py @@ -13,5 +13,8 @@ setup(name='home-assistant-frontend', 'hass_frontend.*', 'hass_frontend_es5.*' ]), + install_requires=[ + 'user-agents==1.1.0', + ], include_package_data=True, zip_safe=False)