mirror of
https://github.com/expo/config-plugins.git
synced 2026-11-14 10:08:06 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83b52a3b61 |
No files matched your search
@@ -1,3 +1,10 @@
|
|||||||
|
### @config-plugins/react-native-ble-plx [1.0.2](https://github.com/expo/config-plugins/compare/@config-plugins/[email protected]...@config-plugins/[email protected]) (2022-03-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Other chores
|
||||||
|
|
||||||
|
* git ignore build folders ([#59](https://github.com/expo/config-plugins/issues/59)) ([d6050be](https://github.com/expo/config-plugins/commit/d6050beb2a5c68dc59287c27ec388c2002ec7904))
|
||||||
|
|
||||||
### @config-plugins/react-native-ble-plx [1.0.1](https://github.com/expo/config-plugins/compare/@config-plugins/[email protected]...@config-plugins/[email protected]) (2022-03-16)
|
### @config-plugins/react-native-ble-plx [1.0.1](https://github.com/expo/config-plugins/compare/@config-plugins/[email protected]...@config-plugins/[email protected]) (2022-03-16)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
import { ConfigPlugin } from "@expo/config-plugins";
|
||||||
|
import { BackgroundMode } from "./withBLEBackgroundModes";
|
||||||
|
export { BackgroundMode };
|
||||||
|
declare const _default: ConfigPlugin<void | {
|
||||||
|
isBackgroundEnabled?: boolean | undefined;
|
||||||
|
modes?: BackgroundMode[] | undefined;
|
||||||
|
bluetoothAlwaysPermission?: string | false | undefined;
|
||||||
|
bluetoothPeripheralPermission?: string | false | undefined;
|
||||||
|
}>;
|
||||||
|
export default _default;
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
"use strict";
|
||||||
|
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.BackgroundMode = void 0;
|
||||||
|
const config_plugins_1 = require("@expo/config-plugins");
|
||||||
|
const withBLEAndroidManifest_1 = require("./withBLEAndroidManifest");
|
||||||
|
const withBLEBackgroundModes_1 = require("./withBLEBackgroundModes");
|
||||||
|
Object.defineProperty(exports, "BackgroundMode", { enumerable: true, get: function () { return withBLEBackgroundModes_1.BackgroundMode; } });
|
||||||
|
const withBluetoothPermissions_1 = require("./withBluetoothPermissions");
|
||||||
|
const pkg = { name: "react-native-ble-plx", version: "UNVERSIONED" }; //require('react-native-ble-plx/package.json')
|
||||||
|
/**
|
||||||
|
* Apply BLE configuration for Expo SDK 42 projects.
|
||||||
|
*/
|
||||||
|
const withBLE = (config, props = {}) => {
|
||||||
|
var _a;
|
||||||
|
const _props = props || {};
|
||||||
|
const isBackgroundEnabled = (_a = _props.isBackgroundEnabled) !== null && _a !== void 0 ? _a : false;
|
||||||
|
// iOS
|
||||||
|
config = withBluetoothPermissions_1.withBluetoothPermissions(config, _props);
|
||||||
|
config = withBLEBackgroundModes_1.withBLEBackgroundModes(config, _props.modes || []);
|
||||||
|
// Android
|
||||||
|
config = config_plugins_1.AndroidConfig.Permissions.withPermissions(config, [
|
||||||
|
"android.permission.BLUETOOTH",
|
||||||
|
"android.permission.BLUETOOTH_ADMIN",
|
||||||
|
]);
|
||||||
|
config = withBLEAndroidManifest_1.withBLEAndroidManifest(config, { isBackgroundEnabled });
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
exports.default = config_plugins_1.createRunOncePlugin(withBLE, pkg.name, pkg.version);
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
import { ConfigPlugin, AndroidConfig } from "@expo/config-plugins";
|
||||||
|
declare type InnerManifest = AndroidConfig.Manifest.AndroidManifest['manifest'];
|
||||||
|
declare type ManifestPermission = InnerManifest["permission"];
|
||||||
|
declare type AndroidManifest = {
|
||||||
|
manifest: InnerManifest & {
|
||||||
|
permission?: ManifestPermission;
|
||||||
|
"uses-permission"?: InnerManifest["uses-permission"];
|
||||||
|
"uses-permission-sdk-23"?: InnerManifest["uses-permission"];
|
||||||
|
"uses-feature"?: InnerManifest["uses-feature"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export declare const withBLEAndroidManifest: ConfigPlugin<{
|
||||||
|
isBackgroundEnabled: boolean;
|
||||||
|
}>;
|
||||||
|
export declare function addFineControlPermissionToManifest(androidManifest: AndroidManifest): AndroidManifest;
|
||||||
|
export declare function addBLEHardwareFeatureToManifest(androidManifest: AndroidConfig.Manifest.AndroidManifest): AndroidConfig.Manifest.AndroidManifest;
|
||||||
|
export {};
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
"use strict";
|
||||||
|
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.addBLEHardwareFeatureToManifest = exports.addFineControlPermissionToManifest = exports.withBLEAndroidManifest = void 0;
|
||||||
|
const config_plugins_1 = require("@expo/config-plugins");
|
||||||
|
const withBLEAndroidManifest = (config, { isBackgroundEnabled }) => {
|
||||||
|
return config_plugins_1.withAndroidManifest(config, (config) => {
|
||||||
|
config.modResults = addFineControlPermissionToManifest(config.modResults);
|
||||||
|
if (isBackgroundEnabled) {
|
||||||
|
config.modResults = addBLEHardwareFeatureToManifest(config.modResults);
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
exports.withBLEAndroidManifest = withBLEAndroidManifest;
|
||||||
|
function addFineControlPermissionToManifest(androidManifest) {
|
||||||
|
var _a;
|
||||||
|
// Add `<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION"/>` to the AndroidManifest.xml
|
||||||
|
if (!Array.isArray(androidManifest.manifest["uses-permission-sdk-23"])) {
|
||||||
|
androidManifest.manifest["uses-permission-sdk-23"] = [];
|
||||||
|
}
|
||||||
|
if (!androidManifest.manifest["uses-permission-sdk-23"].find((item) => item.$["android:name"] === "android.permission.ACCESS_FINE_LOCATION")) {
|
||||||
|
(_a = androidManifest.manifest["uses-permission-sdk-23"]) === null || _a === void 0 ? void 0 : _a.push({
|
||||||
|
$: {
|
||||||
|
"android:name": "android.permission.ACCESS_FINE_LOCATION",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return androidManifest;
|
||||||
|
}
|
||||||
|
exports.addFineControlPermissionToManifest = addFineControlPermissionToManifest;
|
||||||
|
// Add this line if your application always requires BLE. More info can be found on: https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#permissions
|
||||||
|
function addBLEHardwareFeatureToManifest(androidManifest) {
|
||||||
|
var _a;
|
||||||
|
// Add `<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>` to the AndroidManifest.xml
|
||||||
|
if (!Array.isArray(androidManifest.manifest["uses-feature"])) {
|
||||||
|
androidManifest.manifest["uses-feature"] = [];
|
||||||
|
}
|
||||||
|
if (!androidManifest.manifest["uses-feature"].find((item) => item.$["android:name"] === "android.hardware.bluetooth_le")) {
|
||||||
|
(_a = androidManifest.manifest["uses-feature"]) === null || _a === void 0 ? void 0 : _a.push({
|
||||||
|
$: {
|
||||||
|
"android:name": "android.hardware.bluetooth_le",
|
||||||
|
"android:required": "true",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return androidManifest;
|
||||||
|
}
|
||||||
|
exports.addBLEHardwareFeatureToManifest = addBLEHardwareFeatureToManifest;
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import { ConfigPlugin } from '@expo/config-plugins';
|
||||||
|
export declare enum BackgroundMode {
|
||||||
|
Central = "central",
|
||||||
|
Peripheral = "peripheral"
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Append `UIBackgroundModes` to the `Info.plist`.
|
||||||
|
*/
|
||||||
|
export declare const withBLEBackgroundModes: ConfigPlugin<BackgroundMode[]>;
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.withBLEBackgroundModes = exports.BackgroundMode = void 0;
|
||||||
|
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||||
|
const config_plugins_1 = require("@expo/config-plugins");
|
||||||
|
var BackgroundMode;
|
||||||
|
(function (BackgroundMode) {
|
||||||
|
BackgroundMode["Central"] = "central";
|
||||||
|
BackgroundMode["Peripheral"] = "peripheral";
|
||||||
|
})(BackgroundMode = exports.BackgroundMode || (exports.BackgroundMode = {}));
|
||||||
|
function ensureKey(arr, key) {
|
||||||
|
if (!arr.find(mode => mode === key)) {
|
||||||
|
arr.push(key);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
const centralKey = 'bluetooth-central';
|
||||||
|
const peripheralKey = 'bluetooth-peripheral';
|
||||||
|
/**
|
||||||
|
* Append `UIBackgroundModes` to the `Info.plist`.
|
||||||
|
*/
|
||||||
|
const withBLEBackgroundModes = (c, modes) => {
|
||||||
|
return config_plugins_1.withInfoPlist(c, config => {
|
||||||
|
if (!Array.isArray(config.modResults.UIBackgroundModes)) {
|
||||||
|
config.modResults.UIBackgroundModes = [];
|
||||||
|
}
|
||||||
|
if (modes.includes(BackgroundMode.Central)) {
|
||||||
|
config.modResults.UIBackgroundModes = ensureKey(config.modResults.UIBackgroundModes, centralKey);
|
||||||
|
}
|
||||||
|
if (modes.includes(BackgroundMode.Peripheral)) {
|
||||||
|
config.modResults.UIBackgroundModes = ensureKey(config.modResults.UIBackgroundModes, peripheralKey);
|
||||||
|
}
|
||||||
|
// Prevent empty array
|
||||||
|
if (!config.modResults.UIBackgroundModes.length) {
|
||||||
|
delete config.modResults.UIBackgroundModes;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
exports.withBLEBackgroundModes = withBLEBackgroundModes;
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
import { ConfigPlugin } from "@expo/config-plugins";
|
||||||
|
export declare const withBluetoothPermissions: ConfigPlugin<{
|
||||||
|
bluetoothAlwaysPermission?: string | false;
|
||||||
|
bluetoothPeripheralPermission?: string | false;
|
||||||
|
}>;
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.withBluetoothPermissions = void 0;
|
||||||
|
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||||
|
const config_plugins_1 = require("@expo/config-plugins");
|
||||||
|
const BLUETOOTH_ALWAYS = "Allow $(PRODUCT_NAME) to connect to bluetooth devices";
|
||||||
|
const BLUETOOTH_PERIPHERAL_USAGE = "Allow $(PRODUCT_NAME) to connect to bluetooth devices";
|
||||||
|
const withBluetoothPermissions = (c, { bluetoothAlwaysPermission, bluetoothPeripheralPermission } = {}) => {
|
||||||
|
return config_plugins_1.withInfoPlist(c, (config) => {
|
||||||
|
if (bluetoothAlwaysPermission !== false) {
|
||||||
|
config.modResults.NSBluetoothAlwaysUsageDescription =
|
||||||
|
bluetoothAlwaysPermission ||
|
||||||
|
config.modResults.NSBluetoothAlwaysUsageDescription ||
|
||||||
|
BLUETOOTH_ALWAYS;
|
||||||
|
}
|
||||||
|
if (bluetoothPeripheralPermission !== false) {
|
||||||
|
config.modResults.NSBluetoothPeripheralUsageDescription =
|
||||||
|
bluetoothPeripheralPermission ||
|
||||||
|
config.modResults.NSBluetoothPeripheralUsageDescription ||
|
||||||
|
BLUETOOTH_PERIPHERAL_USAGE;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
exports.withBluetoothPermissions = withBluetoothPermissions;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@config-plugins/react-native-ble-plx",
|
"name": "@config-plugins/react-native-ble-plx",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "Config plugin to auto configure react-native-ble-plx on prebuild",
|
"description": "Config plugin to auto configure react-native-ble-plx on prebuild",
|
||||||
"main": "build/withBLE.js",
|
"main": "build/withBLE.js",
|
||||||
"types": "build/withBLE.d.ts",
|
"types": "build/withBLE.d.ts",
|
||||||
|
|||||||
Reference in new issue
Block a user