@ng-native/desktop 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/bin/package.mjs +65 -9
  2. package/bin/prebuilt.mjs +25 -4
  3. package/native/CMakeLists.txt +51 -4
  4. package/native/appkit/CMakeLists.txt +16 -2
  5. package/native/appkit/appkit-backend.mm +28 -3
  6. package/native/appkit/cg-canvas.h +5 -0
  7. package/native/appkit/cg-canvas.mm +21 -6
  8. package/native/appkit/desktop-expo.h +6 -0
  9. package/native/appkit/desktop-expo.mm +5 -0
  10. package/native/appkit/host-view.mm +32 -0
  11. package/native/appkit/image-request.h +2 -10
  12. package/native/appkit/image-request.mm +0 -22
  13. package/native/appkit/image-view.mm +121 -4
  14. package/native/appkit/main.mm +130 -185
  15. package/native/appkit/scroll-view.mm +57 -16
  16. package/native/appkit/scrollers.h +22 -2
  17. package/native/appkit/scrollers.mm +221 -2
  18. package/native/appkit/split-view.h +4 -0
  19. package/native/appkit/split-view.mm +60 -12
  20. package/native/appkit/system-access.mm +3 -0
  21. package/native/appkit/system.mm +33 -48
  22. package/native/appkit/text-layout.h +6 -0
  23. package/native/appkit/text-layout.mm +147 -24
  24. package/native/appkit/view-effects.h +27 -0
  25. package/native/appkit/view-effects.mm +90 -0
  26. package/native/cmake/react-native.cmake +9 -0
  27. package/native/cmake/runtime-dependencies.cmake +32 -1
  28. package/native/core/include/ngn/app-info.h +3 -2
  29. package/native/core/include/ngn/app-menus.h +5 -11
  30. package/native/core/include/ngn/default-menu.h +16 -6
  31. package/native/core/include/ngn/desktop-expo.h +0 -5
  32. package/native/core/include/ngn/desktop-modules.h +144 -0
  33. package/native/core/include/ngn/dev-server.h +12 -3
  34. package/native/core/include/ngn/host-os.h +45 -0
  35. package/native/core/include/ngn/host-views.h +25 -0
  36. package/native/core/include/ngn/image-source.h +18 -0
  37. package/native/core/include/ngn/launch-settings.h +9 -7
  38. package/native/core/include/ngn/module-registry.h +2 -0
  39. package/native/core/include/ngn/notifications.h +6 -0
  40. package/native/core/include/ngn/runtime.h +4 -1
  41. package/native/core/include/ngn/scrollers.h +5 -0
  42. package/native/core/include/ngn/spawn-rules.h +3 -2
  43. package/native/core/include/ngn/split-view.h +12 -0
  44. package/native/core/include/ngn/system.h +47 -0
  45. package/native/core/include/ngn/text-measurer.h +11 -0
  46. package/native/core/include/ngn/undo.h +27 -0
  47. package/native/core/include/ngn/updates.h +3 -2
  48. package/native/core/include/ngn/view-filter.h +33 -0
  49. package/native/core/src/app-menus.cpp +9 -11
  50. package/native/core/src/default-menu.cpp +6 -2
  51. package/native/core/src/dev-server-helper.cpp +3 -2
  52. package/native/core/src/dev-server.cpp +22 -5
  53. package/native/core/src/host-os.cpp +20 -0
  54. package/native/core/src/host-views.cpp +25 -0
  55. package/native/core/src/image-source.cpp +30 -0
  56. package/native/core/src/launch-settings.cpp +10 -6
  57. package/native/core/src/module-registry.cpp +9 -0
  58. package/native/core/src/modules/app-info.cpp +4 -4
  59. package/native/core/src/modules/app-modules.cpp +4 -2
  60. package/native/core/src/modules/desktop-expo.cpp +0 -5
  61. package/native/core/src/modules/desktop-modules.cpp +132 -0
  62. package/native/core/src/modules/notifications.cpp +4 -4
  63. package/native/core/src/runtime.cpp +2 -0
  64. package/native/core/src/scrollers.cpp +11 -0
  65. package/native/core/src/spawn-rules.cpp +1 -4
  66. package/native/core/src/split-view.cpp +10 -0
  67. package/native/core/src/system.cpp +52 -0
  68. package/native/core/src/text-layout-manager.cpp +13 -0
  69. package/native/core/src/undo-stacks.cpp +71 -0
  70. package/native/core/src/view-filter.cpp +114 -0
  71. package/native/scripts/build-hermes.sh +19 -7
  72. package/native/scripts/build-icu.sh +36 -0
  73. package/native/scripts/build-lock.sh +21 -0
  74. package/native/scripts/build.sh +46 -7
  75. package/native/scripts/fetch-hermes.sh +70 -0
  76. package/native/scripts/fetch.sh +24 -2
  77. package/native/scripts/hermes-built.sh +5 -4
  78. package/native/scripts/hermes-target.sh +18 -0
  79. package/native/scripts/icu-filter.json +22 -0
  80. package/native/scripts/make-prebuilt.mjs +13 -6
  81. package/native/scripts/prebuilt-host-cache.mjs +1 -1
  82. package/native/shim/openssl/sha.h +108 -3
  83. package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
  84. package/package.json +2 -2
  85. package/prebuilt.json +6 -6
package/bin/package.mjs CHANGED
@@ -29,6 +29,7 @@ export const MINIMUM_MACOS = '14.0';
29
29
  export const DEFAULT_OUTPUT = 'dist/macos';
30
30
 
31
31
  const FORMATS = ['app', 'dmg', 'mas'];
32
+ const HERMES_FRAMEWORK = 'hermesvm.framework';
32
33
 
33
34
  export const PACKAGE_USAGE = `Usage: ng-native-desktop package [--format app|dmg|mas] [--output <dir>] [--feed-url <url> [--sparkle-key <key>]] [--skip-notarize]
34
35
 
@@ -439,16 +440,18 @@ function signsInWithApple(sys, expo, format) {
439
440
  * network, the files the user picks, and the app's identity on the team. `appleSignIn` adds Sign
440
441
  * in with Apple and `push` remote notifications (production APNs, which both distribution formats
441
442
  * use), and either adds to a `dmg` the app's identity on the team, which its profile is for.
443
+ * `loadsAdHocFramework` turns off library validation in an ad hoc signed `dmg`, which loads its
444
+ * embedded Hermes framework with no team to check it against.
442
445
  *
443
446
  * @param {DesktopAppConfig} config
444
447
  * @param {'app' | 'dmg' | 'mas'} format
445
- * @param {{ bundleIdentifier: string, team?: string, appleSignIn?: boolean, push?: boolean }} identity
448
+ * @param {{ bundleIdentifier: string, team?: string, appleSignIn?: boolean, push?: boolean, loadsAdHocFramework?: boolean }} identity
446
449
  * @returns {string | null}
447
450
  */
448
451
  export function entitlements(
449
452
  config,
450
453
  format,
451
- { bundleIdentifier, team, appleSignIn = false, push = false },
454
+ { bundleIdentifier, team, appleSignIn = false, push = false, loadsAdHocFramework = false },
452
455
  ) {
453
456
  if (format === 'app') return null;
454
457
  /** @type {import('./plist.mjs').PlistDict} */
@@ -458,6 +461,7 @@ export function entitlements(
458
461
  if (appleSignIn) granted['com.apple.developer.applesignin'] = ['Default'];
459
462
  if (push) granted['com.apple.developer.aps-environment'] = 'production';
460
463
  if (format === 'dmg') {
464
+ if (loadsAdHocFramework) granted['com.apple.security.cs.disable-library-validation'] = true;
461
465
  if (!appleSignIn && !push) return plist(granted);
462
466
  return plist({
463
467
  ...granted,
@@ -716,11 +720,16 @@ export async function packageApp(options, sys) {
716
720
  ]),
717
721
  'expo export:embed did not bundle the app for macos; the output above says why.',
718
722
  );
719
- compileBytecode(sys, hermesc, javascript, path.join(resources, 'main.jsbundle'));
723
+ // Compiled beside the bundle, then copied in: hermesc makes no folder, and an app with no assets
724
+ // has no Resources yet.
725
+ const bytecode = path.join(staging, 'main.jsbundle');
726
+ compileBytecode(sys, hermesc, javascript, bytecode);
727
+ sys.copy(bytecode, path.join(resources, 'main.jsbundle'));
720
728
  const executable = path.join(contents, 'MacOS', config.name);
721
729
  sys.copy(path.join(buildDir, 'appkit', 'ngn-macos'), executable);
722
730
  // Local symbols only, which nothing resolves at run time; the exported ones stay.
723
731
  expectSuccess(sys.run('strip', ['-x', executable]), `strip could not strip ${executable}.`);
732
+ const hermes = embedHermes(sys, buildDir, contents);
724
733
  const iconName = config.icon
725
734
  ? compileIcon(sys, path.resolve(cwd, config.icon), resources, staging)
726
735
  : null;
@@ -742,7 +751,7 @@ export async function packageApp(options, sys) {
742
751
 
743
752
  const made = [app];
744
753
  if (options.format === 'app') {
745
- expectSuccess(sys.run('codesign', ['--force', '--sign', '-', app]), 'codesign failed.');
754
+ signAdHoc(sys, app, hermes);
746
755
  } else if (options.format === 'dmg' && keys) {
747
756
  made.push(
748
757
  ...shipDmg(sys, {
@@ -755,10 +764,13 @@ export async function packageApp(options, sys) {
755
764
  options,
756
765
  signIn,
757
766
  push,
767
+ hermes,
758
768
  }),
759
769
  );
760
770
  } else if (keys) {
761
- made.push(shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, signIn, push }));
771
+ made.push(
772
+ shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, signIn, push, hermes }),
773
+ );
762
774
  }
763
775
  for (const file of made) console.log(path.relative(cwd, file));
764
776
  return 0;
@@ -782,6 +794,36 @@ function fallbackIdentifier(format, expo) {
782
794
  return `dev.ngnative.${slug || 'app'}`;
783
795
  }
784
796
 
797
+ /**
798
+ * An `app` build's ad hoc signature, for this Mac: the embedded Hermes framework first, then the app.
799
+ *
800
+ * @param {System} sys
801
+ * @param {string} app
802
+ * @param {string | null} hermes
803
+ */
804
+ function signAdHoc(sys, app, hermes) {
805
+ for (const target of hermes ? [hermes, app] : [app]) {
806
+ expectSuccess(sys.run('codesign', ['--force', '--sign', '-', target]), 'codesign failed.');
807
+ }
808
+ }
809
+
810
+ /**
811
+ * React Native's Hermes framework, which a host built against it links, from the host build into
812
+ * the app's Frameworks, where the binary's rpath finds it. Null for a host with Hermes linked in.
813
+ *
814
+ * @param {System} sys
815
+ * @param {string} buildDir
816
+ * @param {string} contents
817
+ * @returns {string | null} the embedded framework
818
+ */
819
+ function embedHermes(sys, buildDir, contents) {
820
+ const hermes = path.join(buildDir, 'appkit', HERMES_FRAMEWORK);
821
+ if (!sys.exists(hermes)) return null;
822
+ const embedded = path.join(contents, 'Frameworks', HERMES_FRAMEWORK);
823
+ sys.copy(hermes, embedded);
824
+ return embedded;
825
+ }
826
+
785
827
  /**
786
828
  * Sparkle, from the host build, into the app's Frameworks.
787
829
  *
@@ -807,12 +849,12 @@ function embedSparkle(sys, buildDir, contents) {
807
849
  * only a real identity can get.
808
850
  *
809
851
  * @param {System} sys
810
- * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, options: PackageCommand, signIn: boolean, push: boolean }} build
852
+ * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, options: PackageCommand, signIn: boolean, push: boolean, hermes: string | null }} build
811
853
  * @returns {string[]} the files made beside the app
812
854
  */
813
855
  function shipDmg(
814
856
  sys,
815
- { config, app, output, staging, bundleIdentifier, keys, options, signIn, push },
857
+ { config, app, output, staging, bundleIdentifier, keys, options, signIn, push, hermes },
816
858
  ) {
817
859
  if (signIn || push) embedProfile(sys, keys, app);
818
860
  const file = path.join(staging, 'entitlements.plist');
@@ -821,6 +863,8 @@ function shipDmg(
821
863
  team: keys.team,
822
864
  appleSignIn: signIn,
823
865
  push,
866
+ // An ad hoc signature has no team for library validation to match the framework against.
867
+ loadsAdHocFramework: Boolean(hermes) && keys.identity === '-',
824
868
  });
825
869
  sys.writeFile(file, /** @type {string} */ (granted));
826
870
  const timestamp = keys.identity === '-' ? '--timestamp=none' : '--timestamp';
@@ -839,6 +883,9 @@ function shipDmg(
839
883
  ]),
840
884
  `codesign could not sign ${path.basename(target)}.`,
841
885
  );
886
+ // Nested code before the app, with the app's identity: the hardened runtime loads a framework
887
+ // only from the app's own team.
888
+ if (hermes) sign(hermes);
842
889
  if (options.feedUrl) signSparkle(path.join(app, 'Contents', 'Frameworks', 'Sparkle.framework'));
843
890
  sign(app, ['--entitlements', file]);
844
891
 
@@ -931,9 +978,12 @@ function embedProfile(sys, keys, app) {
931
978
  * Embeds the provisioning profile, signs inside the App Sandbox and makes the installer package.
932
979
  *
933
980
  * @param {System} sys
934
- * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, signIn: boolean, push: boolean }} build
981
+ * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, signIn: boolean, push: boolean, hermes: string | null }} build
935
982
  */
936
- function shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, signIn, push }) {
983
+ function shipMas(
984
+ sys,
985
+ { config, app, output, staging, bundleIdentifier, keys, signIn, push, hermes },
986
+ ) {
937
987
  embedProfile(sys, keys, app);
938
988
  const file = path.join(staging, 'entitlements.plist');
939
989
  const granted = entitlements(config, 'mas', {
@@ -943,6 +993,12 @@ function shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, si
943
993
  push,
944
994
  });
945
995
  sys.writeFile(file, /** @type {string} */ (granted));
996
+ if (hermes) {
997
+ expectSuccess(
998
+ sys.run('codesign', ['--force', '--timestamp', '--sign', keys.identity, hermes]),
999
+ `codesign could not sign ${HERMES_FRAMEWORK}.`,
1000
+ );
1001
+ }
946
1002
  expectSuccess(
947
1003
  sys.run('codesign', [
948
1004
  '--force',
package/bin/prebuilt.mjs CHANGED
@@ -7,8 +7,8 @@
7
7
  * `prebuilt.json` beside this package lists them, one entry per version and flavour; an entry
8
8
  * that names no flavour is a release host. The release workflow writes each entry before
9
9
  * the package is packed (`docs/desktop-host.md` has the steps), so the SHA-256 of each archive
10
- * travels inside the npm package, not beside the archive it vouches for. An archive holds `appkit/ngn-macos`, `appkit/hermesc` and
11
- * `appkit/Sparkle.framework`, the files a host build's `appkit` folder has, and unpacks into the
10
+ * travels inside the npm package, not beside the archive it vouches for. An archive holds `appkit/ngn-macos`, `appkit/hermesc`,
11
+ * `appkit/hermesvm.framework` and `appkit/Sparkle.framework`, the files a host build's `appkit` folder has, and unpacks into the
12
12
  * per-user cache under its own hash, so a new archive never reuses an old one's files.
13
13
  *
14
14
  * `native/scripts/make-prebuilt.mjs` builds and packs one. The host is signed ad hoc unless
@@ -291,21 +291,41 @@ export function fetchPrebuilt(sys, host, cache) {
291
291
  return dir;
292
292
  }
293
293
 
294
+ /**
295
+ * The entitlements of an ad hoc signed host with the hardened runtime. Library validation loads
296
+ * only libraries from the process's own team, and an ad hoc signature has none, so it would refuse
297
+ * React Native's Hermes framework beside the binary. A real identity signs the framework too and
298
+ * keeps validation.
299
+ */
300
+ export const AD_HOC_HOST_ENTITLEMENTS = `<?xml version="1.0" encoding="UTF-8"?>
301
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
302
+ <plist version="1.0">
303
+ <dict>
304
+ <key>com.apple.security.cs.disable-library-validation</key>
305
+ <true/>
306
+ </dict>
307
+ </plist>
308
+ `;
309
+
294
310
  /**
295
311
  * Strips each file's local symbols, then signs it with the hardened runtime: with
296
312
  * `NGN_SIGN_IDENTITY` when that is set and not empty, ad hoc (`--sign -`, no timestamp) otherwise.
313
+ * `adHocEntitlements` go with an ad hoc signature only. A framework is signed as it is, unstripped.
297
314
  * Throws when a command fails.
298
315
  *
299
316
  * @param {(command: string, args: string[]) => { status: number | null }} run
300
317
  * @param {string[]} files
301
318
  * @param {Record<string, string | undefined>} env
319
+ * @param {string} [adHocEntitlements]
302
320
  */
303
- export function signPrebuiltFiles(run, files, env) {
321
+ export function signPrebuiltFiles(run, files, env, adHocEntitlements) {
304
322
  const identity = env['NGN_SIGN_IDENTITY'] || '-';
323
+ const entitlements =
324
+ identity === '-' && adHocEntitlements ? ['--entitlements', adHocEntitlements] : [];
305
325
  for (const file of files) {
306
326
  // Before signing, which stripping would break.
307
327
  for (const [command, args] of /** @type {[string, string[]][]} */ ([
308
- ['strip', ['-x', file]],
328
+ ...(file.endsWith('.framework') ? [] : [['strip', ['-x', file]]]),
309
329
  [
310
330
  'codesign',
311
331
  [
@@ -313,6 +333,7 @@ export function signPrebuiltFiles(run, files, env) {
313
333
  '--options',
314
334
  'runtime',
315
335
  identity === '-' ? '--timestamp=none' : '--timestamp',
336
+ ...entitlements,
316
337
  '--sign',
317
338
  identity,
318
339
  file,
@@ -6,7 +6,8 @@
6
6
  #
7
7
  # scripts/build.sh is the way in: it fetches the pinned sources into the per-user cache and passes
8
8
  # their paths here. NGN_BACKEND=none builds only the core and its tests (any OS, no Hermes), which
9
- # is what proves the core never reaches for a toolkit.
9
+ # is what proves the core never reaches for a toolkit; with NGN_RUNTIME, the runtime half over
10
+ # Hermes too, and its tests, still with no toolkit.
10
11
  cmake_minimum_required(VERSION 3.25)
11
12
  project(ngn_desktop LANGUAGES C CXX)
12
13
 
@@ -18,10 +19,12 @@ endif()
18
19
  set(NGN_BACKEND ${_default_backend} CACHE STRING "appkit or none")
19
20
  set_property(CACHE NGN_BACKEND PROPERTY STRINGS appkit none)
20
21
  option(NGN_TESTS "Build the core tests" ON)
22
+ option(NGN_RUNTIME "With NGN_BACKEND=none, build the runtime half over Hermes too" OFF)
21
23
 
22
24
  set(RN_DIR "" CACHE PATH "The installed react-native package")
23
25
  set(NGN_SOURCES "" CACHE PATH "Sources fetched by scripts/fetch.sh (<cache>/src)")
24
26
  set(NGN_HERMES_BUILD "" CACHE PATH "Hermes built by scripts/build-hermes.sh")
27
+ set(NGN_HERMES_PREBUILT "" CACHE PATH "React Native's prebuilt Hermes, from scripts/fetch-hermes.sh")
25
28
  foreach(var RN_DIR NGN_SOURCES)
26
29
  if(NOT IS_DIRECTORY "${${var}}")
27
30
  message(FATAL_ERROR "${var} is not set to a directory; build through scripts/build.sh")
@@ -51,7 +54,7 @@ endif()
51
54
  if(NGN_BACKEND STREQUAL "appkit")
52
55
  set(NGN_WITH_RUNTIME ON)
53
56
  elseif(NGN_BACKEND STREQUAL "none")
54
- set(NGN_WITH_RUNTIME OFF)
57
+ set(NGN_WITH_RUNTIME ${NGN_RUNTIME})
55
58
  else()
56
59
  message(FATAL_ERROR "NGN_BACKEND must be appkit or none, not ${NGN_BACKEND}")
57
60
  endif()
@@ -91,7 +94,10 @@ add_library(ngn_core STATIC
91
94
  core/src/gestures.cpp
92
95
  core/src/glass.cpp
93
96
  core/src/header-bar.cpp
97
+ core/src/host-os.cpp
94
98
  core/src/host-state.cpp
99
+ core/src/host-views.cpp
100
+ core/src/image-source.cpp
95
101
  core/src/input-dispatcher.cpp
96
102
  core/src/input-script.cpp
97
103
  core/src/key-value-store.cpp
@@ -106,6 +112,7 @@ add_library(ngn_core STATIC
106
112
  core/src/text-input.cpp
107
113
  core/src/text-layout-manager.cpp
108
114
  core/src/tray-and-dock.cpp
115
+ core/src/undo-stacks.cpp
109
116
  core/src/safe-areas.cpp
110
117
  core/src/scrollers.cpp
111
118
  core/src/posix-launcher.cpp
@@ -116,10 +123,12 @@ add_library(ngn_core STATIC
116
123
  core/src/split-view.cpp
117
124
  core/src/svg.cpp
118
125
  core/src/symbol.cpp
126
+ core/src/system.cpp
119
127
  core/src/tabs-host.cpp
120
128
  core/src/download.cpp
121
129
  core/src/updates.cpp
122
130
  core/src/view-box.cpp
131
+ core/src/view-filter.cpp
123
132
  core/src/view-transform.cpp
124
133
  core/src/red-box.cpp
125
134
  core/src/expo-image.cpp
@@ -142,6 +151,7 @@ add_library(ngn_core STATIC
142
151
  core/src/modules/core-modules.cpp
143
152
  core/src/modules/crypto.cpp
144
153
  core/src/modules/desktop-expo.cpp
154
+ core/src/modules/desktop-modules.cpp
145
155
  core/src/modules/file-system.cpp
146
156
  core/src/modules/fonts.cpp
147
157
  core/src/modules/image-loader.cpp
@@ -175,7 +185,8 @@ target_compile_options(ngn_core PRIVATE -Wall -Wextra -Werror -Wno-unused-parame
175
185
  if(NGN_TESTS)
176
186
  file(GLOB core_test_SRC CONFIGURE_DEPENDS core/tests/*.cpp)
177
187
  add_executable(ngn_core_tests ${core_test_SRC} core/testing/fake-backend.cpp core/testing/fake-network.cpp core/testing/fake-system.cpp)
178
- target_include_directories(ngn_core_tests PRIVATE core/testing core/tests)
188
+ # shim/ for the SHA-256 shim's own test.
189
+ target_include_directories(ngn_core_tests PRIVATE core/testing core/tests shim)
179
190
  target_link_libraries(ngn_core_tests PRIVATE ngn_core doctest)
180
191
  # doctest includes <ciso646> under clang, which libstdc++ 15 marks deprecated with a #warning;
181
192
  # keep it a warning rather than an error under -Werror (libc++, on Apple, has no such warning).
@@ -184,6 +195,15 @@ if(NGN_TESTS)
184
195
  target_compile_options(ngn_core_tests PRIVATE
185
196
  $<$<CXX_COMPILER_ID:Clang>:-Wno-error=\#warnings>
186
197
  $<$<CXX_COMPILER_ID:GNU>:-Wno-error=cpp>)
198
+ # clang 22's -Wpedantic calls doctest's __COUNTER__ a C2y extension. -Wpedantic comes from
199
+ # React Native's interface options, which follow the target's own, so the exception goes on
200
+ # the sources, whose options come last.
201
+ include(CheckCXXCompilerFlag)
202
+ check_cxx_compiler_flag(-Wc2y-extensions NGN_HAS_WC2Y_EXTENSIONS)
203
+ if(NGN_HAS_WC2Y_EXTENSIONS)
204
+ set(NGN_DOCTEST_SOURCE_OPTIONS -Wno-c2y-extensions)
205
+ set_source_files_properties(${core_test_SRC} PROPERTIES COMPILE_OPTIONS -Wno-c2y-extensions)
206
+ endif()
187
207
  endif()
188
208
  # The AppKit backend's own logic that needs no window: on macOS only, over the system's frameworks.
189
209
  if(APPLE)
@@ -232,12 +252,17 @@ if(NGN_TESTS)
232
252
  appkit/menu-bar.mm appkit/tests/menu-bar.test.mm
233
253
  appkit/system.mm appkit/tests/system.test.mm
234
254
  appkit/image-request.mm appkit/tests/image-request.test.mm
255
+ appkit/view-effects.mm appkit/tests/view-effects.test.mm
235
256
  appkit/tests/pointer-buttons.test.mm
236
- appkit/test-launch.mm appkit/desktop-expo.mm appkit/tests/test-launch.test.mm appkit/tests/locales.test.mm)
257
+ appkit/test-launch.mm appkit/desktop-expo.mm appkit/tests/test-launch.test.mm appkit/tests/locales.test.mm
258
+ appkit/tests/desktop-expo.test.mm)
237
259
  target_compile_options(ngn_core_tests PRIVATE $<$<COMPILE_LANGUAGE:OBJCXX>:-fobjc-arc>)
238
260
  target_link_libraries(ngn_core_tests PRIVATE "-framework Foundation" "-framework Security" "-framework IOKit" "-framework SystemConfiguration" "-framework Network" "-framework AppKit" "-framework CoreText" "-framework ImageIO" "-framework Vision" "-framework UniformTypeIdentifiers" "-framework EventKit" "-framework AVFoundation" "-framework CoreMedia" "-framework Photos" "-framework PhotosUI" "-framework AppTrackingTransparency" "-framework AdSupport" "-framework CoreLocation" "-framework MapKit" "-framework WebKit" "-framework PDFKit" "-framework CoreImage" "-framework AuthenticationServices" "-framework AVKit" "-framework UserNotifications")
239
261
  endif()
240
262
  enable_testing()
263
+ if(NGN_HERMES_TEST_RPATH)
264
+ target_link_options(ngn_core_tests PRIVATE ${NGN_HERMES_TEST_RPATH})
265
+ endif()
241
266
  add_test(NAME core COMMAND ngn_core_tests)
242
267
  endif()
243
268
 
@@ -261,6 +286,28 @@ if(NGN_WITH_RUNTIME)
261
286
  file(CONFIGURE OUTPUT ${CMAKE_BINARY_DIR}/generated/red-box-errors.h CONTENT
262
287
  "// Generated by CMakeLists.txt from core/src/red-box-errors.js.\n#pragma once\nconstexpr const char *kRedBoxErrors = R\"ngn(@NGN_RED_BOX_ERRORS_JS@)ngn\";\n" @ONLY)
263
288
  target_include_directories(ngn_core_runtime PRIVATE ${CMAKE_BINARY_DIR}/generated)
289
+
290
+ # Hermes and the runtime half linked whole, as a host links them: what no backend links yet on
291
+ # Linux, so an unresolved symbol or a missing ICU fails here first.
292
+ if(NGN_TESTS)
293
+ file(GLOB runtime_test_SRC CONFIGURE_DEPENDS core/runtime-tests/*.cpp)
294
+ add_executable(ngn_runtime_tests ${runtime_test_SRC})
295
+ target_link_libraries(ngn_runtime_tests PRIVATE "$<LINK_LIBRARY:WHOLE_ARCHIVE,ngn_core_runtime>" doctest)
296
+ # doctest's warnings, as for the core tests above.
297
+ if(NOT APPLE)
298
+ target_compile_options(ngn_runtime_tests PRIVATE
299
+ $<$<CXX_COMPILER_ID:Clang>:-Wno-error=\#warnings>
300
+ $<$<CXX_COMPILER_ID:GNU>:-Wno-error=cpp>)
301
+ endif()
302
+ if(NGN_DOCTEST_SOURCE_OPTIONS)
303
+ set_source_files_properties(${runtime_test_SRC} PROPERTIES COMPILE_OPTIONS ${NGN_DOCTEST_SOURCE_OPTIONS})
304
+ endif()
305
+ # A prebuilt Hermes framework loads through @rpath, as for the core tests above.
306
+ if(NGN_HERMES_TEST_RPATH)
307
+ target_link_options(ngn_runtime_tests PRIVATE ${NGN_HERMES_TEST_RPATH})
308
+ endif()
309
+ add_test(NAME runtime COMMAND ngn_runtime_tests)
310
+ endif()
264
311
  endif()
265
312
 
266
313
  # --- libraries' components (react-native-screens, react-native-safe-area-context) ---------------
@@ -81,6 +81,7 @@ add_library(ngn_appkit OBJECT
81
81
  text-layout.mm
82
82
  text-recognition.mm
83
83
  undo.mm
84
+ view-effects.mm
84
85
  updates.mm
85
86
  web-browser.mm
86
87
  app-updater.mm)
@@ -105,8 +106,16 @@ target_compile_definitions(ngn-macos PRIVATE NGN_REACT_NATIVE_VERSION="${_rn_ver
105
106
  # The hermesc built with the Hermes the binary links, beside it, where `package` takes it from to
106
107
  # compile the bundle to bytecode of the version this Hermes runs.
107
108
  add_custom_command(TARGET ngn-macos POST_BUILD
108
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NGN_HERMES_BUILD}/bin/hermesc $<TARGET_FILE_DIR:ngn-macos>/hermesc
109
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NGN_HERMESC} $<TARGET_FILE_DIR:ngn-macos>/hermesc
109
110
  VERBATIM)
111
+ # React Native's prebuilt Hermes beside the binary, which loads it from there in a build and
112
+ # `package` embeds in Contents/Frameworks.
113
+ if(NGN_HERMES_FRAMEWORK)
114
+ add_custom_command(TARGET ngn-macos POST_BUILD
115
+ COMMAND rm -rf $<TARGET_FILE_DIR:ngn-macos>/hermesvm.framework
116
+ COMMAND ditto ${NGN_HERMES_FRAMEWORK} $<TARGET_FILE_DIR:ngn-macos>/hermesvm.framework
117
+ VERBATIM)
118
+ endif()
110
119
 
111
120
  # Sparkle's framework beside the binary, where `package --format dmg` takes it from to embed it.
112
121
  # The binary never links it: it loads it at runtime in a dmg build only (app-updater.mm).
@@ -122,9 +131,14 @@ endif()
122
131
  # backend the binary uses. Built with the core tests, and run beside them.
123
132
  if(NGN_TESTS)
124
133
  add_executable(ngn_appkit_tests ../core/tests/main.cpp tests/views/accessibility.test.mm tests/views/svg-foreign-object.test.mm
125
- tests/views/tab-walk.test.mm tests/views/camera-view.test.mm tests/views/text-input-alignment.test.mm)
134
+ tests/views/tab-walk.test.mm tests/views/camera-view.test.mm tests/views/text-input-alignment.test.mm
135
+ tests/views/image-view.test.mm tests/views/modal-beside-split.test.mm
136
+ tests/views/split-under-pushed-screen.test.mm tests/views/view-effects.test.mm)
126
137
  target_include_directories(ngn_appkit_tests PRIVATE ../core/tests)
127
138
  target_link_libraries(ngn_appkit_tests PRIVATE ngn_appkit doctest ${NGN_APPKIT_FRAMEWORKS})
139
+ if(NGN_HERMES_TEST_RPATH)
140
+ target_link_options(ngn_appkit_tests PRIVATE ${NGN_HERMES_TEST_RPATH})
141
+ endif()
128
142
  ngn_link_swift(ngn_appkit_tests)
129
143
  add_test(NAME appkit COMMAND ngn_appkit_tests)
130
144
  endif()
@@ -78,7 +78,7 @@ void AppKitBackend::deleteView(SurfaceId, Tag tag) {
78
78
  [sourceLists_ removeObjectForKey:@(tag)];
79
79
  }
80
80
 
81
- void AppKitBackend::insertChild(SurfaceId, Tag parent, Tag child, int index) {
81
+ void AppKitBackend::insertChild(SurfaceId surfaceId, Tag parent, Tag child, int index) {
82
82
  NGNView *parentView = views_[@(parent)];
83
83
  NGNView *childView = views_[@(child)];
84
84
  if (parentView == nil || childView == nil) {
@@ -86,7 +86,16 @@ void AppKitBackend::insertChild(SurfaceId, Tag parent, Tag child, int index) {
86
86
  }
87
87
  // The index counts Fabric children only: a TextInput holds an NSTextField of its own.
88
88
  if ([childView isKindOfClass:NGNModalHostView.class] && ![childView isKindOfClass:NGNPresentedScreenView.class]) {
89
- [(NGNModalHostView *)childView presentOver:parentView];
89
+ // A view beside a split view at the root has no window: the split view's controller took the
90
+ // window's content, surface and all. The modal goes over the surface's window all the same.
91
+ NSView *over = parentView;
92
+ if (over.window == nil) {
93
+ // A surface already removed (a mount queued before it went) has no window to give.
94
+ NGNSurfaceView *surface = surfaces_[@(surfaceId)];
95
+ NSView *content = surface != nil ? NGNWindowOfSplit(surface).contentView : nil;
96
+ over = content != nil ? content : parentView;
97
+ }
98
+ [(NGNModalHostView *)childView presentOver:over];
90
99
  return;
91
100
  }
92
101
  if ([parentView conformsToProtocol:@protocol(NGNMountsChildren)]) {
@@ -155,7 +164,23 @@ void AppKitBackend::dispatchCommand(Tag tag, const std::string &name, const foll
155
164
  }
156
165
 
157
166
  void AppKitBackend::setCovered(SurfaceId, Tag tag, bool covered) {
158
- views_[@(tag)].covered = covered;
167
+ NGNView *screen = views_[@(tag)];
168
+ if (screen == nil) {
169
+ return;
170
+ }
171
+ screen.covered = covered;
172
+ // A window's split view on the covered screen gives the window back to the screen in front.
173
+ // ponytail: walks the screen's views on each push and pop; keep a registry if that shows up.
174
+ NSMutableArray<NSView *> *queue = [NSMutableArray arrayWithObject:screen];
175
+ while (queue.count > 0) {
176
+ NSView *view = queue.firstObject;
177
+ [queue removeObjectAtIndex:0];
178
+ if ([view isKindOfClass:NGNSplitView.class]) {
179
+ [(NGNSplitView *)view setScreenCovered:covered];
180
+ continue;
181
+ }
182
+ [queue addObjectsFromArray:view.subviews];
183
+ }
159
184
  }
160
185
 
161
186
  NGNHeaderToolbar *AppKitBackend::toolbarFor(SurfaceId surfaceId) {
@@ -7,6 +7,7 @@
7
7
  #include "ngn/svg.h"
8
8
 
9
9
  #include <memory>
10
+ #include <string>
10
11
 
11
12
  // Both answer a +1 reference the caller releases.
12
13
  CGColorRef NGNCreateColor(uint32_t argb, double opacity);
@@ -22,3 +23,7 @@ std::unique_ptr<ngn::SvgCanvas> NGNMakeCGCanvas(
22
23
  CGFloat scale,
23
24
  void (^imageLoaded)(void),
24
25
  NSView * (^viewFor)(ngn::Tag) = nil);
26
+
27
+ // Whether the load of an svg image's uri failed, or its data was no image, so that later draws
28
+ // skip it. Tests wait on it to know the failure was recorded.
29
+ bool NGNSvgImageLoadFailed(const std::string &uri);
@@ -78,6 +78,13 @@ NSCache<NSString *, NSImage *> *imageCache() {
78
78
  return cache;
79
79
  }
80
80
 
81
+ // The uris whose load failed or whose data is no image: not asked for again on each draw, like a
82
+ // browser's broken image, for as long as the app runs.
83
+ NSMutableSet<NSString *> *failedImages() {
84
+ static NSMutableSet<NSString *> *failed = [NSMutableSet set];
85
+ return failed;
86
+ }
87
+
81
88
  // The canvas drawSvg draws on: Core Graphics calls on the view's context, or on a mask's while
82
89
  // one is drawn. It tracks the user transform itself, so a mask, drawn in a context of its own,
83
90
  // starts where the drawing is.
@@ -369,7 +376,9 @@ class CGCanvas final : public ngn::SvgCanvas {
369
376
  NSString *key = @(uri.c_str());
370
377
  NSImage *image = [imageCache() objectForKey:key];
371
378
  if (image == nil) {
372
- load(key);
379
+ if (![failedImages() containsObject:key]) {
380
+ load(key);
381
+ }
373
382
  return;
374
383
  }
375
384
  NSSize natural = image.size;
@@ -622,11 +631,13 @@ class CGCanvas final : public ngn::SvgCanvas {
622
631
  dispatch_async(dispatch_get_main_queue(), ^{
623
632
  NSArray *waiters = loading[uri];
624
633
  [loading removeObjectForKey:uri];
625
- if (image != nil) {
626
- [imageCache() setObject:image forKey:uri];
627
- for (void (^waiter)(void) in waiters) {
628
- waiter();
629
- }
634
+ if (image == nil) {
635
+ [failedImages() addObject:uri];
636
+ return;
637
+ }
638
+ [imageCache() setObject:image forKey:uri];
639
+ for (void (^waiter)(void) in waiters) {
640
+ waiter();
630
641
  }
631
642
  });
632
643
  }] resume];
@@ -645,6 +656,10 @@ class CGCanvas final : public ngn::SvgCanvas {
645
656
 
646
657
  } // namespace
647
658
 
659
+ bool NGNSvgImageLoadFailed(const std::string &uri) {
660
+ return [failedImages() containsObject:@(uri.c_str())];
661
+ }
662
+
648
663
  CGColorRef NGNCreateColor(uint32_t argb, double opacity) {
649
664
  return createColorImpl(argb, opacity);
650
665
  }
@@ -7,10 +7,16 @@
7
7
  #include "ngn/launch-settings.h"
8
8
 
9
9
  #include <memory>
10
+ #include <set>
10
11
  #include <string>
11
12
 
12
13
  namespace ngn::appkit {
13
14
 
15
+ // Whether the app can use the Data Protection keychain: its signature has a Team ID, and an
16
+ // entitlement that gives it a keychain access group (an application identifier, as a Mac App Store
17
+ // build has, or keychain-access-groups). Without one the keychain refuses it (errSecMissingEntitlement).
18
+ bool usesDataProtectionKeychain(const std::string &teamId, const std::set<std::string> &entitlements);
19
+
14
20
  std::shared_ptr<SecretStore> makeKeychain();
15
21
  // Removes the file keychain items another test launch left when it ended without removing them.
16
22
  // Reads attributes only, so no item's data is asked for.
@@ -144,6 +144,11 @@ class Trackpad final : public HapticPlayer {
144
144
 
145
145
  } // namespace
146
146
 
147
+ bool usesDataProtectionKeychain(const std::string &teamId, const std::set<std::string> &entitlements) {
148
+ return !teamId.empty() &&
149
+ (entitlements.contains("com.apple.application-identifier") || entitlements.contains("keychain-access-groups"));
150
+ }
151
+
147
152
  std::shared_ptr<SecretStore> makeKeychain() {
148
153
  auto [team, entitlements] = ownSigning();
149
154
  if (!usesDataProtectionKeychain(team, entitlements)) {
@@ -13,6 +13,7 @@
13
13
  #import "scroll-view.h"
14
14
  #import "split-view.h"
15
15
  #import "svg-view.h"
16
+ #import "view-effects.h"
16
17
  #import "symbol-view.h"
17
18
  #import "glass-view.h"
18
19
 
@@ -211,6 +212,9 @@ static ngn::InputDispatcher *gViewInput;
211
212
  // drawRect draws the box (ngn/view-box.h), which the layer does not.
212
213
  BOOL _boxDrawn;
213
214
  NSMutableArray<CALayer *> *_shadowLayers;
215
+ // The `filter` and `mix-blend-mode` on the layer now, so a layout does not set them again.
216
+ std::vector<ngn::FilterStep> _filterSteps;
217
+ BlendMode _blendMode;
214
218
  // The transform from the props, as NGNViewLayer holds it.
215
219
  CATransform3D _transform;
216
220
  }
@@ -653,6 +657,7 @@ static BOOL focusFromKeyboard() {
653
657
  layer.masksToBounds = viewProps->yogaStyle.overflow() != facebook::yoga::Overflow::Visible;
654
658
  layer.mask = box.clip ? shapeLayer(*box.clip, NO, self.bounds) : nil;
655
659
  [self applyShadows:box.shadows];
660
+ [self applyEffects:*viewProps];
656
661
  // Its transform, about its centre on a layer anchored at its corner (view-transform.h).
657
662
  CATransform3D transform = CATransform3DIdentity;
658
663
  if (auto matrix = ngn::layerTransform(*viewProps, _layout)) {
@@ -673,6 +678,33 @@ static BOOL focusFromKeyboard() {
673
678
  _boxDrawn = box.drawn;
674
679
  }
675
680
 
681
+ // `filter` and `mix-blend-mode` as Core Animation filters on the layer, which apply to the view's
682
+ // children too, and to nothing at all when the props have none: a filter or blend removed is
683
+ // taken off.
684
+ - (void)applyEffects:(const ViewProps &)props {
685
+ auto steps = ngn::filterSteps(props.filter);
686
+ CALayer *layer = self.layer;
687
+ if (steps != _filterSteps) {
688
+ _filterSteps = steps;
689
+ NSArray<CIFilter *> *filters = ngn::appkit::layerFilters(steps);
690
+ if (filters != nil) {
691
+ self.layerUsesCoreImageFilters = YES;
692
+ }
693
+ layer.filters = filters;
694
+ }
695
+ if (props.mixBlendMode != _blendMode) {
696
+ _blendMode = props.mixBlendMode;
697
+ NSString *blend = ngn::appkit::blendFilterName(_blendMode);
698
+ if (blend != nil) {
699
+ self.layerUsesCoreImageFilters = YES;
700
+ }
701
+ layer.compositingFilter = blend;
702
+ }
703
+ if (layer.filters.count == 0 && layer.compositingFilter == nil) {
704
+ self.layerUsesCoreImageFilters = NO;
705
+ }
706
+ }
707
+
676
708
  // Each box shadow as a layer under the children, as RCTViewComponentView adds them.
677
709
  - (void)applyShadows:(const std::vector<ngn::BoxShadowLayer> &)shadows {
678
710
  for (CALayer *old in _shadowLayers) {
@@ -1,21 +1,13 @@
1
- // What an Image asks for (image-view.h): the source whose scale is nearest the screen's, and the
2
- // request it is loaded with, its method, headers and body included.
1
+ // The request an Image loads its source with (image-view.h), its method, headers and body included.
2
+ // Which source it loads is the core's (ngn/image-source.h).
3
3
  #pragma once
4
4
 
5
5
  #import <Foundation/Foundation.h>
6
6
 
7
7
  #include <react/renderer/imagemanager/primitives.h>
8
8
 
9
- #include <optional>
10
- #include <vector>
11
-
12
9
  namespace ngn::appkit {
13
10
 
14
- // The source with a uri whose scale is nearest `screenScale`, as React Native iOS picks, or none.
15
- std::optional<facebook::react::ImageSource> pickImageSource(
16
- const std::vector<facebook::react::ImageSource> &sources, double screenScale);
17
- // Whether two sources load the same thing: ImageSource's own == compares only the uri.
18
- bool sameImageRequest(const facebook::react::ImageSource &a, const facebook::react::ImageSource &b);
19
11
  // The request for `url`, which the source's uri gave, with the source's method, headers and body.
20
12
  NSURLRequest *imageRequest(NSURL *url, const facebook::react::ImageSource &source);
21
13