@ng-native/desktop 0.26.0 → 0.27.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 (256) hide show
  1. package/README.md +6 -3
  2. package/bin/app-config.mjs +1 -0
  3. package/bin/archive.mjs +166 -0
  4. package/bin/autolink.mjs +61 -30
  5. package/bin/cli.mjs +127 -27
  6. package/bin/host.mjs +255 -58
  7. package/bin/package-linux.mjs +1394 -0
  8. package/bin/package.mjs +171 -35
  9. package/bin/plist.mjs +6 -2
  10. package/bin/png-icon.mjs +315 -0
  11. package/bin/prebuilt.mjs +147 -26
  12. package/bin/toolchain.mjs +258 -19
  13. package/native/CMakeLists.txt +64 -6
  14. package/native/appkit/CMakeLists.txt +2 -1
  15. package/native/appkit/appkit-backend.h +1 -0
  16. package/native/appkit/appkit-backend.mm +13 -0
  17. package/native/appkit/header-toolbar.mm +28 -25
  18. package/native/appkit/host-view.h +10 -0
  19. package/native/appkit/host-view.mm +146 -40
  20. package/native/appkit/input-replay.h +6 -0
  21. package/native/appkit/input-replay.mm +21 -12
  22. package/native/appkit/main.mm +11 -7
  23. package/native/appkit/native-controls.mm +13 -1
  24. package/native/appkit/split-view.mm +7 -13
  25. package/native/appkit/text-input-field.h +4 -0
  26. package/native/appkit/text-input-field.mm +20 -1
  27. package/native/cmake/curl.cmake +79 -0
  28. package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
  29. package/native/cmake/libraries/react-native-worklets.cmake +5 -0
  30. package/native/cmake/linked-modules.cmake +20 -4
  31. package/native/cmake/react-native.cmake +18 -1
  32. package/native/core/include/ngn/accent-colors.h +38 -0
  33. package/native/core/include/ngn/accessibility-relations.h +65 -0
  34. package/native/core/include/ngn/accessibility.h +26 -0
  35. package/native/core/include/ngn/animated-frame-loop.h +56 -0
  36. package/native/core/include/ngn/app-info.h +24 -8
  37. package/native/core/include/ngn/app-menus.h +14 -1
  38. package/native/core/include/ngn/app-windows.h +15 -2
  39. package/native/core/include/ngn/aria-role.h +96 -0
  40. package/native/core/include/ngn/audio.h +2 -0
  41. package/native/core/include/ngn/camera.h +9 -0
  42. package/native/core/include/ngn/control-sizes.h +7 -2
  43. package/native/core/include/ngn/crash-report.h +31 -0
  44. package/native/core/include/ngn/curl-network.h +93 -0
  45. package/native/core/include/ngn/dbus-menu.h +39 -0
  46. package/native/core/include/ngn/default-menu.h +36 -0
  47. package/native/core/include/ngn/desktop-expo.h +7 -1
  48. package/native/core/include/ngn/desktop-modules.h +22 -0
  49. package/native/core/include/ngn/desktop-props.h +21 -1
  50. package/native/core/include/ngn/desktop-view-props.h +6 -0
  51. package/native/core/include/ngn/focus-order.h +10 -0
  52. package/native/core/include/ngn/header-bar.h +22 -0
  53. package/native/core/include/ngn/host-os.h +6 -0
  54. package/native/core/include/ngn/host-reload.h +21 -0
  55. package/native/core/include/ngn/host-state.h +23 -0
  56. package/native/core/include/ngn/image-source.h +26 -1
  57. package/native/core/include/ngn/input-script.h +3 -3
  58. package/native/core/include/ngn/input.h +4 -1
  59. package/native/core/include/ngn/launch-frame.h +21 -0
  60. package/native/core/include/ngn/launch-settings.h +23 -5
  61. package/native/core/include/ngn/mounting-backend.h +5 -0
  62. package/native/core/include/ngn/mounting-manager.h +1 -0
  63. package/native/core/include/ngn/native-controls.h +26 -5
  64. package/native/core/include/ngn/notification-schedule.h +74 -0
  65. package/native/core/include/ngn/notifications.h +2 -1
  66. package/native/core/include/ngn/openssl-update-crypto.h +15 -0
  67. package/native/core/include/ngn/photo-library.h +60 -20
  68. package/native/core/include/ngn/posix-locale.h +43 -0
  69. package/native/core/include/ngn/runtime.h +5 -0
  70. package/native/core/include/ngn/safe-areas.h +14 -2
  71. package/native/core/include/ngn/split-view.h +78 -0
  72. package/native/core/include/ngn/surface-metrics.h +7 -0
  73. package/native/core/include/ngn/system.h +14 -0
  74. package/native/core/include/ngn/text-input.h +13 -0
  75. package/native/core/include/ngn/text-units.h +38 -0
  76. package/native/core/include/ngn/updates.h +14 -2
  77. package/native/core/include/ngn/view-box.h +40 -0
  78. package/native/core/include/ngn/view-transform.h +15 -0
  79. package/native/core/include/ngn/web-browser.h +46 -0
  80. package/native/core/src/accent-colors.cpp +88 -0
  81. package/native/core/src/accessibility-relations.cpp +138 -0
  82. package/native/core/src/accessibility.cpp +50 -0
  83. package/native/core/src/animated-frame-loop.cpp +166 -0
  84. package/native/core/src/app-menus.cpp +26 -9
  85. package/native/core/src/app-windows.cpp +27 -6
  86. package/native/core/src/aria-role.cpp +127 -0
  87. package/native/core/src/control-sizes.cpp +9 -5
  88. package/native/core/src/crash-report.cpp +196 -0
  89. package/native/core/src/curl-network.cpp +1562 -0
  90. package/native/core/src/dbus-menu.cpp +71 -0
  91. package/native/core/src/default-menu.cpp +134 -0
  92. package/native/core/src/desktop-view-props.cpp +14 -0
  93. package/native/core/src/focus-order.cpp +19 -0
  94. package/native/core/src/header-bar.cpp +20 -0
  95. package/native/core/src/host-os.cpp +19 -0
  96. package/native/core/src/host-reload.cpp +45 -0
  97. package/native/core/src/host-state.cpp +8 -0
  98. package/native/core/src/image-source.cpp +90 -0
  99. package/native/core/src/input-dispatcher.cpp +27 -5
  100. package/native/core/src/input-script.cpp +3 -2
  101. package/native/core/src/launch-settings.cpp +76 -0
  102. package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
  103. package/native/core/src/modules/app-info.cpp +55 -6
  104. package/native/core/src/modules/app-modules.cpp +1 -1
  105. package/native/core/src/modules/audio.cpp +4 -2
  106. package/native/core/src/modules/camera.cpp +8 -11
  107. package/native/core/src/modules/desktop-expo.cpp +10 -5
  108. package/native/core/src/modules/desktop-modules.cpp +106 -41
  109. package/native/core/src/modules/file-photo-picker.cpp +408 -0
  110. package/native/core/src/modules/notifications.cpp +13 -17
  111. package/native/core/src/modules/photo-library.cpp +42 -13
  112. package/native/core/src/modules/web-browser.cpp +89 -0
  113. package/native/core/src/mounting-manager.cpp +12 -0
  114. package/native/core/src/native-controls.cpp +42 -1
  115. package/native/core/src/notification-schedule.cpp +429 -0
  116. package/native/core/src/openssl-update-crypto.cpp +83 -0
  117. package/native/core/src/posix-locale.cpp +192 -0
  118. package/native/core/src/runtime.cpp +30 -1
  119. package/native/core/src/safe-areas.cpp +19 -4
  120. package/native/core/src/spawn-rules.cpp +4 -1
  121. package/native/core/src/split-view.cpp +93 -0
  122. package/native/core/src/system.cpp +19 -0
  123. package/native/core/src/text-input.cpp +18 -1
  124. package/native/core/src/text-units.cpp +99 -0
  125. package/native/core/src/updates.cpp +76 -17
  126. package/native/core/src/view-box.cpp +75 -40
  127. package/native/core/src/view-transform.cpp +28 -0
  128. package/native/docker/Dockerfile +38 -0
  129. package/native/docker/Dockerfile.fedora +36 -0
  130. package/native/docker/glibc-floor.sh +49 -0
  131. package/native/gtk/CMakeLists.txt +137 -0
  132. package/native/gtk/accent-colour.cpp +57 -0
  133. package/native/gtk/accent-colour.h +41 -0
  134. package/native/gtk/accessibility-settings.cpp +159 -0
  135. package/native/gtk/accessibility-settings.h +62 -0
  136. package/native/gtk/accessible-text.cpp +151 -0
  137. package/native/gtk/accessible-text.h +49 -0
  138. package/native/gtk/accessible.cpp +306 -0
  139. package/native/gtk/accessible.h +75 -0
  140. package/native/gtk/alerts.cpp +267 -0
  141. package/native/gtk/alerts.h +30 -0
  142. package/native/gtk/animation-frames.cpp +159 -0
  143. package/native/gtk/animation-frames.h +20 -0
  144. package/native/gtk/app-info.cpp +91 -0
  145. package/native/gtk/app-info.h +25 -0
  146. package/native/gtk/app-windows.cpp +439 -0
  147. package/native/gtk/app-windows.h +150 -0
  148. package/native/gtk/audio.cpp +370 -0
  149. package/native/gtk/audio.h +54 -0
  150. package/native/gtk/auth-session.cpp +73 -0
  151. package/native/gtk/auth-session.h +16 -0
  152. package/native/gtk/battery.cpp +110 -0
  153. package/native/gtk/battery.h +19 -0
  154. package/native/gtk/box-paint.cpp +262 -0
  155. package/native/gtk/box-paint.h +32 -0
  156. package/native/gtk/cairo-canvas.cpp +755 -0
  157. package/native/gtk/cairo-canvas.h +49 -0
  158. package/native/gtk/camera.cpp +909 -0
  159. package/native/gtk/camera.h +69 -0
  160. package/native/gtk/capture.cpp +46 -0
  161. package/native/gtk/capture.h +19 -0
  162. package/native/gtk/clock-format.cpp +151 -0
  163. package/native/gtk/clock-format.h +36 -0
  164. package/native/gtk/crypto.cpp +75 -0
  165. package/native/gtk/crypto.h +14 -0
  166. package/native/gtk/dbus-properties.cpp +131 -0
  167. package/native/gtk/dbus-properties.h +61 -0
  168. package/native/gtk/drag-and-drop.cpp +339 -0
  169. package/native/gtk/drag-and-drop.h +30 -0
  170. package/native/gtk/file-dialogs.cpp +239 -0
  171. package/native/gtk/file-dialogs.h +21 -0
  172. package/native/gtk/file-system.cpp +212 -0
  173. package/native/gtk/file-system.h +25 -0
  174. package/native/gtk/focus.cpp +282 -0
  175. package/native/gtk/focus.h +37 -0
  176. package/native/gtk/fonts.cpp +89 -0
  177. package/native/gtk/fonts.h +22 -0
  178. package/native/gtk/gst-frames.cpp +150 -0
  179. package/native/gtk/gst-frames.h +47 -0
  180. package/native/gtk/gst-playback.cpp +496 -0
  181. package/native/gtk/gst-playback.h +81 -0
  182. package/native/gtk/gtk-backend.cpp +690 -0
  183. package/native/gtk/gtk-backend.h +134 -0
  184. package/native/gtk/host-sources.cpp +354 -0
  185. package/native/gtk/host-sources.h +46 -0
  186. package/native/gtk/image-manipulator.cpp +254 -0
  187. package/native/gtk/image-manipulator.h +30 -0
  188. package/native/gtk/image-view.cpp +256 -0
  189. package/native/gtk/image-view.h +54 -0
  190. package/native/gtk/input-replay.cpp +299 -0
  191. package/native/gtk/input-replay.h +36 -0
  192. package/native/gtk/launcher-badge.cpp +29 -0
  193. package/native/gtk/launcher-badge.h +21 -0
  194. package/native/gtk/locales.cpp +131 -0
  195. package/native/gtk/locales.h +23 -0
  196. package/native/gtk/location.cpp +274 -0
  197. package/native/gtk/location.h +19 -0
  198. package/native/gtk/main.cpp +1092 -0
  199. package/native/gtk/menus.cpp +447 -0
  200. package/native/gtk/menus.h +100 -0
  201. package/native/gtk/native-controls.cpp +831 -0
  202. package/native/gtk/native-controls.h +58 -0
  203. package/native/gtk/network-state.cpp +72 -0
  204. package/native/gtk/network-state.h +24 -0
  205. package/native/gtk/notifications.cpp +235 -0
  206. package/native/gtk/notifications.h +30 -0
  207. package/native/gtk/pango-text.cpp +274 -0
  208. package/native/gtk/pango-text.h +73 -0
  209. package/native/gtk/portal.cpp +451 -0
  210. package/native/gtk/portal.h +71 -0
  211. package/native/gtk/printing.cpp +338 -0
  212. package/native/gtk/printing.h +34 -0
  213. package/native/gtk/proxy-resolver.cpp +74 -0
  214. package/native/gtk/proxy-resolver.h +20 -0
  215. package/native/gtk/screens.cpp +1461 -0
  216. package/native/gtk/screens.h +274 -0
  217. package/native/gtk/scroll-view.cpp +414 -0
  218. package/native/gtk/scroll-view.h +82 -0
  219. package/native/gtk/secret-store.cpp +120 -0
  220. package/native/gtk/secret-store.h +27 -0
  221. package/native/gtk/settings-portal.cpp +129 -0
  222. package/native/gtk/settings-portal.h +47 -0
  223. package/native/gtk/split-view.cpp +1105 -0
  224. package/native/gtk/split-view.h +195 -0
  225. package/native/gtk/status-notifier.cpp +487 -0
  226. package/native/gtk/status-notifier.h +43 -0
  227. package/native/gtk/surface-input.cpp +251 -0
  228. package/native/gtk/surface-input.h +57 -0
  229. package/native/gtk/system-access.cpp +295 -0
  230. package/native/gtk/system-access.h +37 -0
  231. package/native/gtk/text-field.cpp +827 -0
  232. package/native/gtk/text-field.h +78 -0
  233. package/native/gtk/video.cpp +527 -0
  234. package/native/gtk/video.h +47 -0
  235. package/native/gtk/view-widget.cpp +431 -0
  236. package/native/gtk/view-widget.h +105 -0
  237. package/native/gtk/window-scale.cpp +95 -0
  238. package/native/gtk/window-scale.h +35 -0
  239. package/native/scripts/atspi-check.py +310 -0
  240. package/native/scripts/atspi-check.test.py +48 -0
  241. package/native/scripts/build.sh +20 -3
  242. package/native/scripts/compilers.sh +17 -0
  243. package/native/scripts/deb-depends-check.sh +22 -0
  244. package/native/scripts/fetch.sh +23 -2
  245. package/native/scripts/launch-cell.sh +157 -0
  246. package/native/scripts/launch-probe.sh +14 -3
  247. package/native/scripts/make-prebuilt.mjs +133 -44
  248. package/native/scripts/prebuilt-host-cache.mjs +71 -40
  249. package/native/scripts/reset-for-compilers.sh +44 -0
  250. package/native/scripts/start-xvfb.sh +35 -0
  251. package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
  252. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
  253. package/native/shim/worklets/linux-reanimated-props.h +14 -0
  254. package/native/shim/worklets/linux-worklets.h +23 -0
  255. package/package.json +6 -3
  256. package/prebuilt.json +70 -6
@@ -87,12 +87,17 @@ class FrameLoop : public std::enable_shared_from_this<FrameLoop> {
87
87
  reanimated::PlatformDepMethodsHolder platformMethods(const std::shared_ptr<FrameLoop> &loop) {
88
88
  return reanimated::PlatformDepMethodsHolder{
89
89
  .requestRender = [loop](std::function<void(const double)> onRender) { loop->request(std::move(onRender)); },
90
- // react-native-screens' snapshots, which the desktop's screens do not take.
90
+ #ifdef __APPLE__
91
+ // Reanimated has these two on Apple only. react-native-screens' snapshots, which the
92
+ // desktop's screens do not take, and the props a view is mounted with, which Reanimated reads
93
+ // only while its synchronous updates are on (IOS_SYNCHRONOUSLY_UPDATE_UI_PROPS, off): GTK
94
+ // takes the same path as AppKit with the flags as they ship.
91
95
  .forceScreenSnapshotFunction = [](Tag) { return false; },
92
96
  .readMountedViewPropsFunction = [](Tag tag) -> Props::Shared {
93
97
  auto read = workletHost().readMountedProps;
94
98
  return read ? read(tag) : nullptr;
95
99
  },
100
+ #endif
96
101
  .synchronouslyUpdateUIPropsFunction =
97
102
  [](const int tag, const folly::dynamic &props) {
98
103
  if (auto update = workletHost().synchronouslyUpdateView) {
@@ -22,6 +22,54 @@ constexpr int kDesktop = 3;
22
22
 
23
23
  } // namespace
24
24
 
25
+ BundleFacts bundleFactsOf(const std::function<std::optional<std::string>(const std::string &)> &plist) {
26
+ if (!plist) {
27
+ return {};
28
+ }
29
+ return {
30
+ .version = plist("CFBundleShortVersionString"),
31
+ .build = plist("CFBundleVersion"),
32
+ .id = plist("CFBundleIdentifier"),
33
+ .displayName = plist("CFBundleDisplayName"),
34
+ .name = plist("CFBundleName"),
35
+ };
36
+ }
37
+
38
+ std::map<std::string, std::string> osReleaseFields(const std::string &text) {
39
+ std::map<std::string, std::string> fields;
40
+ size_t start = 0;
41
+ while (start < text.size()) {
42
+ size_t end = text.find('\n', start);
43
+ std::string line = text.substr(start, end == std::string::npos ? std::string::npos : end - start);
44
+ start = end == std::string::npos ? text.size() : end + 1;
45
+ auto equals = line.find('=');
46
+ if (line.empty() || line[0] == '#' || equals == std::string::npos || equals == 0) {
47
+ continue;
48
+ }
49
+ std::string key = line.substr(0, equals);
50
+ std::string raw = line.substr(equals + 1);
51
+ while (!raw.empty() && (raw.back() == ' ' || raw.back() == '\r' || raw.back() == '\t')) {
52
+ raw.pop_back();
53
+ }
54
+ // Shell quoting: a quoted value loses its quotes, and inside double quotes a backslash escapes
55
+ // the next character.
56
+ std::string value;
57
+ char quote = !raw.empty() && (raw[0] == '"' || raw[0] == '\'') ? raw[0] : 0;
58
+ for (size_t i = quote ? 1 : 0; i < raw.size(); ++i) {
59
+ char c = raw[i];
60
+ if (quote && c == quote) {
61
+ break;
62
+ }
63
+ if (quote != '\'' && c == '\\' && i + 1 < raw.size()) {
64
+ c = raw[++i];
65
+ }
66
+ value += c;
67
+ }
68
+ fields[key] = value;
69
+ }
70
+ return fields;
71
+ }
72
+
25
73
  std::shared_ptr<NativeModule> makeApplicationModule(BundleFacts bundle, std::string appId, std::string appName) {
26
74
  struct Application : NativeModule {
27
75
  Application(BundleFacts bundle, std::string appId, std::string appName) : NativeModule("NgNativeApplication") {
@@ -38,22 +86,23 @@ std::shared_ptr<NativeModule> makeApplicationModule(BundleFacts bundle, std::str
38
86
  return std::make_shared<Application>(std::move(bundle), std::move(appId), std::move(appName));
39
87
  }
40
88
 
41
- std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine, std::string osName) {
89
+ std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine, const HostOs &os) {
42
90
  struct Device : NativeModule {
43
- Device(const MachineFacts &machine, const std::string &osName) : NativeModule("NgNativeDevice") {
91
+ Device(const MachineFacts &machine, const HostOs &os) : NativeModule("NgNativeDevice") {
92
+ auto maker = orNull(firstOf({os.deviceMaker, machine.manufacturer}));
44
93
  folly::dynamic architectures = folly::dynamic::array();
45
94
  for (const auto &architecture : machine.architectures) {
46
95
  architectures.push_back(architecture);
47
96
  }
48
97
  const std::map<std::string, folly::dynamic> values{
49
- {"brand", "Apple"},
50
- {"manufacturer", "Apple"},
98
+ {"brand", maker},
99
+ {"manufacturer", maker},
51
100
  {"modelName", orNull(firstOf({machine.marketingName, machine.modelId}))},
52
101
  {"modelId", orNull(machine.modelId)},
53
102
  {"designName", nullptr},
54
103
  {"productName", nullptr},
55
104
  {"deviceYearClass", nullptr},
56
- {"osName", osName},
105
+ {"osName", os.name},
57
106
  {"osVersion", orNull(machine.osVersion)},
58
107
  {"osBuildId", orNull(machine.osBuildId)},
59
108
  {"osInternalBuildId", orNull(machine.osBuildId)},
@@ -68,7 +117,7 @@ std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine, std::string
68
117
  }
69
118
  }
70
119
  };
71
- return std::make_shared<Device>(machine, osName);
120
+ return std::make_shared<Device>(machine, os);
72
121
  }
73
122
 
74
123
  } // namespace ngn
@@ -64,7 +64,7 @@ std::shared_ptr<NativeModule> makePlatformConstants(const CoreModuleServices &s)
64
64
  auto facts = system->facts();
65
65
  return folly::dynamic::object("isTesting", false)("isDisableAnimations", false)("reactNativeVersion", rn)(
66
66
  "forceTouchAvailable", false)("osVersion", facts.osVersion)("systemName", facts.systemName)(
67
- "interfaceIdiom", "mac")("isMacCatalyst", false);
67
+ "interfaceIdiom", facts.interfaceIdiom)("isMacCatalyst", false);
68
68
  });
69
69
  }
70
70
  };
@@ -504,10 +504,12 @@ std::shared_ptr<NativeModule> makeAudioModule(std::shared_ptr<AudioOutput> outpu
504
504
  return;
505
505
  }
506
506
  recorder.recording->stop();
507
+ std::string error = recorder.recording->error();
507
508
  if (state->send) {
508
509
  state->send(folly::dynamic::object("type", "recordingStatusUpdate")("id", id)(
509
- "status", folly::dynamic::object("id", id)("isFinished", true)("hasError", false)("error", nullptr)(
510
- "url", fileUri(recorder.path))));
510
+ "status", folly::dynamic::object("id", id)("isFinished", true)("hasError", !error.empty())(
511
+ "error", error.empty() ? folly::dynamic(nullptr) : folly::dynamic(error))(
512
+ "url", error.empty() ? folly::dynamic(fileUri(recorder.path)) : folly::dynamic(nullptr))));
511
513
  }
512
514
  });
513
515
  promise.resolve(nullptr);
@@ -91,7 +91,7 @@ std::string cameraMountError(CameraMount mount) {
91
91
  case CameraMount::NotPermitted:
92
92
  return "Camera permissions not granted - component could not be rendered.";
93
93
  case CameraMount::NoCamera:
94
- return "Camera could not be started - this Mac has no camera.";
94
+ return "Camera could not be started - this computer has no camera.";
95
95
  default:
96
96
  return "";
97
97
  }
@@ -134,13 +134,7 @@ std::string contentsOf(const std::string &path) {
134
134
  return {std::istreambuf_iterator<char>(in), {}};
135
135
  }
136
136
 
137
- // What expo-image-picker's mediaTypes (a MediaType, a list of them, or the deprecated
138
- // MediaTypeOptions) let the camera take. As on iOS, live photos are photos, and a request that
139
- // names neither photos nor videos (left out, or an empty list) takes photos.
140
- struct MediaKinds {
141
- bool photos{false};
142
- bool videos{false};
143
- };
137
+ } // namespace
144
138
 
145
139
  MediaKinds mediaKindsOf(const folly::dynamic &options) {
146
140
  MediaKinds kinds;
@@ -163,6 +157,8 @@ MediaKinds mediaKindsOf(const folly::dynamic &options) {
163
157
  return kinds;
164
158
  }
165
159
 
160
+ namespace {
161
+
166
162
  // AVFoundation's session preset for expo-image-picker's videoQuality, which on iOS is
167
163
  // UIImagePickerController's QualityType; High for any other value.
168
164
  std::string videoPresetOf(const folly::dynamic &options) {
@@ -258,7 +254,7 @@ void launchPickerCamera(const PickerCamera &camera, bool noPrompts, const folly:
258
254
  return;
259
255
  }
260
256
  if (!camera.hardware->hasCamera()) {
261
- promise.reject("ImagePicker: this Mac has no camera");
257
+ promise.reject("ImagePicker: this computer has no camera");
262
258
  return;
263
259
  }
264
260
  auto kinds = mediaKindsOf(options);
@@ -270,10 +266,11 @@ void launchPickerCamera(const PickerCamera &camera, bool noPrompts, const folly:
270
266
  // no sound when the microphone is refused. Only an app that cannot ask (no
271
267
  // NSMicrophoneUsageDescription, so the request leaves it undetermined) is rejected, as iOS
272
268
  // rejects it.
269
+ // Sound needs a microphone there too: Linux's PipeWire records silence, with no error, from none.
273
270
  using Access = AudioInput::Access;
274
271
  auto access = camera.microphone ? camera.microphone->access() : Access::Denied;
275
272
  if (access != Access::NotDetermined) {
276
- showPickerCamera(camera, options, kinds, access == Access::Granted, std::move(promise));
273
+ showPickerCamera(camera, options, kinds, access == Access::Granted && camera.microphone->hasMicrophone(), std::move(promise));
277
274
  return;
278
275
  }
279
276
  camera.microphone->requestAccess([camera, options, kinds, promise](Access decided) {
@@ -281,7 +278,7 @@ void launchPickerCamera(const PickerCamera &camera, bool noPrompts, const folly:
281
278
  promise.reject(kMissingMicrophone);
282
279
  return;
283
280
  }
284
- showPickerCamera(camera, options, kinds, decided == Access::Granted, promise);
281
+ showPickerCamera(camera, options, kinds, decided == Access::Granted && camera.microphone->hasMicrophone(), promise);
285
282
  });
286
283
  }
287
284
 
@@ -344,10 +344,12 @@ const char *measurement(const std::string &system) {
344
344
  std::shared_ptr<NativeModule> makeLocalizationModule(std::shared_ptr<LocaleSource> source, std::string regionCode) {
345
345
  struct Localization : NativeModule {
346
346
  Localization(std::shared_ptr<LocaleSource> source, std::string region) : NativeModule("NgNativeLocalization") {
347
+ // A backend with no source yet (GTK's) answers as one that knows nothing: English in the
348
+ // system's region, on the Gregorian calendar.
347
349
  sync("getLocales", [source, region](const folly::dynamic &) {
348
- auto locales = source->locales();
350
+ auto locales = source ? source->locales() : std::vector<LocaleFacts>();
349
351
  if (locales.empty()) {
350
- locales.push_back({.languageTag = "en-" + region});
352
+ locales.push_back({.languageTag = region.empty() ? "en" : "en-" + region});
351
353
  }
352
354
  folly::dynamic out = folly::dynamic::array();
353
355
  for (const auto &locale : locales) {
@@ -363,7 +365,7 @@ std::shared_ptr<NativeModule> makeLocalizationModule(std::shared_ptr<LocaleSourc
363
365
  return out;
364
366
  });
365
367
  sync("getCalendars", [source](const folly::dynamic &) {
366
- auto c = source->calendars();
368
+ auto c = source ? source->calendars() : CalendarFacts{.calendar = "gregorian"};
367
369
  return folly::dynamic::array(folly::dynamic::object("calendar", orNull(c.calendar))("timeZone", orNull(c.timeZone))(
368
370
  "uses24hourClock", c.uses24hourClock)("firstWeekday", c.firstWeekday));
369
371
  });
@@ -378,8 +380,11 @@ std::string mimeTypeOf(const std::string &name) {
378
380
  {"md", "text/markdown"}, {"json", "application/json"}, {"xml", "application/xml"},
379
381
  {"pdf", "application/pdf"}, {"zip", "application/zip"}, {"png", "image/png"}, {"jpg", "image/jpeg"},
380
382
  {"jpeg", "image/jpeg"}, {"gif", "image/gif"}, {"heic", "image/heic"}, {"webp", "image/webp"},
381
- {"svg", "image/svg+xml"}, {"tiff", "image/tiff"}, {"mp3", "audio/mpeg"}, {"m4a", "audio/mp4"},
382
- {"wav", "audio/wav"}, {"mp4", "video/mp4"}, {"mov", "video/quicktime"},
383
+ {"svg", "image/svg+xml"}, {"tiff", "image/tiff"}, {"tif", "image/tiff"}, {"bmp", "image/bmp"},
384
+ {"avif", "image/avif"}, {"heif", "image/heif"}, {"mp3", "audio/mpeg"}, {"m4a", "audio/mp4"},
385
+ {"wav", "audio/wav"}, {"mp4", "video/mp4"}, {"m4v", "video/x-m4v"}, {"mov", "video/quicktime"},
386
+ {"webm", "video/webm"}, {"mkv", "video/x-matroska"}, {"ogv", "video/ogg"}, {"avi", "video/x-msvideo"},
387
+ {"3gp", "video/3gpp"}, {"3gpp", "video/3gpp"}, {"3g2", "video/3gpp2"},
383
388
  };
384
389
  auto dot = name.rfind('.');
385
390
  if (dot == std::string::npos) {
@@ -6,6 +6,55 @@
6
6
 
7
7
  namespace ngn {
8
8
 
9
+ std::shared_ptr<NativeModule> makeHostModule(std::vector<std::string> absent) {
10
+ struct Host : NativeModule {
11
+ explicit Host(std::vector<std::string> absent) : NativeModule("NgNativeHost") {
12
+ constants([absent = std::move(absent)] {
13
+ folly::dynamic names = folly::dynamic::array();
14
+ for (const auto &name : absent) {
15
+ names.push_back(name);
16
+ }
17
+ return folly::dynamic::object("absentModules", std::move(names));
18
+ });
19
+ }
20
+ };
21
+ return std::make_shared<Host>(std::move(absent));
22
+ }
23
+
24
+ namespace {
25
+
26
+ // The input of a backend that has none to record from: nothing to allow and no microphone.
27
+ std::shared_ptr<AudioInput> noAudioInput() {
28
+ struct None final : AudioInput {
29
+ Access access() override { return Access::Restricted; }
30
+ void requestAccess(std::function<void(Access)> done) override { done(Access::Restricted); }
31
+ bool hasMicrophone() override { return false; }
32
+ std::unique_ptr<AudioRecording> prepare(const std::string &, const RecordingSettings &, std::string &error) override {
33
+ error = "there is no microphone to record from";
34
+ return nullptr;
35
+ }
36
+ };
37
+ return std::make_shared<None>();
38
+ }
39
+
40
+ } // namespace
41
+
42
+ std::shared_ptr<NativeModule> makeDesktopImagePicker(const DesktopModuleSources &s) {
43
+ std::optional<PickerCamera> camera;
44
+ if (s.cameraHardware && s.cameraSheet) {
45
+ // With no input, a video is recorded without sound.
46
+ camera = PickerCamera{.hardware = s.cameraHardware, .microphone = s.audioInput ? s.audioInput : noAudioInput(), .sheet = s.cameraSheet,
47
+ .folder = s.caches + "/ImagePicker"};
48
+ }
49
+ if (s.photos) {
50
+ // A photo library's picker comes with its camera, or not at all.
51
+ return camera ? makeImagePickerModule(s.photos, s.photos, s.noPrompts, camera) : nullptr;
52
+ }
53
+ // A picker with no photo library behind it (makeFilePhotoPicker), and the camera where the
54
+ // backend has one.
55
+ return s.photoPicker ? makeImagePickerModule(s.photoPicker, nullptr, s.noPrompts, camera) : nullptr;
56
+ }
57
+
9
58
  DesktopModules addDesktopModules(ModuleRegistry &registry, const DesktopModuleSources &s) {
10
59
  // One launcher for the process: a reload gets a new module over it.
11
60
  DesktopModules made{
@@ -19,99 +68,114 @@ DesktopModules addDesktopModules(ModuleRegistry &registry, const DesktopModuleSo
19
68
  auto notifications = s.notifications(made.notificationEvents);
20
69
  made.push = std::make_shared<PushTokens>(s.push, made.notificationEvents);
21
70
 
22
- addModule(registry, "NgNativeWindows", [windows = s.windows] { return makeWindowsModule(windows); });
23
- addModule(registry, "NgNativeMenus", [menus = s.menus] { return makeMenusModule(menus); });
24
- addModule(registry, "NgNativeTray", [tray = s.tray] { return makeTrayModule(tray); });
25
- addModule(registry, "NgNativeDock", [dock = s.dock] { return makeDockModule(dock); });
71
+ // A module whose source the backend did not give is not registered. NgNativeHost names it, so
72
+ // its JavaScript reads it as absent by design rather than as a host built without it.
73
+ auto addSourced = [&registry, &absent = made.absent](const auto &source, const char *name, auto make) {
74
+ if (source) {
75
+ addModule(registry, name, std::move(make));
76
+ } else {
77
+ absent.emplace_back(name);
78
+ }
79
+ };
80
+
81
+ addSourced(s.windows, "NgNativeWindows", [windows = s.windows] { return makeWindowsModule(windows); });
82
+ addSourced(s.menus, "NgNativeMenus", [menus = s.menus] { return makeMenusModule(menus); });
83
+ addSourced(s.tray, "NgNativeTray", [tray = s.tray] { return makeTrayModule(tray); });
84
+ addSourced(s.dock, "NgNativeDock", [dock = s.dock] { return makeDockModule(dock); });
26
85
  addModule(registry, "NgNativeProcesses", [launcher = made.launcher, processes = s.processes] {
27
86
  return makeProcessesModule(launcher, processes);
28
87
  });
29
- addModule(registry, "NgNativeShell", [shell = s.shell, files = s.files] { return makeShellModule(shell, files); });
88
+ addSourced(s.shell, "NgNativeShell", [shell = s.shell, files = s.files] { return makeShellModule(shell, files); });
30
89
  // The desktop Expo modules (DESKTOP_MODULES in @ng-native/expo).
31
- addModule(registry, "NgNativeSecureStore", [secrets = s.secrets, service = s.appId] {
90
+ addSourced(s.secrets, "NgNativeSecureStore", [secrets = s.secrets, service = s.appId] {
32
91
  return makeSecureStoreModule(secrets, service);
33
92
  });
34
93
  addModule(registry, "NgNativeClipboard", [system = s.system, state = s.state] {
35
94
  return makeDesktopClipboardModule(system, state);
36
95
  });
37
- addModule(registry, "NgNativeNotifications", [notifications, events = made.notificationEvents, push = made.push] {
96
+ addSourced(notifications, "NgNativeNotifications", [notifications, events = made.notificationEvents, push = s.push ? made.push : nullptr] {
38
97
  return makeNotificationsModule(notifications, events, push);
39
98
  });
40
- addModule(registry, "NgNativeUndo", [undo = s.undo] { return makeUndoModule(undo); });
41
- addModule(registry, "NgNativeKeepAwake", [awake = std::make_shared<KeepAwakeTags>(s.sleep)] {
99
+ addSourced(s.undo, "NgNativeUndo", [undo = s.undo] { return makeUndoModule(undo); });
100
+ addSourced(s.sleep, "NgNativeKeepAwake", [awake = std::make_shared<KeepAwakeTags>(s.sleep)] {
42
101
  return makeKeepAwakeModule(awake);
43
102
  });
44
- addModule(registry, "NgNativeHaptics", [haptics = s.haptics] { return makeHapticsModule(haptics); });
45
- addModule(registry, "NgNativeFileSystem", [files = s.files, watcher = s.fileWatcher] {
103
+ addSourced(s.haptics, "NgNativeHaptics", [haptics = s.haptics] { return makeHapticsModule(haptics); });
104
+ addSourced(s.files && s.fileWatcher, "NgNativeFileSystem", [files = s.files, watcher = s.fileWatcher] {
46
105
  return makeFileSystemModule(files, watcher);
47
106
  });
48
- addModule(registry, "NgNativeDocumentPicker", [dialogs = s.fileDialogs, caches = s.caches, files = s.files] {
107
+ addSourced(s.fileDialogs, "NgNativeDocumentPicker", [dialogs = s.fileDialogs, caches = s.caches, files = s.files] {
49
108
  return makeDocumentPickerModule(dialogs, caches, files);
50
109
  });
51
110
  // expo-sqlite keeps its databases in the app's documents, under SQLite; here, in its data.
52
111
  addModule(registry, "NgNativeSqlite", [databases = s.system->appDataDirectory() + "/SQLite", files = s.files] {
53
112
  return makeSqliteModule(databases, files);
54
113
  });
55
- addModule(registry, "NgNativeLocation", [location = s.location, noPrompts = s.noPrompts, geocoder = s.geocoder] {
114
+ addSourced(s.location, "NgNativeLocation", [location = s.location, noPrompts = s.noPrompts, geocoder = s.geocoder] {
56
115
  return makeLocationModule(location, noPrompts, geocoder);
57
116
  });
58
- addModule(registry, "NgNativeLocalAuthentication", [authenticator = s.authenticator] {
117
+ addSourced(s.authenticator, "NgNativeLocalAuthentication", [authenticator = s.authenticator] {
59
118
  return makeLocalAuthenticationModule(authenticator);
60
119
  });
61
120
  addModule(registry, "NgNativeApplication", [bundle = s.bundle, appId = s.appId, appName = s.appName] {
62
121
  return makeApplicationModule(bundle, appId, appName);
63
122
  });
64
- addModule(registry, "NgNativeDevice", [machine = s.machine, os = s.os.name] { return makeDeviceModule(machine, os); });
65
- addModule(registry, "NgNativeNetwork", [monitor = s.pathMonitor] { return makeNetworkModule(monitor); });
66
- addModule(registry, "NgNativeBattery", [power = s.power] { return makeBatteryModule(power); });
67
- addModule(registry, "NgNativeFont", [registrar = s.fontRegistrar, fonts = made.fonts, http = s.http, caches = s.caches, files = s.files] {
123
+ addModule(registry, "NgNativeDevice", [machine = s.machine, os = s.os] { return makeDeviceModule(machine, os); });
124
+ addSourced(s.pathMonitor, "NgNativeNetwork", [monitor = s.pathMonitor] { return makeNetworkModule(monitor); });
125
+ addSourced(s.power, "NgNativeBattery", [power = s.power] { return makeBatteryModule(power); });
126
+ addSourced(s.fontRegistrar, "NgNativeFont", [registrar = s.fontRegistrar, fonts = made.fonts, http = s.http, caches = s.caches, files = s.files] {
68
127
  return makeFontModule(registrar, fonts, http, caches + "/fonts", files);
69
128
  });
70
129
  addModule(registry, "NgNativeWebBrowser", [system = s.system, sessions = s.authSession, noPrompts = s.noPrompts] {
71
130
  return makeWebBrowserModule(system, sessions, noPrompts);
72
131
  });
73
- addModule(registry, "NgNativeTextRecognition", [reader = s.textReader, files = s.files] {
132
+ addSourced(s.textReader, "NgNativeTextRecognition", [reader = s.textReader, files = s.files] {
74
133
  return makeTextRecognitionModule(reader, files);
75
134
  });
76
- addModule(registry, "NgNativeCalendar", [calendars = s.calendars, noPrompts = s.noPrompts] {
135
+ addSourced(s.calendars, "NgNativeCalendar", [calendars = s.calendars, noPrompts = s.noPrompts] {
77
136
  return makeCalendarModule(calendars, noPrompts);
78
137
  });
79
138
  // Players and recorders end with the runtime: a reload stops what the app played.
80
- addModule(registry, "NgNativeAudio", [output = s.audioOutput, input = s.audioInput, caches = s.caches, noPrompts = s.noPrompts, files = s.files] {
139
+ // Playing needs only the output: with no input, a recording is refused for want of a microphone.
140
+ addSourced(s.audioOutput, "NgNativeAudio", [output = s.audioOutput, input = s.audioInput ? s.audioInput : noAudioInput(), caches = s.caches, noPrompts = s.noPrompts, files = s.files] {
81
141
  return makeAudioModule(output, input, caches + "/Audio", noPrompts, files);
82
142
  });
83
- addModule(registry, "NgNativeVideo", [output = s.videoOutput, files = s.files] { return makeVideoModule(output, files); });
84
- addModule(registry, "NgNativeLocalLlm", [engine = s.languageModel] { return makeLocalLlmModule(engine); });
85
- addModule(registry, "NgNativeScreenCapture", [shield = s.captureShield] { return makeScreenCaptureModule(shield); });
86
- addModule(registry, "NgNativeSplashScreen", [splash = s.splash] { return makeSplashScreenModule(splash); });
87
- addModule(registry, "NgNativeMediaLibrary", [photos = s.photos, noPrompts = s.noPrompts, files = s.files] {
143
+ addSourced(s.videoOutput, "NgNativeVideo", [output = s.videoOutput, files = s.files] { return makeVideoModule(output, files); });
144
+ addSourced(s.languageModel, "NgNativeLocalLlm", [engine = s.languageModel] { return makeLocalLlmModule(engine); });
145
+ addSourced(s.captureShield, "NgNativeScreenCapture", [shield = s.captureShield] { return makeScreenCaptureModule(shield); });
146
+ addSourced(s.splash, "NgNativeSplashScreen", [splash = s.splash] { return makeSplashScreenModule(splash); });
147
+ addSourced(s.photos, "NgNativeMediaLibrary", [photos = s.photos, noPrompts = s.noPrompts, files = s.files] {
88
148
  return makeMediaLibraryModule(photos, noPrompts, files);
89
149
  });
90
- addModule(registry, "NgNativeImagePicker", [photos = s.photos, noPrompts = s.noPrompts, camera = PickerCamera{.hardware = s.cameraHardware, .microphone = s.audioInput, .sheet = s.cameraSheet, .folder = s.caches + "/ImagePicker"}] {
91
- return makeImagePickerModule(photos, noPrompts, camera);
92
- });
93
- addModule(registry, "NgNativeTrackingTransparency", [tracking = s.tracking, noPrompts = s.noPrompts] {
150
+ // Made again for each runtime, as every module is: over the photo library only with its camera,
151
+ // and over a picker with no library with or without one.
152
+ if (s.photos) {
153
+ addSourced(s.cameraHardware && s.cameraSheet, "NgNativeImagePicker", [s] { return makeDesktopImagePicker(s); });
154
+ } else {
155
+ addSourced(s.photoPicker, "NgNativeImagePicker", [s] { return makeDesktopImagePicker(s); });
156
+ }
157
+ addSourced(s.tracking, "NgNativeTrackingTransparency", [tracking = s.tracking, noPrompts = s.noPrompts] {
94
158
  return makeTrackingModule(tracking, noPrompts);
95
159
  });
96
- addModule(registry, "NgNativeAddressSearch", [lookup = s.addressLookup] { return makeAddressSearchModule(lookup); });
160
+ addSourced(s.addressLookup, "NgNativeAddressSearch", [lookup = s.addressLookup] { return makeAddressSearchModule(lookup); });
97
161
  addModule(registry, "NgNativeAsset", [http = s.http, caches = s.caches, files = s.files] {
98
162
  return makeAssetModule(http, caches, files);
99
163
  });
100
- addModule(registry, "NgNativeSymbol", [measurer = s.symbolMeasurer] { return makeSymbolModule(measurer); });
101
- addModule(registry, "NgNativeSharing", [picker = s.sharePicker, noPrompts = s.noPrompts, files = s.files] {
164
+ addSourced(s.symbolMeasurer, "NgNativeSymbol", [measurer = s.symbolMeasurer] { return makeSymbolModule(measurer); });
165
+ addSourced(s.sharePicker, "NgNativeSharing", [picker = s.sharePicker, noPrompts = s.noPrompts, files = s.files] {
102
166
  return makeSharingModule(picker, noPrompts, files);
103
167
  });
104
- addModule(registry, "NgNativeImageManipulator", [codec = s.imageCodec, http = s.http, caches = s.caches, files = s.files] {
168
+ addSourced(s.imageCodec, "NgNativeImageManipulator", [codec = s.imageCodec, http = s.http, caches = s.caches, files = s.files] {
105
169
  return makeImageManipulatorModule(codec, http, caches + "/ImageManipulator", files);
106
170
  });
107
- addModule(registry, "NgNativeCamera", [hardware = s.cameraHardware, views = made.cameraViews, caches = s.caches, noPrompts = s.noPrompts] {
171
+ addSourced(s.cameraHardware, "NgNativeCamera", [hardware = s.cameraHardware, views = made.cameraViews, caches = s.caches, noPrompts = s.noPrompts] {
108
172
  return makeCameraModule(hardware, views, caches + "/Camera", noPrompts);
109
173
  });
110
- addModule(registry, "NgNativeMaps", [views = made.mapViews] { return makeMapsModule(views); });
111
- addModule(registry, "NgNativeAppleAuthentication", [provider = s.appleId, noPrompts = s.noPrompts] {
174
+ addSourced(s.mapViews, "NgNativeMaps", [views = made.mapViews] { return makeMapsModule(views); });
175
+ addSourced(s.appleId, "NgNativeAppleAuthentication", [provider = s.appleId, noPrompts = s.noPrompts] {
112
176
  return makeAppleAuthenticationModule(provider, noPrompts);
113
177
  });
114
- addModule(registry, "NgNativePrint", [system = s.printSystem, http = s.http, caches = s.caches, files = s.files, noPrompts = s.noPrompts] {
178
+ addSourced(s.printSystem, "NgNativePrint", [system = s.printSystem, http = s.http, caches = s.caches, files = s.files, noPrompts = s.noPrompts] {
115
179
  return makePrintModule(system, http, caches + "/Print", files, noPrompts);
116
180
  });
117
181
  // react-native-webview's navigation answers; harmless in a host built without the library.
@@ -119,13 +183,14 @@ DesktopModules addDesktopModules(ModuleRegistry &registry, const DesktopModuleSo
119
183
  addModule(registry, "NgNativeStoreReview", [prompt = s.reviewPrompt, noPrompts = s.noPrompts] {
120
184
  return makeStoreReviewModule(prompt, noPrompts);
121
185
  });
122
- addModule(registry, "NgNativeCrypto", [crypto = s.crypto] { return makeCryptoModule(crypto); });
123
- addModule(registry, "NgNativeLocalization", [locales = s.locales, regionCode = s.regionCode] {
186
+ addSourced(s.crypto, "NgNativeCrypto", [crypto = s.crypto] { return makeCryptoModule(crypto); });
187
+ addSourced(s.locales && s.regionCode, "NgNativeLocalization", [locales = s.locales, regionCode = s.regionCode] {
124
188
  return makeLocalizationModule(locales, regionCode());
125
189
  });
126
- addModule(registry, "NgNativeUpdates", [updates = s.updates, fromDevServer = s.fromDevServer, reload = s.reload, appUpdater = s.appUpdater] {
190
+ addSourced(s.updates, "NgNativeUpdates", [updates = s.updates, fromDevServer = s.fromDevServer, reload = s.reload, appUpdater = s.appUpdater] {
127
191
  return makeUpdatesModule(updates, fromDevServer, reload, appUpdater);
128
192
  });
193
+ addModule(registry, "NgNativeHost", [absent = made.absent] { return makeHostModule(absent); });
129
194
  return made;
130
195
  }
131
196