Skip to content

Commit cba680f

Browse files
authored
feat: PWA (#199)
* favicon path fix * Add service worker * Add routes * Dynamic Manifest * Workbox 5.1.2 updated
1 parent 04cae7a commit cba680f

20 files changed

+145
-2
lines changed

lms/lmsweb/manifest.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from lms.lmsweb.config import SERVER_ADDRESS
2+
3+
4+
MANIFEST = {
5+
'name': "Python's Course LMS",
6+
'short_name': 'LMS',
7+
'theme_color': '#1290f4',
8+
'background_color': '#2196f3',
9+
'display': 'standalone',
10+
'scope': SERVER_ADDRESS,
11+
'start_url': SERVER_ADDRESS,
12+
'icons': [
13+
{
14+
'src': '/static/avatar.jpg',
15+
'type': 'image/jpeg',
16+
'sizes': '512x512',
17+
},
18+
{
19+
'src': '/static/icons/android-icon-36x36.png',
20+
'sizes': '36x36',
21+
'type': 'image/png',
22+
'density': '0.75',
23+
},
24+
{
25+
'src': '/static/icons/android-icon-48x48.png',
26+
'sizes': '48x48',
27+
'type': 'image/png',
28+
'density': '1.0',
29+
},
30+
{
31+
'src': '/static/icons/android-icon-72x72.png',
32+
'sizes': '72x72',
33+
'type': 'image/png',
34+
'density': '1.5',
35+
},
36+
{
37+
'src': '/static/icons/android-icon-96x96.png',
38+
'sizes': '96x96',
39+
'type': 'image/png',
40+
'density': '2.0',
41+
},
42+
{
43+
'src': '/static/icons/android-icon-144x144.png',
44+
'sizes': '144x144',
45+
'type': 'image/png',
46+
'density': '3.0',
47+
},
48+
{
49+
'src': '/static/icons/android-icon-192x192.png',
50+
'sizes': '192x192',
51+
'type': 'image/png',
52+
'density': '4.0',
53+
},
54+
],
55+
}

lms/lmsweb/views.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from functools import wraps
32
from typing import Optional
43
from urllib.parse import urljoin, urlparse
@@ -24,12 +23,14 @@
2423
)
2524
from lms.lmsweb import babel, routes, webapp
2625
from lms.lmsweb.config import LANGUAGES, LOCALE
26+
from lms.lmsweb.manifest import MANIFEST
2727
from lms.models import notifications, share_link, solutions, upload
2828
from lms.models.errors import LmsError, UploadError, fail
2929
from lms.utils.consts import RTL_LANGUAGES
3030
from lms.utils.files import get_language_name_by_extension
3131
from lms.utils.log import log
3232

33+
3334
login_manager = LoginManager()
3435
login_manager.init_app(webapp)
3536
login_manager.session_protection = 'strong'
@@ -132,12 +133,27 @@ def logout():
132133
@webapp.route('/favicon.ico')
133134
def favicon():
134135
return send_from_directory(
135-
os.path.join(webapp.root_path, 'static'),
136+
webapp.static_folder,
136137
'favicon.ico',
137138
mimetype='image/vnd.microsoft.icon',
138139
)
139140

140141

142+
@webapp.route('/manifest.json')
143+
def manifest():
144+
return jsonify(MANIFEST)
145+
146+
147+
@webapp.route('/sw.js')
148+
def serviceWorker():
149+
response = make_response(send_from_directory(
150+
webapp.static_folder,
151+
'sw.js',
152+
))
153+
response.headers['Cache-Control'] = 'no-cache'
154+
return response
155+
156+
141157
@webapp.before_request
142158
def banned_page():
143159
if (
16.3 KB
Loading
25.9 KB
Loading
3.03 KB
Loading
4.16 KB
Loading
6.51 KB
Loading
9.2 KB
Loading
23.5 KB
Loading
26.5 KB
Loading

0 commit comments

Comments
 (0)