Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PWA support #40

Merged
merged 4 commits into from Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion flasquelistan/factory.py
Expand Up @@ -36,10 +36,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">

{% assets "css_common" %}
<link rel="stylesheet" href="{{ ASSET_URL }}">
Expand All @@ -23,5 +24,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