mirror of https://github.com/keeweb/keeweb.git
fix #156: using ServiceWorker instead of AppCache
This commit is contained in:
parent
b280c6f723
commit
a01d85411c
24
Gruntfile.js
24
Gruntfile.js
|
@ -183,19 +183,9 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
files: { 'dist/manifest.appcache': 'app/manifest.appcache' }
|
files: { 'dist/manifest.appcache': 'app/manifest.appcache' }
|
||||||
},
|
},
|
||||||
'manifest-html': {
|
'service-worker': {
|
||||||
options: {
|
options: { replacements: [{ pattern: '0.0.0', replacement: pkg.version }] },
|
||||||
replacements: [
|
files: { 'dist/service-worker.js': 'app/service-worker.js' }
|
||||||
{ pattern: '<html', replacement: '<html manifest="manifest.appcache"' }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
files: { 'dist/index.html': 'dist/index.html' }
|
|
||||||
},
|
|
||||||
'desktop-html': {
|
|
||||||
options: {
|
|
||||||
replacements: [{ pattern: ' manifest="manifest.appcache"', replacement: '' }]
|
|
||||||
},
|
|
||||||
files: { 'tmp/desktop/app/index.html': 'dist/index.html' }
|
|
||||||
},
|
},
|
||||||
'desktop-public-key': {
|
'desktop-public-key': {
|
||||||
options: {
|
options: {
|
||||||
|
@ -481,14 +471,6 @@ module.exports = function(grunt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'sign-html': {
|
|
||||||
app: {
|
|
||||||
options: {
|
|
||||||
file: 'dist/index.html',
|
|
||||||
skip: grunt.option('skip-sign')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'sign-exe': {
|
'sign-exe': {
|
||||||
options: {
|
options: {
|
||||||
spc: 'keys/keeweb.spc',
|
spc: 'keys/keeweb.spc',
|
||||||
|
|
|
@ -2,9 +2,3 @@ CACHE MANIFEST
|
||||||
|
|
||||||
# YYYY-MM-DD:v0.0.0
|
# YYYY-MM-DD:v0.0.0
|
||||||
# updmin:v0.0.0
|
# updmin:v0.0.0
|
||||||
|
|
||||||
CACHE:
|
|
||||||
index.html
|
|
||||||
|
|
||||||
NETWORK:
|
|
||||||
*
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ const RuntimeInfo = {
|
||||||
beta: !!'@@BETA',
|
beta: !!'@@BETA',
|
||||||
buildDate: '@@DATE',
|
buildDate: '@@DATE',
|
||||||
commit: '@@COMMIT',
|
commit: '@@COMMIT',
|
||||||
|
devMode: '@@DEVMODE',
|
||||||
userAgent: navigator.userAgent,
|
userAgent: navigator.userAgent,
|
||||||
launcher: Launcher ? Launcher.name + ' v' + Launcher.version : ''
|
launcher: Launcher ? Launcher.name + ' v' + Launcher.version : ''
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,12 +40,21 @@ const Updater = {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.scheduleNextCheck();
|
this.scheduleNextCheck();
|
||||||
if (!Launcher && window.applicationCache) {
|
if (!Launcher && navigator.serviceWorker && !RuntimeInfo.beta && !RuntimeInfo.devMode) {
|
||||||
window.applicationCache.addEventListener(
|
navigator.serviceWorker
|
||||||
'updateready',
|
.register('service-worker.js')
|
||||||
this.checkAppCacheUpdateReady.bind(this)
|
.then(reg => {
|
||||||
);
|
logger.info('Service worker registered');
|
||||||
this.checkAppCacheUpdateReady();
|
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 err.toString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
|
||||||
|
|
||||||
checkAppCacheUpdateReady() {
|
|
||||||
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
|
|
||||||
try {
|
|
||||||
window.applicationCache.swapCache();
|
|
||||||
} catch (e) {}
|
|
||||||
UpdateModel.set({ updateStatus: 'ready' });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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))
|
||||||
|
);
|
||||||
|
});
|
|
@ -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 = '<meta name="kw-signature" content="';
|
|
||||||
const ix = fileStr.indexOf(marker);
|
|
||||||
if (ix < 0) {
|
|
||||||
grunt.warn('Signature placeholder not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sign(null, data)
|
|
||||||
.then(signature => {
|
|
||||||
signature = signature.toString('base64');
|
|
||||||
fileStr = fileStr.replace(marker, marker + signature);
|
|
||||||
fs.writeFileSync(this.options().file, fileStr, 'utf8');
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(e => {
|
|
||||||
if (e === 'Cannot find PIN') {
|
|
||||||
grunt.warn(
|
|
||||||
'Error signing app html. To build without sign, please launch grunt with --skip-sign.'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
grunt.warn('Sign error: ' + e);
|
|
||||||
}
|
|
||||||
done(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -99,7 +99,8 @@ function config(grunt, mode = 'production') {
|
||||||
pattern: /@@COMMIT/g,
|
pattern: /@@COMMIT/g,
|
||||||
replacement: () =>
|
replacement: () =>
|
||||||
grunt.config.get('gitinfo.local.branch.current.shortSHA')
|
grunt.config.get('gitinfo.local.branch.current.shortSHA')
|
||||||
}
|
},
|
||||||
|
{ pattern: /@@DEVMODE/g, replacement: () => (devMode ? '1' : '') }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
grunt.registerTask('default', 'Default: build web app', [
|
grunt.registerTask('default', 'Default: build web app', [
|
||||||
'build-web-app',
|
'build-web-app'
|
||||||
'sign-html'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
|
|
|
@ -11,7 +11,7 @@ module.exports = function(grunt) {
|
||||||
'webpack',
|
'webpack',
|
||||||
'inline',
|
'inline',
|
||||||
'htmlmin',
|
'htmlmin',
|
||||||
'string-replace:manifest-html',
|
'string-replace:service-worker',
|
||||||
'string-replace:manifest',
|
'string-replace:manifest',
|
||||||
'copy:dist-icons',
|
'copy:dist-icons',
|
||||||
'copy:dist-manifest'
|
'copy:dist-manifest'
|
||||||
|
@ -19,8 +19,7 @@ module.exports = function(grunt) {
|
||||||
|
|
||||||
grunt.registerTask('build-desktop-app-content', [
|
grunt.registerTask('build-desktop-app-content', [
|
||||||
'copy:desktop-app-content',
|
'copy:desktop-app-content',
|
||||||
'string-replace:desktop-public-key',
|
'string-replace:desktop-public-key'
|
||||||
'string-replace:desktop-html'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
grunt.registerTask('build-desktop-update', [
|
grunt.registerTask('build-desktop-update', [
|
||||||
|
|
|
@ -90,9 +90,9 @@
|
||||||
"start": "grunt",
|
"start": "grunt",
|
||||||
"test": "grunt test",
|
"test": "grunt test",
|
||||||
"postinstall": "cd desktop && npm install",
|
"postinstall": "cd desktop && npm install",
|
||||||
"build-beta": "grunt --skip-sign --beta && sed 's/<html manifest=\"manifest.appcache\">//' 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/<html manifest=\"manifest.appcache\">//' 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",
|
"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"
|
"babel-helpers": "babel-external-helpers -l 'slicedToArray,toConsumableArray,defineProperty,typeof' -t global > app/lib/babel-helpers.js"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
|
|
|
@ -10,6 +10,7 @@ Release notes
|
||||||
`+` #743: copying entry fields to clipboard
|
`+` #743: copying entry fields to clipboard
|
||||||
`+` #713: markdown notes
|
`+` #713: markdown notes
|
||||||
`+` #336: moving entries across files
|
`+` #336: moving entries across files
|
||||||
|
`*` #156: using ServiceWorker instead of AppCache
|
||||||
`*` devtools are now opened with alt-cmd-I
|
`*` devtools are now opened with alt-cmd-I
|
||||||
`-` fix #764: multiple attachments display
|
`-` fix #764: multiple attachments display
|
||||||
`-` fix multi-line fields display in history
|
`-` fix multi-line fields display in history
|
||||||
|
|
Loading…
Reference in New Issue