forked from vgaicuks/django-pwa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included the default serviceworker, updated the manifest, Add the def…
…ault offline page, updated the unit test, Redme
- Loading branch information
1 parent
73151d2
commit 79c6963
Showing
25 changed files
with
252 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include *.md | ||
recursive-include pwa/templates * | ||
recursive-include pwa/templates * | ||
recursive-include pwa/static * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = 'pwa.apps.PwaConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% load static %}<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Default offline template</title> | ||
<link href="{% static '/css/django-pwa-app.css' %}" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<h1>You are currently not connected to any networks.</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,53 @@ | ||
// Empty Service Worker implementation. To use your own Service Worker, set the PWA_SERVICE_WORKER_PATH variable in | ||
// settings.py | ||
// Base Service Worker implementation. To use your own Service Worker, set the PWA_SERVICE_WORKER_PATH variable in settings.py | ||
|
||
var staticCacheName = "django-pwa-v" + new Date().getTime(); | ||
var filesToCache = [ | ||
'/offline', | ||
'/static/css/django-pwa-app.css', | ||
'/static/images/icons/icon-72x72.png', | ||
'/static/images/icons/icon-96x96.png', | ||
'/static/images/icons/icon-128x128.png', | ||
'/static/images/icons/icon-144x144.png', | ||
'/static/images/icons/icon-152x152.png', | ||
'/static/images/icons/icon-192x192.png', | ||
'/static/images/icons/icon-384x384.png', | ||
'/static/images/icons/icon-512x512.png', | ||
]; | ||
|
||
// Cache on install | ||
self.addEventListener("install", event => { | ||
this.skipWaiting(); | ||
event.waitUntil( | ||
caches.open(staticCacheName) | ||
.then(cache => { | ||
return cache.addAll(filesToCache); | ||
}) | ||
) | ||
}); | ||
|
||
// Clear cache on activate | ||
self.addEventListener('activate', event => { | ||
event.waitUntil( | ||
caches.keys().then(cacheNames => { | ||
return Promise.all( | ||
cacheNames | ||
.filter(cacheName => (cacheName.startsWith("django-pwa-"))) | ||
.filter(cacheName => (cacheName !== staticCacheName)) | ||
.map(cacheName => caches.delete(cacheName)) | ||
); | ||
}) | ||
); | ||
}); | ||
|
||
// Serve from Cache | ||
self.addEventListener("fetch", event => { | ||
event.respondWith( | ||
caches.match(event.request) | ||
.then(response => { | ||
return response || fetch(event.request); | ||
}) | ||
.catch(() => { | ||
return caches.match('offline'); | ||
}) | ||
) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from django.conf.urls import url | ||
from .views import manifest, service_worker | ||
from django.urls import path | ||
|
||
from .views import Manifest, ServiceWorker, OfflineView | ||
|
||
# Serve up serviceworker.js and manifest.json at the root | ||
urlpatterns = [ | ||
url('^serviceworker.js$', service_worker, name="serviceworker"), | ||
url('^manifest.json$', manifest, name="manifest") | ||
path('serviceworker.js', ServiceWorker.as_view(), name='serviceworker'), | ||
path('manifest.json', Manifest.as_view(), name='manifest'), | ||
path('offline', OfflineView.as_view(), name='offline') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
from django.views.generic.base import TemplateView | ||
|
||
from . import app_settings | ||
|
||
|
||
def service_worker(request): | ||
response = HttpResponse(open(app_settings.PWA_SERVICE_WORKER_PATH).read(), content_type='application/javascript') | ||
return response | ||
class ServiceWorker(TemplateView): | ||
content_type = 'application/javascript' | ||
template_name = app_settings.PWA_SERVICE_WORKER_PATH | ||
|
||
def get_context_data(self, **kwargs): | ||
kwargs['PWA_APP_FETCH_URL'] = app_settings.PWA_APP_FETCH_URL | ||
return super().get_context_data(**kwargs) | ||
|
||
|
||
def manifest(request): | ||
return render(request, 'manifest.json', { | ||
setting_name: getattr(app_settings, setting_name) | ||
for setting_name in dir(app_settings) | ||
if setting_name.startswith('PWA_') | ||
}) | ||
class Manifest(TemplateView): | ||
content_type = 'application/json' | ||
template_name = 'manifest.json' | ||
|
||
def get_context_data(self, **kwargs): | ||
for setting_name in dir(app_settings): | ||
if setting_name.startswith('PWA_'): | ||
kwargs[setting_name] = getattr(app_settings, setting_name) | ||
return super().get_context_data(**kwargs) | ||
|
||
|
||
class OfflineView(TemplateView): | ||
template_name = "offline.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,6 @@ | |
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'mydatabase', | ||
} | ||
} | ||
} | ||
|
||
STATIC_URL = '/static/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.