From 0ad3f30cfb3efd502894320c075fa2045bd9ebac Mon Sep 17 00:00:00 2001 From: ROUL Date: Sun, 3 Jun 2018 07:00:44 +0200 Subject: [PATCH 1/4] Append SW with pull and sync features --- lib/dev-server.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/dev-server.js b/lib/dev-server.js index a8c7ff7..3916a11 100644 --- a/lib/dev-server.js +++ b/lib/dev-server.js @@ -65,7 +65,20 @@ class DevServer { this.server.use(function (req, res, next) { if (req.url === '/service-worker.js') { res.setHeader('Content-Type', 'text/javascript') - res.send(resetScript) + if (cfg.pwa.swPlugins && cfg.pwa.swPlugins.push) { + res.write(fs.readFileSync( + path.join(appPaths.pwaDir, cfg.pwa.swPlugins.push), + 'utf-8' + )) + } + if (cfg.pwa.swPlugins && cfg.pwa.swPlugins.sync) { + res.write(fs.readFileSync( + path.join(appPaths.pwaDir, cfg.pwa.swPlugins.sync), + 'utf-8' + )) + } + res.write(resetScript) + res.end() } else { next() From f9499d766c7c7d32e339ee272a61a518d5560f80 Mon Sep 17 00:00:00 2001 From: ROUL Date: Sun, 3 Jun 2018 07:02:15 +0200 Subject: [PATCH 2/4] Add SW push/sync feature --- lib/quasar-config.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/quasar-config.js b/lib/quasar-config.js index b7a689f..da1ee41 100644 --- a/lib/quasar-config.js +++ b/lib/quasar-config.js @@ -412,6 +412,10 @@ class QuasarConfig { cfg.pwa = merge({ workboxPluginMode: 'GenerateSW', workboxOptions: {}, + swPlugins: { + push: 'push-service-worker.js', + sync: 'sync-service-worker.js' + }, manifest: { name: this.pkg.productName || this.pkg.name || 'Quasar App', short_name: this.pkg.name || 'quasar-pwa', From bb824b2184c011eaa449abc1c08c58263bf40bf7 Mon Sep 17 00:00:00 2001 From: ROUL Date: Sun, 3 Jun 2018 07:03:21 +0200 Subject: [PATCH 3/4] Add SW push/sync features --- templates/pwa/push-service-worker.js | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 templates/pwa/push-service-worker.js diff --git a/templates/pwa/push-service-worker.js b/templates/pwa/push-service-worker.js new file mode 100644 index 0000000..a0d7932 --- /dev/null +++ b/templates/pwa/push-service-worker.js @@ -0,0 +1,29 @@ +/* + * This file (which will be part of your service worker) + * is picked up by the build system and appended at the end of the service-worker + * To do so, You must active this option in + * quasar.conf > pwa > swPlugins > push by setting the name of this file + * THIS PART OF THE CODE is OUT of Hot Reload managment : You should refresh page to reload it. + */ + +/** + * Start listening for web notification (client part), and will display them to the user. + * Fill free to add/remove anypart of the code + */ +self.addEventListener('push', function (event) { + if (!event.data) { + console.error('This push event has no data.', event) + return + } + + let msg + try { + msg = event.data.json() + } catch (e) { + console.error('This push event data is not valid JSON.', event.data) + return + } + // Sending message to the service-worker for display + const promiseChain = self.registration.showNotification(msg.title, msg.options) + event.waitUntil(promiseChain) +}) From a79d854d2d643877c78a8da7233a5a7091438b4a Mon Sep 17 00:00:00 2001 From: ROUL Date: Sun, 3 Jun 2018 07:03:47 +0200 Subject: [PATCH 4/4] Add SW push/sync features --- templates/pwa/sync-service-worker.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 templates/pwa/sync-service-worker.js diff --git a/templates/pwa/sync-service-worker.js b/templates/pwa/sync-service-worker.js new file mode 100644 index 0000000..d132ffc --- /dev/null +++ b/templates/pwa/sync-service-worker.js @@ -0,0 +1,11 @@ +/* + * This file (which will be part of your service worker) + * is picked up by the build system and appended at the end of the service-worker + * To do so, You must active this option in + * quasar.conf > pwa > swPlugins > sync by setting the name of this file + * THIS PART OF THE CODE is OUT of Hot Reload managment : You should refresh page to reload it. + */ + +self.addEventListener('sync', function (event) { + // Implement your 'sync' event managment. +})