forked from star-micronics/react-native-star-io10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.plugin.js
96 lines (84 loc) · 2.57 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
const {
withProjectBuildGradle,
withPlugins,
withInfoPlist,
AndroidConfig,
} = require("@expo/config-plugins");
const BLUETOOTH_ALWAYS =
"Allow $(PRODUCT_NAME) to connect to bluetooth devices";
const LOCAL_NETWORK_USAGE =
"Allow $(PRODUCT_NAME) to discover devices on the network";
function setMinSdkVersion(buildGradle, minVersion) {
const regexpMinSdkVersion = /\bminSdkVersion\s*=\s*(\d+)/;
const match = buildGradle.match(regexpMinSdkVersion);
if (match) {
const version = parseInt(match[1], 10);
if (version < minVersion) {
buildGradle = buildGradle.replace(
/\bminSdkVersion\s*=\s*\d+/,
`minSdkVersion = ${minVersion}`
);
} else {
console.warn(`WARN: minSdkVersion is already >= ${version}`);
}
}
return buildGradle;
}
const withIosPermissions = (
c,
{ bluetoothAlwaysPermission, localNetworkUsagePermission } = {}
) => {
return withInfoPlist(c, (config) => {
if (bluetoothAlwaysPermission !== false) {
config.modResults.NSBluetoothAlwaysUsageDescription =
bluetoothAlwaysPermission ||
config.modResults.NSBluetoothAlwaysUsageDescription ||
BLUETOOTH_ALWAYS;
}
if (localNetworkUsagePermission !== false) {
config.modResults.NSLocalNetworkUsageDescription =
localNetworkUsagePermission ||
config.modResults.NSLocalNetworkUsageDescription ||
LOCAL_NETWORK_USAGE;
}
return config;
});
};
const withAccessoryProtocols = (c, props) => {
return withInfoPlist(c, (config) => {
const existingProtocols = config.modResults.NSBluetoothProtocols || [];
config.modResults.UISupportedExternalAccessoryProtocols = [
...existingProtocols,
"jp.star-m.starpro",
];
return config;
});
};
const withMinSdkVersion = (config, { minSdkVersion } = {}) => {
return withProjectBuildGradle(config, (config) => {
if (config.modResults.language === "groovy") {
config.modResults.contents = setMinSdkVersion(
config.modResults.contents,
minSdkVersion || 23
);
} else {
throw new Error(
"Can't set minSdkVersion in the project build.gradle, because it's not groovy"
);
}
return config;
});
};
const withAndroidPermissions = (config, props) => {
config = AndroidConfig.Permissions.withPermissions(config, [
"android.permission.BLUETOOTH_CONNECT ",
]);
return config;
};
module.exports = (config, props) =>
withPlugins(config, [
[withMinSdkVersion, props],
[withIosPermissions, props],
[withAccessoryProtocols, props],
[withAndroidPermissions, props],
]);