@ng-native/desktop 0.26.1 → 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
@@ -0,0 +1,43 @@
1
+ // What a POSIX system's locale settings (LANGUAGE, LC_MESSAGES, LANG and the C library's locale
2
+ // data) say, in the shapes Localization answers (desktop-expo.h): the parsing a backend on such a
3
+ // system shares, toolkit-free. The backend reads the settings; these only turn them into tags and
4
+ // facts.
5
+ #pragma once
6
+
7
+ #include <optional>
8
+ #include <string>
9
+ #include <vector>
10
+
11
+ namespace ngn {
12
+
13
+ // A POSIX locale name as a BCP 47 tag: "en_GB.UTF-8" is "en-GB", "sr_RS@latin" is "sr-Latn-RS",
14
+ // "ca_ES@valencia" is "ca-ES-valencia". Nothing for "C", "POSIX" or an empty name, which name no
15
+ // language.
16
+ std::optional<std::string> languageTagOf(const std::string &posixLocale);
17
+
18
+ // The user's languages, most preferred first, as tags: LANGUAGE's colon-separated list, as gettext
19
+ // reads it, else the messages locale. As in glibc, LANGUAGE counts only when the messages locale
20
+ // names a language. Repeats are dropped.
21
+ std::vector<std::string> preferredLanguageTags(const std::string &languageList, const std::string &messagesLocale);
22
+
23
+ // The region of a locale name ("en_GB.UTF-8" is "GB"), or empty.
24
+ std::string regionOfLocale(const std::string &posixLocale);
25
+
26
+ // Whether a language ("ar", "he-IL") is written right to left.
27
+ bool rightToLeftLanguage(const std::string &tag);
28
+
29
+ // The first day of the week, 1 for Sunday, from glibc's LC_TIME `week-1stday` (a date, 19971130 a
30
+ // Sunday) and `first_weekday` (1 for that day).
31
+ int firstWeekdayOf(unsigned weekFirstDay, int firstWeekday);
32
+
33
+ // Whether a strftime time format (LC_TIME's `t_fmt`) shows the hour on a 24-hour clock.
34
+ bool uses24HourClockIn(const std::string &timeFormat);
35
+
36
+ // LC_MEASUREMENT's `measurement` (1 metric, 2 US) as NSLocale says the system: "Metric", "U.S.",
37
+ // or "U.K." in the United Kingdom, whose roads keep miles.
38
+ std::string measurementSystemOf(int measurement, const std::string &region);
39
+
40
+ // The unit a region gives temperatures in: "fahrenheit" where CLDR says so, else "celsius".
41
+ std::string temperatureUnitOf(const std::string &region);
42
+
43
+ } // namespace ngn
@@ -37,6 +37,8 @@ class Runtime;
37
37
 
38
38
  namespace ngn {
39
39
 
40
+ class AnimatedFrameLoop;
41
+
40
42
  // The OS's HTTP and WebSocket clients, which Networking, WebSocket and the dev server use.
41
43
  struct NetworkClients {
42
44
  std::shared_ptr<Http> http;
@@ -151,7 +153,10 @@ class Runtime {
151
153
  // False once the destructor has run, so a shutdown whose reload `done` destroyed the runtime
152
154
  // stops before it touches it again.
153
155
  std::shared_ptr<bool> alive_ = std::make_shared<bool>(true);
156
+ void closeAnimatedFrames();
154
157
  std::unique_ptr<facebook::react::ReactHost> host_;
158
+ // The frames host_'s animated module renders on, closed before host_ goes: see closeHost.
159
+ std::shared_ptr<AnimatedFrameLoop> animatedFrames_;
155
160
  struct Surface {
156
161
  std::string moduleName;
157
162
  SurfaceMetrics metrics;
@@ -30,6 +30,10 @@ struct ContainerInsets {
30
30
  // the sidebar pane under them, and 0 in the content pane beside a sidebar, which they do not
31
31
  // reach.
32
32
  double titlebarLeading{0};
33
+ // How far window controls reach in from the trailing edge, for
34
+ // --safe-area-inset-titlebar-trailing: 0 on macOS, whose controls are on the leading side, and
35
+ // on the GTK host but in a window whose content runs under its header bar.
36
+ double titlebarTrailing{0};
33
37
  bool operator==(const ContainerInsets &) const = default;
34
38
  };
35
39
 
@@ -40,6 +44,8 @@ EdgeInsets insetsWithin(const ContainerInsets &container, const Rect &frame);
40
44
  // its leading edge: the left one, or the right one right to left, where AppKit puts the controls
41
45
  // on the right. 0 when they lie outside it.
42
46
  double titlebarLeading(double minX, double maxX, double width, bool rightToLeft);
47
+ // The same from its trailing edge: the right one, or the left one right to left.
48
+ double titlebarTrailing(double minX, double maxX, double width, bool rightToLeft);
43
49
 
44
50
  class SafeAreas {
45
51
  public:
@@ -59,7 +65,12 @@ class SafeAreas {
59
65
  protected:
60
66
  // Where the insets leave the core: the provider's event, and the views' state through the
61
67
  // library's glue. Tests record them instead.
62
- virtual void emitInsetsChange(const ViewTree::Node &provider, EdgeInsets insets, Rect frame, double titlebarLeading);
68
+ virtual void emitInsetsChange(
69
+ const ViewTree::Node &provider,
70
+ EdgeInsets insets,
71
+ Rect frame,
72
+ double titlebarLeading,
73
+ double titlebarTrailing);
63
74
  virtual void setStateInsets(const ViewTree::Node &view, EdgeInsets insets);
64
75
  // The margin a view's mounted state adds for its insets, for a view that moves itself by them
65
76
  // (library-glue.h); nothing for one that pads its content instead.
@@ -72,8 +83,9 @@ class SafeAreas {
72
83
  bool known{false};
73
84
  EdgeInsets insets;
74
85
  Rect frame;
75
- // A provider's: the last titlebarLeading its event said.
86
+ // A provider's: the last titlebarLeading and titlebarTrailing its event said.
76
87
  double titlebarLeading{0};
88
+ double titlebarTrailing{0};
77
89
  };
78
90
  std::unordered_map<Tag, Tracked> tracked_;
79
91
  std::unordered_map<Tag, ContainerInsets> containers_;
@@ -21,6 +21,9 @@
21
21
  #include <react/renderer/components/view/ViewProps.h>
22
22
  #include <react/renderer/core/ConcreteComponentDescriptor.h>
23
23
 
24
+ #include <folly/dynamic.h>
25
+
26
+ #include <optional>
24
27
  #include <string>
25
28
  #include <unordered_map>
26
29
  #include <unordered_set>
@@ -68,6 +71,12 @@ struct SidebarWidths {
68
71
  // `props` is the sidebar's, or null before it has any.
69
72
  SidebarWidths sidebarWidths(const SplitPaneProps *props);
70
73
 
74
+ // The narrowest the content pane is beside the sidebar, in points: a window narrower than the
75
+ // sidebar's narrowest plus this is compact, and a split view that folds into a stack (FoldingSplit)
76
+ // folds there.
77
+ constexpr facebook::react::Float kSplitContentMinWidth = 360;
78
+ facebook::react::Float sidebarCompactWidth(const SidebarWidths &widths);
79
+
71
80
  // The size the toolkit gives a pane, or a custom row's width (height unused). Zero until it reports.
72
81
  struct SplitPaneState {
73
82
  facebook::react::Size size{};
@@ -257,12 +266,81 @@ class SidebarCollapse {
257
266
  // The toolkit's state changed: whether to tell the app, which it does when the app's prop
258
267
  // says otherwise.
259
268
  bool toolkitChanged(bool collapsed);
269
+ // What the toolkit shows now.
270
+ bool collapsed() const {
271
+ return toolkit_;
272
+ }
260
273
 
261
274
  private:
262
275
  bool prop_{false};
263
276
  bool toolkit_{false};
264
277
  };
265
278
 
279
+ // Where a toolkit with no autosave of its own (GTK's) keeps a sidebar's collapsed state between
280
+ // launches: in the app's preferences under its `autosaveName`, as window frames are (app-windows.h).
281
+ // Its width is not kept, since libadwaita's sidebar has no divider to drag. None for no name.
282
+ std::optional<std::string> sidebarCollapsedKey(const std::string &autosaveName);
283
+ // The state saved there, or none for nothing saved or a value that is not a boolean.
284
+ std::optional<bool> savedSidebarCollapsed(const std::optional<folly::dynamic> &value);
285
+
286
+ // A split view that folds into a stack whose root is the sidebar (libadwaita's
287
+ // AdwNavigationSplitView), and what it shows. The core decides, the toolkit only shows the result:
288
+ // - side by side, the sidebar beside the content, while the window is wide and the sidebar is not
289
+ // collapsed;
290
+ // - a stack with the content in front while the window is wide and the sidebar is collapsed, so a
291
+ // collapsed sidebar is out of sight as it is on macOS;
292
+ // - a stack at a compact width, whose front pane is the stack's own: the content until Show Sidebar
293
+ // brings the sidebar forward, and the content again once an item is chosen there. That is no
294
+ // collapse the app hears of, so the panes are side by side again as the window widens.
295
+ class FoldingSplit {
296
+ public:
297
+ struct Showing {
298
+ bool stacked{false};
299
+ // In a stack, the content in front, else the sidebar.
300
+ bool content{true};
301
+ bool operator==(const Showing &) const = default;
302
+ };
303
+ Showing showing() const;
304
+ // The window crossed the compact width (sidebarCompactWidth).
305
+ void setCompact(bool compact);
306
+ bool compact() const {
307
+ return compact_;
308
+ }
309
+ // The sidebar's collapsed state, as SidebarCollapse settles it.
310
+ void setCollapsed(bool collapsed);
311
+ // An item chosen in the sidebar: a stack shows the content.
312
+ void chose();
313
+ // Show Sidebar (F9, the header bar's sidebar button). At a compact width the stack swaps its
314
+ // front pane; otherwise the sidebar's collapsed state flips, and the new state is returned for
315
+ // the toolkit to report (SidebarCollapse::toolkitChanged).
316
+ std::optional<bool> toggle();
317
+
318
+ private:
319
+ bool compact_{false};
320
+ bool collapsed_{false};
321
+ bool sidebarInFront_{false};
322
+ };
323
+
324
+ // What a toolkit drawing a source list keeps between the lists the core sends: the sections the
325
+ // user folded with their disclosure, each forgotten as its section goes.
326
+ class SourceListFolds {
327
+ public:
328
+ // The list now: the folds of sections no longer in it go.
329
+ void setList(const SourceList &list);
330
+ void fold(Tag section, bool folded);
331
+ bool folded(Tag section) const;
332
+
333
+ private:
334
+ std::unordered_set<Tag> folded_;
335
+ };
336
+
337
+ // The row the app has selected in `list`, if any: the last one that says so.
338
+ std::optional<Tag> selectedRow(const SourceList &list);
339
+ // Whether `a` and `b` differ in which row is selected and nothing else: a toolkit then moves the
340
+ // selection rather than building the list again, which would take the rows away from under the
341
+ // pointer that just chose one.
342
+ bool onlySelectionDiffers(const SourceList &a, const SourceList &b);
343
+
266
344
  // Sizes reported as the toolkit lays out (every step of a divider drag), coalesced so layout hears
267
345
  // each view's latest at most once per display frame.
268
346
  class FrameSizes {
@@ -19,6 +19,13 @@ struct SurfaceMetrics {
19
19
  float fontScale{1};
20
20
  };
21
21
 
22
+ // The text size multiplier a Linux desktop asks for, from GTK's `gtk-xft-dpi`: the text scaling
23
+ // factor times 96 dots per inch, in 1024ths of one, so 98304 is 1. Unset (-1, or 0) is 1. macOS's
24
+ // is always 1.
25
+ inline float xftFontScale(int xftDpi) {
26
+ return xftDpi > 0 ? static_cast<float>(xftDpi) / (96.0f * 1024.0f) : 1.0f;
27
+ }
28
+
22
29
  // The surface's root constraints: its size, and the direction its layout starts from, which React
23
30
  // Native's iOS surfaces take from I18nManager.
24
31
  inline facebook::react::LayoutConstraints surfaceConstraints(const SurfaceMetrics &metrics, bool rightToLeft) {
@@ -20,6 +20,8 @@ struct DeviceFacts {
20
20
  std::string osVersion;
21
21
  // "macOS"
22
22
  std::string systemName;
23
+ // PlatformConstants' interfaceIdiom: "mac" on macOS, "desktop" on Linux.
24
+ std::string interfaceIdiom{"mac"};
23
25
  // A BCP 47 identifier such as "en-GB" (React Native's localeIdentifier uses an underscore).
24
26
  std::string locale;
25
27
  // The system's layout direction for the app's preferred language.
@@ -45,6 +47,18 @@ struct AlertRequest {
45
47
  std::string defaultValue;
46
48
  };
47
49
 
50
+ // An alert's buttons as GNOME lays them out: in reading order, Cancel first and the affirmative (the
51
+ // request's first button) last, the rest between them as AppKit has them. Return presses the
52
+ // affirmative unless it is destructive or the cancel button, and Escape presses Cancel. Indices are
53
+ // the request's; -1 for no button.
54
+ struct AlertLayout {
55
+ std::vector<int> order;
56
+ int returnIndex{-1};
57
+ int escapeIndex{-1};
58
+ bool operator==(const AlertLayout &) const = default;
59
+ };
60
+ AlertLayout gnomeAlertLayout(const AlertRequest &request);
61
+
48
62
  // How an announcement takes its turn with what a screen reader is saying: low and medium wait for
49
63
  // it, high interrupts.
50
64
  enum class AnnouncementPriority { Low, Medium, High };
@@ -6,6 +6,8 @@
6
6
  // React Native's BaseTextInputShadowNode over it: it measures and lays out as on iOS.
7
7
  #pragma once
8
8
 
9
+ #include "ngn/desktop-props.h"
10
+
9
11
  #include <react/renderer/components/iostextinput/primitives.h>
10
12
  #include <react/renderer/components/textinput/BaseTextInputProps.h>
11
13
  #include <react/renderer/components/textinput/BaseTextInputShadowNode.h>
@@ -16,6 +18,8 @@
16
18
 
17
19
  #include <cstddef>
18
20
  #include <optional>
21
+ #include <string>
22
+ #include <vector>
19
23
 
20
24
  namespace ngn {
21
25
 
@@ -31,6 +35,10 @@ class DesktopTextInputProps final : public facebook::react::BaseTextInputProps {
31
35
  std::optional<facebook::react::Selection> selection{};
32
36
  // Curly quotes and em dashes as the user types. Unset follows `autoCorrect`.
33
37
  std::optional<bool> smartQuotes{};
38
+ // `accessibilityDescribedBy` (`aria-describedby`), as a view's desktop props have it.
39
+ std::vector<std::string> accessibilityDescribedBy;
40
+ // `aria-required`, `aria-invalid` and the rest, as a view's desktop props have them.
41
+ AriaFields aria;
34
42
  };
35
43
 
36
44
  extern const char DesktopTextInputComponentName[];
@@ -131,4 +139,9 @@ std::u16string fitReplacement(
131
139
  // composing.
132
140
  bool controlledTextIsCurrent(int mostRecentEventCount, int fieldEventCount, bool composing);
133
141
 
142
+ // The `selection` prop as a field applies it, start before end in UTF-16 units, when it is new in
143
+ // `now` against `before` (null for a field just made): React Native iOS applies it only then, so
144
+ // the user moving the selection away is not undone by an unchanged prop.
145
+ std::optional<std::pair<int, int>> newSelection(const DesktopTextInputProps *before, const DesktopTextInputProps &now);
146
+
134
147
  } // namespace ngn
@@ -0,0 +1,38 @@
1
+ // What a screen reader reads of a run of text when it moves by character, word, sentence, line or
2
+ // paragraph: the span of that unit around a character, as AT-SPI's Text interface answers
3
+ // GetStringAtOffset. The toolkit's text layout finds where words, sentences and lines start (Pango's
4
+ // log attributes on Linux); the spans are worked out here, the same for any toolkit. Offsets count
5
+ // characters (Unicode code points), as AT-SPI's do.
6
+ #pragma once
7
+
8
+ #include <string>
9
+ #include <vector>
10
+
11
+ namespace ngn {
12
+
13
+ enum class TextUnit { Character, Word, Sentence, Line, Paragraph };
14
+
15
+ struct TextSpan {
16
+ int start{0};
17
+ int end{0};
18
+ bool operator==(const TextSpan &other) const = default;
19
+ };
20
+
21
+ // Where each unit but characters and paragraphs starts, in character offsets, ascending. A list
22
+ // that does not start at 0 is read as if it did.
23
+ struct TextBreaks {
24
+ std::vector<int> words;
25
+ std::vector<int> sentences;
26
+ std::vector<int> lines;
27
+ };
28
+
29
+ // The span of `unit` holding the character at `offset` in `text` (UTF-8), from the start of that
30
+ // unit to the start of the next one, or the end of the text: a word takes the spaces after it, and
31
+ // a paragraph its line break. An offset past either end is taken at that end. A character at the
32
+ // end is the empty span there.
33
+ TextSpan textUnitAt(const std::string &text, const TextBreaks &breaks, int offset, TextUnit unit);
34
+
35
+ // The characters from `start` to `end` of `text` (UTF-8), clamped to it.
36
+ std::string textBetween(const std::string &text, int start, int end);
37
+
38
+ } // namespace ngn
@@ -2,7 +2,8 @@
2
2
  // self-hosted server: EAS Update refuses `macos`, and the iOS client is Swift over RCT and
3
3
  // ExpoModulesCore, neither of which the desktop host has. Toolkit-free: requests go through the
4
4
  // Http interface (network.h), the hash and the signature through UpdateCrypto, which a backend
5
- // implements over the OS's own (CommonCrypto and Security on macOS), and files through
5
+ // implements over the OS's own (CommonCrypto and Security on macOS, the system OpenSSL 3 on Linux:
6
+ // openssl-update-crypto.h), and files through
6
7
  // std::filesystem under the app's data directory.
7
8
  //
8
9
  // - check: GET the server's URL with the protocol's headers (platform, runtime version, the
@@ -23,7 +24,9 @@
23
24
  // of a downloaded update is marked before it starts and cleared once it has run for a while
24
25
  // (markLaunchSucceeded); a marker still set at the next startup means that launch crashed, so the
25
26
  // update is marked failed and the one before it, or the embedded bundle, runs instead. Expo's own
26
- // recovery covers JavaScript errors only; a native crash needs this marker.
27
+ // recovery covers JavaScript errors only; a native crash needs this marker. An update for
28
+ // another runtime version, or fetched over an embedded bundle that a package or app update has
29
+ // since replaced, is stale: it never runs, and its folder is deleted.
27
30
  //
28
31
  // `assetRequestHeaders` from a multipart response's extensions are not sent with the asset requests.
29
32
  #pragma once
@@ -133,6 +136,9 @@ struct LaunchState {
133
136
  std::string runtimeVersion;
134
137
  // The launch asset, relative to the directory.
135
138
  std::string file;
139
+ // The embedded bundle it was fetched over (its size and modification time): a package or app
140
+ // update that brings another one makes it stale, and the new embedded bundle runs.
141
+ std::string embedded;
136
142
  bool operator==(const Update &) const = default;
137
143
  };
138
144
  std::optional<Update> current;
@@ -150,6 +156,8 @@ class UpdatesClient {
150
156
  bool enabled() const {
151
157
  return !config_.url.empty();
152
158
  }
159
+ // Why updates are off, for a check; empty when they are on.
160
+ std::string offReason() const;
153
161
  const UpdatesConfig &config() const {
154
162
  return config_;
155
163
  }
@@ -202,6 +210,10 @@ class UpdatesClient {
202
210
  void save(const LaunchState &state) const;
203
211
  std::string pathOf(const LaunchState::Update &update) const;
204
212
  bool usable(const LaunchState::Update &update, const LaunchState &state) const;
213
+ // For another runtime version, or fetched over another embedded bundle: never run, nor kept.
214
+ bool stale(const LaunchState::Update &update) const;
215
+ // Deletes the folders of the updates neither `state` nor this launch names.
216
+ void prune(const LaunchState &state) const;
205
217
  void markLocked();
206
218
  // Why a manifest's (or the `what` named) signature header does not verify its bytes, when the
207
219
  // app requires signing.
@@ -79,6 +79,46 @@ std::vector<SvgRect> backgroundTiles(
79
79
  const facebook::react::BackgroundPosition &position,
80
80
  const facebook::react::BackgroundRepeat &repeat);
81
81
 
82
+ // A view's box as CSS describes it, for a toolkit that paints each part itself (GSK on Linux):
83
+ // what viewBox below shapes for Core Animation, before any of it is shaped.
84
+ struct EdgeColors {
85
+ std::optional<uint32_t> top, right, bottom, left;
86
+ bool operator==(const EdgeColors &) const = default;
87
+ };
88
+
89
+ // One background image: its gradient filling a tile whose top left is at (0, 0), and where its
90
+ // tiles go in the view's coordinates (backgroundTiles), all of one size.
91
+ struct BackgroundLayer {
92
+ SvgGradient gradient;
93
+ std::vector<SvgRect> tiles;
94
+ bool operator==(const BackgroundLayer &) const = default;
95
+ };
96
+
97
+ struct BoxDescription {
98
+ // The border box, from (0, 0).
99
+ SvgRect bounds;
100
+ std::optional<uint32_t> background;
101
+ // Over the background colour, cut to the border box's shape: the last listed first, at the
102
+ // bottom. An image with nothing to draw is left out.
103
+ std::vector<BackgroundLayer> backgroundImages;
104
+ CornerRadii radii;
105
+ EdgeWidths borderWidths;
106
+ EdgeColors borderColors;
107
+ // Every side's style when they are the same; solid when they differ.
108
+ facebook::react::BorderStyle borderStyle{facebook::react::BorderStyle::Solid};
109
+ // `overflow` other than visible: the children are cut to the border box's shape.
110
+ bool clips{false};
111
+ // In CSS's order: the first is on top.
112
+ std::vector<facebook::react::BoxShadow> shadows;
113
+ };
114
+
115
+ BoxDescription describeBox(const facebook::react::ViewProps &props, const facebook::react::LayoutMetrics &layout);
116
+
117
+ // Draws a described box's border as drawViewBox does: a solid one as its ring, or each side in its
118
+ // own colour, and a dashed or dotted one as a dashed stroke along the middle of its widest side.
119
+ // For a toolkit that draws only some borders itself (GSK draws no dashes below GTK 4.14).
120
+ void drawBorder(const BoxDescription &box, SvgCanvas &canvas);
121
+
82
122
  // A box shadow as a layer the size of the view, which Core Animation blurs.
83
123
  struct BoxShadowLayer {
84
124
  bool inset{false};
@@ -23,4 +23,19 @@ std::optional<facebook::react::Point> layerPointAt(
23
23
  const facebook::react::Transform &transform,
24
24
  facebook::react::Point point);
25
25
 
26
+ // The plane's picture under `transform` as a 2D map in steps a 2D toolkit takes: the point is
27
+ // scaled, then skewed along x (degrees), then rotated (degrees, clockwise with y down), then moved.
28
+ // A transform with no perspective draws the plane (z = 0) with such a map whatever it does in z,
29
+ // which is what a renderer that only draws 2D (GSK's cairo one) needs. Nothing when the transform
30
+ // has perspective, or flattens the plane to a line or a point.
31
+ struct PlaneSteps {
32
+ facebook::react::Float scaleX{1};
33
+ facebook::react::Float scaleY{1};
34
+ facebook::react::Float skewX{0};
35
+ facebook::react::Float rotate{0};
36
+ facebook::react::Float translateX{0};
37
+ facebook::react::Float translateY{0};
38
+ };
39
+ std::optional<PlaneSteps> planeSteps(const facebook::react::Transform &transform);
40
+
26
41
  } // namespace ngn
@@ -15,8 +15,10 @@
15
15
  #include "ngn/native-module.h"
16
16
  #include "ngn/system.h"
17
17
 
18
+ #include <cstdint>
18
19
  #include <functional>
19
20
  #include <memory>
21
+ #include <mutex>
20
22
  #include <optional>
21
23
  #include <string>
22
24
 
@@ -40,6 +42,50 @@ class AuthSession {
40
42
  // Whether `url` is http or https: what expo-web-browser opens.
41
43
  bool webUrl(const std::string &url);
42
44
 
45
+ // An AuthSession for a host with no sign-in sheet of its own (GTK's): the page opens in the user's
46
+ // browser, and the session ends on the first link back to the app on its callback scheme, which
47
+ // the OS hands the running app as it would any link (a second launch, or D-Bus activation). That
48
+ // link ends the session and nothing else hears it, as ASWebAuthenticationSession keeps its own.
49
+ // While the session runs the host shows a prompt over the app saying the sign-in goes on in the
50
+ // browser, whose Cancel ends it as cancelled: without one, a browser closed before the redirect
51
+ // would leave the session waiting for ever. `ephemeral` is not the host's to give, since the
52
+ // browser keeps its own cookies.
53
+ class LinkAuthSession final : public AuthSession, public std::enable_shared_from_this<LinkAuthSession> {
54
+ public:
55
+ struct Hooks {
56
+ // Opens the page in the user's browser; `opened` hears whether it did. Any thread.
57
+ std::function<void(const std::string &url, std::function<void(bool opened)> opened)> openUrl;
58
+ // Shows the prompt, whose Cancel calls `cancelled`, and answers how to take it away. Any
59
+ // thread; empty for no prompt.
60
+ std::function<std::function<void()>(std::function<void()> cancelled)> prompt;
61
+ };
62
+ explicit LinkAuthSession(Hooks hooks);
63
+ void start(const Request &request, std::function<void(std::optional<std::string> url, std::string error)> done) override;
64
+ void cancel() override;
65
+ // A link the app was opened with: true when it is on the scheme of the session in progress,
66
+ // which it ends, and which the app's Linking then never hears. Any thread.
67
+ bool receive(const std::string &url);
68
+
69
+ private:
70
+ struct Ending {
71
+ std::function<void(std::optional<std::string>, std::string)> done;
72
+ std::function<void()> hide;
73
+ };
74
+ // Takes the session's completion and prompt; call with mutex_ held.
75
+ Ending take();
76
+ static void end(Ending ending, std::optional<std::string> url, std::string error);
77
+ // Ends the session in progress, or only when it is still `attempt` (a callback of an earlier
78
+ // session ends nothing).
79
+ void finish(std::optional<uint64_t> attempt, std::optional<std::string> url, std::string error);
80
+
81
+ Hooks hooks_;
82
+ std::mutex mutex_;
83
+ std::string scheme_;
84
+ uint64_t attempt_{0};
85
+ std::function<void(std::optional<std::string>, std::string)> done_;
86
+ std::function<void()> hidePrompt_;
87
+ };
88
+
43
89
  std::shared_ptr<NativeModule> makeWebBrowserModule(std::shared_ptr<System> system, std::shared_ptr<AuthSession> sessions, bool noPrompts);
44
90
 
45
91
  } // namespace ngn
@@ -0,0 +1,88 @@
1
+ #include "ngn/accent-colors.h"
2
+
3
+ #include <algorithm>
4
+ #include <cmath>
5
+ #include <cstdio>
6
+
7
+ namespace ngn {
8
+
9
+ namespace {
10
+
11
+ struct Oklab {
12
+ double L, a, b;
13
+ };
14
+
15
+ double toLinear(double v) {
16
+ return v >= 0.04045 ? std::pow((v + 0.055) / 1.055, 2.4) : v / 12.92;
17
+ }
18
+
19
+ double toGamma(double v) {
20
+ return v > 0.0031308 ? 1.055 * std::pow(v, 1 / 2.4) - 0.055 : 12.92 * v;
21
+ }
22
+
23
+ Oklab oklab(Rgb c) {
24
+ double r = toLinear(c.red), g = toLinear(c.green), b = toLinear(c.blue);
25
+ double l = std::cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
26
+ double m = std::cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
27
+ double s = std::cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
28
+ return {0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s, 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
29
+ 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s};
30
+ }
31
+
32
+ Rgb rgb(Oklab c) {
33
+ double l = std::pow(c.L + 0.3963377774 * c.a + 0.2158037573 * c.b, 3);
34
+ double m = std::pow(c.L - 0.1055613458 * c.a - 0.0638541728 * c.b, 3);
35
+ double s = std::pow(c.L - 0.0894841775 * c.a - 1.2914855480 * c.b, 3);
36
+ auto channel = [](double v) { return std::clamp(toGamma(v), 0.0, 1.0); };
37
+ return {channel(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
38
+ channel(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
39
+ channel(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s)};
40
+ }
41
+
42
+ Rgb hex(unsigned value) {
43
+ return {((value >> 16) & 0xff) / 255.0, ((value >> 8) & 0xff) / 255.0, (value & 0xff) / 255.0};
44
+ }
45
+
46
+ // libadwaita's accent colour nearest `c`: slate for a grey, else by OKLCh hue.
47
+ Rgb nearestAccent(Rgb c) {
48
+ auto lab = oklab(c);
49
+ double chroma = std::hypot(lab.a, lab.b);
50
+ double hue = std::fmod(std::atan2(lab.b, lab.a) * 180 / M_PI + 360, 360);
51
+ if (chroma < 0.04) return hex(0x6f8396); // slate
52
+ if (hue > 345) return hex(0xd56199); // pink
53
+ if (hue > 280) return hex(0x9141ac); // purple
54
+ if (hue > 230) return hex(0x3584e4); // blue
55
+ if (hue > 175) return hex(0x2190a4); // teal
56
+ if (hue > 130) return hex(0x3a944a); // green
57
+ if (hue > 75.5) return hex(0xc88800); // yellow
58
+ if (hue > 35) return hex(0xed5b00); // orange
59
+ if (hue > 10) return hex(0xe62d42); // red
60
+ return hex(0xd56199); // pink
61
+ }
62
+
63
+ } // namespace
64
+
65
+ std::optional<AccentColors> accentColors(Rgb accent, bool dark) {
66
+ auto inRange = [](double v) { return v >= 0 && v <= 1; };
67
+ if (!inRange(accent.red) || !inRange(accent.green) || !inRange(accent.blue)) {
68
+ return std::nullopt;
69
+ }
70
+ Rgb background = nearestAccent(accent);
71
+ auto lab = oklab(background);
72
+ lab.L = dark ? std::max(lab.L, 0.85) : std::min(lab.L, 0.5);
73
+ return AccentColors{.background = background, .foreground = {1, 1, 1}, .standalone = rgb(lab)};
74
+ }
75
+
76
+ std::string cssColor(Rgb color) {
77
+ char out[32];
78
+ auto byte = [](double v) { return static_cast<int>(std::lround(std::clamp(v, 0.0, 1.0) * 255)); };
79
+ std::snprintf(out, sizeof out, "rgb(%d,%d,%d)", byte(color.red), byte(color.green), byte(color.blue));
80
+ return out;
81
+ }
82
+
83
+ std::string accentCss(const AccentColors &colors) {
84
+ return "@define-color accent_bg_color " + cssColor(colors.background) + ";\n@define-color accent_fg_color " +
85
+ cssColor(colors.foreground) + ";\n@define-color accent_color " + cssColor(colors.standalone) + ";\n";
86
+ }
87
+
88
+ } // namespace ngn