-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RMET-3145:::Show app's privacy policy dialog (#105)
* feat: Show app's privacy policy dialog https://outsystemsrd.atlassian.net/browse/RMET-3145 * chore: Cosmetic change https://outsystemsrd.atlassian.net/browse/RMET-3145 * chore: Cosmetic change https://outsystemsrd.atlassian.net/browse/RMET-3145
- Loading branch information
1 parent
edeb1c5
commit d000eb4
Showing
6 changed files
with
67 additions
and
1 deletion.
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 @@ | ||
"use strict"; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { ConfigParser } = require('cordova-common'); | ||
const et = require('elementtree'); | ||
const { fileExists } = require('./utils'); | ||
let fileNamePrivacyPolicy = "HealthConnect_PrivacyPolicy.txt"; | ||
|
||
module.exports = async function (context) { | ||
const projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot; | ||
const platformPath = path.join(projectRoot, `platforms/android/app/src/main/assets/www/${fileNamePrivacyPolicy}`); | ||
|
||
if (fileExists(platformPath)) { | ||
const configXML = path.join(projectRoot, 'config.xml'); | ||
const configParser = new ConfigParser(configXML); | ||
|
||
setPrivacyPolicyUrl(configParser, projectRoot); | ||
} else { | ||
throw new Error("Privacy Policy file not found in the resources folder."); | ||
} | ||
}; | ||
|
||
function setPrivacyPolicyUrl(configParser, projectRoot) { | ||
const hostname = configParser.getPreference('hostname', 'android'); | ||
const applicationNameUrl = configParser.getPreference('DefaultApplicationURL', 'android'); | ||
|
||
if (hostname && applicationNameUrl) { | ||
const url = `https://${hostname}/${applicationNameUrl}/${fileNamePrivacyPolicy}`; | ||
const stringsPath = path.join(projectRoot, 'platforms/android/app/src/main/res/values/strings.xml'); | ||
const stringsFile = fs.readFileSync(stringsPath).toString(); | ||
const etreeStrings = et.parse(stringsFile); | ||
|
||
let privacyPolicyUrl = etreeStrings.find('./string[@name="privacy_policy_url"]'); | ||
if (!privacyPolicyUrl) { | ||
console.error('Privacy policy URL string not found in strings.xml'); | ||
return; | ||
} | ||
privacyPolicyUrl.text = url; | ||
const resultXmlStrings = etreeStrings.write({method: 'xml'}); | ||
fs.writeFileSync(stringsPath, resultXmlStrings); | ||
} else { | ||
throw new Error("Error getting the environment variables."); | ||
} | ||
} |
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,11 @@ | ||
"use strict" | ||
|
||
var fs = require("fs"); | ||
|
||
function fileExists(filePath) { | ||
return fs.existsSync(filePath); | ||
} | ||
|
||
module.exports = { | ||
fileExists | ||
}; |
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