MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / addPermission

Function addPermission

utils/storage_manager.mjs:15–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13const permissionRegex = /^\s*<uses-permission android:name="android\.permission\.MANAGE_EXTERNAL_STORAGE"\s*\/>\s*$/gm;
14
15async function addPermission() {
16 try {
17 let xml = await readFile(pluginXmlPath, 'utf-8');
18
19 if (xml.includes('android.permission.MANAGE_EXTERNAL_STORAGE')) {
20 console.log('Permission already exists in plugin.xml');
21 return false;
22 }
23
24 const pattern = /<config-file\s+target="AndroidManifest\.xml"\s+parent="\/manifest">\s*<\/config-file>/;
25
26 if (pattern.test(xml)) {
27 xml = xml.replace(pattern, match => {
28 return match.replace(
29 '</config-file>',
30 `\n${permissionLine}\n </config-file>`
31 );
32 });
33
34 await writeFile(pluginXmlPath, xml, 'utf-8');
35 console.log('Permission added inside existing <config-file> block.');
36 return true
37 } else {
38 console.error('Could not find <config-file parent="/manifest"> block.');
39 return false
40 }
41 } catch (err) {
42 console.error('Failed to add permission:', err);
43 return false
44 }
45}
46
47async function removePermission() {
48 try {

Callers 1

handleAnswerFunction · 0.85

Calls 4

logMethod · 0.80
readFileFunction · 0.50
writeFileFunction · 0.50
errorMethod · 0.45

Tested by

no test coverage detected