mirror of
https://github.com/expo/config-plugins.git
synced 2026-11-13 20:28:07 -10:00
chore(react-native-ble-plx): lint fix
This commit is contained in:
1 parent
331ecb163f
commit
a99c60efd5
5 files changed
+56
-51
No files matched your search
@@ -1,42 +1,44 @@
|
||||
import { AndroidConfig, XML } from '@expo/config-plugins'
|
||||
import { AndroidConfig, XML } from "@expo/config-plugins";
|
||||
import { resolve } from "path";
|
||||
|
||||
import { resolve } from 'path'
|
||||
import {
|
||||
addBLEHardwareFeatureToManifest,
|
||||
addFineControlPermissionToManifest,
|
||||
} from "../withBLEAndroidManifest";
|
||||
|
||||
import { addBLEHardwareFeatureToManifest, addFineControlPermissionToManifest } from '../withBLEAndroidManifest'
|
||||
const { readAndroidManifestAsync } = AndroidConfig.Manifest;
|
||||
|
||||
const { readAndroidManifestAsync } = AndroidConfig.Manifest
|
||||
const sampleManifestPath = resolve(__dirname, "fixtures/AndroidManifest.xml");
|
||||
|
||||
const sampleManifestPath = resolve(__dirname, 'fixtures/AndroidManifest.xml')
|
||||
|
||||
describe('addFineControlPermissionToManifest', () => {
|
||||
describe("addFineControlPermissionToManifest", () => {
|
||||
it(`adds element`, async () => {
|
||||
let androidManifest = await readAndroidManifestAsync(sampleManifestPath)
|
||||
androidManifest = await addFineControlPermissionToManifest(androidManifest)
|
||||
expect(androidManifest.manifest['uses-permission-sdk-23']).toStrictEqual([
|
||||
{ $: { 'android:name': 'android.permission.ACCESS_FINE_LOCATION' } }
|
||||
])
|
||||
let androidManifest = await readAndroidManifestAsync(sampleManifestPath);
|
||||
androidManifest = await addFineControlPermissionToManifest(androidManifest);
|
||||
expect(androidManifest.manifest["uses-permission-sdk-23"]).toStrictEqual([
|
||||
{ $: { "android:name": "android.permission.ACCESS_FINE_LOCATION" } },
|
||||
]);
|
||||
// Sanity
|
||||
expect(XML.format(androidManifest)).toMatch(
|
||||
/<uses-permission-sdk-23 android:name="android\.permission\.ACCESS_FINE_LOCATION"\/>/
|
||||
)
|
||||
})
|
||||
})
|
||||
describe('addBLEHardwareFeatureToManifest', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe("addBLEHardwareFeatureToManifest", () => {
|
||||
it(`adds element`, async () => {
|
||||
let androidManifest = await readAndroidManifestAsync(sampleManifestPath)
|
||||
androidManifest = await addBLEHardwareFeatureToManifest(androidManifest)
|
||||
let androidManifest = await readAndroidManifestAsync(sampleManifestPath);
|
||||
androidManifest = await addBLEHardwareFeatureToManifest(androidManifest);
|
||||
|
||||
expect(androidManifest.manifest['uses-feature']).toStrictEqual([
|
||||
expect(androidManifest.manifest["uses-feature"]).toStrictEqual([
|
||||
{
|
||||
$: {
|
||||
'android:name': 'android.hardware.bluetooth_le',
|
||||
'android:required': 'true'
|
||||
}
|
||||
}
|
||||
])
|
||||
"android:name": "android.hardware.bluetooth_le",
|
||||
"android:required": "true",
|
||||
},
|
||||
},
|
||||
]);
|
||||
// Sanity
|
||||
expect(XML.format(androidManifest)).toMatch(
|
||||
/<uses-feature android:name="android\.hardware\.bluetooth_le" android:required="true"\/>/
|
||||
)
|
||||
})
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||
|
||||
import {
|
||||
AndroidConfig,
|
||||
ConfigPlugin,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||
|
||||
import {
|
||||
ConfigPlugin,
|
||||
withAndroidManifest,
|
||||
AndroidConfig,
|
||||
} from "@expo/config-plugins";
|
||||
|
||||
type InnerManifest = AndroidConfig.Manifest.AndroidManifest['manifest'];
|
||||
type InnerManifest = AndroidConfig.Manifest.AndroidManifest["manifest"];
|
||||
|
||||
type ManifestPermission = InnerManifest["permission"];
|
||||
|
||||
|
||||
@@ -1,42 +1,50 @@
|
||||
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||
import { ConfigPlugin, withInfoPlist } from '@expo/config-plugins'
|
||||
import { ConfigPlugin, withInfoPlist } from "@expo/config-plugins";
|
||||
|
||||
export enum BackgroundMode {
|
||||
Central = 'central',
|
||||
Peripheral = 'peripheral'
|
||||
Central = "central",
|
||||
Peripheral = "peripheral",
|
||||
}
|
||||
|
||||
function ensureKey(arr: string[], key: string) {
|
||||
if (!arr.find(mode => mode === key)) {
|
||||
arr.push(key)
|
||||
if (!arr.find((mode) => mode === key)) {
|
||||
arr.push(key);
|
||||
}
|
||||
return arr
|
||||
return arr;
|
||||
}
|
||||
|
||||
const centralKey = 'bluetooth-central'
|
||||
const peripheralKey = 'bluetooth-peripheral'
|
||||
const centralKey = "bluetooth-central";
|
||||
const peripheralKey = "bluetooth-peripheral";
|
||||
|
||||
/**
|
||||
* Append `UIBackgroundModes` to the `Info.plist`.
|
||||
*/
|
||||
export const withBLEBackgroundModes: ConfigPlugin<BackgroundMode[]> = (c, modes) => {
|
||||
return withInfoPlist(c, config => {
|
||||
export const withBLEBackgroundModes: ConfigPlugin<BackgroundMode[]> = (
|
||||
c,
|
||||
modes
|
||||
) => {
|
||||
return withInfoPlist(c, (config) => {
|
||||
if (!Array.isArray(config.modResults.UIBackgroundModes)) {
|
||||
config.modResults.UIBackgroundModes = []
|
||||
config.modResults.UIBackgroundModes = [];
|
||||
}
|
||||
|
||||
if (modes.includes(BackgroundMode.Central)) {
|
||||
config.modResults.UIBackgroundModes = ensureKey(config.modResults.UIBackgroundModes, centralKey)
|
||||
config.modResults.UIBackgroundModes = ensureKey(
|
||||
config.modResults.UIBackgroundModes,
|
||||
centralKey
|
||||
);
|
||||
}
|
||||
if (modes.includes(BackgroundMode.Peripheral)) {
|
||||
config.modResults.UIBackgroundModes = ensureKey(config.modResults.UIBackgroundModes, peripheralKey)
|
||||
config.modResults.UIBackgroundModes = ensureKey(
|
||||
config.modResults.UIBackgroundModes,
|
||||
peripheralKey
|
||||
);
|
||||
}
|
||||
|
||||
// Prevent empty array
|
||||
if (!config.modResults.UIBackgroundModes.length) {
|
||||
delete config.modResults.UIBackgroundModes
|
||||
delete config.modResults.UIBackgroundModes;
|
||||
}
|
||||
|
||||
return config
|
||||
})
|
||||
}
|
||||
return config;
|
||||
});
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable flowtype/no-types-missing-file-annotation */
|
||||
import { ConfigPlugin, withInfoPlist } from "@expo/config-plugins";
|
||||
|
||||
const BLUETOOTH_ALWAYS =
|
||||
|
||||
Reference in new issue
Block a user