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

Custom manifest.json and fixed some issues #90

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dist/
*.egg-info/
.tox/
.coverage
.DS_Store
.DS_Store
venv
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Configure your app name, description, icons and splash screen images in settings
```python

PWA_APP_NAME = 'My App'
PWA_APP_SHORT_NAME = 'My App Short Name'
PWA_APP_DESCRIPTION = "My app description"
PWA_APP_THEME_COLOR = '#0A0302'
PWA_APP_BACKGROUND_COLOR = '#ffffff'
Expand All @@ -58,13 +59,13 @@ PWA_APP_STATUS_BAR_COLOR = 'default'
PWA_APP_ICONS = [
{
'src': '/static/images/my_app_icon.png',
'sizes': '160x160'
'size': '160x160'
}
]
PWA_APP_ICONS_APPLE = [
{
'src': '/static/images/my_apple_icon.png',
'sizes': '160x160'
'size': '160x160'
}
]
PWA_APP_SPLASH_SCREEN = [
Expand Down Expand Up @@ -186,11 +187,13 @@ self.addEventListener("fetch", event => {

Adding Your Own Service Worker
=====
To add service worker functionality, you'll want to create a `serviceworker.js` or similarly named template in a template directory, and then point at it using the PWA_SERVICE_WORKER_PATH variable (PWA_APP_FETCH_URL is passed through).
To add service worker and manifest functionality, you'll want to create a `serviceworker.js` and `manifest.json` respectively or similarly named template in a template directory, and then point at it using the PWA_SERVICE_WORKER_PATH and PWA_MANIFEST_PATH variable (PWA_APP_FETCH_URL is passed through).

```python
PWA_SERVICE_WORKER_PATH = os.path.join(BASE_DIR, 'my_app', 'serviceworker.js')

PWA_MANIFEST_PATH = os.path.join(BASE_DIR, 'my_app','manifest.json')

```

The offline view
Expand Down
8 changes: 8 additions & 0 deletions pwa/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
PWA_SERVICE_WORKER_PATH = getattr(settings, 'PWA_SERVICE_WORKER_PATH',
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates',
'serviceworker.js'))

# Path to the manifest implementation.
PWA_MANIFEST_PATH = getattr(settings,'PWA_MANIFEST_PATH',
os.path.join(os.path.abspath(os.path.dirname(__file__)), 'templates',
'manifest.json'))


# App parameters to include in manifest.json and appropriate meta tags
PWA_APP_NAME = getattr(settings, 'PWA_APP_NAME', 'MyApp')
PWA_APP_SHORT_NAME = getattr(settings,'PWA_APP_SHORT_NAME','My App Short Name')
PWA_APP_DESCRIPTION = getattr(settings, 'PWA_APP_DESCRIPTION', 'My Progressive Web App')
PWA_APP_ROOT_URL = resolve_url(getattr(settings, 'PWA_APP_ROOT_URL', _PWA_SCRIPT_PREFIX))
PWA_APP_THEME_COLOR = getattr(settings, 'PWA_APP_THEME_COLOR', '#000')
Expand Down
2 changes: 1 addition & 1 deletion pwa/templates/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load pwa %}
{
"name": {{ PWA_APP_NAME|js }},
"short_name": {{ PWA_APP_NAME|js }},
"short_name": {{ PWA_APP_SHORT_NAME|js }},
"description": {{ PWA_APP_DESCRIPTION|js }},
"start_url": {{ PWA_APP_START_URL|js }},
"display": {{ PWA_APP_DISPLAY|js }},
Expand Down
5 changes: 4 additions & 1 deletion pwa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ def service_worker(request):


def manifest(request):
response = HttpResponse(open(app_settings.PWA_MANIFEST_PATH).read(), content_type='application/json')
if response != None and response != '':
return response
return render(request, 'manifest.json', {
setting_name: getattr(app_settings, setting_name)
for setting_name in dir(app_settings)
if setting_name.startswith('PWA_')
}, content_type='application/json')


def offline(request):
return render(request, "offline.html")