@blotch/angular-lynx-native 22.2.26 → 22.3.0

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.
Files changed (36) hide show
  1. package/README.md +12 -10
  2. package/dist/android/project.d.ts +11 -0
  3. package/dist/android/project.d.ts.map +1 -1
  4. package/dist/android/project.js +36 -10
  5. package/dist/app-links.d.ts +53 -0
  6. package/dist/app-links.d.ts.map +1 -0
  7. package/dist/app-links.js +115 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +14 -0
  10. package/dist/ios/build.d.ts.map +1 -1
  11. package/dist/ios/build.js +5 -0
  12. package/dist/ios/project.d.ts +14 -1
  13. package/dist/ios/project.d.ts.map +1 -1
  14. package/dist/ios/project.js +46 -5
  15. package/dist/options.d.ts +11 -1
  16. package/dist/options.d.ts.map +1 -1
  17. package/dist/options.js +19 -0
  18. package/dist/permissions.d.ts.map +1 -1
  19. package/dist/permissions.js +7 -0
  20. package/package.json +1 -1
  21. package/templates/android/README.md +6 -4
  22. package/templates/android/app/build.gradle.kts +22 -13
  23. package/templates/android/app/proguard-rules.pro +67 -55
  24. package/templates/android/app/src/main/java/dev/angularlynx/shell/LinkingModule.kt +42 -0
  25. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +39 -6
  26. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +15 -0
  27. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +14 -0
  28. package/templates/android/build.gradle.kts +1 -1
  29. package/templates/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  30. package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  31. package/templates/android/gradlew.bat +41 -11
  32. package/templates/ios/App/AngularLynxWebGLContext.m +79 -5
  33. package/templates/ios/App/AppDelegate.swift +46 -0
  34. package/templates/ios/App/LinkingModule.swift +62 -1
  35. package/templates/ios/App/LynxViewController.swift +11 -5
  36. package/templates/ios/App/ShellModule.swift +26 -0
@@ -26,6 +26,33 @@
26
26
  @rem Set local scope for the variables, and ensure extensions are enabled
27
27
  setlocal EnableExtensions
28
28
 
29
+ @rem Catch executions from older scripts and ensure they exit cleanly.
30
+ @rem This can be removed once we can be reasonably confident that few people
31
+ @rem will be migrating directly to this new wrapper.
32
+ goto afterSafetyNet
33
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
34
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
35
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
37
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
38
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
39
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
40
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
41
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
42
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
44
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
45
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
46
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
47
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
48
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
49
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
50
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
51
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
52
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
53
+ goto exitWithErrorLevel
54
+ :afterSafetyNet
55
+
29
56
  set DIRNAME=%~dp0
30
57
  if "%DIRNAME%"=="" set DIRNAME=.
31
58
  @rem This is normally unused
@@ -45,13 +72,14 @@ set JAVA_EXE=java.exe
45
72
  %JAVA_EXE% -version >NUL 2>&1
46
73
  if %ERRORLEVEL% equ 0 goto execute
47
74
 
48
- echo. 1>&2
49
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50
- echo. 1>&2
51
- echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52
- echo location of your Java installation. 1>&2
75
+ 1>&2 echo.
76
+ 1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
77
+ 1>&2 echo.
78
+ 1>&2 echo Please set the JAVA_HOME variable in your environment to match the
79
+ 1>&2 echo location of your Java installation.
53
80
 
54
81
  "%COMSPEC%" /c exit 1
82
+ goto exitWithErrorLevel
55
83
 
56
84
  :findJavaFromJavaHome
57
85
  set JAVA_HOME=%JAVA_HOME:"=%
@@ -59,13 +87,14 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59
87
 
60
88
  if exist "%JAVA_EXE%" goto execute
61
89
 
62
- echo. 1>&2
63
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64
- echo. 1>&2
65
- echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66
- echo location of your Java installation. 1>&2
90
+ 1>&2 echo.
91
+ 1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
92
+ 1>&2 echo.
93
+ 1>&2 echo Please set the JAVA_HOME variable in your environment to match the
94
+ 1>&2 echo location of your Java installation.
67
95
 
68
96
  "%COMSPEC%" /c exit 1
97
+ goto exitWithErrorLevel
69
98
 
70
99
  :execute
71
100
  @rem Setup the command line
@@ -75,8 +104,9 @@ echo location of your Java installation. 1>&2
75
104
  @rem Execute gradlew
76
105
  @rem endlocal doesn't take effect until after the line is parsed and variables are expanded
77
106
  @rem which allows us to clear the local environment before executing the java command
78
- endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
107
+ endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
79
108
 
109
+ @rem This label must not be changed. We rely on old scripts being able to jump to this point.
80
110
  :exitWithErrorLevel
81
111
  @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
82
112
  "%COMSPEC%" /c exit %ERRORLEVEL%
@@ -195,6 +195,11 @@ static NSUInteger componentsOf(GLenum format) {
195
195
  GLuint _readFramebuffer;
196
196
  GLuint _renderbuffer;
197
197
 
198
+ /// The errors taken off GL, which a read does to learn whether the read
199
+ /// itself failed, in the order GL gave them. getError reports them. GL
200
+ /// keeps one flag for each code, and so does the set.
201
+ NSMutableOrderedSet<NSNumber *> *_heldErrors;
202
+
198
203
  // The runtime's object ids, to GL names (ids are never reused).
199
204
  GLuint *_names;
200
205
  NSUInteger _namesCapacity;
@@ -254,6 +259,7 @@ static NSUInteger componentsOf(GLenum format) {
254
259
  _stencil = [attributes[@"stencil"] isEqual:@YES];
255
260
  _preserveDrawingBuffer = [attributes[@"preserveDrawingBuffer"] isEqual:@YES];
256
261
  _syncs = [NSMutableDictionary dictionary];
262
+ _heldErrors = [NSMutableOrderedSet orderedSet];
257
263
  _namesCapacity = 256;
258
264
  _names = calloc(_namesCapacity, sizeof(GLuint));
259
265
 
@@ -667,6 +673,24 @@ static NSUInteger componentsOf(GLenum format) {
667
673
  return @{@"base64" : [file base64EncodedStringWithOptions:0], @"type" : type};
668
674
  }
669
675
 
676
+ #pragma mark - Errors
677
+
678
+ /// Moves every error GL has recorded into _heldErrors, and answers whether
679
+ /// there were any. GL records several at once, one for each code, and
680
+ /// glGetError takes one off a call, so only a loop leaves GL with none.
681
+ - (BOOL)holdErrors {
682
+ BOOL any = NO;
683
+ // GL has eight error codes, so eight calls empty it. The count is there so
684
+ // a GL that answers an error to every call can't hang the engine thread.
685
+ for (int i = 0; i < 8; i++) {
686
+ GLenum error = glGetError();
687
+ if (error == GL_NO_ERROR) break;
688
+ [_heldErrors addObject:@(error)];
689
+ any = YES;
690
+ }
691
+ return any;
692
+ }
693
+
670
694
  #pragma mark - Objects
671
695
 
672
696
  - (GLuint)nameOf:(GLuint)objectId {
@@ -2149,8 +2173,16 @@ static BOOL isUnsignedUniform(GLenum type) {
2149
2173
  switch ((ALWebGLOp)op) {
2150
2174
  case ALWebGLOpGetParameter:
2151
2175
  return [self parameter:nextEnum(r)];
2152
- case ALWebGLOpGetError:
2153
- return @(glGetError());
2176
+ case ALWebGLOpGetError: {
2177
+ // The errors a read held come first, and GL's own after them. Taking
2178
+ // GL's too reports a code once when a call raised it again after a
2179
+ // read held it, as GL would have with its one flag.
2180
+ [self holdErrors];
2181
+ NSNumber *error = _heldErrors.firstObject;
2182
+ if (!error) return @(GL_NO_ERROR);
2183
+ [_heldErrors removeObjectAtIndex:0];
2184
+ return error;
2185
+ }
2154
2186
  case ALWebGLOpShaderInfo: {
2155
2187
  GLuint shader = [self nameOf:nextUInt(r)];
2156
2188
  GLint compiled = GL_FALSE;
@@ -2381,11 +2413,53 @@ static BOOL isUnsignedUniform(GLenum type) {
2381
2413
  GLsizei width = nextInt(r), height = nextInt(r);
2382
2414
  GLenum format = nextEnum(r), type = nextEnum(r);
2383
2415
  NSUInteger length = (NSUInteger)MAX(0, nextNumber(r));
2384
- NSMutableData *data = [NSMutableData dataWithLength:(length + 3) / 4 * 4];
2416
+ // Read into a pixel pack buffer and mapped, rather than straight into
2417
+ // memory, as encodeImageOfType: does: ANGLE on Metal is slow at the
2418
+ // read into memory. In the Simulator that took a whole readPixels() of
2419
+ // a 2048 by 1365 canvas from about 418 ms to 342 (the rest is the
2420
+ // trip back as numbers), and one of 256 by 256 from 23 to 13. The
2421
+ // app's pack alignment, row length and
2422
+ // skips lay the pixels out in a buffer just as they do in memory, so
2423
+ // they stay as the app set them, and `length` (the runtime's count of
2424
+ // what they need) is the buffer's size.
2425
+ //
2426
+ // A failed read writes nothing, and WebGL leaves the app's array alone
2427
+ // then. Into memory that was a zeroed array; a buffer holds whatever
2428
+ // it was given. So GL's error tells: the errors from before the read
2429
+ // are held for getError, and one after it means the read failed and
2430
+ // answers nil, which the runtime takes as nothing read. Every earlier
2431
+ // error is taken, not one: a second one left on GL would be found
2432
+ // after the read, and a read that worked would answer nil.
2433
+ [self holdErrors];
2434
+ // The runtime sends this only while no pack buffer is bound (an app
2435
+ // reading into one sends ReadPixelsToBuffer), but the binding is put
2436
+ // back whatever it was.
2437
+ GLint packBuffer = 0;
2438
+ glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &packBuffer);
2439
+ GLuint pack = 0;
2440
+ glGenBuffers(1, &pack);
2441
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, pack);
2442
+ glBufferData(GL_PIXEL_PACK_BUFFER, (GLsizeiptr)length, NULL, GL_STREAM_READ);
2385
2443
  BOOL resolved = [self beginRead];
2386
- glReadPixels(x, y, width, height, format, type, data.mutableBytes);
2444
+ glReadPixels(x, y, width, height, format, type, 0);
2387
2445
  [self endRead:resolved];
2388
- return wordsFromBytes(data.bytes, length);
2446
+ // The read's own error is held with the rest, for getError, and
2447
+ // leaves the answer nil.
2448
+ BOOL read = ![self holdErrors];
2449
+ NSArray *result = nil;
2450
+ if (read && length == 0) {
2451
+ result = wordsFromBytes(NULL, 0);
2452
+ } else if (read) {
2453
+ const void *mapped =
2454
+ glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, (GLsizeiptr)length, GL_MAP_READ_BIT);
2455
+ if (mapped) {
2456
+ result = wordsFromBytes(mapped, length);
2457
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
2458
+ }
2459
+ }
2460
+ glDeleteBuffers(1, &pack);
2461
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, (GLuint)packBuffer);
2462
+ return result;
2389
2463
  }
2390
2464
  case ALWebGLOpGetBufferSubData: {
2391
2465
  GLenum target = nextEnum(r);
@@ -13,6 +13,18 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
13
13
  _ application: UIApplication,
14
14
  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
15
15
  ) -> Bool {
16
+ // Lynx's frameworks are built for release, where Lynx logs at INFO: a
17
+ // line for every touch move, hit test, flush, layout, event listener and
18
+ // main-thread module call, each written with a synchronous NSLog on the
19
+ // thread that logged it. Mostly that's the engine thread, where Angular,
20
+ // layout and Lynx's animator share each frame, and during a touch the
21
+ // UI thread. A release app keeps Lynx's warnings and errors, which carry
22
+ // the app's JavaScript errors; the Debug configuration that
23
+ // `ng serve --platform ios` builds keeps every line for debugging.
24
+ // First, so the lines Lynx logs while it starts are left out too.
25
+ #if !DEBUG
26
+ SetMinimumLoggingLevel(.warning)
27
+ #endif
16
28
  XElementRegistry.register()
17
29
  // Before any LynxView, so its first transition already asks for 120 fps.
18
30
  AnimationFrameRate.install()
@@ -53,12 +65,46 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
53
65
  options connectionOptions: UIScene.ConnectionOptions
54
66
  ) {
55
67
  guard let windowScene = scene as? UIWindowScene else { return }
68
+ // A link that started the app: one with one of the app's schemes, or a
69
+ // Universal Link (an https link to one of angular.json's appLinkDomains),
70
+ // which comes as a web browsing activity. It comes only here, not to
71
+ // scene(_:openURLContexts:) or scene(_:continue:) too, and before the
72
+ // LynxView exists, so it goes out with the first global props
73
+ // (LinkCenter).
74
+ LinkCenter.shared.initialURL =
75
+ (connectionOptions.urlContexts.first?.url
76
+ ?? connectionOptions.userActivities.lazy.compactMap(Self.universalLink).first)?
77
+ .absoluteString
56
78
  let window = UIWindow(windowScene: windowScene)
57
79
  window.rootViewController = LynxViewController()
58
80
  window.makeKeyAndVisible()
59
81
  self.window = window
60
82
  }
61
83
 
84
+ // A link with one of the app's schemes while the app is open, in front or
85
+ // in the background: the runtime's LynxLinking takes it, and the router
86
+ // navigates to it.
87
+ func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
88
+ for context in URLContexts {
89
+ LinkCenter.shared.open(context.url)
90
+ }
91
+ }
92
+
93
+ // A Universal Link while the app is open: the same as a link with one of
94
+ // its schemes.
95
+ func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
96
+ if let url = Self.universalLink(userActivity) {
97
+ LinkCenter.shared.open(url)
98
+ }
99
+ }
100
+
101
+ /// The https link a Universal Link's activity carries. iOS hands the app
102
+ /// one for a link to a domain in its Associated Domains entitlement, once
103
+ /// that domain's apple-app-site-association names the app.
104
+ private static func universalLink(_ activity: NSUserActivity) -> URL? {
105
+ activity.activityType == NSUserActivityTypeBrowsingWeb ? activity.webpageURL : nil
106
+ }
107
+
62
108
  // Out of sight, a collection's pause can't show, and the memory it frees
63
109
  // makes the app less likely to be ended while it's in the background.
64
110
  func sceneDidEnterBackground(_ scene: UIScene) {
@@ -2,6 +2,60 @@ import Lynx
2
2
  import SafariServices
3
3
  import UIKit
4
4
 
5
+ /// The links that opened the app: those with one of angular.json's
6
+ /// `deepLinkSchemes`, and Universal Links, https links to its
7
+ /// `appLinkDomains`.
8
+ ///
9
+ /// The one that starts the app arrives in the scene's connection options,
10
+ /// before there's a LynxView: it becomes the `initialURL` global prop, which
11
+ /// LynxViewController sends before the bundle runs, so the router's first
12
+ /// screen is already the link's. One that arrives while the app is open
13
+ /// (SceneDelegate's `scene(_:openURLContexts:)` and `scene(_:continue:)`)
14
+ /// waits here, and the runtime's
15
+ /// `LynxLinking` takes it with `takeURLs` when it hears the `angularLynxURL`
16
+ /// global event, and once as it starts listening. A link waits for as long
17
+ /// as that takes, so one that arrives while Angular is still starting isn't
18
+ /// lost, and none is handled twice. ShortcutCenter works the same way.
19
+ final class LinkCenter {
20
+ static let shared = LinkCenter()
21
+
22
+ /// The global event that says a link is waiting. It carries nothing: the
23
+ /// listener answers by taking them.
24
+ static let event = "angularLynxURL"
25
+
26
+ /// The link that started the app, if one did. Set before the
27
+ /// LynxViewController is made.
28
+ var initialURL: String?
29
+
30
+ /// Lynx calls modules off the main thread, and the scene delegate leaves
31
+ /// links on it.
32
+ private let lock = NSLock()
33
+ private var waiting: [String] = []
34
+
35
+ /// The app's LynxView, which LynxViewController sets once it has one.
36
+ weak var lynxView: LynxView?
37
+
38
+ /// Leaves a link that arrived while the app is open for the runtime, and
39
+ /// tells it. Called on the main thread.
40
+ func open(_ url: URL) {
41
+ lock.lock()
42
+ waiting.append(url.absoluteString)
43
+ lock.unlock()
44
+ // Before the LynxView exists there's nobody to tell, and the runtime
45
+ // asks when it starts listening anyway.
46
+ lynxView?.sendGlobalEvent(Self.event, withParams: [])
47
+ }
48
+
49
+ /// The waiting links, oldest first, which stop waiting.
50
+ func take() -> [String] {
51
+ lock.lock()
52
+ defer { lock.unlock() }
53
+ let taken = waiting
54
+ waiting = []
55
+ return taken
56
+ }
57
+ }
58
+
5
59
  /// The native module behind the runtime's `LynxLinking`, which calls it as
6
60
  /// `NativeModules.AngularLynxLinking` (from the background thread, where
7
61
  /// NativeModules lives).
@@ -10,7 +64,9 @@ import UIKit
10
64
  /// its own. `openURL` hands it to iOS, which opens it in Safari, Mail or the
11
65
  /// app that claims it, and `openInApp` shows it in SFSafariViewController over
12
66
  /// the app. Each method calls back once: with `{}` when it's done, `{ value }`
13
- /// for `canOpenURL`, or `{ error: "failed", message }`.
67
+ /// for `canOpenURL`, or `{ error: "failed", message }`. `takeURLs` calls back
68
+ /// with `{ urls }`: the links to the app that arrived since the last call
69
+ /// (see LinkCenter).
14
70
  final class LinkingModule: NSObject, LynxModule, SFSafariViewControllerDelegate {
15
71
  static var name: String { "AngularLynxLinking" }
16
72
 
@@ -19,6 +75,7 @@ final class LinkingModule: NSObject, LynxModule, SFSafariViewControllerDelegate
19
75
  "openURL": NSStringFromSelector(#selector(openURL(_:callback:))),
20
76
  "openInApp": NSStringFromSelector(#selector(openInApp(_:options:callback:))),
21
77
  "canOpenURL": NSStringFromSelector(#selector(canOpenURL(_:callback:))),
78
+ "takeURLs": NSStringFromSelector(#selector(takeURLs(_:))),
22
79
  ]
23
80
  }
24
81
 
@@ -67,6 +124,10 @@ final class LinkingModule: NSObject, LynxModule, SFSafariViewControllerDelegate
67
124
  }
68
125
  }
69
126
 
127
+ @objc func takeURLs(_ callback: @escaping LynxCallbackBlock) {
128
+ callback(["urls": LinkCenter.shared.take()])
129
+ }
130
+
70
131
  /// Shows `address` in SFSafariViewController and calls back once the
71
132
  /// person closes it. `options` may hold `toolbarColor` and `controlsColor`,
72
133
  /// each a `#` and eight hex digits: red, green, blue and alpha.
@@ -77,8 +77,9 @@ final class LynxViewController: UIViewController {
77
77
  lynxView.layoutHeightMode = .exact
78
78
  view.addSubview(lynxView)
79
79
  self.lynxView = lynxView
80
- // Who hears that a shortcut ran while the app is open.
80
+ // Who hears that a shortcut ran, or a link arrived, while the app is open.
81
81
  ShortcutCenter.shared.lynxView = lynxView
82
+ LinkCenter.shared.lynxView = lynxView
82
83
 
83
84
  layoutLynxView()
84
85
  lynxView.updateGlobalProps(with: globalProps())
@@ -174,10 +175,10 @@ final class LynxViewController: UIViewController {
174
175
  /// The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
175
176
  /// (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
176
177
  /// build option's Intl.DateTimeFormat), the accessibility settings
177
- /// (LynxAccessibilitySettings) and `osVersion` (LynxSystemInfo), plus the
178
- /// safe-area insets and `edgeToEdge`, which env(safe-area-inset-*) reads.
179
- /// The Android shell sends the same keys, and Lynx Explorer sends theme and
180
- /// isNotchScreen too.
178
+ /// (LynxAccessibilitySettings), `osVersion` (LynxSystemInfo) and
179
+ /// `initialURL` (LynxLinking and the router), plus the safe-area insets and
180
+ /// `edgeToEdge`, which env(safe-area-inset-*) reads. The Android shell
181
+ /// sends the same keys, and Lynx Explorer sends theme and isNotchScreen too.
181
182
  private func globalProps() -> LynxTemplateData {
182
183
  let insets = view.safeAreaInsets
183
184
  var props: [String: Any] = [
@@ -214,6 +215,11 @@ final class LynxViewController: UIViewController {
214
215
  // option's Intl.DateTimeFormat formats in the device's zone by default,
215
216
  // which it reads from the engine's local time, and names it with this.
216
217
  props["appTimeZone"] = TimeZone.current.identifier
218
+ // The link that started the app, which the router starts at. In every
219
+ // update, since each sends the whole set.
220
+ if let url = LinkCenter.shared.initialURL {
221
+ props["initialURL"] = url
222
+ }
217
223
  // Without useBoolLiterals, Lynx turns a Bool into 1 or 0.
218
224
  return LynxTemplateData(dictionary: props, useBoolLiterals: true)
219
225
  }
@@ -1,5 +1,6 @@
1
1
  import Lynx
2
2
  import UIKit
3
+ import os
3
4
 
4
5
  /// The native module the AngularLynx runtime calls as
5
6
  /// `NativeModules.AngularLynxShell` (from the background thread, where
@@ -18,6 +19,12 @@ import UIKit
18
19
  /// `hideSplashScreen` fades out the copy of the launch screen the shell keeps
19
20
  /// over the app until its first screen is ready (SplashScreen.swift). The
20
21
  /// runtime's LynxSplashScreen calls it.
22
+ ///
23
+ /// `reportFullyDrawn` marks the moment the app's first screen is complete
24
+ /// (the runtime's `reportFullyDrawn()`) with an `os_signpost` event named
25
+ /// `Fully Drawn` in the Points of Interest category, which Instruments shows
26
+ /// beside the App Launch template's phases. iOS has no API of its own for it,
27
+ /// as Android has `Activity.reportFullyDrawn()`.
21
28
  final class ShellModule: NSObject, LynxModule {
22
29
  static var name: String { "AngularLynxShell" }
23
30
 
@@ -25,6 +32,7 @@ final class ShellModule: NSObject, LynxModule {
25
32
  [
26
33
  "collectGarbage": NSStringFromSelector(#selector(collectGarbage)),
27
34
  "hideSplashScreen": NSStringFromSelector(#selector(hideSplashScreen)),
35
+ "reportFullyDrawn": NSStringFromSelector(#selector(reportFullyDrawn)),
28
36
  ]
29
37
  }
30
38
 
@@ -52,4 +60,22 @@ final class ShellModule: NSObject, LynxModule {
52
60
  SplashScreen.shared.hide()
53
61
  }
54
62
  }
63
+
64
+ private static let pointsOfInterest = OSLog(
65
+ subsystem: Bundle.main.bundleIdentifier ?? "AngularLynx", category: .pointsOfInterest)
66
+ private static let fullyDrawnOnce = NSLock()
67
+ private static var fullyDrawn = false
68
+
69
+ // Emitted on the calling thread: the runtime calls it from Lynx's engine
70
+ // thread, through main-thread modules, and a hop to the main queue would
71
+ // add a frame's wait to the moment it marks. os_signpost is thread-safe.
72
+ @objc func reportFullyDrawn() {
73
+ ShellModule.fullyDrawnOnce.lock()
74
+ defer { ShellModule.fullyDrawnOnce.unlock() }
75
+ // Once per process, as Android's is: the development build loads the app
76
+ // again on every edit, and each load reports.
77
+ guard !ShellModule.fullyDrawn else { return }
78
+ ShellModule.fullyDrawn = true
79
+ os_signpost(.event, log: ShellModule.pointsOfInterest, name: "Fully Drawn")
80
+ }
55
81
  }