From f6e0dccfb2a6906c37b5f89f2d2170c3ff420d97 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Tue, 19 Dec 2017 08:39:17 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=B8=EF=B8=8F=20Issue=20#2109:=20Receiv?= =?UTF-8?q?e=20push=20notifications=20when=20using=20cordova-browser=20>?= =?UTF-8?q?=205.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hooks/browser/updateManifest.js | 49 +++++++++++++++++++++++++++++++++ plugin.xml | 1 + 2 files changed, 50 insertions(+) create mode 100644 hooks/browser/updateManifest.js diff --git a/hooks/browser/updateManifest.js b/hooks/browser/updateManifest.js new file mode 100644 index 000000000..4dabf6026 --- /dev/null +++ b/hooks/browser/updateManifest.js @@ -0,0 +1,49 @@ +module.exports = function(context) { + console.log('Updating manifest.json with push properties…'); + var path = require('path'); + var fs = require('fs'); + + var platformProjPath = path.join( + context.opts.projectRoot, + 'platforms/browser' + ); + + if (!fs.existsSync(platformProjPath)) { + platformProjPath = context.opts.projectRoot; + } + + var platformManifestJson = path.join(platformProjPath, 'www/manifest.json'); + + if (!fs.existsSync(platformManifestJson)) { + return; + } + + fs.readFile(platformManifestJson, 'utf8', function(err, platformJson) { + if (err) throw err; // we'll not consider error handling for now + var platformManifest = JSON.parse(platformJson); + + var pluginManifestPath = path.join( + context.opts.projectRoot, + 'plugins/phonegap-plugin-push/src/browser/manifest.json' + ); + + fs.readFile(pluginManifestPath, 'utf8', function(err, pluginJson) { + if (err) throw err; // we'll not consider error handling for now + var pluginManifest = JSON.parse(pluginJson); + + platformManifest['gcm_sender_id'] = pluginManifest['gcm_sender_id']; + + fs.writeFile( + platformManifestJson, + JSON.stringify(platformManifest), + function(err) { + if (err) { + return console.log(err); + } + + console.log('Manifest updated with push sender ID'); + } + ); + }); + }); +}; diff --git a/plugin.xml b/plugin.xml index c61604636..d725f1aaf 100755 --- a/plugin.xml +++ b/plugin.xml @@ -61,6 +61,7 @@ +