Dynamically-generated manifests.

This commit is contained in:
Ian Gulliver
2016-01-07 20:01:56 -08:00
parent 55f49734ab
commit defbc3d38a
3 changed files with 33 additions and 0 deletions

View File

@@ -12,6 +12,10 @@ handlers:
http_headers: http_headers:
X-Content-Type-Options: nosniff X-Content-Type-Options: nosniff
- url: /manifest.json
script: manifest.app
secure: always
- url: /baby/.* - url: /baby/.*
static_files: static/babystats.html static_files: static/babystats.html
upload: static/babystats.html upload: static/babystats.html

23
manifest.py Normal file
View File

@@ -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),
])

View File

@@ -147,6 +147,10 @@ BabyStats.prototype.checkInit_ = function() {
return; return;
} }
this.manifest_ = document.createElement('link');
this.manifest_.rel = 'manifest';
document.head.appendChild(this.manifest_);
this.buildCells_(); this.buildCells_();
this.buildLayout_(); this.buildLayout_();
@@ -251,6 +255,8 @@ BabyStats.prototype.handleMessage_ = function(isEvent, message) {
} }
document.title = message.message.child_name; document.title = message.message.child_name;
this.displayChildName_.textContent = message.message.child_name; this.displayChildName_.textContent = message.message.child_name;
this.manifest_.href =
'/manifest.json?name=' + encodeURIComponent(this.childName_.value);
break; break;
default: default: