forked from chemerisuk/cordova-plugin-firebase-analytics
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from OutSystems/development
Prepare `main` for `5.0.0-OS13`
- Loading branch information
Showing
5 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { ConfigParser } = require('cordova-common'); | ||
const xml2js = require('xml2js'); | ||
const q = require('q'); | ||
|
||
module.exports = function (context) { | ||
let projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot; | ||
let configXML = path.join(projectRoot, 'config.xml'); | ||
let configParser = new ConfigParser(configXML); | ||
|
||
let manifestPath = path.join(projectRoot, 'platforms/android/app/src/main/AndroidManifest.xml'); | ||
|
||
let defer = q.defer(); | ||
|
||
let collectionEnabled = configParser.getGlobalPreference("ANALYTICS_COLLECTION_ENABLED"); | ||
if (collectionEnabled.toLowerCase() == 'false') { | ||
let parser = new xml2js.Parser(); | ||
parser.parseStringPromise(fs.readFileSync(manifestPath, 'utf8')).then((result) => { | ||
let metadata = result.manifest.application[0]['meta-data']; | ||
metadata.push({ | ||
'$': { | ||
'android:name': 'firebase_analytics_collection_enabled', | ||
'android:value': 'false' | ||
} | ||
}) | ||
|
||
let builder = new xml2js.Builder(); | ||
let xml = builder.buildObject(result); | ||
|
||
fs.writeFileSync(manifestPath, xml, (err) => { | ||
throw new Error (`OUTSYSTEMS_PLUGIN_ERROR: Something went wrong while saving the AndroidManifest.xml file. Please check the logs for more information.`); | ||
}); | ||
|
||
defer.resolve(); | ||
}) | ||
.catch((err) => { | ||
throw new Error (`OUTSYSTEMS_PLUGIN_ERROR: Something went wrong while parsing the AndroidManifest.xml file. Please check the logs for more information.`); | ||
}); | ||
} else { | ||
defer.resolve(); | ||
} | ||
|
||
return defer.promise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters