@sfourdrinier/react-native-ble-plx
Version:
React Native Bluetooth Low Energy library
48 lines (47 loc) • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withBLEDebugLogging = exports.BLEPLX_DEBUG_LOGGING_ANDROID_META_DATA_NAME = exports.BLEPLX_DEBUG_LOGGING_PLIST_KEY = void 0;
exports.setBlePlxDebugLoggingInfoPlist = setBlePlxDebugLoggingInfoPlist;
exports.setBlePlxDebugLoggingAndroidManifest = setBlePlxDebugLoggingAndroidManifest;
const config_plugins_1 = require("@expo/config-plugins");
exports.BLEPLX_DEBUG_LOGGING_PLIST_KEY = 'BlePlxDebugLogging';
exports.BLEPLX_DEBUG_LOGGING_ANDROID_META_DATA_NAME = 'BlePlxDebugLogging';
function setBlePlxDebugLoggingInfoPlist(infoPlist, debugEnabled) {
infoPlist[exports.BLEPLX_DEBUG_LOGGING_PLIST_KEY] = debugEnabled;
return infoPlist;
}
function setBlePlxDebugLoggingAndroidManifest(androidManifest, debugEnabled) {
const mainApplication = config_plugins_1.AndroidConfig.Manifest.getMainApplicationOrThrow(androidManifest);
// Ensure meta-data is an array. When there's only one meta-data entry,
// the XML parser returns an object instead of an array. We must preserve
// existing entries to avoid wiping host app configuration.
if (!Array.isArray(mainApplication['meta-data'])) {
mainApplication['meta-data'] = mainApplication['meta-data'] ? [mainApplication['meta-data']] : [];
}
const existing = mainApplication['meta-data'].find(item => item.$?.['android:name'] === exports.BLEPLX_DEBUG_LOGGING_ANDROID_META_DATA_NAME);
const value = debugEnabled ? 'true' : 'false';
if (existing) {
existing.$['android:value'] = value;
}
else {
mainApplication['meta-data'].push({
$: {
'android:name': exports.BLEPLX_DEBUG_LOGGING_ANDROID_META_DATA_NAME,
'android:value': value
}
});
}
return androidManifest;
}
const withBLEDebugLogging = (config, { debugEnabled }) => {
config = (0, config_plugins_1.withInfoPlist)(config, config => {
setBlePlxDebugLoggingInfoPlist(config.modResults, debugEnabled);
return config;
});
config = (0, config_plugins_1.withAndroidManifest)(config, config => {
setBlePlxDebugLoggingAndroidManifest(config.modResults, debugEnabled);
return config;
});
return config;
};
exports.withBLEDebugLogging = withBLEDebugLogging;