From fe485cc27df7c24c7d279c9d9f706e77db4d69dd Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 7 Dec 2015 23:43:28 -0800 Subject: [PATCH] Initial service worker support --- homeassistant/components/frontend/__init__.py | 16 +++++++++++++--- homeassistant/components/frontend/version.py | 2 +- .../frontend/www_static/frontend.html | 18 +++++++++--------- .../frontend/www_static/home-assistant-polymer | 2 +- .../frontend/www_static/service_worker.js | 5 +++++ script/build_frontend | 1 + 6 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 homeassistant/components/frontend/www_static/service_worker.js diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index dac2041fa56..5c97d855713 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -22,8 +22,7 @@ _LOGGER = logging.getLogger(__name__) FRONTEND_URLS = [ URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState', - '/devEvent', '/devInfo'] -STATES_URL = re.compile(r'/states(/([a-zA-Z\._\-0-9/]+)|)') + '/devEvent', '/devInfo', '/states'] _FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE) @@ -37,7 +36,8 @@ def setup(hass, config): for url in FRONTEND_URLS: hass.http.register_path('GET', url, _handle_get_root, False) - hass.http.register_path('GET', STATES_URL, _handle_get_root, False) + hass.http.register_path('GET', '/service_worker.js', + _handle_get_service_worker, False) # Static files hass.http.register_path( @@ -78,6 +78,16 @@ def _handle_get_root(handler, path_match, data): handler.wfile.write(template_html.encode("UTF-8")) +def _handle_get_service_worker(handler, path_match, data): + if handler.server.development: + sw_path = "home-assistant-polymer/build/service_worker.js" + else: + sw_path = "service_worker.js" + + handler.write_file(os.path.join(os.path.dirname(__file__), 'www_static', + sw_path)) + + def _handle_get_static(handler, path_match, data): """ Returns a static file for the frontend. """ req_file = util.sanitize_path(path_match.group('file')) diff --git a/homeassistant/components/frontend/version.py b/homeassistant/components/frontend/version.py index e291ca5bee6..83383baf11d 100644 --- a/homeassistant/components/frontend/version.py +++ b/homeassistant/components/frontend/version.py @@ -1,2 +1,2 @@ """ DO NOT MODIFY. Auto-generated by build_frontend script """ -VERSION = "d07b7ed1734ae3f2472f9ae88e0c3dea" +VERSION = "aac488c33cd4291cd0924e60a55bd309" diff --git a/homeassistant/components/frontend/www_static/frontend.html b/homeassistant/components/frontend/www_static/frontend.html index 376307744b8..907722b09ee 100644 --- a/homeassistant/components/frontend/www_static/frontend.html +++ b/homeassistant/components/frontend/www_static/frontend.html @@ -6080,12 +6080,12 @@ case"touchend":return this.addPointerListenerEnd(t,e,i,n);case"touchmove":return font-weight: 300; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; - } \ No newline at end of file + } \ No newline at end of file diff --git a/homeassistant/components/frontend/www_static/home-assistant-polymer b/homeassistant/components/frontend/www_static/home-assistant-polymer index 044a6d9810b..2bc0f827b24 160000 --- a/homeassistant/components/frontend/www_static/home-assistant-polymer +++ b/homeassistant/components/frontend/www_static/home-assistant-polymer @@ -1 +1 @@ -Subproject commit 044a6d9810b6aa662b82af0f67deb662725ad4cb +Subproject commit 2bc0f827b2477e0f338f67b24e7107243581493f diff --git a/homeassistant/components/frontend/www_static/service_worker.js b/homeassistant/components/frontend/www_static/service_worker.js new file mode 100644 index 00000000000..b60f00119e8 --- /dev/null +++ b/homeassistant/components/frontend/www_static/service_worker.js @@ -0,0 +1,5 @@ +!function(e){function t(r){if(n[r])return n[r].exports;var s=n[r]={exports:{},id:r,loaded:!1};return e[r].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([/*!*************************************!*\ + !*** ./src/service-worker/index.js ***! + \*************************************/ +function(e,t,n){"use strict";var r="0.10",s="/",c=["/","/logbook","/history","/map","/devService","/devState","/devEvent","/devInfo","/states"],i=["/static/favicon-192x192.png"];self.addEventListener("install",function(e){e.waitUntil(caches.open(r).then(function(e){return e.addAll(i.concat(s))}))}),self.addEventListener("activate",function(e){}),self.addEventListener("message",function(e){}),self.addEventListener("fetch",function(e){var t=e.request.url.substr(e.request.url.indexOf("/",7));i.includes(t)&&e.respondWith(caches.open(r).then(function(t){return t.match(e.request)})),c.includes(t)&&e.respondWith(caches.open(r).then(function(t){return t.match(s).then(function(n){var r=fetch(e.request).then(function(e){return t.put(s,e.clone()),e});return n||r})}))})}]); +//# sourceMappingURL=service_worker.js.map \ No newline at end of file diff --git a/script/build_frontend b/script/build_frontend index 70eacdb6baf..5920026486e 100755 --- a/script/build_frontend +++ b/script/build_frontend @@ -7,6 +7,7 @@ npm run frontend_prod cp bower_components/webcomponentsjs/webcomponents-lite.min.js .. cp build/frontend.html .. +cp build/service_worker.js .. # Generate the MD5 hash of the new frontend cd ../..