Skip to content

Commit

Permalink
Merge pull request #40 from teknologkoren/pwa
Browse files Browse the repository at this point in the history
Add PWA support
  • Loading branch information
reinefjord committed Jun 11, 2019
2 parents 93fab75 + 24053a0 commit 7adce44
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flasquelistan/factory.py
Expand Up @@ -35,10 +35,11 @@ def create_app(config=None, instance_config=None):


def register_blueprints(app):
from flasquelistan.views import auth, admin, more, quotes, strequelistan
from flasquelistan.views import auth, admin, more, quotes, serviceworker, strequelistan
app.register_blueprint(auth.mod)
app.register_blueprint(admin.mod)
app.register_blueprint(more.mod)
app.register_blueprint(serviceworker.mod)
app.register_blueprint(strequelistan.mod)
app.register_blueprint(quotes.mod)

Expand Down
Binary file added flasquelistan/static/images/icon-192.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions flasquelistan/static/js/install-serviceworker.js
@@ -0,0 +1,9 @@
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
console.log('ServiceWorker registration failed: ', err);
});
});
}
Empty file.
14 changes: 14 additions & 0 deletions flasquelistan/static/manifest.json
@@ -0,0 +1,14 @@
{
"name": "Strequelistan",
"short_name": "Streque",
"start_url": "/",
"display": "standalone",
"theme_color": "black",
"icons": [
{
"src": "/static/images/icon-192.png",
"type": "image/png",
"sizes": "192x192"
}
]
}
2 changes: 2 additions & 0 deletions flasquelistan/templates/base.html
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Strequelistan</title>
<link rel="manifest" href="/static/manifest.json">

<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/streque.css') }}">
Expand All @@ -24,5 +25,6 @@ <h1>Strequelistan</h1>
{% endblock %}
{% block base_body %}
{% endblock %}
<script src="{{ url_for('static', filename='js/install-serviceworker.js') }}"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions flasquelistan/views/serviceworker.py
@@ -0,0 +1,9 @@
import flask

mod = flask.Blueprint('serviceworker', __name__)

@mod.route('/sw.js')
def serviceworker():
response = flask.send_from_directory('static', filename='js/serviceworker.js')
response.headers['Cache-Control'] = 'no-cache'
return response

0 comments on commit 7adce44

Please sign in to comment.