1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const xml2js_1 = require("xml2js");
|
4 |
|
5 | function getIntentFilters(config) {
|
6 | var _a, _b;
|
7 | return _b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.intentFilters, (_b !== null && _b !== void 0 ? _b : []);
|
8 | }
|
9 | exports.getIntentFilters = getIntentFilters;
|
10 | async function setAndroidIntentFilters(config, manifestDocument) {
|
11 | const intentFilters = getIntentFilters(config);
|
12 | if (!intentFilters.length) {
|
13 | return manifestDocument;
|
14 | }
|
15 | let intentFiltersXML = renderIntentFilters(intentFilters).join('');
|
16 | const parser = new xml2js_1.Parser();
|
17 | const intentFiltersJSON = await parser.parseStringPromise(intentFiltersXML);
|
18 | let mainActivity = manifestDocument.manifest.application[0].activity.filter((e) => e['$']['android:name'] === '.MainActivity');
|
19 | mainActivity[0]['intent-filter'] = mainActivity[0]['intent-filter'].concat(intentFiltersJSON['intent-filter']);
|
20 | return manifestDocument;
|
21 | }
|
22 | exports.setAndroidIntentFilters = setAndroidIntentFilters;
|
23 | function renderIntentFilters(intentFilters) {
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | return intentFilters.map((intentFilter) => {
|
38 | const autoVerify = intentFilter.autoVerify ? ' android:autoVerify="true"' : '';
|
39 | return `<intent-filter${autoVerify}>
|
40 | ${renderIntentFilterData(intentFilter.data)}
|
41 | <action android:name="android.intent.action.${intentFilter.action}"/>
|
42 | ${renderIntentFilterCategory(intentFilter.category)}
|
43 | </intent-filter>`;
|
44 | });
|
45 | }
|
46 | exports.default = renderIntentFilters;
|
47 | function renderIntentFilterDatumEntries(datum) {
|
48 | return Object.keys(datum)
|
49 | .map(key => `android:${key}="${datum[key]}"`)
|
50 | .join(' ');
|
51 | }
|
52 | function renderIntentFilterData(data) {
|
53 | return (Array.isArray(data) ? data : [data])
|
54 | .map(datum => `<data ${renderIntentFilterDatumEntries(datum)}/>`)
|
55 | .join('\n');
|
56 | }
|
57 | function renderIntentFilterCategory(category) {
|
58 | return (Array.isArray(category) ? category : [category])
|
59 | .map(cat => `<category android:name="android.intent.category.${cat}"/>`)
|
60 | .join('\n');
|
61 | }
|
62 |
|
\ | No newline at end of file |