diff --git a/html/account-me.ejs b/html/account-me.ejs index 7c5b353a..4528f476 100644 --- a/html/account-me.ejs +++ b/html/account-me.ejs @@ -92,4 +92,10 @@ a { - \ No newline at end of file + + + \ No newline at end of file diff --git a/html/channel.ejs b/html/channel.ejs index 65f0e388..f2869bd6 100644 --- a/html/channel.ejs +++ b/html/channel.ejs @@ -1416,4 +1416,9 @@ document.getElementById('search').addEventListener('keyup', function () { <% } catch (error) { %> - <% } %> \ No newline at end of file + <% } %> + \ No newline at end of file diff --git a/html/landing.ejs b/html/landing.ejs index db7a823b..164341da 100644 --- a/html/landing.ejs +++ b/html/landing.ejs @@ -108,4 +108,9 @@ body { - \ No newline at end of file + + \ No newline at end of file diff --git a/html/poketube.ejs b/html/poketube.ejs index a34b6259..48f366d5 100644 --- a/html/poketube.ejs +++ b/html/poketube.ejs @@ -3130,4 +3130,10 @@ window.addEventListener('load', () => { <% } catch (error) { %> <%- error %> - <% } %> \ No newline at end of file + <% } %> + + \ No newline at end of file diff --git a/html/search-web.ejs b/html/search-web.ejs index 085cbb01..5177c905 100644 --- a/html/search-web.ejs +++ b/html/search-web.ejs @@ -469,4 +469,8 @@ Web - \ No newline at end of file + \ No newline at end of file diff --git a/html/search.ejs b/html/search.ejs index afa3933c..7a7bc521 100644 --- a/html/search.ejs +++ b/html/search.ejs @@ -578,4 +578,8 @@ font-weight: 1000; - \ No newline at end of file + \ No newline at end of file diff --git a/pwa/offline.html b/pwa/offline.html new file mode 100644 index 00000000..3aa7c5fb --- /dev/null +++ b/pwa/offline.html @@ -0,0 +1,47 @@ + + + + PokeTube + + +
+
+

Oh no ;-;

+

Looks like you're offline, check your internet connection and try again.

+
+
+ + + + \ No newline at end of file diff --git a/pwa/service-worker.js b/pwa/service-worker.js new file mode 100644 index 00000000..2ce1c1d8 --- /dev/null +++ b/pwa/service-worker.js @@ -0,0 +1,34 @@ +'use strict'; + +var cacheVersion = 1; +var currentCache = { + offline: 'offline-cache' + cacheVersion +}; +const offlineUrl = 'offline'; + +this.addEventListener('install', event => { + event.waitUntil( + caches.open(currentCache.offline).then(function (cache) { + return cache.addAll([ + offlineUrl + ]); + }) + ); +}); + +this.addEventListener('fetch', event => { + if (event.request.mode === 'navigate' || (event.request.method === 'GET' && event.request.headers.get('accept').includes('text/html'))) { + event.respondWith( + fetch(event.request.url).catch(error => { + return caches.match(offlineUrl); + }) + ); + } + else { + event.respondWith(caches.match(event.request) + .then(function (response) { + return response || fetch(event.request); + }) + ); + } +}); \ No newline at end of file diff --git a/src/libpoketube/init/pages-static.js b/src/libpoketube/init/pages-static.js index 3ca2d6db..31467383 100644 --- a/src/libpoketube/init/pages-static.js +++ b/src/libpoketube/init/pages-static.js @@ -87,8 +87,16 @@ module.exports = function (app, config, renderTemplate) { renderTemplate(res, req, "content-settings.ejs"); }); - app.get("/manifest.json", function (req, res) { - res.sendFile("manifest.json", { root: location_pwa }); + app.get("/offline", function (req, res) { + res.sendFile("offline.html", { root: location_pwa }); + }); + + app.get("/manifest.json", function (req, res) { + res.sendFile("manifest.json", { root: location_pwa }); + }); + + app.get("/service-worker.js", function (req, res) { + res.sendFile("service-worker.js", { root: location_pwa }); });