@blotch/angular-lynx-native 22.2.26 → 22.2.27

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 +3 -1
  22. package/templates/android/app/build.gradle.kts +15 -9
  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
package/dist/options.js CHANGED
@@ -15,6 +15,13 @@ const APP_ID = /^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)+$/;
15
15
  /** Up to three period-separated integers, as App Store Connect requires. */
16
16
  const VERSION = /^\d+(\.\d+){0,2}$/;
17
17
  const SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
18
+ /**
19
+ * A host name of two labels or more, optionally after `*.` for its
20
+ * subdomains, as both the `applinks:` entitlement and an intent filter's
21
+ * `android:host` take it. No scheme, port or path: iOS takes a port only in
22
+ * its developer mode, and the site's file chooses the paths.
23
+ */
24
+ const APP_LINK_DOMAIN = /^(\*\.)?([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]([a-z0-9-]*[a-z0-9])?$/;
18
25
  /**
19
26
  * The colors both CSS and Android resources read the same way. Android also
20
27
  * takes `#ARGB` and `#AARRGGBB`, but CSS reads 4 and 8 digits with the alpha
@@ -62,6 +69,7 @@ const PERMISSIONS = [
62
69
  'savePhotos',
63
70
  'contacts',
64
71
  'notifications',
72
+ 'localNetwork',
65
73
  ];
66
74
  /**
67
75
  * Applies defaults and validates the options, so the generators never see a
@@ -108,6 +116,16 @@ export const resolveAppOptions = (rawOptions, defaults) => {
108
116
  throw new NativeConfigError(`deepLinkSchemes entry "${scheme}" is not a valid URL scheme.`);
109
117
  }
110
118
  }
119
+ // Host names are case-insensitive, so "Example.com" and "example.com" are
120
+ // one.
121
+ const appLinkDomains = [
122
+ ...new Set((options.appLinkDomains ?? []).map((domain) => domain.toLowerCase())),
123
+ ];
124
+ for (const domain of appLinkDomains) {
125
+ if (!APP_LINK_DOMAIN.test(domain)) {
126
+ throw new NativeConfigError(`appLinkDomains entry "${domain}" is not a domain. Give the host name alone, without https:// or a path, e.g. "example.com", or "*.example.com" for its subdomains.`);
127
+ }
128
+ }
111
129
  const userQueriedSchemes = options.canOpenURLSchemes ?? [];
112
130
  for (const scheme of userQueriedSchemes) {
113
131
  if (!SCHEME.test(scheme)) {
@@ -158,6 +176,7 @@ export const resolveAppOptions = (rawOptions, defaults) => {
158
176
  edgeToEdge: options.edgeToEdge ?? true,
159
177
  permissions,
160
178
  deepLinkSchemes,
179
+ appLinkDomains,
161
180
  canOpenURLSchemes,
162
181
  shortcuts,
163
182
  icon: options.icon,
@@ -1 +1 @@
1
- {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,UAAU,EACV;IACE,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C,CAuCF,CAAC"}
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,UAAU,EACV;IACE,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C,CA8CF,CAAC"}
@@ -36,6 +36,13 @@ export const PERMISSION_MAP = {
36
36
  ios: ['NSContactsUsageDescription'],
37
37
  android: ['android.permission.READ_CONTACTS'],
38
38
  },
39
+ // Connecting to a device or server on the local network, such as a printer,
40
+ // a TV or a server on the Mac during development: iOS (14 and later) asks
41
+ // first, with this reason. Android needs no permission for it.
42
+ localNetwork: {
43
+ ios: ['NSLocalNetworkUsageDescription'],
44
+ android: [],
45
+ },
39
46
  // iOS asks for notification permission at runtime without a usage string.
40
47
  notifications: {
41
48
  ios: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotch/angular-lynx-native",
3
- "version": "22.2.26",
3
+ "version": "22.2.27",
4
4
  "description": "Builds AngularLynx apps into iOS and Android binaries",
5
5
  "homepage": "https://github.com/Blotch-Smart-Frames/AngularLynx#readme",
6
6
  "bugs": {
@@ -25,6 +25,8 @@ Build commands and outputs (no flavors, so the names are fixed):
25
25
  # app/build/outputs/bundle/release/app-release.aab
26
26
  ```
27
27
 
28
+ The release build runs R8 and the resource shrinker (`isMinifyEnabled`, `isShrinkResources`), and writes the mapping that turns the renamed classes back to `app/build/outputs/mapping/release/mapping.txt`, which also goes in the `.aab` for Google Play. Lynx's AAR ships keep rules for its own classes; `app/proguard-rules.pro` adds the ones they miss, each with what broke without it (the app aborting on launch, for one). Any class Lynx or the shell reaches only by name needs a rule there. How they were found, and the sizes, are in `investigations/native-app-builds.md` ("R8 in the Android release build").
29
+
28
30
  ## How the shell loads the app
29
31
 
30
32
  - **Bundles** come from `assets/` (`ResourceFetchers.kt`, `BundleAssets.kt`). A URL without a scheme (`/static/…`, `static/…`), `asset:///…` and `file:///android_asset/…` all mean "the file at that path in `assets/`", so the bundle works with Rspeedy's default asset prefix (`/`) and doesn't need a platform-specific one. Absolute `http(s)` URLs are fetched with OkHttp.
@@ -52,7 +54,7 @@ PrimJS, which runs the app's JavaScript on Lynx's main thread, collects garbage
52
54
 
53
55
  ## Links
54
56
 
55
- `NativeModules.AngularLynxLinking` (`LinkingModule.kt`, behind the runtime's `LynxLinking`) opens links outside the app. `MainActivity` registers it with itself as the param, since the module starts activities from it and watches its lifecycle.
57
+ `NativeModules.AngularLynxLinking` (`LinkingModule.kt`, behind the runtime's `LynxLinking`) opens links outside the app. `MainActivity` registers it with itself as the param, since the module starts activities from it and watches its lifecycle. Its `takeURLs(callback)` calls back with `{ urls }`, the links with one of angular.json's `deepLinkSchemes`, and the App Links to its `appLinkDomains`, that arrived while the app was open: `MainActivity.onNewIntent` keeps each one with the module and sends the `angularLynxURL` global event, which the runtime answers by taking them. The link that started the app goes in the `initialURL` global prop instead, read from the intent in `onCreate` unless the app was reopened from Recents.
56
58
 
57
59
  - **`openURL(url, callback)`** starts an `ACTION_VIEW` intent, which the browser, the mail app or the app that claims the URL opens, and calls back with `{}`, or with `{ error, message }` when nothing does.
58
60
  - **`openInApp(url, options, callback)`** opens an http(s) URL in a Custom Tab, with `options.toolbarColor` as its toolbar color. Android says nothing when a Custom Tab closes, so the module watches the activity's lifecycle and calls back when it resumes after pausing for the tab: the person closed the tab or came back to the app another way. It doesn't touch `WebAuthModule`'s session, which `MainActivity` tracks on its own.
@@ -28,7 +28,7 @@ val hasReleaseSigning = releaseSigning.values.all { !it.isNullOrEmpty() }
28
28
 
29
29
  // One place for the Lynx version, so a Lynx upgrade is a one-line change.
30
30
  val lynxVersion = "4.1.0"
31
- val primjsVersion = "4.1.1"
31
+ val primjsVersion = "4.2.1"
32
32
  // Lynx's image service is written against Fresco 2.3, and Lynx Explorer ships
33
33
  // the same version, so stay on it until Lynx moves.
34
34
  val frescoVersion = "2.3.0"
@@ -72,11 +72,17 @@ android {
72
72
 
73
73
  buildTypes {
74
74
  release {
75
- // R8 shrinking is off until the Lynx keep rules in
76
- // proguard-rules.pro are verified against every AngularLynx
77
- // feature; Lynx reaches much of its Java code through JNI and
78
- // reflection, which R8 can't see.
79
- isMinifyEnabled = false
75
+ // R8 shrinks, optimizes and renames the app's Java and Kotlin,
76
+ // and the resource shrinker drops the resources nothing uses.
77
+ // Most of the code is libraries the app uses a little of (media3
78
+ // and Guava behind <video>, appcompat and material behind
79
+ // XElement): R8 takes the dex from 19.5 MB to 3.3 MB, and what an
80
+ // arm64 phone downloads from 13.6 MB to 7.5 MB. Lynx reaches much
81
+ // of its Java through JNI and reflection, which R8 can't see:
82
+ // Lynx's AAR ships keep rules for its own classes, and
83
+ // proguard-rules.pro adds the ones they miss.
84
+ isMinifyEnabled = true
85
+ isShrinkResources = true
80
86
  proguardFiles(
81
87
  getDefaultProguardFile("proguard-android-optimize.txt"),
82
88
  "proguard-rules.pro",
@@ -120,7 +126,7 @@ android {
120
126
  }
121
127
 
122
128
  dependencies {
123
- implementation("androidx.activity:activity-ktx:1.10.1")
129
+ implementation("androidx.activity:activity-ktx:1.13.0")
124
130
  implementation("androidx.core:core-ktx:1.16.0")
125
131
  // The splash screen (MainActivity, themes.xml): Android 12's on every
126
132
  // version the app runs on, and kept up until the app's first screen is
@@ -152,7 +158,7 @@ dependencies {
152
158
  implementation("com.facebook.fresco:animated-webp:$frescoVersion")
153
159
  implementation("com.facebook.fresco:webpsupport:$frescoVersion")
154
160
  implementation("com.facebook.fresco:animated-base:$frescoVersion")
155
- implementation("com.squareup.okhttp3:okhttp:4.12.0")
161
+ implementation("com.squareup.okhttp3:okhttp:4.12.1")
156
162
 
157
163
  // XElement: <input>, <textarea>, <overlay>, <svg>, <blur-view>,
158
164
  // <viewpager>, <refresh>, the <scroll-coordinator> family, <webview> and
@@ -172,6 +178,6 @@ dependencies {
172
178
  // vectordrawable 1.0.0 and vectordrawable-animated 1.0.0. Those two share
173
179
  // the namespace androidx.vectordrawable, and AGP 9's manifest merger
174
180
  // fails the build on that; newer versions give them distinct namespaces.
175
- implementation("androidx.appcompat:appcompat:1.7.1")
181
+ implementation("androidx.appcompat:appcompat:1.8.0")
176
182
  implementation("com.google.android.material:material:1.12.0")
177
183
  }
@@ -1,65 +1,77 @@
1
- # Lynx's keep rules, from Lynx's integration guide
2
- # (https://lynxjs.org/guide/start/integrate-with-existing-apps). Only used once
3
- # isMinifyEnabled is turned on in build.gradle.kts.
4
- # LYNX START
5
- # use @Keep to annotate retained classes.
6
- -dontwarn android.support.annotation.Keep
7
- -keep @android.support.annotation.Keep class **
8
- -keep @android.support.annotation.Keep class ** {
9
- @android.support.annotation.Keep <fields>;
10
- @android.support.annotation.Keep <methods>;
11
- }
12
- -dontwarn androidx.annotation.Keep
13
- -keep @androidx.annotation.Keep class **
14
- -keep @androidx.annotation.Keep class ** {
15
- @androidx.annotation.Keep <fields>;
16
- @androidx.annotation.Keep <methods>;
17
- }
18
- # native method call
19
- -keepclasseswithmembers,includedescriptorclasses class * {
20
- native <methods>;
21
- }
1
+ # The release build's keep rules, on top of the ones its libraries ship.
2
+ #
3
+ # R8 (isMinifyEnabled in build.gradle.kts) removes and renames whatever it
4
+ # can't see used. Lynx reaches much of its Java through JNI and reflection,
5
+ # which R8 can't see, so Lynx's AAR carries keep rules of its own (its
6
+ # proguard.txt, which R8 applies by itself): @Keep classes, native and
7
+ # @CalledByNative methods, @LynxMethod modules, @LynxProp and @LynxUIMethod
8
+ # members, and every LynxBaseUI, ShadowNode and LynxModule subclass. They're
9
+ # the rules from Lynx's integration guide, plus a few. Fresco's core library,
10
+ # XElement's modules and the AndroidX libraries ship theirs too.
11
+ #
12
+ # The rules below cover what those miss. They were found by listing every
13
+ # reflective call and every method native code calls in the Lynx, XElement and
14
+ # Fresco classes, checking the release APK's dex for each, and running the E2E
15
+ # tests and a page that drives every XElement on an emulator.
16
+ # investigations/native-app-builds.md has the details.
17
+ #
18
+ # Methods Lynx's native code calls. Lynx's rules keep the ones marked with
19
+ # com.lynx.tasm.base.CalledByNative, but lynx-base and lynx-trace, which ship
20
+ # no rules, mark theirs with annotations of their own. Without these, R8
21
+ # removed LynxLog.log(), which lynx-base's native library looks up as Lynx
22
+ # starts, and the app aborted on launch ("JNI DETECTED ERROR IN APPLICATION:
23
+ # mid == null" from LynxBaseTrace.nativeInitBaseTrace).
22
24
  -keepclasseswithmembers class * {
23
- @com.lynx.tasm.base.CalledByNative <methods>;
25
+ @com.lynx.base.CalledByNative <methods>;
24
26
  }
25
-
26
- # to customize a module, you need to keep the class name and the method annotated as LynxMethod.
27
27
  -keepclasseswithmembers class * {
28
- @com.lynx.jsbridge.LynxMethod <methods>;
28
+ @com.lynx.trace.CalledByNative <methods>;
29
29
  }
30
30
 
31
- -keepclassmembers class * {
32
- @com.lynx.tasm.behavior.LynxProp <methods>;
33
- @com.lynx.tasm.behavior.LynxPropGroup <methods>;
34
- @com.lynx.tasm.behavior.LynxUIMethod <methods>;
35
- }
31
+ # Most of the rest come from R8's full mode, AGP's default since AGP 8: a
32
+ # -keep rule that names a class without members keeps the class but not its
33
+ # constructor. The libraries' rules were written for ProGuard, which kept it,
34
+ # so a class they create with Class.newInstance() lost its constructor, and
35
+ # with it the methods only an instance could call.
36
36
 
37
- -keepclassmembers class com.lynx.tasm.behavior.ui.UIGroup {
38
- public boolean needCustomLayout();
39
- }
37
+ # Lynx's generated setters and method invokers. Lynx finds the ones for each
38
+ # element class by name (<class>$$PropsSetter, <class>$$MethodInvoker) and
39
+ # creates them with newInstance(). Without these rules R8 emptied them (none
40
+ # had a constructor left), and Lynx then set every property and called every
41
+ # UI method through reflection instead.
42
+ -keep class * implements com.lynx.tasm.behavior.utils.Settable { <init>(); }
43
+ -keep class * implements com.lynx.tasm.behavior.utils.LynxUIMethodInvoker { <init>(); }
44
+ # The same for a JSI object's descriptor (<class>$$Descriptor).
45
+ -keep class * implements com.lynx.jsbridge.jsi.ILynxJSIObjectDescriptor { <init>(); }
40
46
 
41
- # in case R8 compiler may remove mLoader in bytecode.
42
- # as mLoader is not used in java and passed as a WeakRef in JNI.
43
- -keepclassmembers class com.lynx.tasm.LynxTemplateRender {
44
- private com.lynx.tasm.core.resource.LynxResourceLoader mLoader;
45
- private com.lynx.tasm.core.resource.LynxResourceLoader mResourceLoader;
46
- }
47
+ # Fresco creates its WebP transcoder by name, and R8 had removed its
48
+ # constructor and methods.
49
+ -keep class com.facebook.imagepipeline.nativecode.WebpTranscoderImpl { <init>(); }
47
50
 
48
- # the automatically generated setter classes use the class names of LynxBaseUI and ShadowNode and their subclasses.
49
- -keep class com.lynx.tasm.behavior.ui.LynxBaseUI
50
- -keep class com.lynx.tasm.behavior.shadow.ShadowNode
51
- -keep class com.lynx.jsbridge.LynxModule { *; }
52
- -keep class * extends com.lynx.tasm.behavior.ui.LynxBaseUI
53
- -keep class * extends com.lynx.tasm.behavior.shadow.ShadowNode
54
- -keep class * extends com.lynx.jsbridge.LynxModule { *; }
55
- -keep class * extends com.lynx.jsbridge.LynxContextModule
56
- -keep class * implements com.lynx.tasm.behavior.utils.Settable
57
- -keep class * implements com.lynx.tasm.behavior.utils.LynxUISetter
58
- -keep class * implements com.lynx.tasm.behavior.utils.LynxUIMethodInvoker
59
- -keep class com.lynx.tasm.rendernode.compat.**{
60
- *;
51
+ # <viewpager> reads ViewPager's private mIsUnableToDrag by name, which
52
+ # XElement's own rules (they keep only populate()) leave R8 to rename.
53
+ -keepclassmembers class androidx.viewpager.widget.ViewPager {
54
+ private boolean mIsUnableToDrag;
61
55
  }
62
- -keep class com.lynx.tasm.rendernode.compat.RenderNodeFactory{
63
- *;
56
+
57
+ # <text enable-emoji-compat> looks up AndroidX's EmojiCompat by name, which R8
58
+ # had renamed.
59
+ -keep class androidx.emoji2.text.EmojiCompat {
60
+ public static androidx.emoji2.text.EmojiCompat get();
61
+ public java.lang.CharSequence process(java.lang.CharSequence);
64
62
  }
65
- # LYNX END
63
+
64
+ # Classes the app doesn't have, which R8 would otherwise fail the build on.
65
+ # XElement's umbrella registers <animax-view> and <markdown>, whose modules
66
+ # build.gradle.kts leaves out, so those two tags can't be created (the runtime
67
+ # doesn't support them). Lynx uses Gson only to describe its environment for
68
+ # debugging tools.
69
+ -dontwarn com.lynx.animax.**
70
+ -dontwarn com.lynx.xelement.markdown.**
71
+ -dontwarn com.google.gson.**
72
+
73
+ # Keep the file names and line numbers in stack traces. The mapping file
74
+ # (app/build/outputs/mapping/release/mapping.txt, which Gradle also puts in
75
+ # the .aab for Google Play) turns the renamed classes and methods back.
76
+ -keepattributes SourceFile,LineNumberTable
77
+ -renamesourcefileattribute SourceFile
@@ -14,6 +14,7 @@ import androidx.lifecycle.LifecycleOwner
14
14
  import com.lynx.jsbridge.LynxMethod
15
15
  import com.lynx.jsbridge.LynxModule
16
16
  import com.lynx.react.bridge.Callback
17
+ import com.lynx.react.bridge.JavaOnlyArray
17
18
  import com.lynx.react.bridge.JavaOnlyMap
18
19
  import com.lynx.react.bridge.ReadableMap
19
20
 
@@ -29,6 +30,18 @@ import com.lynx.react.bridge.ReadableMap
29
30
  * Custom Tab over the app. Each method calls back once: with `{}` when it's
30
31
  * done, `{ value }` for `canOpenURL`, or `{ error: "failed", message }`, as
31
32
  * the iOS module does.
33
+ *
34
+ * It also hands over the links that open the app: those with one of
35
+ * angular.json's `deepLinkSchemes`, and App Links, https links to its
36
+ * `appLinkDomains`. The one that starts it is MainActivity's `initialURL`
37
+ * global prop, which goes out before the bundle runs, so the router's first
38
+ * screen is already the link's. One that arrives while the app is open
39
+ * (MainActivity.onNewIntent) waits here, and the runtime's `LynxLinking`
40
+ * takes it with `takeURLs`, which calls back with `{ urls }`, when it hears
41
+ * the `angularLynxURL` global event, and once as it starts listening. A link
42
+ * waits for as long as that takes, so one that arrives while Angular is still
43
+ * starting isn't lost, and none is handled twice. ShortcutsModule works the
44
+ * same way.
32
45
  */
33
46
  class LinkingModule(context: Context, param: Any?) : LynxModule(context, param) {
34
47
  private val activity = param as ComponentActivity
@@ -125,6 +138,15 @@ class LinkingModule(context: Context, param: Any?) : LynxModule(context, param)
125
138
  }
126
139
  }
127
140
 
141
+ @LynxMethod
142
+ fun takeURLs(callback: Callback) {
143
+ val urls = JavaOnlyArray()
144
+ for (url in takeWaiting()) {
145
+ urls.pushString(url)
146
+ }
147
+ callback.invoke(JavaOnlyMap.from(mapOf("urls" to urls)))
148
+ }
149
+
128
150
  private fun closed(watcher: DefaultLifecycleObserver) {
129
151
  activity.lifecycle.removeObserver(watcher)
130
152
  sheet = null
@@ -145,5 +167,25 @@ class LinkingModule(context: Context, param: Any?) : LynxModule(context, param)
145
167
 
146
168
  companion object {
147
169
  const val NAME = "AngularLynxLinking"
170
+
171
+ // The global event that says a link is waiting. It carries nothing:
172
+ // the listener answers by taking them.
173
+ const val EVENT = "angularLynxURL"
174
+
175
+ // The activity leaves them on the main thread, and Lynx calls
176
+ // modules off it.
177
+ private val waiting = mutableListOf<String>()
178
+
179
+ /** Leaves a link that arrived while the app is open for the runtime. */
180
+ fun open(url: String) {
181
+ synchronized(waiting) { waiting.add(url) }
182
+ }
183
+
184
+ private fun takeWaiting(): List<String> =
185
+ synchronized(waiting) {
186
+ val taken = waiting.toList()
187
+ waiting.clear()
188
+ taken
189
+ }
148
190
  }
149
191
  }
@@ -84,6 +84,11 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
84
84
  }
85
85
  private var webAuthSession: WebAuthSession? = null
86
86
 
87
+ // The link that started the app, with one of angular.json's
88
+ // deepLinkSchemes or an App Link to one of its appLinkDomains, sent as
89
+ // the initialURL global prop (see LinkingModule).
90
+ private var initialURL: String? = null
91
+
87
92
  // The Photo Picker (see ImagePickerModule), and who to tell what was
88
93
  // picked. An activity registers for results as it's created, before it
89
94
  // starts, so a result that arrives after Android recreated it still
@@ -138,6 +143,17 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
138
143
  ) {
139
144
  ShortcutsModule.run(intent)
140
145
  }
146
+ // A link that started the app, which the router starts at. Unlike a
147
+ // shortcut it's read again when Android recreates the activity: the
148
+ // app starts again then, and a link tapped after Android ended the
149
+ // app in the background starts it that way too. Reopening the app
150
+ // from Recents hands over the link it last started with, which isn't
151
+ // the person following it again.
152
+ if (intent.action == Intent.ACTION_VIEW &&
153
+ intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY == 0
154
+ ) {
155
+ initialURL = intent.dataString
156
+ }
141
157
 
142
158
  // The bundle in the app's assets, or in the debug build `ng serve
143
159
  // --platform android` runs, the dev server's (DevServer.kt).
@@ -295,6 +311,11 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
295
311
  splashTimeout.removeCallbacksAndMessages(null)
296
312
  }
297
313
 
314
+ // Activity.reportFullyDrawn() counts once per launch itself.
315
+ override fun markFullyDrawn() {
316
+ reportFullyDrawn()
317
+ }
318
+
298
319
  override fun startWebAuthSession(url: Uri, callbackScheme: String, done: (WebAuthModule.Result) -> Unit) {
299
320
  if (webAuthSession != null) {
300
321
  done(WebAuthModule.Result.Failed("A sign-in is already open."))
@@ -320,14 +341,22 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
320
341
  lynxView.sendGlobalEvent(ShortcutsModule.EVENT, JavaOnlyArray())
321
342
  return
322
343
  }
344
+ if (intent.action != Intent.ACTION_VIEW) return
345
+ val url = intent.data ?: return
323
346
  // The sign-in page's redirect to the callback scheme: the deep link
324
347
  // comes back to this activity, which closes the Custom Tab above it.
325
348
  // It arrives before onResume, which then finds no session open.
326
- val url = intent.data ?: return
327
- val session = webAuthSession ?: return
328
- if (url.scheme?.lowercase() != session.scheme) return
329
- webAuthSession = null
330
- session.done(WebAuthModule.Result.Returned(url.toString()))
349
+ val session = webAuthSession
350
+ if (session != null && url.scheme?.lowercase() == session.scheme) {
351
+ webAuthSession = null
352
+ session.done(WebAuthModule.Result.Returned(url.toString()))
353
+ return
354
+ }
355
+ // Any other link with one of the app's schemes, or an App Link: the
356
+ // runtime's LynxLinking takes it when it hears the event, and the
357
+ // router navigates to it.
358
+ LinkingModule.open(url.toString())
359
+ lynxView.sendGlobalEvent(LinkingModule.EVENT, JavaOnlyArray())
331
360
  }
332
361
 
333
362
  // The manifest's configChanges keeps the activity, and the running app,
@@ -358,7 +387,8 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
358
387
  * The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
359
388
  * (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
360
389
  * build option's Intl.DateTimeFormat), the accessibility settings
361
- * (LynxAccessibilitySettings) and `osVersion` (LynxSystemInfo), plus the
390
+ * (LynxAccessibilitySettings), `osVersion` (LynxSystemInfo) and
391
+ * `initialURL` (LynxLinking and the router), plus the
362
392
  * safe-area insets in dp and `edgeToEdge`, which env(safe-area-inset-*)
363
393
  * reads. The iOS shell sends the same keys, and Lynx Explorer sends theme
364
394
  * and isNotchScreen too. Android 12 and later also send the wallpaper's
@@ -393,6 +423,9 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
393
423
  // which it reads from the engine's local time, and names it with this.
394
424
  props["appTimeZone"] = java.util.TimeZone.getDefault().id
395
425
  DynamicColors.read(this)?.let { props["dynamicColors"] = it }
426
+ // The link that started the app, which the router starts at. In
427
+ // every update, since each sends the whole set.
428
+ initialURL?.let { props["initialURL"] = it }
396
429
  return props
397
430
  }
398
431
 
@@ -2,6 +2,7 @@ package dev.angularlynx.shell
2
2
 
3
3
  import android.app.Application
4
4
  import android.content.ComponentCallbacks2
5
+ import android.content.pm.ApplicationInfo
5
6
  import com.facebook.drawee.backends.pipeline.Fresco
6
7
  import com.facebook.imagepipeline.core.ImagePipelineConfig
7
8
  import com.facebook.imagepipeline.memory.PoolConfig
@@ -10,6 +11,7 @@ import com.lynx.service.http.LynxHttpService
10
11
  import com.lynx.service.image.LynxImageService
11
12
  import com.lynx.service.log.LynxLogService
12
13
  import com.lynx.tasm.LynxEnv
14
+ import com.lynx.tasm.base.LLog
13
15
  import com.lynx.tasm.service.LynxServiceCenter
14
16
 
15
17
  /**
@@ -36,6 +38,19 @@ class ShellApplication : Application() {
36
38
  // No global template provider or custom elements: MainActivity passes
37
39
  // its loaders to the LynxView it builds.
38
40
  LynxEnv.inst().init(this, null, null, null)
41
+
42
+ // Lynx's libraries are built for release, where Lynx logs at INFO: a
43
+ // line for every touch, flush, layout, event listener and main-thread
44
+ // module call, each a call from native code back into Java and an
45
+ // android.util.Log write on the thread that logged it, mostly the
46
+ // engine thread Angular runs on. A release app keeps Lynx's warnings
47
+ // and errors, which carry the app's JavaScript errors; the debuggable
48
+ // build `ng serve --platform android` installs keeps every line for
49
+ // debugging. After init, which loads Lynx's native library: before
50
+ // it, the call does nothing.
51
+ if ((applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
52
+ LLog.setMinimumLoggingLevel(LLog.WARN)
53
+ }
39
54
  }
40
55
 
41
56
  // Lynx leaves it to the host app to report memory pressure. Either level
@@ -33,6 +33,14 @@ import com.lynx.tasm.LynxEnv
33
33
  * `hideSplashScreen` lets the splash screen go, which MainActivity keeps up
34
34
  * until the app's first screen is ready. The runtime's LynxSplashScreen
35
35
  * calls it.
36
+ *
37
+ * `reportFullyDrawn` calls `Activity.reportFullyDrawn()` when the app's first
38
+ * screen is complete (the runtime's `reportFullyDrawn()`), which logcat prints
39
+ * as `Fully drawn` and Android's startup tools (Macrobenchmark,
40
+ * `am start -W`'s callers) read as time to full display. It's called on the
41
+ * thread the runtime calls from, Lynx's engine thread: the system takes it
42
+ * from any thread, and a post to the UI thread would add a wait to the moment
43
+ * it marks.
36
44
  */
37
45
  class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
38
46
  private val host = param as Host
@@ -41,6 +49,7 @@ class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
41
49
  interface Host {
42
50
  fun setBackHandlerEnabled(enabled: Boolean)
43
51
  fun hideSplashScreen()
52
+ fun markFullyDrawn()
44
53
  }
45
54
 
46
55
  @LynxMethod
@@ -53,6 +62,11 @@ class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
53
62
  main.post { host.hideSplashScreen() }
54
63
  }
55
64
 
65
+ @LynxMethod
66
+ fun reportFullyDrawn() {
67
+ host.markFullyDrawn()
68
+ }
69
+
56
70
  @LynxMethod
57
71
  fun collectGarbage() {
58
72
  main.post { LynxEnv.inst().trimMemory(MEMORY_PRESSURE_MODERATE) }
@@ -1,5 +1,5 @@
1
1
  // AGP 9 compiles Kotlin itself (built-in Kotlin), so there is no separate
2
2
  // org.jetbrains.kotlin.android plugin to apply.
3
3
  plugins {
4
- id("com.android.application") version "9.4.1" apply false
4
+ id("com.android.application") version "9.5.1" apply false
5
5
  }
@@ -1,7 +1,7 @@
1
1
  distributionBase=GRADLE_USER_HOME
2
2
  distributionPath=wrapper/dists
3
- distributionSha256Sum=9c0f7faeeb306cb14e4279a3e084ca6b596894089a0638e68a07c945a32c9e14
4
- distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
3
+ distributionSha256Sum=d8a18a7a841dd5df825d35a685fad6f2d7f12ac0c280e57b67c27b4a520ba228
4
+ distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-bin.zip
5
5
  networkTimeout=10000
6
6
  retries=0
7
7
  retryBackOffMs=500
@@ -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%