Skip to content

Commit 1631a4f

Browse files
RMET-4025 - Prepare to release version 2.6.8-OS23 (#39)
* RMET-4025 - Update hook to avoid duplicates in strings.xml (#38) * feat: update hook to avoid adding duplicated entries in strings.xml References: https://outsystemsrd.atlassian.net/browse/RMET-4025 * fix: fix comparison with true References: https://outsystemsrd.atlassian.net/browse/RMET-4025 * feat: check if entry exist and replace if needed References: https://outsystemsrd.atlassian.net/browse/RMET-4025 * fix: fixing variable name References: https://outsystemsrd.atlassian.net/browse/RMET-4025 * chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-4025 * chore(release): raise to version 2.6.8-OS23 References: https://outsystemsrd.atlassian.net/browse/RMET-4278
1 parent 7963d86 commit 1631a4f

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
2.6.8-OS23 - 2025-07-08
5+
------------------
6+
- Fix: [android] Updates hook to avoid duplicates in `strings.xml` (https://outsystemsrd.atlassian.net/browse/RMET-4025).
7+
48
2.6.8-OS22 - 2025-06-06
59
------------------
610
- Fix: [Android] Capacitor Release builds failure.

hooks/android/androidCopyPreferences.js

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,64 @@ module.exports = function (context) {
1818
const stringsXmlString = fs.readFileSync(stringsXmlPath, 'utf-8');
1919
const stringsXmlDoc = parser.parseFromString(stringsXmlString, 'text/xml')
2020

21-
if(authenticate == "true"){
22-
// insert bool value in strings.xml
23-
const booleanElements = stringsXmlDoc.getElementsByTagName('bool');
24-
25-
// set text for each <bool> element
26-
for (let i = 0; i < booleanElements.length; i++) {
27-
const name = booleanElements[i].getAttribute('name');
28-
if (name == "migration_auth") {
29-
booleanElements[i].textContent = authenticate;
21+
// Keys to update and their values
22+
const boolKey = "migration_auth";
23+
const stringKeys = {
24+
biometric_prompt_title: auth_prompt_title,
25+
biometric_prompt_subtitle: auth_prompt_subtitle,
26+
biometric_prompt_negative_button: auth_prompt_negative_button
27+
};
28+
29+
// process <bool> entry
30+
const boolElements = Array.from(stringsXmlDoc.getElementsByTagName('bool'));
31+
const boolMatches = boolElements.filter(el => el.getAttribute('name') === boolKey);
32+
33+
if (authenticate == "true") {
34+
if (boolMatches.length > 0) {
35+
// remove any duplicates beyond the first
36+
for (let i = 1; i < boolMatches.length; i++) {
37+
boolMatches[i].parentNode.removeChild(boolMatches[i]);
38+
}
39+
40+
// update first match if needed
41+
const existingBool = boolMatches[0];
42+
if (existingBool.textContent !== authenticate) {
43+
existingBool.textContent = authenticate;
3044
}
45+
} else {
46+
// add new <bool> if it doesn't exist
47+
const newBool = stringsXmlDoc.createElement('bool');
48+
newBool.setAttribute('name', boolKey);
49+
newBool.textContent = authenticate;
50+
stringsXmlDoc.documentElement.appendChild(newBool);
3151
}
3252
}
3353

34-
// insert string values in strings.xml
35-
const stringElements = stringsXmlDoc.getElementsByTagName('string');
54+
// process <string> entries
55+
const allStrings = Array.from(stringsXmlDoc.getElementsByTagName('string'));
3656

37-
// set text for each <string> element
38-
for (let i = 0; i < stringElements.length; i++) {
39-
const name = stringElements[i].getAttribute('name');
40-
if (name == "biometric_prompt_title" && auth_prompt_title != "") {
41-
stringElements[i].textContent = auth_prompt_title;
42-
}
43-
else if (name == "biometric_prompt_subtitle" && auth_prompt_subtitle != "") {
44-
stringElements[i].textContent = auth_prompt_subtitle;
45-
}
46-
else if (name == "biometric_prompt_negative_button" && auth_prompt_negative_button != "") {
47-
stringElements[i].textContent = auth_prompt_negative_button;
57+
for (const [key, value] of Object.entries(stringKeys)) {
58+
if (!value || value.trim() === "") continue;
59+
60+
const matchingStrings = allStrings.filter(el => el.getAttribute('name') === key);
61+
62+
if (matchingStrings.length > 0) {
63+
// remove duplicates beyond the first
64+
for (let i = 1; i < matchingStrings.length; i++) {
65+
matchingStrings[i].parentNode.removeChild(matchingStrings[i]);
66+
}
67+
68+
// update first if needed
69+
const existingString = matchingStrings[0];
70+
if (existingString.textContent !== value) {
71+
existingString.textContent = value;
72+
}
73+
} else {
74+
// add new <string> if it doesn't exist
75+
const newString = stringsXmlDoc.createElement('string');
76+
newString.setAttribute('name', key);
77+
newString.textContent = value;
78+
stringsXmlDoc.documentElement.appendChild(newString);
4879
}
4980
}
5081

@@ -54,5 +85,4 @@ module.exports = function (context) {
5485

5586
// write the updated XML string back to the same file
5687
fs.writeFileSync(stringsXmlPath, updatedXmlString, 'utf-8');
57-
5888
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-secure-storage",
3-
"version": "2.6.8-OS22",
3+
"version": "2.6.8-OS23",
44
"description": "Secure storage plugin for iOS & Android",
55
"author": "Yiorgis Gozadinos <ggozad@crypho.com>",
66
"contributors": [

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="cordova-plugin-secure-storage"
5-
version="2.6.8-OS22">
5+
version="2.6.8-OS23">
66

77
<name>SecureStorage</name>
88
<author>Crypho AS</author>

0 commit comments

Comments
 (0)