Skip to content

Commit 9993427

Browse files
Mitchell Swaynclaude
andcommitted
feat(mobile): open T3 Code from the iPhone Camera Control button
iOS only lists apps under Settings > Camera > Camera Control when they ship a Locked Camera Capture extension and a control that runs a CameraCaptureIntent, so T3 Code could not be picked there. Add withCameraControl, which at prebuild adds a T3CameraCapture ExtensionKit target (com.apple.securecapture), a T3CameraControl control in the existing widget extension, and a shared T3CaptureIntent compiled into the app, widget, and capture targets. Unlocked, the button opens the app directly. Locked, the extension shows a viewfinder and a second press or the Open T3 Code button unlocks into the app. Personal Team builds skip it, like the other extensions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0712398 commit 9993427

9 files changed

Lines changed: 475 additions & 4 deletions

File tree

‎apps/mobile/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ project. pnpm gives each patch hash a new package path; Pods can otherwise keep
8080
previous directory.
8181

8282
If your Xcode account only has a Personal Team, use a bundle identifier you control and opt into the
83-
reduced-capability local build. Personal Team builds omit the widget and share extensions, push
84-
entitlement, and native Sign in with Apple entitlement; builds without this opt-in are unchanged.
83+
reduced-capability local build. Personal Team builds omit the widget, share, and Camera Control
84+
extensions, push entitlement, and native Sign in with Apple entitlement; builds without this opt-in
85+
are unchanged.
8586

8687
```bash
8788
T3CODE_IOS_PERSONAL_TEAM=1 \

‎apps/mobile/app.config.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ const config: ExpoConfig = {
418418
// Compile out the unused pedometer to avoid an iOS motion purpose string.
419419
["expo-sensors", { motionPermission: false }],
420420
// Mods run in reverse order; expo-widgets must create and wipe the target before assets are added.
421-
...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
421+
...(!isIosPersonalTeamBuild
422+
? ["./plugins/withCameraControl.cjs", "./plugins/withWidgetLogoAsset.cjs", widgetsPlugin]
423+
: []),
422424
"./plugins/withAndroidCleartextTraffic.cjs",
423425
"./plugins/withAndroidGradleHeap.cjs",
424426
"./plugins/withAndroidInputBackground.cjs",

‎apps/mobile/fingerprint.config.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ if (!majorVersion) {
1414

1515
module.exports = {
1616
nativeModuleSourceType: "files",
17-
extraSources: [{ type: "contents", id: "appMajorVersion", contents: majorVersion }],
17+
extraSources: [
18+
{ type: "contents", id: "appMajorVersion", contents: majorVersion },
19+
// withCameraControl copies these Swift sources into native targets at prebuild.
20+
{ type: "dir", filePath: "targets", reasons: ["iosCameraControl"] },
21+
],
1822
};
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
"use strict";
2+
3+
const SOURCE_FILES = {
4+
intent: "T3CaptureIntent.swift",
5+
control: "T3CameraControl.swift",
6+
extension: "T3CameraCapture.swift",
7+
};
8+
const EMBED_PHASE_NAME = "Embed ExtensionKit Extensions";
9+
10+
function stripComments(map) {
11+
return Object.fromEntries(Object.entries(map ?? {}).filter(([key]) => !key.endsWith("_comment")));
12+
}
13+
14+
function findByName(map, name) {
15+
const entry = Object.entries(stripComments(map)).find(
16+
([, value]) => value?.name === name || value?.name === `"${name}"`,
17+
);
18+
return entry ? { uuid: entry[0], value: entry[1] } : null;
19+
}
20+
21+
function addObject(proj, section, object, comment) {
22+
const objects = proj.hash.project.objects;
23+
const uuid = proj.generateUuid();
24+
objects[section] ??= {};
25+
objects[section][uuid] = object;
26+
objects[section][`${uuid}_comment`] = comment;
27+
return uuid;
28+
}
29+
30+
function sourcesPhaseOf(proj, target, targetName) {
31+
const phases = proj.hash.project.objects.PBXSourcesBuildPhase ?? {};
32+
const ref = target.buildPhases?.find(({ value }) => phases[value]);
33+
if (!ref) {
34+
throw new Error(`addCameraControlTargets: ${targetName} has no Sources build phase.`);
35+
}
36+
return phases[ref.value];
37+
}
38+
39+
function addBuildFile(proj, phase, fileRef, name, phaseName, settings) {
40+
const uuid = addObject(
41+
proj,
42+
"PBXBuildFile",
43+
{ isa: "PBXBuildFile", fileRef, fileRef_comment: name, ...(settings ? { settings } : {}) },
44+
`${name} in ${phaseName}`,
45+
);
46+
phase.files.push({ value: uuid, comment: `${name} in ${phaseName}` });
47+
}
48+
49+
function addPhase(proj, target, section, name, extra = {}) {
50+
const phase = {
51+
isa: section,
52+
buildActionMask: 2147483647,
53+
files: [],
54+
runOnlyForDeploymentPostprocessing: 0,
55+
...extra,
56+
};
57+
const uuid = addObject(proj, section, phase, name);
58+
target.buildPhases.push({ value: uuid, comment: name });
59+
return phase;
60+
}
61+
62+
/**
63+
* Adds the locked camera capture extension and wires the shared intent into the app and widget targets.
64+
* @param {import('xcode').XcodeProject} proj
65+
* @param {{ appTargetName: string, widgetTargetName: string, extensionTargetName: string,
66+
* bundleIdentifier: string, displayName: string, cameraUsageDescription: string,
67+
* marketingVersion: string, buildNumber: string, appleTeamId?: string }} opts
68+
*/
69+
function addCameraControlTargets(proj, opts) {
70+
const objects = proj.hash.project.objects;
71+
if (findByName(objects.PBXNativeTarget, opts.extensionTargetName)) return false;
72+
73+
const appTarget = findByName(objects.PBXNativeTarget, opts.appTargetName);
74+
const widgetTarget = findByName(objects.PBXNativeTarget, opts.widgetTargetName);
75+
if (!appTarget || !widgetTarget) {
76+
throw new Error(
77+
`addCameraControlTargets: missing ${appTarget ? opts.widgetTargetName : opts.appTargetName} target. ` +
78+
"Register withCameraControl before expo-widgets so its mods run after the widget target exists.",
79+
);
80+
}
81+
82+
const fileRefs = {};
83+
for (const [key, name] of Object.entries(SOURCE_FILES)) {
84+
fileRefs[key] = addObject(
85+
proj,
86+
"PBXFileReference",
87+
{
88+
isa: "PBXFileReference",
89+
lastKnownFileType: "sourcecode.swift",
90+
path: name,
91+
sourceTree: '"<group>"',
92+
},
93+
name,
94+
);
95+
}
96+
const infoPlistRef = addObject(
97+
proj,
98+
"PBXFileReference",
99+
{
100+
isa: "PBXFileReference",
101+
lastKnownFileType: "text.plist.xml",
102+
path: "Info.plist",
103+
sourceTree: '"<group>"',
104+
},
105+
"Info.plist",
106+
);
107+
const groupUuid = addObject(
108+
proj,
109+
"PBXGroup",
110+
{
111+
isa: "PBXGroup",
112+
children: [
113+
...Object.entries(SOURCE_FILES).map(([key, name]) => ({
114+
value: fileRefs[key],
115+
comment: name,
116+
})),
117+
{ value: infoPlistRef, comment: "Info.plist" },
118+
],
119+
path: opts.extensionTargetName,
120+
sourceTree: '"<group>"',
121+
},
122+
opts.extensionTargetName,
123+
);
124+
const mainGroup = objects.PBXGroup[proj.getFirstProject().firstProject.mainGroup];
125+
mainGroup.children.push({ value: groupUuid, comment: opts.extensionTargetName });
126+
127+
const productName = `${opts.extensionTargetName}.appex`;
128+
const productRef = addObject(
129+
proj,
130+
"PBXFileReference",
131+
{
132+
isa: "PBXFileReference",
133+
explicitFileType: '"wrapper.extensionkit-extension"',
134+
includeInIndex: 0,
135+
path: productName,
136+
sourceTree: "BUILT_PRODUCTS_DIR",
137+
},
138+
productName,
139+
);
140+
const productsGroup = findByName(objects.PBXGroup, "Products");
141+
productsGroup?.value.children.push({ value: productRef, comment: productName });
142+
143+
const buildSettings = {
144+
APPLICATION_EXTENSION_API_ONLY: "YES",
145+
CODE_SIGN_STYLE: "Automatic",
146+
CURRENT_PROJECT_VERSION: `"${opts.buildNumber}"`,
147+
...(opts.appleTeamId ? { DEVELOPMENT_TEAM: opts.appleTeamId } : {}),
148+
GENERATE_INFOPLIST_FILE: "YES",
149+
INFOPLIST_FILE: `${opts.extensionTargetName}/Info.plist`,
150+
INFOPLIST_KEY_CFBundleDisplayName: `"${opts.displayName}"`,
151+
INFOPLIST_KEY_NSCameraUsageDescription: `"${opts.cameraUsageDescription}"`,
152+
IPHONEOS_DEPLOYMENT_TARGET: "18.0",
153+
LD_RUNPATH_SEARCH_PATHS: [
154+
'"$(inherited)"',
155+
'"@executable_path/Frameworks"',
156+
'"@executable_path/../../Frameworks"',
157+
],
158+
MARKETING_VERSION: `"${opts.marketingVersion}"`,
159+
PRODUCT_BUNDLE_IDENTIFIER: `"${opts.bundleIdentifier}"`,
160+
PRODUCT_NAME: '"$(TARGET_NAME)"',
161+
SDKROOT: "iphoneos",
162+
SKIP_INSTALL: "YES",
163+
SWIFT_VERSION: "5.0",
164+
TARGETED_DEVICE_FAMILY: '"1,2"',
165+
};
166+
const { uuid: configurationListUuid } = proj.addXCConfigurationList(
167+
["Debug", "Release"].map((name) => ({
168+
name,
169+
isa: "XCBuildConfiguration",
170+
buildSettings: { ...buildSettings },
171+
})),
172+
"Release",
173+
`Build configuration list for PBXNativeTarget "${opts.extensionTargetName}"`,
174+
);
175+
176+
const extensionTarget = {
177+
isa: "PBXNativeTarget",
178+
buildConfigurationList: configurationListUuid,
179+
buildPhases: [],
180+
buildRules: [],
181+
dependencies: [],
182+
name: opts.extensionTargetName,
183+
productName: opts.extensionTargetName,
184+
productReference: productRef,
185+
productType: '"com.apple.product-type.extensionkit-extension"',
186+
};
187+
const extensionTargetUuid = addObject(
188+
proj,
189+
"PBXNativeTarget",
190+
extensionTarget,
191+
opts.extensionTargetName,
192+
);
193+
const extensionSources = addPhase(proj, extensionTarget, "PBXSourcesBuildPhase", "Sources");
194+
addPhase(proj, extensionTarget, "PBXFrameworksBuildPhase", "Frameworks");
195+
addPhase(proj, extensionTarget, "PBXResourcesBuildPhase", "Resources");
196+
addBuildFile(proj, extensionSources, fileRefs.extension, SOURCE_FILES.extension, "Sources");
197+
addBuildFile(proj, extensionSources, fileRefs.intent, SOURCE_FILES.intent, "Sources");
198+
199+
proj.addToPbxProjectSection({ uuid: extensionTargetUuid, pbxNativeTarget: extensionTarget });
200+
// addTargetDependency silently does nothing unless both sections exist.
201+
objects.PBXTargetDependency ??= {};
202+
objects.PBXContainerItemProxy ??= {};
203+
proj.addTargetDependency(appTarget.uuid, [extensionTargetUuid]);
204+
205+
const embedPhase = addPhase(proj, appTarget.value, "PBXCopyFilesBuildPhase", EMBED_PHASE_NAME, {
206+
dstPath: '"$(EXTENSIONS_FOLDER_PATH)"',
207+
dstSubfolderSpec: 16,
208+
name: `"${EMBED_PHASE_NAME}"`,
209+
});
210+
addBuildFile(proj, embedPhase, productRef, productName, EMBED_PHASE_NAME, {
211+
ATTRIBUTES: ["RemoveHeadersOnCopy"],
212+
});
213+
214+
const appSources = sourcesPhaseOf(proj, appTarget.value, opts.appTargetName);
215+
addBuildFile(proj, appSources, fileRefs.intent, SOURCE_FILES.intent, "Sources");
216+
const widgetSources = sourcesPhaseOf(proj, widgetTarget.value, opts.widgetTargetName);
217+
addBuildFile(proj, widgetSources, fileRefs.intent, SOURCE_FILES.intent, "Sources");
218+
addBuildFile(proj, widgetSources, fileRefs.control, SOURCE_FILES.control, "Sources");
219+
return true;
220+
}
221+
222+
module.exports = { addCameraControlTargets, SOURCE_FILES };
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"use strict";
2+
3+
// Camera Control lists apps that ship a locked camera capture extension and a CameraCaptureIntent control.
4+
// Precede expo-widgets so its reverse-ordered mods create and wipe the widget target before we extend it.
5+
6+
const fs = require("fs");
7+
const path = require("path");
8+
const { withDangerousMod, withXcodeProject } = require("expo/config-plugins");
9+
const { addCameraControlTargets, SOURCE_FILES } = require("./lib/addCameraControlTargets.cjs");
10+
11+
const EXTENSION_TARGET = "T3CameraCapture";
12+
const WIDGET_TARGET = "ExpoWidgetsTarget";
13+
const WIDGET_BUNDLE_ANCHOR = "WidgetLiveActivity()";
14+
const CAMERA_USAGE =
15+
"Allow T3 Code to show the camera on the Lock Screen so Camera Control can open the app.";
16+
17+
const INFO_PLIST = `<?xml version="1.0" encoding="UTF-8"?>
18+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
19+
<plist version="1.0">
20+
<dict>
21+
<key>EXAppExtensionAttributes</key>
22+
<dict>
23+
<key>EXExtensionPointIdentifier</key>
24+
<string>com.apple.securecapture</string>
25+
</dict>
26+
</dict>
27+
</plist>
28+
`;
29+
30+
function withSourceFiles(config) {
31+
return withDangerousMod(config, [
32+
"ios",
33+
(cfg) => {
34+
const { projectRoot, platformProjectRoot } = cfg.modRequest;
35+
const sourceDir = path.join(projectRoot, "targets", "camera-control");
36+
const targetDir = path.join(platformProjectRoot, EXTENSION_TARGET);
37+
fs.mkdirSync(targetDir, { recursive: true });
38+
for (const name of Object.values(SOURCE_FILES)) {
39+
fs.copyFileSync(path.join(sourceDir, name), path.join(targetDir, name));
40+
}
41+
fs.writeFileSync(path.join(targetDir, "Info.plist"), INFO_PLIST);
42+
43+
const bundlePath = path.join(platformProjectRoot, WIDGET_TARGET, "index.swift");
44+
const bundle = fs.readFileSync(bundlePath, "utf8");
45+
if (!bundle.includes("T3CameraControl()")) {
46+
if (bundle.split(WIDGET_BUNDLE_ANCHOR).length !== 2) {
47+
throw new Error(
48+
`withCameraControl: expected one ${WIDGET_BUNDLE_ANCHOR} in ${bundlePath}.`,
49+
);
50+
}
51+
fs.writeFileSync(
52+
bundlePath,
53+
bundle.replace(
54+
WIDGET_BUNDLE_ANCHOR,
55+
`${WIDGET_BUNDLE_ANCHOR}\n if #available(iOS 18.0, *) {\n T3CameraControl()\n }`,
56+
),
57+
);
58+
}
59+
return cfg;
60+
},
61+
]);
62+
}
63+
64+
function withTargets(config, bundleIdentifier) {
65+
return withXcodeProject(config, (cfg) => {
66+
addCameraControlTargets(cfg.modResults, {
67+
appTargetName: cfg.modRequest.projectName,
68+
widgetTargetName: WIDGET_TARGET,
69+
extensionTargetName: EXTENSION_TARGET,
70+
bundleIdentifier,
71+
displayName: cfg.name,
72+
cameraUsageDescription: CAMERA_USAGE,
73+
marketingVersion: cfg.ios?.version ?? cfg.version ?? "1.0",
74+
buildNumber: cfg.ios?.buildNumber ?? "1",
75+
appleTeamId: cfg.ios?.appleTeamId,
76+
});
77+
return cfg;
78+
});
79+
}
80+
81+
// EAS only provisions extension bundle identifiers it is told about.
82+
function withEasAppExtension(config, bundleIdentifier) {
83+
const ios = config.extra?.eas?.build?.experimental?.ios ?? {};
84+
const appExtensions = (ios.appExtensions ?? []).filter(
85+
(extension) => extension.targetName !== EXTENSION_TARGET,
86+
);
87+
config.extra = {
88+
...config.extra,
89+
eas: {
90+
...config.extra?.eas,
91+
build: {
92+
...config.extra?.eas?.build,
93+
experimental: {
94+
...config.extra?.eas?.build?.experimental,
95+
ios: {
96+
...ios,
97+
appExtensions: [...appExtensions, { targetName: EXTENSION_TARGET, bundleIdentifier }],
98+
},
99+
},
100+
},
101+
},
102+
};
103+
return config;
104+
}
105+
106+
module.exports = function withCameraControl(config) {
107+
const bundleIdentifier = `${config.ios.bundleIdentifier}.camera-capture`;
108+
return withTargets(
109+
withSourceFiles(withEasAppExtension(config, bundleIdentifier)),
110+
bundleIdentifier,
111+
);
112+
};

0 commit comments

Comments
 (0)