Skip to content

Commit

Permalink
Updated service worker to delete old caches properly. Removed call fo…
Browse files Browse the repository at this point in the history
…r stats that are no longer in use. Removed duplicate search IDs. Versioned.
  • Loading branch information
cdevroe committed Apr 2, 2019
1 parent c7103ab commit 598ea7a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 50 deletions.
2 changes: 1 addition & 1 deletion application/config/config.php
Expand Up @@ -11,7 +11,7 @@
| version.point.release
|
*/
$config['unmark_version'] = '1.9.1';
$config['unmark_version'] = '1.9.2';

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions application/views/layouts/navigation/nav_panels.php
Expand Up @@ -21,7 +21,7 @@
<h4 class="nav-heading"><?php echo unmark_phrase('Timeline')?></h4>
<?php $this->load->view('layouts/timeline'); ?>
</div>
<div id="panel-search" class="nav-panel">
<!-- <div id="panel-search" class="nav-panel">
<h4 class="nav-heading"><?php echo unmark_phrase('Search')?></h4>
<form method="get" action="/marks/search" id="search-form">
<input type="text" name="q" id="search-input" placeholder="<?php echo unmark_phrase('SEARCH...') ?>" autocapitalize="off">
Expand All @@ -31,7 +31,7 @@
<ul class="tag-list">
<?php $this->load->view('layouts/navigation/tags_list.php'); ?>
</ul>
</div>
</div> -->
<div id="panel-settings" class="nav-panel">

<?php $this->load->view('layouts/accountlinks'); ?>
Expand Down
1 change: 1 addition & 0 deletions assets/js/unmark.actions.js
Expand Up @@ -155,6 +155,7 @@
};

// Update the count in the sidebar and graph upon mark archive/unarchive
// Not in use as of 1.9.2 (unless we bring back stats)
unmark.updateCounts = function () {
unmark.getData('stats', function (res) {

Expand Down
2 changes: 1 addition & 1 deletion assets/js/unmark.marks.js
Expand Up @@ -101,7 +101,7 @@
}
}
unmark.getData('labels', updateLabelCount);
unmark.updateCounts();
// Removed 1.9.2 unmark.updateCounts();
};

// Archive & Restore Mark
Expand Down
4 changes: 2 additions & 2 deletions assets/js/unmark.pwa.js
Expand Up @@ -7,8 +7,8 @@ if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/service-worker.js').then(function(registration) {
// Registration was successful
//console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
// registration failed :(
//console.log('ServiceWorker registration failed: ', err);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "unmark",
"url": "https://unmark.it",
"version": "1.9.1",
"version": "1.9.2",
"repository": "https://github.com/cdevroe/unmark",
"license": "https://github.com/cdevroe/unmark/blob/master/license.txt",
"description": "The open source to-do application for bookmarks.",
Expand Down
54 changes: 11 additions & 43 deletions service-worker.js
@@ -1,4 +1,4 @@
var CACHE_NAME = 'unmark-version-1.9.1';
var CACHE_NAME = 'unmark-version-1.9.2';
var urlsToCache = [
'/assets/css/unmark.css',
'/assets/libraries/jquery/jquery-2.1.0.min.js',
Expand All @@ -8,11 +8,13 @@ var urlsToCache = [
];

self.addEventListener('install', function(event) {
self.skipWaiting();
console.log('Service Worker: Installed');
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
console.log('Service Worker: Opened cache');
return cache.addAll(urlsToCache);
})
);
Expand All @@ -26,8 +28,8 @@ self.addEventListener('activate', e => {
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== cacheName) {
console.log('Service Worker: Clearing Old Cache');
if (cache !== CACHE_NAME) {
console.log('Service Worker: Clearing Old Cache ' + cache);
return caches.delete(cache);
}
})
Expand All @@ -36,42 +38,8 @@ self.addEventListener('activate', e => {
);
});

self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}

return fetch(event.request).then(
function(response) {
// Check if we received a valid response
if(!response || response.status !== 200 || response.type !== 'basic') {
return response;
}

// IMPORTANT: Clone the response. A response is a stream
// and because we want the browser to consume the response
// as well as the cache consuming the response, we need
// to clone it so we have two streams.
var responseToCache = response.clone();

caches.open(CACHE_NAME)
.then(function(cache) {
cache.put(event.request, responseToCache);
});

return response;
}
);
})
);
});


// self.addEventListener("OpenGraphData", function(e) {
// var shareData = JSON.parse(e.detail);
// $("#shared").text(shareData.url);
// })
// Call Fetch Event
self.addEventListener('fetch', e => {
console.log('Service Worker: Fetching ' + e.request);
e.respondWith(fetch(e.request).catch(() => caches.match(e.request)));
});

0 comments on commit 598ea7a

Please sign in to comment.