@blotch/angular-lynx-native 22.3.1 → 22.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -15
- package/dist/android/project.d.ts +90 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +369 -5
- package/dist/eject.d.ts +15 -1
- package/dist/eject.d.ts.map +1 -1
- package/dist/eject.js +13 -2
- package/dist/features.d.ts +70 -0
- package/dist/features.d.ts.map +1 -0
- package/dist/features.js +115 -0
- package/dist/generate.d.ts +17 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +12 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/ios/build.d.ts.map +1 -1
- package/dist/ios/build.js +8 -2
- package/dist/ios/frameworks.d.ts +6 -5
- package/dist/ios/frameworks.d.ts.map +1 -1
- package/dist/ios/frameworks.js +46 -15
- package/dist/ios/project.d.ts +173 -11
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +767 -33
- package/dist/options.d.ts +140 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +127 -0
- package/dist/permissions.d.ts +18 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +63 -3
- package/package.json +1 -1
- package/templates/android/README.md +35 -2
- package/templates/android/angular-lynx.properties +2 -0
- package/templates/android/app/build.gradle.kts +51 -2
- package/templates/android/app/src/main/AndroidManifest.xml +14 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +376 -6
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +25 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +168 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +6 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +47 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
- package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
- package/templates/android/app/src/main/res/values/share_target.xml +11 -0
- package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
- package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
- package/templates/android/build.gradle.kts +1 -1
- package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
- package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
- package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
- package/templates/ios/App/AngularLynxVideo.h +37 -0
- package/templates/ios/App/AngularLynxVideo.m +435 -0
- package/templates/ios/App/AngularLynxWebGL.h +69 -7
- package/templates/ios/App/AngularLynxWebGL.m +538 -29
- package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
- package/templates/ios/App/AppDelegate.swift +34 -2
- package/templates/ios/App/AppleSignInButton.swift +106 -0
- package/templates/ios/App/AppleSignInModule.swift +222 -0
- package/templates/ios/App/BarcodeScannerModule.swift +284 -0
- package/templates/ios/App/BiometricsModule.swift +256 -0
- package/templates/ios/App/BluetoothModule.swift +1086 -0
- package/templates/ios/App/CalendarModule.swift +158 -0
- package/templates/ios/App/FilePickerModule.swift +240 -0
- package/templates/ios/App/HapticsModule.swift +90 -0
- package/templates/ios/App/Info.plist +2 -0
- package/templates/ios/App/LynxViewController.swift +210 -6
- package/templates/ios/App/MotionModule.swift +430 -0
- package/templates/ios/App/NfcModule.swift +346 -0
- package/templates/ios/App/PhotoLibraryModule.swift +169 -0
- package/templates/ios/App/ShareTargetModule.swift +150 -0
- package/templates/ios/App/ShellModule.swift +17 -0
- package/templates/ios/App/StoreReviewModule.swift +61 -0
- package/templates/ios/App/TrackingModule.swift +121 -0
- package/templates/ios/App/WifiModule.swift +237 -0
- package/templates/ios/App/XElementRegistry.swift +13 -3
- package/templates/ios/ShareExtension/Info.plist +42 -0
- package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
package/dist/ios/project.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { copyFileSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { leaveOutWifi, removeMarkedLines, removeTemplateFiles, } from "../features.js";
|
|
4
|
+
import { ANGLE_IOS_FRAMEWORKS } from "./frameworks.js";
|
|
3
5
|
import { readPngSize } from "../png.js";
|
|
4
6
|
import { APP_NAME_PLACEHOLDER, shortcutIdentifier, } from "../options.js";
|
|
5
7
|
import { PERMISSION_MAP } from "../permissions.js";
|
|
@@ -21,10 +23,21 @@ const ORIENTATIONS = {
|
|
|
21
23
|
* Writes the app options into the iOS template: build settings go in
|
|
22
24
|
* Config/App.xcconfig (which App.xcodeproj reads), Info.plist entries go
|
|
23
25
|
* between the template's `angular-lynx:info` markers, the shortcuts
|
|
24
|
-
* become App/AppShortcuts.swift, the
|
|
25
|
-
* Config/App.entitlements, and the icon and the splash go in the asset
|
|
26
|
-
* catalog.
|
|
26
|
+
* become App/AppShortcuts.swift, the options that need a capability
|
|
27
|
+
* (IOS_ENTITLEMENTS) become Config/App.entitlements, and the icon and the splash go in the asset
|
|
28
|
+
* catalog. The barcode scanner's module stays only in an app with the
|
|
29
|
+
* `camera` permission, the Bluetooth module only in an app with the
|
|
30
|
+
* `bluetooth` permission, the store review module only in an app with
|
|
31
|
+
* `storeReview`, the calendar module only in one with `calendar`, the
|
|
32
|
+
* Sign in with Apple module only in one with `signInWithApple`, the
|
|
33
|
+
* tracking module only in one with `permissions.tracking`, the NFC module
|
|
34
|
+
* only in one with `permissions.nfc`, the motion module only in one with
|
|
35
|
+
* `motion`, the Share Extension, its target and
|
|
36
|
+
* its module only in one with `shareTarget`, and the Wi-Fi module only in
|
|
37
|
+
* one with `wifi`, with only the parts it turns on.
|
|
27
38
|
*/
|
|
39
|
+
/** LynxBarcodeScanner's module, which needs the `camera` permission. */
|
|
40
|
+
export const IOS_BARCODE_SCANNER_SOURCE = 'App/BarcodeScannerModule.swift';
|
|
28
41
|
export const iosGenerator = {
|
|
29
42
|
configure: (dir, app, projectRoot, development = false) => {
|
|
30
43
|
writeFileSync(path.join(dir, 'Config/App.xcconfig'), xcconfig(app));
|
|
@@ -35,13 +48,41 @@ export const iosGenerator = {
|
|
|
35
48
|
if (app.shortcuts.length > 0) {
|
|
36
49
|
writeFileSync(path.join(dir, 'App/AppShortcuts.swift'), appShortcutsSwift(app));
|
|
37
50
|
}
|
|
51
|
+
// App Store Connect flags an app whose code uses the camera without
|
|
52
|
+
// NSCameraUsageDescription (ITMS-90683), which only the `camera`
|
|
53
|
+
// permission writes. So an app that doesn't ask for the camera leaves
|
|
54
|
+
// the scanner's module out, and on Android its module and the Play
|
|
55
|
+
// services library behind it (see androidGenerator). LynxViewController
|
|
56
|
+
// registers the module by name only when it's compiled in.
|
|
57
|
+
if (!app.permissions.camera) {
|
|
58
|
+
rmSync(path.join(dir, IOS_BARCODE_SCANNER_SOURCE), { force: true });
|
|
59
|
+
}
|
|
60
|
+
// App Store Connect flags an app whose code uses CoreBluetooth without
|
|
61
|
+
// NSBluetoothAlwaysUsageDescription (ITMS-90683), which only the
|
|
62
|
+
// `bluetooth` permission writes. So an app that doesn't ask for Bluetooth
|
|
63
|
+
// leaves the module out, and ships no Bluetooth code at all, on Android
|
|
64
|
+
// as well (see androidGenerator). LynxViewController registers the module
|
|
65
|
+
// by name only when it's compiled in.
|
|
66
|
+
if (!app.permissions.bluetooth) {
|
|
67
|
+
rmSync(path.join(dir, 'App/BluetoothModule.swift'), { force: true });
|
|
68
|
+
}
|
|
38
69
|
// In Config/, beside the xcconfig that points the target at it, rather
|
|
39
70
|
// than in App/: Xcode would copy a file in that synchronized folder into
|
|
40
|
-
// the app as a resource. An app
|
|
41
|
-
// entitlements, as the template does.
|
|
42
|
-
if (app
|
|
71
|
+
// the app as a resource. An app whose options need no capability signs
|
|
72
|
+
// with no entitlements, as the template does.
|
|
73
|
+
if (hasEntitlements(app)) {
|
|
43
74
|
writeFileSync(path.join(dir, ENTITLEMENTS), entitlementsPlist(app));
|
|
44
75
|
}
|
|
76
|
+
// The Share Extension, with its own target, Info.plist and entitlements.
|
|
77
|
+
// The app's half (App Groups, the share scheme and ShareTargetModule) is
|
|
78
|
+
// in the entitlements and Info.plist written above.
|
|
79
|
+
if (app.shareTarget) {
|
|
80
|
+
const projectFile = path.join(dir, PROJECT_FILE);
|
|
81
|
+
writeFileSync(projectFile, withShareExtension(readFileSync(projectFile, 'utf8'), app));
|
|
82
|
+
const extensionPlist = path.join(dir, IOS_SHARE_EXTENSION_DIR, 'Info.plist');
|
|
83
|
+
writeFileSync(extensionPlist, replaceMarker(readFileSync(extensionPlist, 'utf8'), 'share-extension', shareExtensionPlistEntries(app)));
|
|
84
|
+
writeFileSync(path.join(dir, SHARE_EXTENSION_ENTITLEMENTS), shareExtensionEntitlementsPlist(app));
|
|
85
|
+
}
|
|
45
86
|
if (app.icon) {
|
|
46
87
|
const icon = path.resolve(projectRoot, app.icon);
|
|
47
88
|
const size = readPngSize(icon);
|
|
@@ -52,10 +93,307 @@ export const iosGenerator = {
|
|
|
52
93
|
}
|
|
53
94
|
writeIosSplash(dir, app, projectRoot);
|
|
54
95
|
},
|
|
96
|
+
leaveOut: (dir, features, app) => {
|
|
97
|
+
// Face ID, Touch ID and the Keychain items behind them are only for an
|
|
98
|
+
// app that says why it uses them: without NSFaceIDUsageDescription Face
|
|
99
|
+
// ID fails, and App Review asks about LocalAuthentication code an app
|
|
100
|
+
// gives no reason for. LynxViewController registers the module by name,
|
|
101
|
+
// so the shell builds without it.
|
|
102
|
+
if (!app.permissions.biometrics) {
|
|
103
|
+
removeTemplateFiles(dir, IOS_BIOMETRICS_SOURCES);
|
|
104
|
+
}
|
|
105
|
+
// The document picker is only for an app that turns it on with
|
|
106
|
+
// `filePicker`; LynxViewController registers it by name too.
|
|
107
|
+
if (!app.filePicker) {
|
|
108
|
+
removeTemplateFiles(dir, IOS_FILE_PICKER_SOURCES);
|
|
109
|
+
}
|
|
110
|
+
// An app that doesn't ask for ratings in the app (angular.json's
|
|
111
|
+
// `storeReview`) ships no StoreKit review code it never calls.
|
|
112
|
+
// LynxViewController registers the module by name too.
|
|
113
|
+
if (!app.storeReview) {
|
|
114
|
+
removeTemplateFiles(dir, [IOS_STORE_REVIEW_SOURCE]);
|
|
115
|
+
}
|
|
116
|
+
// Nor does an app that doesn't add events to the calendar (`calendar`)
|
|
117
|
+
// ship EventKit code it never calls.
|
|
118
|
+
if (!app.calendar) {
|
|
119
|
+
removeTemplateFiles(dir, [IOS_CALENDAR_SOURCE]);
|
|
120
|
+
}
|
|
121
|
+
// Sign in with Apple's sheet goes with its entitlement (see
|
|
122
|
+
// IOS_ENTITLEMENTS): an app that doesn't offer it has neither, and
|
|
123
|
+
// LynxViewController registers the module by name.
|
|
124
|
+
if (!app.signInWithApple) {
|
|
125
|
+
removeTemplateFiles(dir, IOS_APPLE_SIGN_IN_SOURCES);
|
|
126
|
+
}
|
|
127
|
+
// App Tracking Transparency's prompt is only for an app that says why it
|
|
128
|
+
// tracks (`permissions.tracking`): iOS ends an app that asks without
|
|
129
|
+
// NSUserTrackingUsageDescription.
|
|
130
|
+
if (!app.permissions.tracking) {
|
|
131
|
+
removeTemplateFiles(dir, [IOS_TRACKING_SOURCE]);
|
|
132
|
+
}
|
|
133
|
+
// An app that isn't a share target has no extension, no App Group and
|
|
134
|
+
// no module reading one; the project has no target for the extension
|
|
135
|
+
// either (configure adds it only with shareTarget).
|
|
136
|
+
if (!app.shareTarget) {
|
|
137
|
+
removeTemplateFiles(dir, [IOS_SHARE_TARGET_SOURCE]);
|
|
138
|
+
rmSync(path.join(dir, IOS_SHARE_EXTENSION_DIR), { recursive: true });
|
|
139
|
+
}
|
|
140
|
+
// Core NFC goes with its usage description and entitlement, which only
|
|
141
|
+
// `permissions.nfc` writes: an app without them would be ended, or
|
|
142
|
+
// refused, as it opened a session, and App Review asks about NFC code an
|
|
143
|
+
// app gives no reason for.
|
|
144
|
+
if (!app.permissions.nfc) {
|
|
145
|
+
removeTemplateFiles(dir, [IOS_NFC_SOURCE]);
|
|
146
|
+
}
|
|
147
|
+
// Saving to the photo library is only for an app that says why, with
|
|
148
|
+
// its own reason for the prompt. Every app has a reason for the share
|
|
149
|
+
// sheet's Save Image (see infoPlistEntries), but App Review asks about
|
|
150
|
+
// Photos code an app has no use for. Registered by name, as above.
|
|
151
|
+
if (!app.permissions.savePhotos) {
|
|
152
|
+
removeTemplateFiles(dir, IOS_PHOTO_LIBRARY_SOURCES);
|
|
153
|
+
}
|
|
154
|
+
// The Wi-Fi module goes with its entitlements (see IOS_ENTITLEMENTS),
|
|
155
|
+
// each part with its own: an app keeps only the code of the parts it
|
|
156
|
+
// turns on (`// angular-lynx:wifi-read`, `// angular-lynx:wifi-join`).
|
|
157
|
+
// The location code especially, which App Store Connect flags in an app
|
|
158
|
+
// without a location usage description.
|
|
159
|
+
leaveOutWifi(dir, app.wifi, IOS_WIFI_SOURCE);
|
|
160
|
+
// An app that doesn't read the motion sensors (angular.json's `motion`)
|
|
161
|
+
// ships no Core Motion or compass code it never calls. LynxViewController
|
|
162
|
+
// registers the module by name, so the shell builds without it.
|
|
163
|
+
if (!app.motion) {
|
|
164
|
+
removeTemplateFiles(dir, [IOS_MOTION_SOURCE]);
|
|
165
|
+
}
|
|
166
|
+
if (features.webgl)
|
|
167
|
+
return;
|
|
168
|
+
if (features.canvas) {
|
|
169
|
+
// A 2D canvas keeps the module and the canvas's view, without the
|
|
170
|
+
// WebGL2 context and the module's lines that make one.
|
|
171
|
+
removeTemplateFiles(dir, IOS_WEBGL_SOURCES);
|
|
172
|
+
for (const file of IOS_WEBGL_MARKED) {
|
|
173
|
+
removeMarkedLines(path.join(dir, file), 'webgl');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
removeTemplateFiles(dir, IOS_CANVAS_SOURCES);
|
|
178
|
+
}
|
|
179
|
+
// Only the WebGL2 context draws with ANGLE. The canvas's view is still
|
|
180
|
+
// a CAMetalLayer, which is QuartzCore's: a 2D context shows its bitmap
|
|
181
|
+
// in a CALayer over it.
|
|
182
|
+
const projectFile = path.join(dir, PROJECT_FILE);
|
|
183
|
+
writeFileSync(projectFile, withoutFrameworks(readFileSync(projectFile, 'utf8'), ANGLE_IOS_FRAMEWORKS));
|
|
184
|
+
},
|
|
55
185
|
bundleDir: (dir) => path.join(dir, 'LynxBundle'),
|
|
56
186
|
};
|
|
187
|
+
/** The module behind `LynxStoreReview`, which only `storeReview` keeps. */
|
|
188
|
+
export const IOS_STORE_REVIEW_SOURCE = 'App/StoreReviewModule.swift';
|
|
189
|
+
/** The module behind `LynxCalendar`, which only `calendar` keeps. */
|
|
190
|
+
export const IOS_CALENDAR_SOURCE = 'App/CalendarModule.swift';
|
|
191
|
+
/**
|
|
192
|
+
* The module behind `LynxAppleSignIn` and the `<apple-sign-in-button>`
|
|
193
|
+
* element, which only `signInWithApple` keeps.
|
|
194
|
+
*/
|
|
195
|
+
export const IOS_APPLE_SIGN_IN_SOURCES = [
|
|
196
|
+
'App/AppleSignInModule.swift',
|
|
197
|
+
'App/AppleSignInButton.swift',
|
|
198
|
+
];
|
|
199
|
+
/** The module behind `LynxNfc`, which only `permissions.nfc` keeps. */
|
|
200
|
+
export const IOS_NFC_SOURCE = 'App/NfcModule.swift';
|
|
201
|
+
/** The module behind `LynxWifi`, which only `wifi` keeps. */
|
|
202
|
+
export const IOS_WIFI_SOURCE = 'App/WifiModule.swift';
|
|
203
|
+
/** The module behind `LynxMotion`, which only `motion` keeps. */
|
|
204
|
+
export const IOS_MOTION_SOURCE = 'App/MotionModule.swift';
|
|
205
|
+
/**
|
|
206
|
+
* The module behind `LynxTracking`, which only an app with
|
|
207
|
+
* `permissions.tracking` keeps.
|
|
208
|
+
*/
|
|
209
|
+
export const IOS_TRACKING_SOURCE = 'App/TrackingModule.swift';
|
|
210
|
+
/**
|
|
211
|
+
* The shell's biometrics module, `AngularLynxBiometrics` (LynxBiometrics, and
|
|
212
|
+
* the values LynxSecureStorage keeps behind Face ID or Touch ID), which only
|
|
213
|
+
* an app with `permissions.biometrics` keeps.
|
|
214
|
+
*/
|
|
215
|
+
export const IOS_BIOMETRICS_SOURCES = ['App/BiometricsModule.swift'];
|
|
216
|
+
/**
|
|
217
|
+
* The shell's file picker module, `AngularLynxFilePicker` (LynxFilePicker),
|
|
218
|
+
* which only an app with `filePicker` keeps.
|
|
219
|
+
*/
|
|
220
|
+
export const IOS_FILE_PICKER_SOURCES = ['App/FilePickerModule.swift'];
|
|
221
|
+
/**
|
|
222
|
+
* The shell's photo library module, `AngularLynxPhotoLibrary`
|
|
223
|
+
* (LynxPhotoLibrary), which only an app with `permissions.savePhotos` keeps.
|
|
224
|
+
*/
|
|
225
|
+
export const IOS_PHOTO_LIBRARY_SOURCES = [
|
|
226
|
+
'App/PhotoLibraryModule.swift',
|
|
227
|
+
];
|
|
228
|
+
/**
|
|
229
|
+
* The shell's `<canvas>`, its `AngularLynxWebGL` module and its contexts, and
|
|
230
|
+
* `<video>`'s readable frames: about 176 kB of the executable. Swift reaches
|
|
231
|
+
* them only by name (NSClassFromString in LynxViewController and
|
|
232
|
+
* XElementRegistry), so without them the shell registers no canvas, keeps
|
|
233
|
+
* XElement's own `<video>`, and still builds: App/ is a synchronized folder,
|
|
234
|
+
* which compiles what's in it.
|
|
235
|
+
*/
|
|
236
|
+
export const IOS_CANVAS_SOURCES = [
|
|
237
|
+
'App/AngularLynxBitmapRendererContext.m',
|
|
238
|
+
'App/AngularLynxCanvas2DContext.m',
|
|
239
|
+
'App/AngularLynxCanvas2DOps.h',
|
|
240
|
+
'App/AngularLynxVideo.h',
|
|
241
|
+
'App/AngularLynxVideo.m',
|
|
242
|
+
'App/AngularLynxWebGL.h',
|
|
243
|
+
'App/AngularLynxWebGL.m',
|
|
244
|
+
'App/AngularLynxWebGLContext.m',
|
|
245
|
+
'App/AngularLynxWebGLOps.h',
|
|
246
|
+
];
|
|
247
|
+
/**
|
|
248
|
+
* The WebGL2 context, which an app that draws only in 2D leaves out with
|
|
249
|
+
* ANGLE (issue #847).
|
|
250
|
+
*/
|
|
251
|
+
export const IOS_WEBGL_SOURCES = [
|
|
252
|
+
'App/AngularLynxWebGLContext.m',
|
|
253
|
+
'App/AngularLynxWebGLOps.h',
|
|
254
|
+
];
|
|
255
|
+
/**
|
|
256
|
+
* The files whose lines between `// angular-lynx:webgl` markers name the
|
|
257
|
+
* WebGL2 context, and go with it: the class's declaration, and the module's
|
|
258
|
+
* methods that make and run one. Nothing else names it.
|
|
259
|
+
*/
|
|
260
|
+
const IOS_WEBGL_MARKED = [
|
|
261
|
+
'App/AngularLynxWebGL.h',
|
|
262
|
+
'App/AngularLynxWebGL.m',
|
|
263
|
+
];
|
|
264
|
+
const PROJECT_FILE = 'App.xcodeproj/project.pbxproj';
|
|
265
|
+
/**
|
|
266
|
+
* The project without the XCFrameworks named, which it then neither links
|
|
267
|
+
* nor embeds: ANGLE's, about 6 MB of an app, are only for WebGL. Each
|
|
268
|
+
* reference to a framework is one line of the project (its file, its build
|
|
269
|
+
* files, and their places in the group, the link phase and the embed phase).
|
|
270
|
+
*/
|
|
271
|
+
export const withoutFrameworks = (project, frameworks) => {
|
|
272
|
+
const names = frameworks.map((name) => `${name}.xcframework`);
|
|
273
|
+
// A renamed framework would otherwise stay in every app unnoticed.
|
|
274
|
+
for (const name of names) {
|
|
275
|
+
if (!project.includes(name)) {
|
|
276
|
+
throw new Error(`The project has no ${name} to leave out.`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return project
|
|
280
|
+
.split('\n')
|
|
281
|
+
.filter((line) => !names.some((name) => line.includes(name)))
|
|
282
|
+
.join('\n');
|
|
283
|
+
};
|
|
57
284
|
/** The app's entitlements, from the project folder (see xcconfig). */
|
|
58
285
|
const ENTITLEMENTS = 'Config/App.entitlements';
|
|
286
|
+
/**
|
|
287
|
+
* Each option that needs an iOS capability, and the entitlements it adds to
|
|
288
|
+
* Config/App.entitlements. A feature that needs one (Wi-Fi, in-app
|
|
289
|
+
* purchases, push...) adds its entry here, rather than writing the file: the generator
|
|
290
|
+
* writes the file, and points the target at it, only when an entry adds
|
|
291
|
+
* something, and {@link mergeEntitlements} joins two options' lists under
|
|
292
|
+
* the same key, as Associated Domains holds both `applinks:` and
|
|
293
|
+
* `webcredentials:` domains.
|
|
294
|
+
*/
|
|
295
|
+
export const IOS_ENTITLEMENTS = [
|
|
296
|
+
{
|
|
297
|
+
// Universal Links: iOS opens the app for an https link to one of the
|
|
298
|
+
// domains, once the domain's apple-app-site-association names the app
|
|
299
|
+
// (see appLinkFiles). iOS fetches that file through Apple's CDN when the
|
|
300
|
+
// app is installed.
|
|
301
|
+
option: 'appLinkDomains',
|
|
302
|
+
capability: 'Associated Domains',
|
|
303
|
+
entitlements: (app) => app.appLinkDomains.length === 0
|
|
304
|
+
? {}
|
|
305
|
+
: {
|
|
306
|
+
'com.apple.developer.associated-domains': app.appLinkDomains.map((domain) => `applinks:${domain}`),
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
// ASAuthorizationAppleIDProvider's sheet fails without it
|
|
311
|
+
// (ASAuthorizationError 1000). "Default" is the only value Apple
|
|
312
|
+
// defines: the app is its own primary App ID for the sign-in.
|
|
313
|
+
option: 'signInWithApple',
|
|
314
|
+
capability: 'Sign In with Apple',
|
|
315
|
+
entitlements: (app) => app.signInWithApple
|
|
316
|
+
? { 'com.apple.developer.applesignin': ['Default'] }
|
|
317
|
+
: {},
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
// The container the Share Extension leaves each share in for the app
|
|
321
|
+
// (ShareTargetModule). The extension has the same group in its own
|
|
322
|
+
// entitlements (shareExtensionEntitlementsPlist).
|
|
323
|
+
option: 'shareTarget',
|
|
324
|
+
capability: 'App Groups',
|
|
325
|
+
entitlements: (app) => app.shareTarget
|
|
326
|
+
? { 'com.apple.security.application-groups': [shareGroup(app)] }
|
|
327
|
+
: {},
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
// Core NFC's NFCNDEFReaderSession, behind LynxNfc. TAG is the only
|
|
331
|
+
// format an app for iOS 13 and later may declare: it covers NDEF
|
|
332
|
+
// sessions too, and Xcode rejects the older NDEF value.
|
|
333
|
+
option: 'permissions.nfc',
|
|
334
|
+
capability: 'NFC Tag Reading',
|
|
335
|
+
entitlements: (app) => app.permissions.nfc
|
|
336
|
+
? { 'com.apple.developer.nfc.readersession.formats': ['TAG'] }
|
|
337
|
+
: {},
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
// NEHotspotConfigurationManager's apply fails without it, behind
|
|
341
|
+
// LynxWifi.join().
|
|
342
|
+
option: 'wifi.join',
|
|
343
|
+
capability: 'Hotspot Configuration',
|
|
344
|
+
entitlements: (app) => app.wifi.join
|
|
345
|
+
? { 'com.apple.developer.networking.HotspotConfiguration': true }
|
|
346
|
+
: {},
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
// NEHotspotNetwork.fetchCurrent answers nil without it, behind
|
|
350
|
+
// LynxWifi.currentNetwork().
|
|
351
|
+
option: 'wifi.readCurrentNetwork',
|
|
352
|
+
capability: 'Access WiFi Information',
|
|
353
|
+
entitlements: (app) => app.wifi.readCurrentNetwork
|
|
354
|
+
? { 'com.apple.developer.networking.wifi-info': true }
|
|
355
|
+
: {},
|
|
356
|
+
},
|
|
357
|
+
];
|
|
358
|
+
/**
|
|
359
|
+
* Joins the entitlements several options add into one dictionary, its keys
|
|
360
|
+
* sorted, as Xcode writes them. Two lists under one key become one, each
|
|
361
|
+
* value once, in the order the options name them. Two different flags or
|
|
362
|
+
* strings under one key can't both be signed, so they throw, naming the
|
|
363
|
+
* options.
|
|
364
|
+
*/
|
|
365
|
+
export const mergeEntitlements = (contributions) => {
|
|
366
|
+
const merged = new Map();
|
|
367
|
+
for (const { option, entitlements } of contributions) {
|
|
368
|
+
for (const [key, value] of Object.entries(entitlements)) {
|
|
369
|
+
const seen = merged.get(key);
|
|
370
|
+
if (!seen) {
|
|
371
|
+
merged.set(key, {
|
|
372
|
+
value: Array.isArray(value) ? [...new Set(value)] : value,
|
|
373
|
+
from: option,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
else if (Array.isArray(seen.value) && Array.isArray(value)) {
|
|
377
|
+
seen.value = [...new Set([...seen.value, ...value])];
|
|
378
|
+
seen.from = `${seen.from}, ${option}`;
|
|
379
|
+
}
|
|
380
|
+
else if (seen.value !== value) {
|
|
381
|
+
throw new Error(`${seen.from} and ${option} set the ${key} entitlement to different values (${JSON.stringify(seen.value)}, ${JSON.stringify(value)}).`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return Object.fromEntries([...merged.keys()].sort().map((key) => [key, merged.get(key).value]));
|
|
386
|
+
};
|
|
387
|
+
/**
|
|
388
|
+
* The options that add entitlements to `app`, in IOS_ENTITLEMENTS' order.
|
|
389
|
+
*/
|
|
390
|
+
const entitlementContributions = (app) => IOS_ENTITLEMENTS.map(({ option, entitlements }) => ({
|
|
391
|
+
option,
|
|
392
|
+
entitlements: entitlements(app),
|
|
393
|
+
})).filter(({ entitlements }) => Object.keys(entitlements).length > 0);
|
|
394
|
+
/** The app's entitlements, from every option that adds some. */
|
|
395
|
+
export const iosEntitlements = (app) => mergeEntitlements(entitlementContributions(app));
|
|
396
|
+
const hasEntitlements = (app) => entitlementContributions(app).length > 0;
|
|
59
397
|
/**
|
|
60
398
|
* xcconfig values can't be quoted; `$` and `//` would start a variable or a comment.
|
|
61
399
|
*/
|
|
@@ -70,37 +408,54 @@ export const xcconfig = (app) => [
|
|
|
70
408
|
`MARKETING_VERSION = ${app.version}`,
|
|
71
409
|
`CURRENT_PROJECT_VERSION = ${app.buildNumber}`,
|
|
72
410
|
`DEVELOPMENT_TEAM = ${app.ios.teamId ?? ''}`,
|
|
73
|
-
// Only
|
|
74
|
-
|
|
411
|
+
// Only when an option needs a capability (IOS_ENTITLEMENTS): an
|
|
412
|
+
// entitlement nobody asked for could keep a free Personal Team from
|
|
413
|
+
// signing the app.
|
|
414
|
+
...(hasEntitlements(app)
|
|
75
415
|
? [`CODE_SIGN_ENTITLEMENTS = ${ENTITLEMENTS}`]
|
|
76
416
|
: []),
|
|
77
417
|
'',
|
|
78
418
|
].join('\n');
|
|
79
419
|
/**
|
|
80
|
-
* Config/App.entitlements: the
|
|
81
|
-
*
|
|
82
|
-
* once the domain's apple-app-site-association names the app (see
|
|
83
|
-
* appLinkFiles). iOS fetches that file through Apple's CDN when the app is
|
|
84
|
-
* installed.
|
|
420
|
+
* Config/App.entitlements: the capabilities the app's options ask for
|
|
421
|
+
* ({@link IOS_ENTITLEMENTS}), merged.
|
|
85
422
|
*
|
|
86
|
-
* Signing
|
|
87
|
-
* Personal Team can't sign Associated Domains
|
|
88
|
-
*
|
|
423
|
+
* Signing most of them needs a team in the paid Apple Developer Program: a
|
|
424
|
+
* free Personal Team can't sign Associated Domains, Sign in with Apple, NFC
|
|
425
|
+
* Tag Reading or App Groups (explainSigningFailure in build.ts names the
|
|
426
|
+
* option). The simulator app
|
|
427
|
+
* needs no team.
|
|
89
428
|
*/
|
|
90
|
-
export const entitlementsPlist = (app) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
]
|
|
429
|
+
export const entitlementsPlist = (app) => {
|
|
430
|
+
const options = entitlementContributions(app).map(({ option }) => option);
|
|
431
|
+
const value = (entitlement) => {
|
|
432
|
+
if (typeof entitlement === 'boolean') {
|
|
433
|
+
return [entitlement ? '\t<true/>' : '\t<false/>'];
|
|
434
|
+
}
|
|
435
|
+
if (typeof entitlement === 'string') {
|
|
436
|
+
return [`\t<string>${escapeXml(entitlement)}</string>`];
|
|
437
|
+
}
|
|
438
|
+
return [
|
|
439
|
+
'\t<array>',
|
|
440
|
+
...entitlement.map((item) => `\t\t<string>${escapeXml(item)}</string>`),
|
|
441
|
+
'\t</array>',
|
|
442
|
+
];
|
|
443
|
+
};
|
|
444
|
+
return [
|
|
445
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
446
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
447
|
+
`<!-- Written by @blotch/angular-lynx-native from ${options.join(', ')} in angular.json. -->`,
|
|
448
|
+
'<plist version="1.0">',
|
|
449
|
+
'<dict>',
|
|
450
|
+
...Object.entries(iosEntitlements(app)).flatMap(([key, entitlement]) => [
|
|
451
|
+
`\t<key>${escapeXml(key)}</key>`,
|
|
452
|
+
...value(entitlement),
|
|
453
|
+
]),
|
|
454
|
+
'</dict>',
|
|
455
|
+
'</plist>',
|
|
456
|
+
'',
|
|
457
|
+
].join('\n');
|
|
458
|
+
};
|
|
104
459
|
/** What iOS shows the first time someone taps Save Image, without `savePhotos`. */
|
|
105
460
|
export const DEFAULT_SAVE_PHOTOS_REASON = 'Saves the images you choose to your photo library.';
|
|
106
461
|
/**
|
|
@@ -126,6 +481,12 @@ export const infoPlistEntries = (app, { development = false } = {}) => {
|
|
|
126
481
|
// Read by LynxViewController, which lays the LynxView out over the whole
|
|
127
482
|
// screen or inside the safe area.
|
|
128
483
|
lines.push('<key>AngularLynxEdgeToEdge</key>', app.edgeToEdge ? '<true/>' : '<false/>');
|
|
484
|
+
// Read by LynxViewController, which sets the LynxView's font scale from
|
|
485
|
+
// Dynamic Type, capped at the max, or keeps it at 1.
|
|
486
|
+
lines.push('<key>AngularLynxTextScaling</key>', app.textScaling.enabled ? '<true/>' : '<false/>');
|
|
487
|
+
if (app.textScaling.max !== undefined) {
|
|
488
|
+
lines.push('<key>AngularLynxMaxTextScale</key>', `<real>${app.textScaling.max}</real>`);
|
|
489
|
+
}
|
|
129
490
|
// The share sheet LynxShare opens has Save Image for an image, which adds
|
|
130
491
|
// it to the photo library, and iOS ends an app that does so without a
|
|
131
492
|
// reason in Info.plist. So every app has one, which `savePhotos` changes.
|
|
@@ -150,11 +511,27 @@ export const infoPlistEntries = (app, { development = false } = {}) => {
|
|
|
150
511
|
if (development && !app.permissions.localNetwork) {
|
|
151
512
|
lines.push('<key>NSLocalNetworkUsageDescription</key>', `<string>${escapeXml(LOCAL_NETWORK_REASON)}</string>`);
|
|
152
513
|
}
|
|
514
|
+
// The app's Documents folder in the Files app, under On My iPhone, where
|
|
515
|
+
// LynxFilePicker's save() can put a file and pick() find it again. iOS
|
|
516
|
+
// lists the folder only with both keys.
|
|
517
|
+
if (app.fileSharing) {
|
|
518
|
+
lines.push('<key>UIFileSharingEnabled</key>', '<true/>', '<key>LSSupportsOpeningDocumentsInPlace</key>', '<true/>');
|
|
519
|
+
}
|
|
153
520
|
// The schemes LinkingModule's canOpenURL can ask about: iOS answers false
|
|
154
521
|
// for any other. UIApplication.open needs none of them.
|
|
155
522
|
array('LSApplicationQueriesSchemes', app.canOpenURLSchemes);
|
|
156
|
-
|
|
157
|
-
|
|
523
|
+
// The Share Extension opens the app with a scheme of its own, which
|
|
524
|
+
// SceneDelegate tells from a deep link, and leaves the share in the App
|
|
525
|
+
// Group ShareTargetModule reads.
|
|
526
|
+
const schemes = [
|
|
527
|
+
...app.deepLinkSchemes,
|
|
528
|
+
...(app.shareTarget ? [shareScheme(app)] : []),
|
|
529
|
+
];
|
|
530
|
+
if (app.shareTarget) {
|
|
531
|
+
lines.push('<key>AngularLynxShareGroup</key>', `<string>${escapeXml(shareGroup(app))}</string>`, '<key>AngularLynxShareScheme</key>', `<string>${escapeXml(shareScheme(app))}</string>`);
|
|
532
|
+
}
|
|
533
|
+
if (schemes.length > 0) {
|
|
534
|
+
lines.push('<key>CFBundleURLTypes</key>', '<array>', '\t<dict>', '\t\t<key>CFBundleURLName</key>', `\t\t<string>${escapeXml(app.id)}</string>`, '\t\t<key>CFBundleURLSchemes</key>', '\t\t<array>', ...schemes.map((scheme) => `\t\t\t<string>${escapeXml(scheme)}</string>`), '\t\t</array>', '\t</dict>', '</array>');
|
|
158
535
|
}
|
|
159
536
|
return lines.join('\n');
|
|
160
537
|
};
|
|
@@ -238,3 +615,360 @@ export const appShortcutsSwift = (app) => {
|
|
|
238
615
|
'',
|
|
239
616
|
].join('\n');
|
|
240
617
|
};
|
|
618
|
+
// ─── shareTarget: the Share Extension ────────────────────────────────────────
|
|
619
|
+
/** LynxShareTarget's module in the app, which only `shareTarget` keeps. */
|
|
620
|
+
export const IOS_SHARE_TARGET_SOURCE = 'App/ShareTargetModule.swift';
|
|
621
|
+
/**
|
|
622
|
+
* The Share Extension's folder: the extension's code and its Info.plist,
|
|
623
|
+
* which only `shareTarget` keeps, with the target the generator adds to the
|
|
624
|
+
* project for it ({@link withShareExtension}).
|
|
625
|
+
*/
|
|
626
|
+
export const IOS_SHARE_EXTENSION_DIR = 'ShareExtension';
|
|
627
|
+
/** The extension's entitlements, beside the app's (see ENTITLEMENTS). */
|
|
628
|
+
const SHARE_EXTENSION_ENTITLEMENTS = 'Config/ShareExtension.entitlements';
|
|
629
|
+
/**
|
|
630
|
+
* The App Group the app and its Share Extension share, where the extension
|
|
631
|
+
* leaves each share for the app: `group.` and the app's bundle ID, as Xcode
|
|
632
|
+
* names a new group.
|
|
633
|
+
*/
|
|
634
|
+
export const shareGroup = (app) => `group.${app.id}`;
|
|
635
|
+
/**
|
|
636
|
+
* The URL scheme the Share Extension opens the app with once it has left a
|
|
637
|
+
* share: one of the app's own, from its bundle ID, so no other app answers
|
|
638
|
+
* to it. SceneDelegate takes it for the share, never for a deep link.
|
|
639
|
+
*/
|
|
640
|
+
export const shareScheme = (app) => `angularlynx-share.${app.id.toLowerCase().replace(/[^a-z0-9.-]/g, '-')}`;
|
|
641
|
+
/**
|
|
642
|
+
* The activation rule's keys for `mimeTypes`: which kinds of things in a
|
|
643
|
+
* share sheet show the app. Apple's rule can't name a MIME type, only kinds,
|
|
644
|
+
* so a type that isn't text, a link, an image or a video allows files, and
|
|
645
|
+
* the extension then checks each file's own type against the list.
|
|
646
|
+
*/
|
|
647
|
+
export const shareActivationRule = (mimeTypes) => {
|
|
648
|
+
const takes = (kind) => mimeTypes.some((type) => type === '*/*' || type === `${kind}/*` || type.startsWith(`${kind}/`));
|
|
649
|
+
// Version 2 shows the app when the share holds one thing it takes. The
|
|
650
|
+
// first version asks that it take everything shared, and Safari shares a
|
|
651
|
+
// page as both a link and text, so a text-only app wasn't listed there.
|
|
652
|
+
const rule = {
|
|
653
|
+
NSExtensionActivationDictionaryVersion: 2,
|
|
654
|
+
};
|
|
655
|
+
// The most of each kind iOS offers the app for. It only decides whether
|
|
656
|
+
// the app shows in the share sheet: the extension's 20 MiB of files per
|
|
657
|
+
// share is what limits a share, so this is high enough that a selection
|
|
658
|
+
// of small photos that fits is never refused for its count alone.
|
|
659
|
+
const most = 100;
|
|
660
|
+
if (mimeTypes.some((type) => type === '*/*' || type === 'text/*' || type === 'text/plain')) {
|
|
661
|
+
rule['NSExtensionActivationSupportsText'] = true;
|
|
662
|
+
}
|
|
663
|
+
// Links for text/plain too, as Android shares them: iOS doesn't count a
|
|
664
|
+
// page's link as text, and the extension hands a link to an app that
|
|
665
|
+
// takes only text as its text.
|
|
666
|
+
if (mimeTypes.some((type) => type === '*/*' ||
|
|
667
|
+
type === 'text/*' ||
|
|
668
|
+
type === 'text/uri-list' ||
|
|
669
|
+
type === 'text/plain')) {
|
|
670
|
+
rule['NSExtensionActivationSupportsWebURLWithMaxCount'] = 1;
|
|
671
|
+
rule['NSExtensionActivationSupportsWebPageWithMaxCount'] = 1;
|
|
672
|
+
}
|
|
673
|
+
if (takes('image')) {
|
|
674
|
+
rule['NSExtensionActivationSupportsImageWithMaxCount'] = most;
|
|
675
|
+
}
|
|
676
|
+
if (takes('video')) {
|
|
677
|
+
rule['NSExtensionActivationSupportsMovieWithMaxCount'] = most;
|
|
678
|
+
}
|
|
679
|
+
if (mimeTypes.some((type) => !type.startsWith('image/') &&
|
|
680
|
+
!type.startsWith('video/') &&
|
|
681
|
+
type !== 'text/plain' &&
|
|
682
|
+
type !== 'text/uri-list')) {
|
|
683
|
+
rule['NSExtensionActivationSupportsFileWithMaxCount'] = most;
|
|
684
|
+
}
|
|
685
|
+
return Object.fromEntries(Object.keys(rule)
|
|
686
|
+
.sort()
|
|
687
|
+
.map((key) => [key, rule[key]]));
|
|
688
|
+
};
|
|
689
|
+
/**
|
|
690
|
+
* The Share Extension's Info.plist entries, between its template's
|
|
691
|
+
* `angular-lynx:share-extension` markers: the extension point, the
|
|
692
|
+
* activation rule for `mimeTypes`, and what the extension reads (the types,
|
|
693
|
+
* the App Group and the app's share scheme).
|
|
694
|
+
*/
|
|
695
|
+
export const shareExtensionPlistEntries = (app) => {
|
|
696
|
+
const { mimeTypes } = app.shareTarget;
|
|
697
|
+
return [
|
|
698
|
+
'<key>AngularLynxShareGroup</key>',
|
|
699
|
+
`<string>${escapeXml(shareGroup(app))}</string>`,
|
|
700
|
+
'<key>AngularLynxShareScheme</key>',
|
|
701
|
+
`<string>${escapeXml(shareScheme(app))}</string>`,
|
|
702
|
+
'<key>AngularLynxShareMimeTypes</key>',
|
|
703
|
+
'<array>',
|
|
704
|
+
...mimeTypes.map((type) => `\t<string>${escapeXml(type)}</string>`),
|
|
705
|
+
'</array>',
|
|
706
|
+
'<key>NSExtension</key>',
|
|
707
|
+
'<dict>',
|
|
708
|
+
'\t<key>NSExtensionAttributes</key>',
|
|
709
|
+
'\t<dict>',
|
|
710
|
+
'\t\t<key>NSExtensionActivationRule</key>',
|
|
711
|
+
'\t\t<dict>',
|
|
712
|
+
...Object.entries(shareActivationRule(mimeTypes)).flatMap(([key, value]) => [
|
|
713
|
+
`\t\t\t<key>${key}</key>`,
|
|
714
|
+
typeof value === 'boolean'
|
|
715
|
+
? '\t\t\t<true/>'
|
|
716
|
+
: `\t\t\t<integer>${value}</integer>`,
|
|
717
|
+
]),
|
|
718
|
+
'\t\t</dict>',
|
|
719
|
+
'\t</dict>',
|
|
720
|
+
'\t<key>NSExtensionPointIdentifier</key>',
|
|
721
|
+
'\t<string>com.apple.share-services</string>',
|
|
722
|
+
'\t<key>NSExtensionPrincipalClass</key>',
|
|
723
|
+
'\t<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>',
|
|
724
|
+
'</dict>',
|
|
725
|
+
].join('\n');
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Config/ShareExtension.entitlements: the App Group alone, which is all the
|
|
729
|
+
* extension needs to leave a share where the app reads it.
|
|
730
|
+
*/
|
|
731
|
+
export const shareExtensionEntitlementsPlist = (app) => [
|
|
732
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
733
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
734
|
+
'<!-- Written by @blotch/angular-lynx-native from shareTarget in angular.json. -->',
|
|
735
|
+
'<plist version="1.0">',
|
|
736
|
+
'<dict>',
|
|
737
|
+
'\t<key>com.apple.security.application-groups</key>',
|
|
738
|
+
'\t<array>',
|
|
739
|
+
`\t\t<string>${escapeXml(shareGroup(app))}</string>`,
|
|
740
|
+
'\t</array>',
|
|
741
|
+
'</dict>',
|
|
742
|
+
'</plist>',
|
|
743
|
+
'',
|
|
744
|
+
].join('\n');
|
|
745
|
+
/**
|
|
746
|
+
* The IDs of what {@link withShareExtension} adds to the project. Any 24 hex
|
|
747
|
+
* digits do, as long as they're not the template's: fixed ones keep the
|
|
748
|
+
* project the same from one build to the next, which Xcode's incremental
|
|
749
|
+
* build state relies on.
|
|
750
|
+
*/
|
|
751
|
+
const SHARE_IDS = {
|
|
752
|
+
target: '9D15F9546F164C486D749216',
|
|
753
|
+
product: '57C1796F1E1D5E76E66D6B1C',
|
|
754
|
+
embedFile: '7F7C1C4CBB392ABDC1101D98',
|
|
755
|
+
embedPhase: '7AAA86580D6ADC71A7F9AEF7',
|
|
756
|
+
exceptions: '5CCA31789B464279D620DE7A',
|
|
757
|
+
group: 'B63CC0C639B6A1AFBB041D9A',
|
|
758
|
+
frameworks: '37E44BB912BEB62673EF446D',
|
|
759
|
+
resources: '845DC63496E277892316007B',
|
|
760
|
+
sources: 'CF43D7AA4D8685F579119344',
|
|
761
|
+
proxy: '9C2EA95DB61269E81E8FEF29',
|
|
762
|
+
dependency: 'BF032A8D37EBD074ECB8FB5F',
|
|
763
|
+
debug: 'B32A48D083991B263D7C3F38',
|
|
764
|
+
release: '200485B5D20BCAA13A707402',
|
|
765
|
+
configurations: '9BE5D382CCC82CC4917AEC6A',
|
|
766
|
+
};
|
|
767
|
+
/** The template's own objects that the extension's are tied to. */
|
|
768
|
+
const TEMPLATE_IDS = {
|
|
769
|
+
project: '0C772889932C3A1BA02CADB1',
|
|
770
|
+
appTarget: 'FAC36A2364C8DD5EE47C8F83',
|
|
771
|
+
xcconfig: '33520879069FA35A78AACE2A',
|
|
772
|
+
};
|
|
773
|
+
/**
|
|
774
|
+
* The project with the Share Extension's target added: built from the
|
|
775
|
+
* synchronized ShareExtension/ folder, embedded in the app (Embed Foundation
|
|
776
|
+
* Extensions), and built before it. The target reads App.xcconfig, as the
|
|
777
|
+
* app's does, for the version, the team and the display name, and has
|
|
778
|
+
* settings of its own for its bundle ID (the app's, then `.ShareExtension`,
|
|
779
|
+
* as Apple requires), its Info.plist and its entitlements. It links none of
|
|
780
|
+
* Lynx's frameworks: it can't run Lynx.
|
|
781
|
+
*
|
|
782
|
+
* Xcode's project format has no includes, so the target's objects are
|
|
783
|
+
* written into the sections they belong to, and each list that names them
|
|
784
|
+
* (the project's targets, the app's build phases and dependencies, the
|
|
785
|
+
* groups) gets a line after a line of the template's it must find once.
|
|
786
|
+
*/
|
|
787
|
+
export const withShareExtension = (project, app) => {
|
|
788
|
+
const ids = SHARE_IDS;
|
|
789
|
+
const lines = project.split('\n');
|
|
790
|
+
/**
|
|
791
|
+
* Inserts `added` after the one line that is `after`, trimmed.
|
|
792
|
+
*/
|
|
793
|
+
const insertAfter = (after, added) => {
|
|
794
|
+
const found = lines.flatMap((line, index) => line.trim() === after ? [index] : []);
|
|
795
|
+
if (found.length !== 1) {
|
|
796
|
+
throw new Error(`The project template has ${found.length} lines "${after}", where the Share Extension's target needs one.`);
|
|
797
|
+
}
|
|
798
|
+
const indent = /^\s*/.exec(lines[found[0]])[0];
|
|
799
|
+
lines.splice(found[0] + 1, 0, ...added.map((line) => `${indent}${line}`));
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* Inserts a section of its own after the section `after` ends.
|
|
803
|
+
*/
|
|
804
|
+
const section = (after, name, objects) => {
|
|
805
|
+
const end = lines.findIndex((line) => line === `/* End ${after} section */`);
|
|
806
|
+
if (end === -1) {
|
|
807
|
+
throw new Error(`The project template has no ${after} section.`);
|
|
808
|
+
}
|
|
809
|
+
lines.splice(end + 1, 0, '', `/* Begin ${name} section */`, ...objects, `/* End ${name} section */`);
|
|
810
|
+
};
|
|
811
|
+
/**
|
|
812
|
+
* Adds objects at the end of a section the template has.
|
|
813
|
+
*/
|
|
814
|
+
const intoSection = (name, objects) => {
|
|
815
|
+
const end = lines.findIndex((line) => line.trim() === `/* End ${name} section */`);
|
|
816
|
+
if (end === -1) {
|
|
817
|
+
throw new Error(`The project template has no ${name} section.`);
|
|
818
|
+
}
|
|
819
|
+
lines.splice(end, 0, ...objects);
|
|
820
|
+
};
|
|
821
|
+
const settings = (configuration) => [
|
|
822
|
+
`\t\t${ids[configuration === 'Debug' ? 'debug' : 'release']} /* ${configuration} */ = {`,
|
|
823
|
+
'\t\t\tisa = XCBuildConfiguration;',
|
|
824
|
+
`\t\t\tbaseConfigurationReference = ${TEMPLATE_IDS.xcconfig} /* Config/App.xcconfig */;`,
|
|
825
|
+
'\t\t\tbuildSettings = {',
|
|
826
|
+
'\t\t\t\tAPPLICATION_EXTENSION_API_ONLY = YES;',
|
|
827
|
+
`\t\t\t\tCODE_SIGN_ENTITLEMENTS = ${SHARE_EXTENSION_ENTITLEMENTS};`,
|
|
828
|
+
'\t\t\t\tCODE_SIGN_STYLE = Automatic;',
|
|
829
|
+
'\t\t\t\tGENERATE_INFOPLIST_FILE = NO;',
|
|
830
|
+
`\t\t\t\tINFOPLIST_FILE = ${IOS_SHARE_EXTENSION_DIR}/Info.plist;`,
|
|
831
|
+
'\t\t\t\tLD_RUNPATH_SEARCH_PATHS = (',
|
|
832
|
+
'\t\t\t\t\t"$(inherited)",',
|
|
833
|
+
'\t\t\t\t\t"@executable_path/Frameworks",',
|
|
834
|
+
'\t\t\t\t\t"@executable_path/../../Frameworks",',
|
|
835
|
+
'\t\t\t\t);',
|
|
836
|
+
`\t\t\t\tPRODUCT_BUNDLE_IDENTIFIER = "${app.id}.ShareExtension";`,
|
|
837
|
+
'\t\t\t\tPRODUCT_NAME = ShareExtension;',
|
|
838
|
+
'\t\t\t\tSKIP_INSTALL = YES;',
|
|
839
|
+
'\t\t\t\tTARGETED_DEVICE_FAMILY = 1;',
|
|
840
|
+
'\t\t\t};',
|
|
841
|
+
`\t\t\tname = ${configuration};`,
|
|
842
|
+
'\t\t};',
|
|
843
|
+
];
|
|
844
|
+
intoSection('PBXBuildFile', [
|
|
845
|
+
`\t\t${ids.embedFile} /* ShareExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = ${ids.product} /* ShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };`,
|
|
846
|
+
]);
|
|
847
|
+
section('PBXBuildFile', 'PBXContainerItemProxy', [
|
|
848
|
+
`\t\t${ids.proxy} /* PBXContainerItemProxy */ = {`,
|
|
849
|
+
'\t\t\tisa = PBXContainerItemProxy;',
|
|
850
|
+
`\t\t\tcontainerPortal = ${TEMPLATE_IDS.project} /* Project object */;`,
|
|
851
|
+
'\t\t\tproxyType = 1;',
|
|
852
|
+
`\t\t\tremoteGlobalIDString = ${ids.target};`,
|
|
853
|
+
'\t\t\tremoteInfo = ShareExtension;',
|
|
854
|
+
'\t\t};',
|
|
855
|
+
]);
|
|
856
|
+
intoSection('PBXCopyFilesBuildPhase', [
|
|
857
|
+
`\t\t${ids.embedPhase} /* Embed Foundation Extensions */ = {`,
|
|
858
|
+
'\t\t\tisa = PBXCopyFilesBuildPhase;',
|
|
859
|
+
'\t\t\tbuildActionMask = 2147483647;',
|
|
860
|
+
'\t\t\tdstPath = "";',
|
|
861
|
+
'\t\t\tdstSubfolderSpec = 13;',
|
|
862
|
+
'\t\t\tfiles = (',
|
|
863
|
+
`\t\t\t\t${ids.embedFile} /* ShareExtension.appex in Embed Foundation Extensions */,`,
|
|
864
|
+
'\t\t\t);',
|
|
865
|
+
'\t\t\tname = "Embed Foundation Extensions";',
|
|
866
|
+
'\t\t\trunOnlyForDeploymentPostprocessing = 0;',
|
|
867
|
+
'\t\t};',
|
|
868
|
+
]);
|
|
869
|
+
intoSection('PBXFileReference', [
|
|
870
|
+
`\t\t${ids.product} /* ShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };`,
|
|
871
|
+
]);
|
|
872
|
+
intoSection('PBXFileSystemSynchronizedBuildFileExceptionSet', [
|
|
873
|
+
`\t\t${ids.exceptions} /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {`,
|
|
874
|
+
'\t\t\tisa = PBXFileSystemSynchronizedBuildFileExceptionSet;',
|
|
875
|
+
'\t\t\tmembershipExceptions = (',
|
|
876
|
+
'\t\t\t\tInfo.plist,',
|
|
877
|
+
'\t\t\t);',
|
|
878
|
+
`\t\t\ttarget = ${ids.target} /* ShareExtension */;`,
|
|
879
|
+
'\t\t};',
|
|
880
|
+
]);
|
|
881
|
+
intoSection('PBXFileSystemSynchronizedRootGroup', [
|
|
882
|
+
`\t\t${ids.group} /* ShareExtension */ = {`,
|
|
883
|
+
'\t\t\tisa = PBXFileSystemSynchronizedRootGroup;',
|
|
884
|
+
'\t\t\texceptions = (',
|
|
885
|
+
`\t\t\t\t${ids.exceptions} /* PBXFileSystemSynchronizedBuildFileExceptionSet */,`,
|
|
886
|
+
'\t\t\t);',
|
|
887
|
+
`\t\t\tpath = ${IOS_SHARE_EXTENSION_DIR};`,
|
|
888
|
+
'\t\t\tsourceTree = "<group>";',
|
|
889
|
+
'\t\t};',
|
|
890
|
+
]);
|
|
891
|
+
const phase = (id, isa, name) => [
|
|
892
|
+
`\t\t${id} /* ${name} */ = {`,
|
|
893
|
+
`\t\t\tisa = ${isa};`,
|
|
894
|
+
'\t\t\tbuildActionMask = 2147483647;',
|
|
895
|
+
'\t\t\tfiles = (',
|
|
896
|
+
'\t\t\t);',
|
|
897
|
+
'\t\t\trunOnlyForDeploymentPostprocessing = 0;',
|
|
898
|
+
'\t\t};',
|
|
899
|
+
];
|
|
900
|
+
intoSection('PBXFrameworksBuildPhase', phase(ids.frameworks, 'PBXFrameworksBuildPhase', 'Frameworks'));
|
|
901
|
+
intoSection('PBXNativeTarget', [
|
|
902
|
+
`\t\t${ids.target} /* ShareExtension */ = {`,
|
|
903
|
+
'\t\t\tisa = PBXNativeTarget;',
|
|
904
|
+
`\t\t\tbuildConfigurationList = ${ids.configurations} /* Build configuration list for PBXNativeTarget "ShareExtension" */;`,
|
|
905
|
+
'\t\t\tbuildPhases = (',
|
|
906
|
+
`\t\t\t\t${ids.sources} /* Sources */,`,
|
|
907
|
+
`\t\t\t\t${ids.frameworks} /* Frameworks */,`,
|
|
908
|
+
`\t\t\t\t${ids.resources} /* Resources */,`,
|
|
909
|
+
'\t\t\t);',
|
|
910
|
+
'\t\t\tbuildRules = (',
|
|
911
|
+
'\t\t\t);',
|
|
912
|
+
'\t\t\tdependencies = (',
|
|
913
|
+
'\t\t\t);',
|
|
914
|
+
'\t\t\tfileSystemSynchronizedGroups = (',
|
|
915
|
+
`\t\t\t\t${ids.group} /* ShareExtension */,`,
|
|
916
|
+
'\t\t\t);',
|
|
917
|
+
'\t\t\tname = ShareExtension;',
|
|
918
|
+
'\t\t\tproductName = ShareExtension;',
|
|
919
|
+
`\t\t\tproductReference = ${ids.product} /* ShareExtension.appex */;`,
|
|
920
|
+
'\t\t\tproductType = "com.apple.product-type.app-extension";',
|
|
921
|
+
'\t\t};',
|
|
922
|
+
]);
|
|
923
|
+
intoSection('PBXResourcesBuildPhase', phase(ids.resources, 'PBXResourcesBuildPhase', 'Resources'));
|
|
924
|
+
intoSection('PBXSourcesBuildPhase', phase(ids.sources, 'PBXSourcesBuildPhase', 'Sources'));
|
|
925
|
+
section('PBXSourcesBuildPhase', 'PBXTargetDependency', [
|
|
926
|
+
`\t\t${ids.dependency} /* PBXTargetDependency */ = {`,
|
|
927
|
+
'\t\t\tisa = PBXTargetDependency;',
|
|
928
|
+
`\t\t\ttarget = ${ids.target} /* ShareExtension */;`,
|
|
929
|
+
`\t\t\ttargetProxy = ${ids.proxy} /* PBXContainerItemProxy */;`,
|
|
930
|
+
'\t\t};',
|
|
931
|
+
]);
|
|
932
|
+
intoSection('XCBuildConfiguration', [
|
|
933
|
+
...settings('Debug'),
|
|
934
|
+
...settings('Release'),
|
|
935
|
+
]);
|
|
936
|
+
intoSection('XCConfigurationList', [
|
|
937
|
+
`\t\t${ids.configurations} /* Build configuration list for PBXNativeTarget "ShareExtension" */ = {`,
|
|
938
|
+
'\t\t\tisa = XCConfigurationList;',
|
|
939
|
+
'\t\t\tbuildConfigurations = (',
|
|
940
|
+
`\t\t\t\t${ids.debug} /* Debug */,`,
|
|
941
|
+
`\t\t\t\t${ids.release} /* Release */,`,
|
|
942
|
+
'\t\t\t);',
|
|
943
|
+
'\t\t\tdefaultConfigurationIsVisible = 0;',
|
|
944
|
+
'\t\t\tdefaultConfigurationName = Release;',
|
|
945
|
+
'\t\t};',
|
|
946
|
+
]);
|
|
947
|
+
// The lists that name the new objects.
|
|
948
|
+
insertAfter('D84EC48E5D673EC745AF0F7D /* LynxBundle */,', [
|
|
949
|
+
`${ids.group} /* ShareExtension */,`,
|
|
950
|
+
]);
|
|
951
|
+
insertAfter('15B4BAB9D017652EC88BA5A1 /* App.app */,', [
|
|
952
|
+
`${ids.product} /* ShareExtension.appex */,`,
|
|
953
|
+
]);
|
|
954
|
+
// The app embeds the extension after its frameworks, and builds it first.
|
|
955
|
+
insertAfter('60782C70CAE3611E1ABED20A /* Embed Frameworks */,', [
|
|
956
|
+
`${ids.embedPhase} /* Embed Foundation Extensions */,`,
|
|
957
|
+
]);
|
|
958
|
+
const appTarget = lines.findIndex((line) => line.trim().startsWith(`${TEMPLATE_IDS.appTarget} /* App */ = {`));
|
|
959
|
+
const dependencies = lines.findIndex((line, index) => index > appTarget && line.trim() === 'dependencies = (');
|
|
960
|
+
if (appTarget === -1 || dependencies === -1) {
|
|
961
|
+
throw new Error("The project template's App target has no dependencies.");
|
|
962
|
+
}
|
|
963
|
+
const indent = /^\s*/.exec(lines[dependencies])[0];
|
|
964
|
+
lines.splice(dependencies + 1, 0, `${indent}\t${ids.dependency} /* PBXTargetDependency */,`);
|
|
965
|
+
insertAfter(`${TEMPLATE_IDS.appTarget} /* App */,`, [
|
|
966
|
+
`${ids.target} /* ShareExtension */,`,
|
|
967
|
+
]);
|
|
968
|
+
insertAfter('TargetAttributes = {', [
|
|
969
|
+
`\t${ids.target} = {`,
|
|
970
|
+
'\t\tCreatedOnToolsVersion = 27.0;',
|
|
971
|
+
'\t};',
|
|
972
|
+
]);
|
|
973
|
+
return lines.join('\n');
|
|
974
|
+
};
|