@blotch/angular-lynx-native 22.2.25 → 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 (62) hide show
  1. package/README.md +15 -11
  2. package/dist/android/project.d.ts +13 -1
  3. package/dist/android/project.d.ts.map +1 -1
  4. package/dist/android/project.js +40 -11
  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/generate.d.ts +1 -1
  9. package/dist/generate.js +8 -2
  10. package/dist/index.d.ts +3 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +23 -0
  13. package/dist/ios/build.d.ts.map +1 -1
  14. package/dist/ios/build.js +5 -0
  15. package/dist/ios/project.d.ts +16 -2
  16. package/dist/ios/project.d.ts.map +1 -1
  17. package/dist/ios/project.js +57 -6
  18. package/dist/options.d.ts +68 -1
  19. package/dist/options.d.ts.map +1 -1
  20. package/dist/options.js +70 -0
  21. package/dist/permissions.d.ts.map +1 -1
  22. package/dist/permissions.js +7 -0
  23. package/dist/png.d.ts +5 -0
  24. package/dist/png.d.ts.map +1 -1
  25. package/dist/png.js +19 -5
  26. package/dist/splash.d.ts +70 -0
  27. package/dist/splash.d.ts.map +1 -0
  28. package/dist/splash.js +239 -0
  29. package/package.json +1 -1
  30. package/templates/android/README.md +11 -2
  31. package/templates/android/app/build.gradle.kts +19 -9
  32. package/templates/android/app/proguard-rules.pro +67 -55
  33. package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServer.kt +6 -0
  34. package/templates/android/app/src/main/AndroidManifest.xml +3 -1
  35. package/templates/android/app/src/main/java/dev/angularlynx/shell/AssetsModule.kt +2 -1
  36. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +16 -3
  37. package/templates/android/app/src/main/java/dev/angularlynx/shell/LinkingModule.kt +42 -0
  38. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +96 -7
  39. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +15 -0
  40. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +24 -0
  41. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +15 -4
  42. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +10 -1
  43. package/templates/android/app/src/main/res/values/colors.xml +3 -2
  44. package/templates/android/app/src/main/res/values/splash.xml +9 -0
  45. package/templates/android/app/src/main/res/values/themes.xml +14 -0
  46. package/templates/android/app/src/release/java/dev/angularlynx/shell/DevServer.kt +2 -0
  47. package/templates/android/build.gradle.kts +1 -1
  48. package/templates/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  49. package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  50. package/templates/android/gradlew.bat +41 -11
  51. package/templates/ios/App/AngularLynxWebGL.h +34 -6
  52. package/templates/ios/App/AngularLynxWebGL.m +58 -23
  53. package/templates/ios/App/AngularLynxWebGLContext.m +104 -26
  54. package/templates/ios/App/AnimationFrameRate.swift +214 -0
  55. package/templates/ios/App/AppDelegate.swift +48 -0
  56. package/templates/ios/App/AssetsModule.swift +3 -1
  57. package/templates/ios/App/DevServer.swift +3 -0
  58. package/templates/ios/App/Info.plist +12 -5
  59. package/templates/ios/App/LinkingModule.swift +62 -1
  60. package/templates/ios/App/LynxViewController.swift +30 -6
  61. package/templates/ios/App/ShellModule.swift +40 -1
  62. package/templates/ios/App/SplashScreen.swift +71 -0
@@ -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
  }
@@ -23,6 +23,7 @@ import androidx.activity.enableEdgeToEdge
23
23
  import androidx.browser.customtabs.CustomTabsIntent
24
24
  import androidx.core.graphics.Insets
25
25
  import androidx.core.os.ConfigurationCompat
26
+ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
26
27
  import androidx.core.view.ViewCompat
27
28
  import androidx.core.view.WindowInsetsCompat
28
29
  import com.lynx.react.bridge.JavaOnlyArray
@@ -31,6 +32,7 @@ import com.lynx.tasm.LynxError
31
32
  import com.lynx.tasm.LynxView
32
33
  import com.lynx.tasm.LynxViewBuilder
33
34
  import com.lynx.tasm.LynxViewClient
35
+ import com.lynx.tasm.ThreadStrategyForRendering
34
36
  import com.lynx.xelement.XElementBehaviors
35
37
 
36
38
  /**
@@ -60,6 +62,13 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
60
62
  private var contrastListener: Any? = null
61
63
  private var highContrastTextListener: Any? = null
62
64
 
65
+ // Whether the splash screen stays up: until the runtime says the app's
66
+ // first screen is drawn (ShellModule.hideSplashScreen), or
67
+ // SPLASH_TIMEOUT_MS have passed, so a host the runtime can't reach, or a
68
+ // first screen that never settles, doesn't leave the app behind its logo.
69
+ private var keepSplashScreen = true
70
+ private val splashTimeout = Handler(Looper.getMainLooper())
71
+
63
72
  // Disabled until the Angular app enables it (see ShellModule), so by
64
73
  // default back leaves the app like any other root screen.
65
74
  private val backHandler = object : OnBackPressedCallback(false) {
@@ -75,6 +84,11 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
75
84
  }
76
85
  private var webAuthSession: WebAuthSession? = null
77
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
+
78
92
  // The Photo Picker (see ImagePickerModule), and who to tell what was
79
93
  // picked. An activity registers for results as it's created, before it
80
94
  // starts, so a result that arrives after Android recreated it still
@@ -95,10 +109,30 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
95
109
  }
96
110
 
97
111
  override fun onCreate(savedInstanceState: Bundle?) {
112
+ // The splash screen (themes.xml's Theme.AngularLynxShell.Starting),
113
+ // before anything else: it switches the activity to the app's own
114
+ // theme. Android takes a splash screen down at the app's first frame,
115
+ // which would be the empty LynxView: the bundle hasn't run yet, and
116
+ // the first screen may have work to finish first, such as a lazy
117
+ // route or a guard. So it stays up until the runtime says the screen
118
+ // is drawn, and then fades out.
119
+ val splashScreen = installSplashScreen()
98
120
  // Android 15+ always draws apps edge to edge; opting in on older
99
121
  // versions too keeps the layout the same everywhere.
100
122
  enableEdgeToEdge()
101
123
  super.onCreate(savedInstanceState)
124
+ // Checked before each frame while the splash screen is up. The
125
+ // development build's message, such as that the dev server can't be
126
+ // reached, shows at once.
127
+ splashScreen.setKeepOnScreenCondition { keepSplashScreen && !DevServer.isShowingMessage() }
128
+ splashScreen.setOnExitAnimationListener { splash ->
129
+ splash.view.animate()
130
+ .alpha(0f)
131
+ .setDuration(SPLASH_FADE_MS)
132
+ .withEndAction { splash.remove() }
133
+ .start()
134
+ }
135
+ splashTimeout.postDelayed({ hideSplashScreen() }, SPLASH_TIMEOUT_MS)
102
136
 
103
137
  // A shortcut that started the app waits for the runtime to take it.
104
138
  // Android hands a recreated activity the intent it started with
@@ -109,11 +143,34 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
109
143
  ) {
110
144
  ShortcutsModule.run(intent)
111
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
+ }
112
157
 
113
158
  // The bundle in the app's assets, or in the debug build `ng serve
114
159
  // --platform android` runs, the dev server's (DevServer.kt).
115
160
  val bundleUrl = DevServer.bundleUrl(this) ?: BundleAssets.MAIN_BUNDLE
116
161
  lynxView = LynxViewBuilder().apply {
162
+ // Lynx's engine thread, which runs the main thread's JavaScript
163
+ // (the whole Angular app), layout and Lynx's animator, gets a
164
+ // thread of its own. Lynx's default, ALL_ON_UI, runs it on the UI
165
+ // thread, where change detection, a screen being built or a long
166
+ // event handler took frames from what Android runs itself: a
167
+ // scroll view's fling, typing, a web view. Off it, the element
168
+ // tree reaches the screen a step later, once the flush crosses to
169
+ // the UI thread: the build plugin turns on Lynx's pending invokes
170
+ // so UI methods follow it, and the runtime sets enable-async-list
171
+ // on every <list>, which this strategy requires. The iOS shell
172
+ // does the same.
173
+ setThreadStrategyForRendering(ThreadStrategyForRendering.MOST_ON_TASM)
117
174
  setTemplateProvider(AssetTemplateProvider(this@MainActivity))
118
175
  setTemplateResourceFetcher(AssetTemplateResourceFetcher(this@MainActivity))
119
176
  setMediaResourceFetcher(AssetMediaResourceFetcher())
@@ -139,7 +196,8 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
139
196
  registerModule(ShortcutsModule.NAME, ShortcutsModule::class.java, null)
140
197
  // <canvas>'s WebGL (WebGLModule.kt), which the runtime calls from
141
198
  // the main thread, where Angular runs: main-thread modules let
142
- // it get its answers synchronously, with lynx.module(name).
199
+ // it get its answers synchronously, with lynx.module(name). Lynx
200
+ // calls them on its engine thread, not the UI thread.
143
201
  registerModule(WebGLModule.NAME, WebGLModule::class.java, null)
144
202
  // Bundled files for the main thread's fetch and Image (AssetsModule.kt).
145
203
  registerModule(AssetsModule.NAME, AssetsModule::class.java, null)
@@ -245,6 +303,19 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
245
303
  backHandler.isEnabled = enabled
246
304
  }
247
305
 
306
+ // The splash screen goes at the next frame (see onCreate). Once gone,
307
+ // nothing: the development build loads the app again on every edit, and
308
+ // each load asks.
309
+ override fun hideSplashScreen() {
310
+ keepSplashScreen = false
311
+ splashTimeout.removeCallbacksAndMessages(null)
312
+ }
313
+
314
+ // Activity.reportFullyDrawn() counts once per launch itself.
315
+ override fun markFullyDrawn() {
316
+ reportFullyDrawn()
317
+ }
318
+
248
319
  override fun startWebAuthSession(url: Uri, callbackScheme: String, done: (WebAuthModule.Result) -> Unit) {
249
320
  if (webAuthSession != null) {
250
321
  done(WebAuthModule.Result.Failed("A sign-in is already open."))
@@ -270,14 +341,22 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
270
341
  lynxView.sendGlobalEvent(ShortcutsModule.EVENT, JavaOnlyArray())
271
342
  return
272
343
  }
344
+ if (intent.action != Intent.ACTION_VIEW) return
345
+ val url = intent.data ?: return
273
346
  // The sign-in page's redirect to the callback scheme: the deep link
274
347
  // comes back to this activity, which closes the Custom Tab above it.
275
348
  // It arrives before onResume, which then finds no session open.
276
- val url = intent.data ?: return
277
- val session = webAuthSession ?: return
278
- if (url.scheme?.lowercase() != session.scheme) return
279
- webAuthSession = null
280
- 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())
281
360
  }
282
361
 
283
362
  // The manifest's configChanges keeps the activity, and the running app,
@@ -308,7 +387,8 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
308
387
  * The global props the runtime reads: `theme` (LynxTheme), `isNotchScreen`
309
388
  * (LynxSafeArea), `appLocale` (LynxLocale), `appTimeZone` (the `intl`
310
389
  * build option's Intl.DateTimeFormat), the accessibility settings
311
- * (LynxAccessibilitySettings) and `osVersion` (LynxSystemInfo), plus the
390
+ * (LynxAccessibilitySettings), `osVersion` (LynxSystemInfo) and
391
+ * `initialURL` (LynxLinking and the router), plus the
312
392
  * safe-area insets in dp and `edgeToEdge`, which env(safe-area-inset-*)
313
393
  * reads. The iOS shell sends the same keys, and Lynx Explorer sends theme
314
394
  * and isNotchScreen too. Android 12 and later also send the wallpaper's
@@ -343,6 +423,9 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
343
423
  // which it reads from the engine's local time, and names it with this.
344
424
  props["appTimeZone"] = java.util.TimeZone.getDefault().id
345
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 }
346
429
  return props
347
430
  }
348
431
 
@@ -391,11 +474,17 @@ class MainActivity : ComponentActivity(), ShellModule.Host, WebAuthModule.Host {
391
474
  getSystemService(AccessibilityManager::class.java).removeHighContrastTextStateChangeListener(it)
392
475
  }
393
476
  }
477
+ splashTimeout.removeCallbacksAndMessages(null)
394
478
  lynxView.destroy()
395
479
  super.onDestroy()
396
480
  }
397
481
 
398
482
  private companion object {
399
483
  const val TAG = "AngularLynxShell"
484
+
485
+ // The longest the splash screen waits for the app (see onCreate),
486
+ // and its fade, as long as the iOS shell's.
487
+ const val SPLASH_TIMEOUT_MS = 5_000L
488
+ const val SPLASH_FADE_MS = 250L
400
489
  }
401
490
  }
@@ -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
@@ -29,6 +29,18 @@ import com.lynx.tasm.LynxEnv
29
29
  * pressure, so this reports a moderate one. The runtime asks once it has
30
30
  * released about a screen's worth of elements and the app has settled
31
31
  * (`collect-garbage.ts` in `packages/runtime`).
32
+ *
33
+ * `hideSplashScreen` lets the splash screen go, which MainActivity keeps up
34
+ * until the app's first screen is ready. The runtime's LynxSplashScreen
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.
32
44
  */
33
45
  class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
34
46
  private val host = param as Host
@@ -36,6 +48,8 @@ class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
36
48
 
37
49
  interface Host {
38
50
  fun setBackHandlerEnabled(enabled: Boolean)
51
+ fun hideSplashScreen()
52
+ fun markFullyDrawn()
39
53
  }
40
54
 
41
55
  @LynxMethod
@@ -43,6 +57,16 @@ class ShellModule(context: Context, param: Any?) : LynxModule(context, param) {
43
57
  main.post { host.setBackHandlerEnabled(enabled) }
44
58
  }
45
59
 
60
+ @LynxMethod
61
+ fun hideSplashScreen() {
62
+ main.post { host.hideSplashScreen() }
63
+ }
64
+
65
+ @LynxMethod
66
+ fun reportFullyDrawn() {
67
+ host.markFullyDrawn()
68
+ }
69
+
46
70
  @LynxMethod
47
71
  fun collectGarbage() {
48
72
  main.post { LynxEnv.inst().trimMemory(MEMORY_PRESSURE_MODERATE) }
@@ -33,8 +33,13 @@ private const val EGL_OPENGL_ES3_BIT = 0x40
33
33
  * default framebuffer the size of the canvas's `width` and `height`, which
34
34
  * each finished frame is copied from into the canvas's TextureView.
35
35
  *
36
- * The runtime's `run` calls arrive on the UI thread, which makes the context
37
- * current for each and puts back whatever was current before.
36
+ * The runtime's `run` calls arrive on Lynx's engine thread, which the shell
37
+ * runs off the UI thread (MainActivity's thread strategy), while the canvas's
38
+ * TextureView reports its surface on the UI thread. Each call makes the
39
+ * context current for itself and puts back whatever was current before, so
40
+ * either thread can make the next one; the context's lock keeps them from
41
+ * making two at once. The UI thread waits for a batch only when the surface
42
+ * comes, goes or resizes.
38
43
  */
39
44
  class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
40
45
  private val display: EGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY)
@@ -125,6 +130,7 @@ class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
125
130
  }
126
131
  }
127
132
 
133
+ @Synchronized
128
134
  fun destroy() {
129
135
  if (destroyed) return
130
136
  withCurrent {
@@ -167,6 +173,7 @@ class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
167
173
 
168
174
  // --- The view ------------------------------------------------------------
169
175
 
176
+ @Synchronized
170
177
  fun attachView(canvas: CanvasUI?) {
171
178
  if (view === canvas) return
172
179
  view = canvas
@@ -175,6 +182,7 @@ class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
175
182
  }
176
183
 
177
184
  /** The view's surface came, went or changed size. */
185
+ @Synchronized
178
186
  fun surfaceChanged() {
179
187
  if (destroyed) return
180
188
  val texture = view?.surface
@@ -187,8 +195,9 @@ class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
187
195
  } else {
188
196
  windowTexture = texture
189
197
  withCurrent {
190
- // Presenting never waits for the display: it runs on
191
- // the UI thread.
198
+ // Presenting never waits for the display: the frame
199
+ // is copied once into the TextureView, which the UI
200
+ // thread composites at its own pace.
192
201
  EGL14.eglSwapInterval(display, 0)
193
202
  }
194
203
  }
@@ -332,6 +341,7 @@ class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
332
341
  * app has drawn since the last frame was shown, or, once a frame has been
333
342
  * shown without preserveDrawingBuffer, the cleared buffer.
334
343
  */
344
+ @Synchronized
335
345
  fun readDrawingBuffer(): DrawingBufferPixels? {
336
346
  if (destroyed) return null
337
347
  val pixels = ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder())
@@ -640,6 +650,7 @@ class WebGLContext(val canvasId: String, attributes: ReadableMap?) {
640
650
  fun skip() { index++ }
641
651
  }
642
652
 
653
+ @Synchronized
643
654
  fun run(commands: ReadableArray): JavaOnlyArray {
644
655
  val results = JavaOnlyArray()
645
656
  if (destroyed) return results
@@ -28,7 +28,8 @@ import kotlin.math.roundToInt
28
28
  * only come from a main-thread module: MainActivity turns those on
29
29
  * (`setEnableMTSModule`). The runtime batches the calls into one `run` per
30
30
  * frame; see packages/runtime/src/lib/canvas/webgl-bridge.ts for the
31
- * protocol. Lynx calls these methods on the UI thread, where GL runs.
31
+ * protocol. Lynx calls these methods on its engine thread, where the main
32
+ * thread's JavaScript runs, which the shell runs off the UI thread.
32
33
  */
33
34
  class WebGLModule(context: Context, param: Any?) : LynxModule(context, param) {
34
35
  private val contexts = HashMap<Int, WebGLContext>()
@@ -232,18 +233,25 @@ internal object DecodedImages {
232
233
  /**
233
234
  * Pairs canvases with contexts by canvas id: either can come first, as the
234
235
  * runtime may make the context before Lynx has made the element's view.
236
+ *
237
+ * Views come and go on the UI thread, contexts on Lynx's engine thread, so
238
+ * it's locked. It takes a context's lock inside its own, and a context never
239
+ * calls it, so the two can't wait on each other.
235
240
  */
236
241
  internal object CanvasRegistry {
237
242
  private val views = HashMap<String, WeakReference<CanvasUI>>()
238
243
  private val contexts = HashMap<String, WeakReference<WebGLContext>>()
239
244
 
245
+ @Synchronized
240
246
  fun setView(canvasId: String, view: CanvasUI?) {
241
247
  if (view == null) views.remove(canvasId) else views[canvasId] = WeakReference(view)
242
248
  contexts[canvasId]?.get()?.attachView(view)
243
249
  }
244
250
 
251
+ @Synchronized
245
252
  fun view(canvasId: String): CanvasUI? = views[canvasId]?.get()
246
253
 
254
+ @Synchronized
247
255
  fun setContext(canvasId: String, context: WebGLContext?) {
248
256
  if (context == null) {
249
257
  contexts.remove(canvasId)
@@ -253,6 +261,7 @@ internal object CanvasRegistry {
253
261
  }
254
262
  }
255
263
 
264
+ @Synchronized
256
265
  fun context(canvasId: String): WebGLContext? = contexts[canvasId]?.get()
257
266
  }
258
267
 
@@ -1,8 +1,9 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <resources>
3
3
  <!--
4
- The window background, which shows before the first Lynx frame and
5
- behind the system bars. MainActivity sets it again when dark mode
4
+ The window background, which shows behind the splash screen's image
5
+ and the system bars, and behind the page: angular.json's
6
+ splash.backgroundColor. MainActivity sets it again when dark mode
6
7
  switches while the app is open, from values-night's.
7
8
  -->
8
9
  <color name="window_background">#FFFFFFFF</color>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <!--
4
+ The splash screen's image (themes.xml): the launcher icon, as Android 12
5
+ shows by default. With angular.json's splash.image, the generator
6
+ deletes this file and writes drawable-*/splash_icon.png instead.
7
+ -->
8
+ <drawable name="splash_icon">@mipmap/ic_launcher</drawable>
9
+ </resources>
@@ -10,4 +10,18 @@
10
10
  <item name="android:windowLightStatusBar">true</item>
11
11
  <item name="android:windowLightNavigationBar">true</item>
12
12
  </style>
13
+
14
+ <!--
15
+ The splash screen, from the tap on the icon until the app's first screen
16
+ is ready (MainActivity keeps it up until the runtime says so). AndroidX's
17
+ core-splashscreen draws it as Android 12 and later do on every version,
18
+ and switches to the theme above once it's installed. Its color is the
19
+ window's, and its image splash_icon: the launcher icon, or angular.json's
20
+ splash.image, which the generator writes in its place.
21
+ -->
22
+ <style name="Theme.AngularLynxShell.Starting" parent="Theme.SplashScreen">
23
+ <item name="windowSplashScreenBackground">@color/window_background</item>
24
+ <item name="windowSplashScreenAnimatedIcon">@drawable/splash_icon</item>
25
+ <item name="postSplashScreenTheme">@style/Theme.AngularLynxShell</item>
26
+ </style>
13
27
  </resources>
@@ -21,4 +21,6 @@ object DevServer {
21
21
  fun remoteUrl(url: String): String? = null
22
22
 
23
23
  fun loaded(url: String, error: Throwable?) = Unit
24
+
25
+ fun isShowingMessage(): Boolean = false
24
26
  }
@@ -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%