-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.plugin.js
135 lines (116 loc) · 4.12 KB
/
app.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/** @type {import('@expo/config-plugins')} */
const {
withDangerousMod,
withPlugins,
withAndroidManifest,
withInfoPlist,
createRunOncePlugin,
} = require("@expo/config-plugins");
const fs = require("fs");
const path = require("path");
/** @type {import('@expo/config-plugins').ConfigPlugin} */
function withPodfile(config) {
return withDangerousMod(config, [
"ios",
async (config) => {
const filePath = path.join(
config.modRequest.platformProjectRoot,
"Podfile",
);
const contents = fs.readFileSync(filePath, "utf-8");
const newContents = !contents.includes("movesense")
? contents.replace(
/post_install do \|installer\|/,
` pod 'Movesense', :git => 'https://bitbucket.org/movesense/movesense-mobile-lib.git'\n\n post_install do |installer|`,
)
: contents;
fs.writeFileSync(filePath, newContents, { encoding: "utf-8" });
return config;
},
]);
}
// modified mdslib to remove libc++_shared as described here: https://stefanmajiros.medium.com/how-to-integrate-zoom-sdk-into-react-native-47492d4e46a6
/** @type {import('@expo/config-plugins').ConfigPlugin} */
function withCopyMdsAARfile(config) {
return withDangerousMod(config, [
"android",
async (config) => {
// Copy mds lib to android folder
const mdsLibPath =
process.env.EXPO_PUBLIC_MDS_LIB_PATH ??
path.join(
config.modRequest.platformProjectRoot,
"../node_modules/expo-mds/android/libs/",
);
console.log("mdsLibPath", mdsLibPath);
const src = path.join(mdsLibPath, "mdslib-3.15.0(1)-release.aar");
const libs = path.join(config.modRequest.platformProjectRoot, "libs");
const dest = path.join(libs, "mdslib-3.15.0(1)-release.aar");
if (!fs.existsSync(dest)) {
fs.mkdirSync(libs);
fs.copyFileSync(src, dest);
}
return config;
},
]);
}
/** @type {import('@expo/config-plugins').ConfigPlugin} */
function withAndroidPermissions(config) {
return withAndroidManifest(config, (config) => {
config.modResults.manifest["uses-permission"] = [
...(config.modResults.manifest["uses-permission"] ?? []),
{ $: { "android:name": "android.permission.BLUETOOTH" } },
{ $: { "android:name": "android.permission.BLUETOOTH_ADMIN" } },
{ $: { "android:name": "android.permission.BLUETOOTH_SCAN" } },
{ $: { "android:name": "android.permission.ACCESS_COARSE_LOCATION" } },
{ $: { "android:name": "android.permission.ACCESS_FINE_LOCATION" } },
{ $: { "android:name": "android.permission.BLUETOOTH_CONNECT" } },
{
$: { "android:name": "android.permission.ACCESS_BACKGROUND_LOCATION" },
},
];
config.modResults.manifest["uses-feature"] = [
...(config.modResults.manifest["uses-feature"] ?? []),
{
$: {
"android:name": "android.hardware.bluetooth_le",
"android:required": "true",
},
},
];
return config;
});
}
/** @type {import('@expo/config-plugins').ConfigPlugin} */
function withIOSPermissions(config) {
return withInfoPlist(config, (config) => {
config.modResults.NSBluetoothAlwaysUsageDescription =
config.modResults.NSBluetoothAlwaysUsageDescription ||
"Use bluetooth to scan for sensor";
return config;
});
}
/** @type {import('@expo/config-plugins').ConfigPlugin} */
function withBLEBackgroundModes(config) {
return withInfoPlist(config, (config) => {
if (config.modResults.UIBackgroundModes?.includes("bluetooth-peripheral")) {
return config;
}
const backgroundModes = config.modResults.UIBackgroundModes ?? [];
backgroundModes.push("bluetooth-peripheral");
config.modResults.UIBackgroundModes = backgroundModes;
return config;
});
}
const pkg = require("./package.json");
/** @type {import('@expo/config-plugins').ConfigPlugin} */
const mdsPlugins = (config) => {
return withPlugins(config, [
withPodfile,
withCopyMdsAARfile,
withAndroidPermissions,
withIOSPermissions,
withBLEBackgroundModes,
]);
};
module.exports = createRunOncePlugin(mdsPlugins, pkg.name, pkg.version);