Skip to content

Commit

Permalink
fixup! cache webapp using a service worker to enable offline startup
Browse files Browse the repository at this point in the history
  • Loading branch information
niol committed Aug 21, 2018
1 parent 9844c8b commit 417bf48
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion helpers/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function genOfflineSW() {

fwrite($f, "var offlineManifest = {\n");
fwrite($f, " subdir: '" . $subdir . "',\n");
fwrite($f, " version: " . $staticmtime . ",\n");
fwrite($f, ' version: ' . $staticmtime . ",\n");
fwrite($f, " files: [\n");
fwrite($f, " '" . $subdir . "',\n");

Expand Down
18 changes: 8 additions & 10 deletions public/js/selfoss-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ var selfoss = {
window.addEventListener('load', function() {
navigator.serviceWorker.register('selfoss-sw-offline.js')
.then(function(reg) {
selfoss.listenWaitingSW(reg, function(reg) {
selfoss.ui.notifyNewVersion(function() {
if (reg.waiting) {
reg.waiting.postMessage('skipWaiting');
}
selfoss.listenWaitingSW(reg, function(reg) {
selfoss.ui.notifyNewVersion(function() {
if (reg.waiting) {
reg.waiting.postMessage('skipWaiting');
}
});
});
});
});
});

navigator.serviceWorker.addEventListener('controllerchange',
Expand Down Expand Up @@ -602,11 +602,9 @@ var selfoss = {

if (!reg) {
return;
}
else if (reg.waiting) {
} else if (reg.waiting) {
return callback(reg);
}
else if (reg.installing) {
} else if (reg.installing) {
awaitStateChange();
reg.addEventListener('updatefound', awaitStateChange);
}
Expand Down
4 changes: 4 additions & 0 deletions public/js/selfoss-sw-offline.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* ServiceWorker environment, and prepended script */
/* global offlineManifest:false, Promise */


self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(offlineManifest.version).then(function(cache) {
Expand Down
10 changes: 5 additions & 5 deletions public/js/selfoss-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ selfoss.ui = {


notifyNewVersion: function(cb) {
cb = (typeof cb !== 'undefined') ? cb: false;
cb = (typeof cb !== 'undefined') ? cb : false;

if (!cb) {
cb = function() {
Expand All @@ -295,10 +295,10 @@ selfoss.ui = {
}

selfoss.ui.showMessage('selfoss has been updated, please reload',
'Reload',
function() {
cb();
});
'Reload',
function() {
cb();
});
},


Expand Down

0 comments on commit 417bf48

Please sign in to comment.