react-native-nitro-screen-recorder
Version:
A library to capture screen recordings with react-native powered by NitroModules.
144 lines (131 loc) • 8.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.withBroadcastExtensionXcodeProject = void 0;
var _configPlugins = require("@expo/config-plugins");
var _iosConstants = require("../support/iosConstants");
var _ScreenRecorderLog = require("../support/ScreenRecorderLog");
var _assert = _interopRequireDefault(require("assert"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
//───────────────────────────────────────────────────────────────────────────
// Helper: pull DEVELOPMENT_TEAM from the main-app target’s build settings
//───────────────────────────────────────────────────────────────────────────
function getMainAppDevelopmentTeam(pbx, l) {
const configs = pbx.pbxXCBuildConfigurationSection();
for (const key in configs) {
const config = configs[key];
const bs = config.buildSettings;
if (!bs || !bs.PRODUCT_NAME) continue;
const productName = bs.PRODUCT_NAME?.replace(/"/g, '');
// Ignore other extensions/widgets
if (productName && (productName.includes('Extension') || productName.includes('Widget'))) {
continue;
}
const developmentTeam = bs.DEVELOPMENT_TEAM?.replace(/"/g, '');
if (developmentTeam) {
l.log(`Found DEVELOPMENT_TEAM='${developmentTeam}' from main app configuration.`);
return developmentTeam;
}
}
l.error('No DEVELOPMENT_TEAM found in main app build settings. Developer will need to manually add Dev Team.');
return null;
}
//───────────────────────────────────────────────────────────────────────────
// Main Expo config-plugin
//───────────────────────────────────────────────────────────────────────────
const withBroadcastExtensionXcodeProject = (config, props) => {
return (0, _configPlugins.withXcodeProject)(config, newConfig => {
const xcodeProject = newConfig.modResults;
const appIdentifier = newConfig.ios?.bundleIdentifier;
(0, _assert.default)(appIdentifier, "Missing 'ios.bundleIdentifier' in app config");
const bundleIdentifier = (0, _iosConstants.getBroadcastExtensionBundleIdentifier)(appIdentifier, props);
/* ------------------------------------------------------------------ */
/* 0. Resolve DEVELOPMENT_TEAM (props override > auto-detect > none) */
/* ------------------------------------------------------------------ */
const detectedDevTeam = getMainAppDevelopmentTeam(xcodeProject, _ScreenRecorderLog.ScreenRecorderLog);
const devTeam = detectedDevTeam ?? undefined;
/* ------------------------------------------------------------------ */
/* 1. Bail out early if target/group already exist */
/* ------------------------------------------------------------------ */
const existingTarget = xcodeProject.pbxTargetByName(_iosConstants.BROADCAST_EXT_TARGET_NAME);
if (existingTarget) {
_ScreenRecorderLog.ScreenRecorderLog.log(`${_iosConstants.BROADCAST_EXT_TARGET_NAME} already exists in project. Skipping…`);
return newConfig;
}
const existingGroups = xcodeProject.hash.project.objects.PBXGroup;
const groupExists = Object.values(existingGroups).some(group => group && group.name === _iosConstants.BROADCAST_EXT_TARGET_NAME);
if (groupExists) {
_ScreenRecorderLog.ScreenRecorderLog.log(`${_iosConstants.BROADCAST_EXT_TARGET_NAME} group already exists in project. Skipping…`);
return newConfig;
}
/* ------------------------------------------------------------------ */
/* 2. Create target, group & build phases (COMBINED APPROACH) */
/* ------------------------------------------------------------------ */
const pbx = xcodeProject;
// 2.1 Create PBXGroup for the extension (OneSignal style - single group creation)
const extGroup = pbx.addPbxGroup([..._iosConstants.BROADCAST_EXT_SOURCE_FILES, ..._iosConstants.BROADCAST_EXT_CONFIG_FILES], _iosConstants.BROADCAST_EXT_TARGET_NAME, _iosConstants.BROADCAST_EXT_TARGET_NAME);
// 2.2 Add the new PBXGroup to the top level group
const groups = pbx.hash.project.objects.PBXGroup;
Object.keys(groups).forEach(function (key) {
if (typeof groups[key] === 'object' && groups[key].name === undefined && groups[key].path === undefined) {
pbx.addToPbxGroup(extGroup.uuid, key);
}
});
// 2.3 WORK AROUND for addTarget BUG (from OneSignal)
// Xcode projects don't contain these if there is only one target
const projObjects = pbx.hash.project.objects;
projObjects.PBXTargetDependency = projObjects.PBXTargetDependency || {};
projObjects.PBXContainerItemProxy = projObjects.PBXContainerItemProxy || {};
// 2.4 Create native target
const target = pbx.addTarget(_iosConstants.BROADCAST_EXT_TARGET_NAME, 'app_extension', _iosConstants.BROADCAST_EXT_TARGET_NAME);
// 2.5 Add build phases to the new target (OneSignal approach)
pbx.addBuildPhase(_iosConstants.BROADCAST_EXT_SOURCE_FILES,
// Add source files directly to the build phase
'PBXSourcesBuildPhase', 'Sources', target.uuid);
pbx.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid);
pbx.addBuildPhase([], 'PBXFrameworksBuildPhase', 'Frameworks', target.uuid);
// 2.6 Link ReplayKit
pbx.addFramework('ReplayKit.framework', {
target: target.uuid,
sourceTree: 'SDKROOT',
link: true
});
/* ------------------------------------------------------------------ */
/* 3. Build-settings tweaks */
/* ------------------------------------------------------------------ */
const configurations = xcodeProject.pbxXCBuildConfigurationSection();
for (const key in configurations) {
const cfg = configurations[key];
const b = cfg.buildSettings;
if (!b) continue;
if (b.PRODUCT_NAME === `"${_iosConstants.BROADCAST_EXT_TARGET_NAME}"`) {
b.CLANG_ENABLE_MODULES = 'YES';
b.INFOPLIST_FILE = `"${_iosConstants.BROADCAST_EXT_TARGET_NAME}/${_iosConstants.BROADCAST_EXT_TARGET_NAME}-Info.plist"`;
b.CODE_SIGN_ENTITLEMENTS = `"${_iosConstants.BROADCAST_EXT_TARGET_NAME}/${_iosConstants.BROADCAST_EXT_TARGET_NAME}.entitlements"`;
b.CODE_SIGN_STYLE = 'Automatic';
b.CURRENT_PROJECT_VERSION = newConfig.ios?.buildNumber ?? _iosConstants.DEFAULT_BUNDLE_VERSION;
b.MARKETING_VERSION = newConfig.version ?? _iosConstants.DEFAULT_BUNDLE_SHORT_VERSION;
b.PRODUCT_BUNDLE_IDENTIFIER = `"${bundleIdentifier}"`;
b.SWIFT_VERSION = '5.0';
b.SWIFT_EMIT_LOC_STRINGS = 'YES';
b.SWIFT_OBJC_BRIDGING_HEADER = `"${_iosConstants.BROADCAST_EXT_TARGET_NAME}/BroadcastExtension-Bridging-Header.h"`;
b.HEADER_SEARCH_PATHS = `"$(SRCROOT)/${_iosConstants.BROADCAST_EXT_TARGET_NAME}"`;
b.TARGETED_DEVICE_FAMILY = _iosConstants.TARGETED_DEVICE_FAMILY;
if (devTeam) b.DEVELOPMENT_TEAM = devTeam;
}
}
/* ------------------------------------------------------------------ */
/* 4. Apply DevelopmentTeam to both targets */
/* ------------------------------------------------------------------ */
if (devTeam) {
xcodeProject.addTargetAttribute('DevelopmentTeam', devTeam);
const broadcastTarget = xcodeProject.pbxTargetByName(_iosConstants.BROADCAST_EXT_TARGET_NAME);
xcodeProject.addTargetAttribute('DevelopmentTeam', devTeam, broadcastTarget);
}
_ScreenRecorderLog.ScreenRecorderLog.log(`Successfully created ${_iosConstants.BROADCAST_EXT_TARGET_NAME} target with files`);
return newConfig;
});
};
exports.withBroadcastExtensionXcodeProject = withBroadcastExtensionXcodeProject;
//# sourceMappingURL=withBroadcastExtensionXcodeProject.js.map