From a01d85411c8ff7ae47a6637d600f50ec8dbe7604 Mon Sep 17 00:00:00 2001 From: antelle Date: Mon, 23 Sep 2019 20:32:56 +0200 Subject: [PATCH] fix #156: using ServiceWorker instead of AppCache --- Gruntfile.js | 24 +++---------------- app/manifest.appcache | 6 ----- app/scripts/comp/app/runtime-info.js | 1 + app/scripts/comp/app/updater.js | 30 +++++++++++------------ app/service-worker.js | 19 +++++++++++++++ build/tasks/grunt-sign-html.js | 36 ---------------------------- build/webpack.config.js | 3 ++- grunt.entrypoints.js | 3 +-- grunt.tasks.js | 5 ++-- package.json | 4 ++-- release-notes.md | 1 + 11 files changed, 46 insertions(+), 86 deletions(-) create mode 100644 app/service-worker.js delete mode 100644 build/tasks/grunt-sign-html.js diff --git a/Gruntfile.js b/Gruntfile.js index 8bc2bc69..6f556b80 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -183,19 +183,9 @@ module.exports = function(grunt) { }, files: { 'dist/manifest.appcache': 'app/manifest.appcache' } }, - 'manifest-html': { - options: { - replacements: [ - { pattern: ' { + logger.info('Service worker registered'); + reg.addEventListener('updatefound', () => { + if (reg.active) { + logger.info('Service worker found an update'); + UpdateModel.set({ updateStatus: 'ready' }); + } + }); + }) + .catch(e => { + logger.error('Failed to register a service worker', e); + }); } }, @@ -258,15 +267,6 @@ const Updater = { return err.toString(); } return null; - }, - - checkAppCacheUpdateReady() { - if (window.applicationCache.status === window.applicationCache.UPDATEREADY) { - try { - window.applicationCache.swapCache(); - } catch (e) {} - UpdateModel.set({ updateStatus: 'ready' }); - } } }; diff --git a/app/service-worker.js b/app/service-worker.js new file mode 100644 index 00000000..a5fd2a2b --- /dev/null +++ b/app/service-worker.js @@ -0,0 +1,19 @@ +const VERSION = '0.0.0'; + +self.addEventListener('install', event => { + event.waitUntil( + caches.open('v1').then(cache => { + return fetch('.?v=' + VERSION).then(response => { + if (response.ok) { + cache.put('.', response); + } + }); + }) + ); +}); + +self.addEventListener('fetch', event => { + event.respondWith( + caches.match(event.request.url).then(response => response || fetch(event.request)) + ); +}); diff --git a/build/tasks/grunt-sign-html.js b/build/tasks/grunt-sign-html.js deleted file mode 100644 index 1134b6e1..00000000 --- a/build/tasks/grunt-sign-html.js +++ /dev/null @@ -1,36 +0,0 @@ -module.exports = function(grunt) { - grunt.registerMultiTask('sign-html', 'Signs html page with a private key', function() { - if (this.options().skip) { - grunt.log.writeln('Skipped app html signing'); - return; - } - const done = this.async(); - const fs = require('fs'); - const sign = require('../util/sign'); - const data = fs.readFileSync(this.options().file); - let fileStr = data.toString(); - const marker = '//' dist/index.html > ../keeweb-beta/index.html && cd ../keeweb-beta && git add index.html && git commit -a -m 'beta' && git push origin master", + "build-beta": "grunt --beta && sed 's///' dist/index.html > ../keeweb-beta/index.html && cd ../keeweb-beta && git add index.html && git commit -a -m 'beta' && git push origin master", "electron": "ELECTRON_DISABLE_SECURITY_WARNINGS=1 electron desktop --htmlpath=http://localhost:8085", - "dev": "grunt dev --skip-sign", + "dev": "grunt dev", "babel-helpers": "babel-external-helpers -l 'slicedToArray,toConsumableArray,defineProperty,typeof' -t global > app/lib/babel-helpers.js" }, "author": { diff --git a/release-notes.md b/release-notes.md index 9c2e563d..46b76e2a 100644 --- a/release-notes.md +++ b/release-notes.md @@ -10,6 +10,7 @@ Release notes `+` #743: copying entry fields to clipboard `+` #713: markdown notes `+` #336: moving entries across files +`*` #156: using ServiceWorker instead of AppCache `*` devtools are now opened with alt-cmd-I `-` fix #764: multiple attachments display `-` fix multi-line fields display in history