@blotch/angular-lynx-native 22.3.0 → 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.
Files changed (100) hide show
  1. package/README.md +41 -15
  2. package/dist/android/project.d.ts +90 -1
  3. package/dist/android/project.d.ts.map +1 -1
  4. package/dist/android/project.js +369 -5
  5. package/dist/eject.d.ts +15 -1
  6. package/dist/eject.d.ts.map +1 -1
  7. package/dist/eject.js +13 -2
  8. package/dist/features.d.ts +70 -0
  9. package/dist/features.d.ts.map +1 -0
  10. package/dist/features.js +115 -0
  11. package/dist/generate.d.ts +17 -1
  12. package/dist/generate.d.ts.map +1 -1
  13. package/dist/generate.js +12 -4
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -1
  17. package/dist/ios/build.d.ts.map +1 -1
  18. package/dist/ios/build.js +8 -2
  19. package/dist/ios/frameworks.d.ts +6 -5
  20. package/dist/ios/frameworks.d.ts.map +1 -1
  21. package/dist/ios/frameworks.js +46 -15
  22. package/dist/ios/project.d.ts +173 -11
  23. package/dist/ios/project.d.ts.map +1 -1
  24. package/dist/ios/project.js +767 -33
  25. package/dist/options.d.ts +143 -2
  26. package/dist/options.d.ts.map +1 -1
  27. package/dist/options.js +127 -0
  28. package/dist/permissions.d.ts +18 -1
  29. package/dist/permissions.d.ts.map +1 -1
  30. package/dist/permissions.js +63 -3
  31. package/package.json +1 -1
  32. package/templates/android/README.md +37 -2
  33. package/templates/android/angular-lynx.properties +2 -0
  34. package/templates/android/app/build.gradle.kts +70 -1
  35. package/templates/android/app/src/main/AndroidManifest.xml +24 -3
  36. package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
  37. package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
  38. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
  39. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
  40. package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
  41. package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
  42. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
  43. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
  44. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
  45. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
  46. package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
  47. package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
  48. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +376 -6
  49. package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
  50. package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
  51. package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
  52. package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +25 -0
  53. package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +168 -0
  54. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
  55. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +6 -0
  56. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +47 -3
  57. package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
  58. package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
  59. package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
  60. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
  61. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
  62. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
  63. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
  64. package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
  65. package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
  66. package/templates/android/app/src/main/res/values/share_target.xml +11 -0
  67. package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
  68. package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
  69. package/templates/android/build.gradle.kts +1 -1
  70. package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  71. package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
  72. package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
  73. package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
  74. package/templates/ios/App/AngularLynxVideo.h +37 -0
  75. package/templates/ios/App/AngularLynxVideo.m +435 -0
  76. package/templates/ios/App/AngularLynxWebGL.h +69 -7
  77. package/templates/ios/App/AngularLynxWebGL.m +538 -29
  78. package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
  79. package/templates/ios/App/AppDelegate.swift +34 -2
  80. package/templates/ios/App/AppleSignInButton.swift +106 -0
  81. package/templates/ios/App/AppleSignInModule.swift +222 -0
  82. package/templates/ios/App/BarcodeScannerModule.swift +284 -0
  83. package/templates/ios/App/BiometricsModule.swift +256 -0
  84. package/templates/ios/App/BluetoothModule.swift +1086 -0
  85. package/templates/ios/App/CalendarModule.swift +158 -0
  86. package/templates/ios/App/FilePickerModule.swift +240 -0
  87. package/templates/ios/App/HapticsModule.swift +90 -0
  88. package/templates/ios/App/Info.plist +2 -0
  89. package/templates/ios/App/LynxViewController.swift +210 -6
  90. package/templates/ios/App/MotionModule.swift +430 -0
  91. package/templates/ios/App/NfcModule.swift +346 -0
  92. package/templates/ios/App/PhotoLibraryModule.swift +169 -0
  93. package/templates/ios/App/ShareTargetModule.swift +150 -0
  94. package/templates/ios/App/ShellModule.swift +17 -0
  95. package/templates/ios/App/StoreReviewModule.swift +61 -0
  96. package/templates/ios/App/TrackingModule.swift +121 -0
  97. package/templates/ios/App/WifiModule.swift +237 -0
  98. package/templates/ios/App/XElementRegistry.swift +13 -3
  99. package/templates/ios/ShareExtension/Info.plist +42 -0
  100. package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
@@ -25,6 +25,13 @@ import os
25
25
  /// `Fully Drawn` in the Points of Interest category, which Instruments shows
26
26
  /// beside the App Launch template's phases. iOS has no API of its own for it,
27
27
  /// as Android has `Activity.reportFullyDrawn()`.
28
+ ///
29
+ /// `markEvent(name)` marks any other moment the app names, in the same
30
+ /// category, so it shows on Instruments' Points of Interest timeline beside
31
+ /// `Fully Drawn`: the start of the work a profile is about, for example.
32
+ /// Every call marks, not only the first. The benchmark apps mark
33
+ /// `MountStart` as their mount screen starts building (`benchmarks/SPEC.md`),
34
+ /// so the harness can time the screen apart from the launch before it.
28
35
  final class ShellModule: NSObject, LynxModule {
29
36
  static var name: String { "AngularLynxShell" }
30
37
 
@@ -33,6 +40,7 @@ final class ShellModule: NSObject, LynxModule {
33
40
  "collectGarbage": NSStringFromSelector(#selector(collectGarbage)),
34
41
  "hideSplashScreen": NSStringFromSelector(#selector(hideSplashScreen)),
35
42
  "reportFullyDrawn": NSStringFromSelector(#selector(reportFullyDrawn)),
43
+ "markEvent": NSStringFromSelector(#selector(markEvent(_:))),
36
44
  ]
37
45
  }
38
46
 
@@ -78,4 +86,13 @@ final class ShellModule: NSObject, LynxModule {
78
86
  ShellModule.fullyDrawn = true
79
87
  os_signpost(.event, log: ShellModule.pointsOfInterest, name: "Fully Drawn")
80
88
  }
89
+
90
+ // On the calling thread, as reportFullyDrawn is: a mark made from the
91
+ // engine thread lands at the moment it marks. os_signpost takes only a
92
+ // string literal as an event's name, so every mark is an event named
93
+ // `Mark`, and the app's name for it is the event's message, which
94
+ // Instruments shows beside the name.
95
+ @objc func markEvent(_ name: String) {
96
+ os_signpost(.event, log: ShellModule.pointsOfInterest, name: "Mark", "%{public}s", name)
97
+ }
81
98
  }
@@ -0,0 +1,61 @@
1
+ import Lynx
2
+ import StoreKit
3
+ import UIKit
4
+
5
+ /// The native module behind the runtime's `LynxStoreReview`, which calls it
6
+ /// as `NativeModules.AngularLynxStoreReview` (from the background thread,
7
+ /// where NativeModules lives).
8
+ ///
9
+ /// `request` asks StoreKit for its rating prompt over the app's window scene
10
+ /// and calls back once with `{}`. StoreKit decides whether the prompt shows,
11
+ /// and doesn't say: it shows it at most three times in 365 days in an App
12
+ /// Store build, never in a TestFlight one, and every time in a development
13
+ /// build. So the callback says only that the request was made.
14
+ ///
15
+ /// The generator leaves this file out of an app whose angular.json doesn't
16
+ /// set `storeReview`, and LynxViewController registers the module by its
17
+ /// Objective-C name only when it's there, hence the `@objc` name.
18
+ @objc(AngularLynxStoreReviewModule)
19
+ final class StoreReviewModule: NSObject, LynxModule {
20
+ static var name: String { "AngularLynxStoreReview" }
21
+
22
+ static var methodLookup: [String: String] {
23
+ ["request": NSStringFromSelector(#selector(request(_:)))]
24
+ }
25
+
26
+ override init() {
27
+ super.init()
28
+ }
29
+
30
+ // Swift can't import an optional initializer as optional, so Lynx's
31
+ // initWithParam: is required here. Registered without a param, the module
32
+ // ignores it.
33
+ init(param: Any) {
34
+ super.init()
35
+ }
36
+
37
+ // Lynx calls modules off the main thread, and the scene and StoreKit's
38
+ // request belong to the main actor.
39
+ @objc func request(_ callback: @escaping LynxCallbackBlock) {
40
+ Task { @MainActor in
41
+ if let scene = Self.activeScene() {
42
+ if #available(iOS 16.0, *) {
43
+ // SKStoreReviewController's request is deprecated from iOS 18 in
44
+ // favor of this one, which iOS 15 doesn't have.
45
+ AppStore.requestReview(in: scene)
46
+ } else {
47
+ SKStoreReviewController.requestReview(in: scene)
48
+ }
49
+ }
50
+ // Without a scene in the foreground there's nothing to show the prompt
51
+ // over, which is the same to the app as StoreKit choosing not to.
52
+ callback([:])
53
+ }
54
+ }
55
+
56
+ /// The window scene in the foreground: StoreKit shows the prompt over it.
57
+ @MainActor private static func activeScene() -> UIWindowScene? {
58
+ let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
59
+ return scenes.first(where: { $0.activationState == .foregroundActive }) ?? scenes.first
60
+ }
61
+ }
@@ -0,0 +1,121 @@
1
+ import AppTrackingTransparency
2
+ import Lynx
3
+ import UIKit
4
+
5
+ /// The native module behind the runtime's `LynxTracking`, which calls it as
6
+ /// `NativeModules.AngularLynxTracking` (from the background thread, where
7
+ /// NativeModules lives).
8
+ ///
9
+ /// `status` calls back with `{ status }`, App Tracking Transparency's answer
10
+ /// for the app: `authorized`, `denied`, `restricted` or `notDetermined`.
11
+ /// `request` shows ATT's prompt, with Info.plist's
12
+ /// NSUserTrackingUsageDescription (angular.json's `permissions.tracking`),
13
+ /// and calls back with the answer. iOS shows the prompt once per install:
14
+ /// after that, and when the person has turned off "Allow Apps to Request to
15
+ /// Track", it answers at once without showing anything.
16
+ ///
17
+ /// The generator leaves this file out of an app whose angular.json doesn't
18
+ /// set `permissions.tracking`, since iOS ends an app that asks without the
19
+ /// usage description, and App Review asks about ATT code an app gives no
20
+ /// reason for. LynxViewController registers the module by its Objective-C
21
+ /// name only when it's there, hence the `@objc` name.
22
+ @objc(AngularLynxTrackingModule)
23
+ final class TrackingModule: NSObject, LynxModule {
24
+ static var name: String { "AngularLynxTracking" }
25
+
26
+ static var methodLookup: [String: String] {
27
+ [
28
+ "status": NSStringFromSelector(#selector(status(_:))),
29
+ "request": NSStringFromSelector(#selector(request(_:))),
30
+ ]
31
+ }
32
+
33
+ override init() {
34
+ super.init()
35
+ }
36
+
37
+ // Swift can't import an optional initializer as optional, so Lynx's
38
+ // initWithParam: is required here. Registered without a param, the module
39
+ // ignores it.
40
+ init(param: Any) {
41
+ super.init()
42
+ }
43
+
44
+ @objc func status(_ callback: @escaping LynxCallbackBlock) {
45
+ callback(["status": Self.name(of: ATTrackingManager.trackingAuthorizationStatus)])
46
+ }
47
+
48
+ // Lynx calls modules off the main thread, and the application's state and
49
+ // the prompt belong to the main actor.
50
+ @objc func request(_ callback: @escaping LynxCallbackBlock) {
51
+ Task { @MainActor in
52
+ Self.ask { status in callback(["status": Self.name(of: status)]) }
53
+ }
54
+ }
55
+
56
+ /// Asks for the person's answer once the app is active, and asks again
57
+ /// when iOS answers notDetermined because the app stopped being active
58
+ /// before the prompt could show, as when another system alert
59
+ /// (notifications, location) took the screen first: iOS then shows
60
+ /// nothing, and shows the prompt when asked again once the app is back.
61
+ /// `authorized`, `denied` and `restricted` are the person's or the phone's
62
+ /// answer.
63
+ ///
64
+ /// The app may already be active again by the time the completion handler
65
+ /// reaches the main actor, so a notDetermined then asks once more at once.
66
+ /// Only one such retry, since an app that stays active and still gets
67
+ /// notDetermined would otherwise ask forever.
68
+ @MainActor private static func ask(
69
+ retriesWhileActive: Int = 1,
70
+ _ done: @escaping (ATTrackingManager.AuthorizationStatus) -> Void
71
+ ) {
72
+ whenActive {
73
+ ATTrackingManager.requestTrackingAuthorization { status in
74
+ // The completion handler runs on a queue of iOS's choosing, and the
75
+ // application's state belongs to the main actor.
76
+ Task { @MainActor in
77
+ if status != .notDetermined {
78
+ done(status)
79
+ } else if UIApplication.shared.applicationState != .active {
80
+ ask(retriesWhileActive: retriesWhileActive, done)
81
+ } else if retriesWhileActive > 0 {
82
+ ask(retriesWhileActive: retriesWhileActive - 1, done)
83
+ } else {
84
+ done(status)
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ /// Runs `body` now if the app is active, or the next time it becomes
92
+ /// active. ATT shows its prompt only to an active app: asked from an app
93
+ /// still launching, or behind another alert, it answers notDetermined at
94
+ /// once and shows nothing.
95
+ @MainActor private static func whenActive(_ body: @escaping () -> Void) {
96
+ if UIApplication.shared.applicationState == .active {
97
+ body()
98
+ return
99
+ }
100
+ var observer: NSObjectProtocol?
101
+ observer = NotificationCenter.default.addObserver(
102
+ forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main
103
+ ) { _ in
104
+ if let observer { NotificationCenter.default.removeObserver(observer) }
105
+ observer = nil
106
+ body()
107
+ }
108
+ }
109
+
110
+ /// The runtime's name for ATT's status. A status a newer iOS adds counts
111
+ /// as `denied`, so the app doesn't track on an answer it can't read.
112
+ private static func name(of status: ATTrackingManager.AuthorizationStatus) -> String {
113
+ switch status {
114
+ case .authorized: return "authorized"
115
+ case .denied: return "denied"
116
+ case .restricted: return "restricted"
117
+ case .notDetermined: return "notDetermined"
118
+ @unknown default: return "denied"
119
+ }
120
+ }
121
+ }
@@ -0,0 +1,237 @@
1
+ // angular-lynx:wifi-read
2
+ import CoreLocation
3
+ // /angular-lynx:wifi-read
4
+ import Foundation
5
+ import Lynx
6
+ import NetworkExtension
7
+
8
+ // cspell:words BSSID
9
+
10
+ /// The native module behind the runtime's `LynxWifi`, which calls it as
11
+ /// `NativeModules.AngularLynxWifi` (from the background thread, where
12
+ /// NativeModules lives). Every method calls back once, with its answer or
13
+ /// `{ error, message }`.
14
+ ///
15
+ /// - `currentNetwork` calls back with `{ ssid, bssid }` from
16
+ /// `NEHotspotNetwork.fetchCurrent`, or `{ none: true }` off Wi-Fi. iOS
17
+ /// gives the network only to an app with the Access Wi-Fi Information
18
+ /// entitlement and the person's precise location, which it asks for the
19
+ /// first time, with Info.plist's NSLocationWhenInUseUsageDescription
20
+ /// (angular.json's `permissions.location`).
21
+ /// - `join` applies an `NEHotspotConfiguration` (the Hotspot Configuration
22
+ /// entitlement), which has iOS ask the person, and calls back
23
+ /// `{ done: true }` once the phone is on the network.
24
+ /// - `leave` removes the configuration, which takes the phone off it.
25
+ ///
26
+ /// The generator leaves this file out of an app whose angular.json doesn't
27
+ /// set `wifi`, and LynxViewController registers the module by its
28
+ /// Objective-C name only when it's there, hence the `@objc` name. Each part
29
+ /// is between markers the generator takes out with its switch: the location
30
+ /// code (`wifi-read`), which App Store Connect flags without a location
31
+ /// usage description, and the joining code (`wifi-join`). A method taken out
32
+ /// isn't in `methodLookup`, so the runtime rejects it with `unavailable`.
33
+ @objc(AngularLynxWifiModule)
34
+ final class WifiModule: NSObject, LynxModule {
35
+ static var name: String { "AngularLynxWifi" }
36
+
37
+ static var methodLookup: [String: String] {
38
+ var methods: [String: String] = [:]
39
+ // angular-lynx:wifi-read
40
+ methods["currentNetwork"] = NSStringFromSelector(#selector(currentNetwork(_:)))
41
+ // /angular-lynx:wifi-read
42
+ // angular-lynx:wifi-join
43
+ methods["join"] = NSStringFromSelector(#selector(join(_:callback:)))
44
+ methods["leave"] = NSStringFromSelector(#selector(leave(_:callback:)))
45
+ // /angular-lynx:wifi-join
46
+ return methods
47
+ }
48
+
49
+ override init() {
50
+ super.init()
51
+ }
52
+
53
+ // Swift can't import an optional initializer as optional, so Lynx's
54
+ // initWithParam: is required here. Registered without a param, the module
55
+ // ignores it.
56
+ init(param: Any) {
57
+ super.init()
58
+ }
59
+
60
+ // angular-lynx:wifi-read
61
+ /// Asks for the person's location the first time, as iOS gives the
62
+ /// network's name only then, and reads the network.
63
+ @objc func currentNetwork(_ callback: @escaping LynxCallbackBlock) {
64
+ // CLLocationManager wants the main thread, and Lynx calls modules off it.
65
+ DispatchQueue.main.async {
66
+ LocationAccess.shared.request { problem in
67
+ if let problem {
68
+ callback(["error": "denied", "message": problem])
69
+ return
70
+ }
71
+ NEHotspotNetwork.fetchCurrent { network in
72
+ guard let network, !network.ssid.isEmpty else {
73
+ callback(["none": true])
74
+ return
75
+ }
76
+ callback(["ssid": network.ssid, "bssid": network.bssid])
77
+ }
78
+ }
79
+ }
80
+ }
81
+ // /angular-lynx:wifi-read
82
+
83
+ // angular-lynx:wifi-join
84
+ /// Joins `options`: `{ ssid, password?, joinOnce }`. iOS asks the person
85
+ /// before it joins a network the app hasn't joined before.
86
+ @objc func join(_ options: [String: Any], callback: @escaping LynxCallbackBlock) {
87
+ guard let ssid = options["ssid"] as? String, !ssid.isEmpty else {
88
+ callback(["error": "failed", "message": "The network needs its name."])
89
+ return
90
+ }
91
+ let configuration =
92
+ (options["password"] as? String).map {
93
+ NEHotspotConfiguration(ssid: ssid, passphrase: $0, isWEP: false)
94
+ } ?? NEHotspotConfiguration(ssid: ssid)
95
+ configuration.joinOnce = (options["joinOnce"] as? Bool) ?? false
96
+ NEHotspotConfigurationManager.shared.apply(configuration) { error in
97
+ if let error = error as NSError?, error.domain == NEHotspotConfigurationErrorDomain {
98
+ // Already on it is what the app asked for.
99
+ if error.code == NEHotspotConfigurationError.alreadyAssociated.rawValue {
100
+ callback(["done": true])
101
+ return
102
+ }
103
+ callback(Self.answer(for: error))
104
+ return
105
+ }
106
+ if let error {
107
+ callback(["error": "failed", "message": error.localizedDescription])
108
+ return
109
+ }
110
+ Self.confirmJoined(ssid, callback)
111
+ }
112
+ }
113
+
114
+ /// Forgets the configuration `join` applied for `ssid`, which takes the
115
+ /// phone off the network if it's on it. iOS does nothing for one the app
116
+ /// didn't apply.
117
+ @objc func leave(_ ssid: String, callback: @escaping LynxCallbackBlock) {
118
+ NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: ssid)
119
+ callback(["done": true])
120
+ }
121
+
122
+ /// Calls back once the phone is on `ssid`. `apply` answers without an
123
+ /// error when the person allowed the network, even when it then isn't in
124
+ /// range (iOS shows "Unable to join" itself), so a module that can read
125
+ /// the network checks: iOS gives an app the network it configured without
126
+ /// asking for the person's location. Without `readCurrentNetwork` the app
127
+ /// has no entitlement to read it, the check is taken out with the rest of
128
+ /// that code, and this trusts `apply`.
129
+ private static func confirmJoined(_ ssid: String, _ callback: @escaping LynxCallbackBlock) {
130
+ let checks: [(String, Int, @escaping LynxCallbackBlock) -> Void] = [
131
+ // angular-lynx:wifi-read
132
+ checkJoined
133
+ // /angular-lynx:wifi-read
134
+ ]
135
+ guard let check = checks.first else {
136
+ callback(["done": true])
137
+ return
138
+ }
139
+ check(ssid, 6, callback)
140
+ }
141
+
142
+ // angular-lynx:wifi-read
143
+ /// Reads the network until it's `ssid`, `attemptsLeft` more times, half a
144
+ /// second apart: the phone can take a moment after `apply` to associate.
145
+ private static func checkJoined(
146
+ _ ssid: String, _ attemptsLeft: Int, _ callback: @escaping LynxCallbackBlock
147
+ ) {
148
+ NEHotspotNetwork.fetchCurrent { network in
149
+ if network?.ssid == ssid {
150
+ callback(["done": true])
151
+ } else if attemptsLeft > 0 {
152
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
153
+ checkJoined(ssid, attemptsLeft - 1, callback)
154
+ }
155
+ } else {
156
+ callback([
157
+ "error": "notFound",
158
+ "message":
159
+ "The phone didn't join \(ssid): it may be out of range, or the password may be wrong.",
160
+ ])
161
+ }
162
+ }
163
+ }
164
+ // /angular-lynx:wifi-read
165
+
166
+ /// The runtime's error for one of NEHotspotConfigurationManager's.
167
+ private static func answer(for error: NSError) -> [String: Any] {
168
+ switch NEHotspotConfigurationError(rawValue: error.code) {
169
+ case .userDenied:
170
+ return ["error": "canceled", "message": "The person chose not to join the network."]
171
+ case .invalidSSID, .invalidSSIDPrefix, .invalidWPAPassphrase, .invalidWEPPassphrase:
172
+ return ["error": "failed", "message": "iOS refused the network's name or password."]
173
+ case .pending:
174
+ return ["error": "failed", "message": "Another join is still in progress."]
175
+ case .applicationIsNotInForeground:
176
+ return ["error": "failed", "message": "The app can join a network only while it's open."]
177
+ default:
178
+ return ["error": "failed", "message": error.localizedDescription]
179
+ }
180
+ }
181
+ // /angular-lynx:wifi-join
182
+ }
183
+
184
+ // angular-lynx:wifi-read
185
+ /// The person's location permission, which iOS asks for once: the first
186
+ /// time, `request` shows iOS's prompt and waits for the answer.
187
+ private final class LocationAccess: NSObject, CLLocationManagerDelegate {
188
+ static let shared = LocationAccess()
189
+
190
+ private let manager = CLLocationManager()
191
+ /// The requests waiting for the person's answer.
192
+ private var waiting: [(String?) -> Void] = []
193
+
194
+ override init() {
195
+ super.init()
196
+ manager.delegate = self
197
+ }
198
+
199
+ /// Calls `done` with nil once the app may read the network, or with why it
200
+ /// can't. Must be called on the main thread.
201
+ func request(_ done: @escaping (String?) -> Void) {
202
+ if manager.authorizationStatus == .notDetermined {
203
+ waiting.append(done)
204
+ // Once: the delegate answers every waiting request.
205
+ if waiting.count == 1 { manager.requestWhenInUseAuthorization() }
206
+ return
207
+ }
208
+ done(problem())
209
+ }
210
+
211
+ func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
212
+ // Also called as the manager is made, before the person answers.
213
+ guard manager.authorizationStatus != .notDetermined else { return }
214
+ let answer = problem()
215
+ let requests = waiting
216
+ waiting = []
217
+ for request in requests { request(answer) }
218
+ }
219
+
220
+ /// Why iOS won't give the network's name, or nil when it will.
221
+ private func problem() -> String? {
222
+ switch manager.authorizationStatus {
223
+ case .authorizedWhenInUse, .authorizedAlways:
224
+ // iOS gives the network only with precise location.
225
+ return manager.accuracyAuthorization == .fullAccuracy
226
+ ? nil
227
+ : "Reading the Wi-Fi network needs Precise Location, which is off for this app in Settings."
228
+ case .denied:
229
+ return "The person hasn't let the app use their location, which iOS needs to give the Wi-Fi network's name."
230
+ case .restricted:
231
+ return "Location is restricted on this phone, which iOS needs to give the Wi-Fi network's name."
232
+ default:
233
+ return "The app may not use the person's location."
234
+ }
235
+ }
236
+ }
237
+ // /angular-lynx:wifi-read
@@ -3,7 +3,8 @@ import XElement
3
3
 
4
4
  /// Registers XElement's elements: `<input>`, `<textarea>`, `<overlay>`,
5
5
  /// `<svg>`, `<blur-view>`, `<viewpager>`, `<refresh>`, the
6
- /// `<scroll-coordinator>` family, `<webview>` and `<video>`. Lynx's core
6
+ /// `<scroll-coordinator>` family, `<webview>` and `<video>`, and the shell's
7
+ /// own `<canvas>` and `<apple-sign-in-button>`. Lynx's core
7
8
  /// doesn't include them, and a tag nothing is registered for renders nothing.
8
9
  ///
9
10
  /// Lynx Explorer gets these registrations from XElement's `Behavior` subspec,
@@ -13,7 +14,8 @@ import XElement
13
14
  /// classes under the same names here, before the first LynxConfig or LynxView
14
15
  /// exists. `<blur-view>` is XElement's with UIKit's blur materials and glass
15
16
  /// transitions added (BlurView). `<canvas>` is the shell's own, for WebGL
16
- /// (AngularLynxWebGL.h). `<webview>`'s loader is XElement's, wrapped so its web
17
+ /// (AngularLynxWebGL.h), and `<video>` XElement's with frames a canvas can
18
+ /// read (AngularLynxVideo.h). `<webview>`'s loader is XElement's, wrapped so its web
17
19
  /// view doesn't outlive the element (ShellWebViewLoader).
18
20
  enum XElementRegistry {
19
21
  static func register() {
@@ -33,11 +35,19 @@ enum XElementRegistry {
33
35
  ("scroll-coordinator-slot-drag", LynxUIScrollCoordinatorSlotDrag.self),
34
36
  ("scroll-coordinator-toolbar", LynxUIScrollCoordinatorToolbar.self),
35
37
  ("webview", LynxUIWebView.self),
36
- ("video", LynxUIVideo.self),
37
38
  ]
38
39
  for (name, ui) in elements {
39
40
  LynxComponentRegistry.registerUI(ui, withName: name)
40
41
  }
42
+ // <video> is XElement's, with frames the canvas contexts can read
43
+ // (AngularLynxVideo.h).
44
+ LynxComponentRegistry.registerUI(
45
+ NSClassFromString("AngularLynxVideo") ?? LynxUIVideo.self, withName: "video")
46
+ // iOS's Sign in with Apple button (AppleSignInButton), which only an app
47
+ // with angular.json's signInWithApple keeps, so by name.
48
+ if let appleSignInButton = NSClassFromString("AngularLynxAppleSignInButton") {
49
+ LynxComponentRegistry.registerUI(appleSignInButton, withName: "apple-sign-in-button")
50
+ }
41
51
  // The shell's own <canvas> (AngularLynxWebGL.h): Lynx has none.
42
52
  if let canvas = NSClassFromString("AngularLynxCanvas") {
43
53
  LynxComponentRegistry.registerUI(canvas, withName: "canvas")
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <!-- The name in the share sheet: the app's own. -->
8
+ <key>CFBundleDisplayName</key>
9
+ <string>$(ANGULAR_LYNX_DISPLAY_NAME)</string>
10
+ <key>CFBundleExecutable</key>
11
+ <string>$(EXECUTABLE_NAME)</string>
12
+ <key>CFBundleIdentifier</key>
13
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
14
+ <key>CFBundleInfoDictionaryVersion</key>
15
+ <string>6.0</string>
16
+ <key>CFBundleName</key>
17
+ <string>$(PRODUCT_NAME)</string>
18
+ <key>CFBundlePackageType</key>
19
+ <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
20
+ <key>CFBundleShortVersionString</key>
21
+ <string>$(MARKETING_VERSION)</string>
22
+ <key>CFBundleVersion</key>
23
+ <string>$(CURRENT_PROJECT_VERSION)</string>
24
+ <!-- angular-lynx:share-extension -->
25
+ <key>NSExtension</key>
26
+ <dict>
27
+ <key>NSExtensionAttributes</key>
28
+ <dict>
29
+ <key>NSExtensionActivationRule</key>
30
+ <dict>
31
+ <key>NSExtensionActivationSupportsText</key>
32
+ <true/>
33
+ </dict>
34
+ </dict>
35
+ <key>NSExtensionPointIdentifier</key>
36
+ <string>com.apple.share-services</string>
37
+ <key>NSExtensionPrincipalClass</key>
38
+ <string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
39
+ </dict>
40
+ <!-- /angular-lynx:share-extension -->
41
+ </dict>
42
+ </plist>