diff --git a/app.yaml b/app.yaml index 05ce4ec..16fb1be 100644 --- a/app.yaml +++ b/app.yaml @@ -12,6 +12,10 @@ handlers: http_headers: X-Content-Type-Options: nosniff +- url: /manifest.json + script: manifest.app + secure: always + - url: /baby/.* static_files: static/babystats.html upload: static/babystats.html diff --git a/manifest.py b/manifest.py new file mode 100644 index 0000000..f9cceb9 --- /dev/null +++ b/manifest.py @@ -0,0 +1,23 @@ +import json +import webapp2 + + +class Manifest(webapp2.RequestHandler): + + def get(self): + self.response.headers['Content-Type'] = 'application/json' + json.dump({ + 'name': self.request.get('name'), + 'display': 'standalone', + 'icons': [ + { + 'src': '/static/icon.png', + 'sizes': '256x256', + }, + ], + }, self.response.out) + + +app = webapp2.WSGIApplication([ + ('/manifest.json', Manifest), +]) diff --git a/static/babystats.js b/static/babystats.js index 585b1ad..42b6899 100644 --- a/static/babystats.js +++ b/static/babystats.js @@ -147,6 +147,10 @@ BabyStats.prototype.checkInit_ = function() { return; } + this.manifest_ = document.createElement('link'); + this.manifest_.rel = 'manifest'; + document.head.appendChild(this.manifest_); + this.buildCells_(); this.buildLayout_(); @@ -251,6 +255,8 @@ BabyStats.prototype.handleMessage_ = function(isEvent, message) { } document.title = message.message.child_name; this.displayChildName_.textContent = message.message.child_name; + this.manifest_.href = + '/manifest.json?name=' + encodeURIComponent(this.childName_.value); break; default: