@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
@@ -0,0 +1,310 @@
1
+ #!/usr/bin/env python3
2
+ """Launches the GTK host on a bundle and reads its accessibility tree over AT-SPI, as a screen
3
+ reader reads it, with no screen reader: the host's window, and each role named in it with a name.
4
+ Fails when the host exits, draws no first frame, or the tree lacks a role. Prints the tree.
5
+ With --tab, it then presses Tab, as a keyboard user does, and fails unless a node in the host's
6
+ window says it is focused: the core's Tab order reached a real GTK widget that AT-SPI reports.
7
+ With --relation, a node must have that relation (as AT-SPI names it: "described-by",
8
+ "labelled-by") to a node with a name: a view's `aria-describedby` or `aria-labelledby` reached GTK.
9
+ With --heading, a heading must have that level (`aria-level`). With --announce, the node with that
10
+ name is pressed through its AT-SPI action, as a screen reader presses it, and the host
11
+ must send an announcement (`Accessibility.announce()` or a live region). With --action NAME=ACTION,
12
+ the node NAME's declared action (`accessibilityActions`) is invoked the same way, and the app's answer
13
+ must be an announcement too. ACTION is the name GTK exposes, the suffix of `custom.ACTION`: the
14
+ declared name with each character GTK's action names refuse (a space) made a `-` ("mark read" is
15
+ "mark-read"), and a number after a name already taken ("mark-read-2"). GTK announces from 4.14 and
16
+ says a heading's level over AT-SPI from 4.16; below those each is skipped, saying so. --url opens the
17
+ app there.
18
+
19
+ dbus-run-session -- atspi-check.py <ngn-linux> <bundle.js> [--url <link>] [--role "push button"]...
20
+ [--relation described-by]... [--heading 2] [--announce <name>] [--action <name>=<action>] [--tab]
21
+
22
+ GTK 4 answers AT-SPI's Component.GrabFocus with NotSupported, in every release, so a screen reader
23
+ cannot move the keyboard focus in a GTK 4 app and there is nothing here to check it with.
24
+
25
+ Needs a display (Xvfb) and pyatspi. A test launch, as launch-probe.sh starts one: the host keeps its
26
+ state in a new directory and shows no system prompt.
27
+ """
28
+ import argparse
29
+ import ctypes
30
+ import os
31
+ import shutil
32
+ import subprocess
33
+ import sys
34
+ import tempfile
35
+ import time
36
+
37
+ import pyatspi
38
+
39
+
40
+ RELATIONS = {pyatspi.RELATION_LABELLED_BY: "labelled-by", pyatspi.RELATION_DESCRIBED_BY: "described-by"}
41
+
42
+
43
+ def relations_of(node):
44
+ """The node's labelled-by and described-by relations, as (kind, target's name)."""
45
+ found = []
46
+ for relation in node.getRelationSet():
47
+ kind = RELATIONS.get(relation.getRelationType())
48
+ for i in range(relation.getNTargets() if kind else 0):
49
+ found.append((kind, relation.getTarget(i).name or ""))
50
+ return found
51
+
52
+
53
+ def walk(node, depth, out):
54
+ try:
55
+ focused = node.getState().contains(pyatspi.STATE_FOCUSED)
56
+ out.append((depth, node.getRoleName() + (" (focused)" if focused else ""), node.name or "",
57
+ relations_of(node)))
58
+ for i in range(node.childCount):
59
+ walk(node.getChildAtIndex(i), depth + 1, out)
60
+ except Exception as error: # A node can go as it is read.
61
+ out.append((depth, "error", str(error), []))
62
+
63
+
64
+ def host_tree(pid):
65
+ """The host's windows and everything under them, found by its process (GTK 4.12 gives a window
66
+ no name over AT-SPI), or nothing until AT-SPI has them."""
67
+ for app in pyatspi.Registry.getDesktop(0):
68
+ try:
69
+ if app is None or app.get_process_id() != pid or app.childCount == 0:
70
+ continue
71
+ except Exception: # An application can go as it is read.
72
+ continue
73
+ out = []
74
+ for i in range(app.childCount):
75
+ walk(app.getChildAtIndex(i), 0, out)
76
+ return out
77
+ return None
78
+
79
+
80
+ def gtk_minor():
81
+ """The minor version of the GTK 4 the host loads, as this process finds the same library."""
82
+ try:
83
+ return ctypes.CDLL("libgtk-4.so.1").gtk_get_minor_version()
84
+ except OSError:
85
+ return 0
86
+
87
+
88
+ def host_nodes(pid):
89
+ """Every node in the host's windows, as live AT-SPI objects, in tree order."""
90
+ found = []
91
+
92
+ def visit(node):
93
+ found.append(node)
94
+ for i in range(node.childCount):
95
+ visit(node.getChildAtIndex(i))
96
+
97
+ for app in pyatspi.Registry.getDesktop(0):
98
+ try:
99
+ if app is not None and app.get_process_id() == pid:
100
+ for i in range(app.childCount):
101
+ visit(app.getChildAtIndex(i))
102
+ except Exception: # A node can go as it is read.
103
+ continue
104
+ return found
105
+
106
+
107
+ def first(pid, test):
108
+ for node in host_nodes(pid):
109
+ try:
110
+ if test(node):
111
+ return node
112
+ except Exception:
113
+ continue
114
+ return None
115
+
116
+
117
+ def pump(seconds):
118
+ """Runs GLib's main context for a while, which delivers AT-SPI's events to their listeners."""
119
+ from gi.repository import GLib
120
+
121
+ context = GLib.MainContext.default()
122
+ end = time.time() + seconds
123
+ while time.time() < end:
124
+ while context.pending():
125
+ context.iteration(False)
126
+ time.sleep(0.05)
127
+
128
+
129
+ def check_heading(host, level, deadline):
130
+ """A heading whose AT-SPI attributes say `level`."""
131
+ want = "level:%d" % level
132
+ while time.time() < deadline:
133
+ heading = first(host.pid, lambda n: n.getRoleName() == "heading" and want in n.getAttributes())
134
+ if heading:
135
+ print("atspi-check: heading %r at %s" % (heading.name, want))
136
+ return None
137
+ time.sleep(0.5)
138
+ return "no heading at %s" % want
139
+
140
+
141
+ def pick_action(names, action=None):
142
+ """The index in `names`, a node's AT-SPI action names, of the action to invoke, or None. Given
143
+ `action`, only that exact name. Without one, the node's press if it has it, else its first
144
+ action: a native GTK control keeps GTK's own actions and has no press."""
145
+ if action is not None:
146
+ return names.index(action) if action in names else None
147
+ if "accessibility.press" in names:
148
+ return names.index("accessibility.press")
149
+ return 0 if names else None
150
+
151
+
152
+ def action_index(node, action=None):
153
+ """The index of the node's AT-SPI action to invoke (see pick_action), or None."""
154
+ actions = node.queryAction()
155
+ return pick_action([actions.getName(i) for i in range(actions.nActions)], action)
156
+
157
+
158
+ def parse_action_argument(value):
159
+ """The node's name and the action's name from `--action NAME=ACTION`: the split is at the last
160
+ `=`, so a node's name may hold one. Raises ValueError without both."""
161
+ node, separator, action = value.rpartition("=")
162
+ if not separator or not node or not action:
163
+ raise ValueError("--action takes NAME=ACTION, got %r" % value)
164
+ return node, action
165
+
166
+
167
+ def check_announce(host, name, deadline, action=None):
168
+ """Invokes the AT-SPI action of the node named `name`, then waits for the host to announce
169
+ something. `action` is an exact name, such as `custom.repeat`; without one, the node's press, or
170
+ its first action when it has none."""
171
+ said = []
172
+ listener = lambda event: said.append(str(event.any_data))
173
+ pyatspi.Registry.registerEventListener(listener, "object:announcement")
174
+ try:
175
+ node = first(host.pid, lambda n: n.name == name and action_index(n, action) is not None)
176
+ if node is None:
177
+ return "no node named %r with %s" % (name, "the action %r" % action if action else "an action")
178
+ index = action_index(node, action)
179
+ invoked = node.queryAction().getName(index)
180
+ node.queryAction().doAction(index)
181
+ while time.time() < deadline and not said:
182
+ pump(0.5)
183
+ if not said:
184
+ return "%s on %r announced nothing" % (invoked, name)
185
+ print("atspi-check: %s on %r announced %r" % (invoked, name, said[0]))
186
+ return None
187
+ finally:
188
+ pyatspi.Registry.deregisterEventListener(listener, "object:announcement")
189
+
190
+
191
+ def print_tree(tree, stream):
192
+ for depth, role, name, relations in tree:
193
+ said = "".join(" [%s %r]" % relation for relation in relations)
194
+ print("%s%s %r%s" % (" " * depth, role, name, said), file=stream)
195
+
196
+
197
+ def check_tab(host, deadline, fail):
198
+ """Points into the window, so GTK takes it as active with no window manager, then presses Tab
199
+ until a node is focused."""
200
+ pyatspi.Registry.generateMouseEvent(200, 200, pyatspi.MOUSE_ABS)
201
+ tree = None
202
+ while time.time() < deadline:
203
+ pyatspi.Registry.generateKeyboardEvent(0xFF09, None, pyatspi.KEY_SYM) # Tab
204
+ time.sleep(1)
205
+ tree = host_tree(host.pid) or []
206
+ focused = [(r, n) for _, r, n, _ in tree if r.endswith(" (focused)")]
207
+ if focused:
208
+ print_tree(tree, sys.stdout)
209
+ print("atspi-check: Tab focused %s %r" % (focused[0][0].split(" (")[0], focused[0][1]))
210
+ return 0
211
+ return fail("no node in the host's window was focused after Tab", tree)
212
+
213
+
214
+ def main():
215
+ parser = argparse.ArgumentParser()
216
+ parser.add_argument("host")
217
+ parser.add_argument("bundle")
218
+ parser.add_argument("--role", action="append", default=[], help="an AT-SPI role name the tree must hold, named")
219
+ parser.add_argument("--seconds", type=int, default=60)
220
+ parser.add_argument("--tab", action="store_true", help="press Tab and require a focused node")
221
+ parser.add_argument("--relation", action="append", default=[],
222
+ help="an AT-SPI relation (described-by, labelled-by) some node must have to a named node")
223
+ parser.add_argument("--heading", type=int, help="a heading level the tree must hold (GTK 4.16 and later)")
224
+ parser.add_argument("--announce", metavar="NAME", help="press the node NAME and require an announcement (GTK 4.14 and later)")
225
+ parser.add_argument("--action", metavar="NAME=ACTION",
226
+ help="invoke the node NAME's declared action and require an announcement, ACTION being the name "
227
+ "GTK exposes (custom.ACTION): the declared name with spaces made '-', and a number after a "
228
+ "collision (GTK 4.14 and later)")
229
+ parser.add_argument("--url", help="the link the app opens at")
230
+ args = parser.parse_args()
231
+ action_target = None
232
+ if args.action:
233
+ try:
234
+ action_target = parse_action_argument(args.action)
235
+ except ValueError as error:
236
+ parser.error(str(error))
237
+ # GTK announces from 4.14 and gives a heading's level over AT-SPI from 4.16.
238
+ minor = gtk_minor()
239
+ for flag, since in (("heading", 16), ("announce", 14), ("action", 14)):
240
+ if getattr(args, flag) is not None and minor < since:
241
+ print("atspi-check: --%s skipped: GTK 4.%d is below 4.%d" % (flag, minor, since))
242
+ setattr(args, flag, None)
243
+
244
+ # The registry the host's GTK and pyatspi both find through the session bus.
245
+ launcher = subprocess.Popen(["/usr/libexec/at-spi-bus-launcher", "--launch-immediately"],
246
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
247
+ work = tempfile.mkdtemp()
248
+ os.mkdir(os.path.join(work, "state"))
249
+ env = dict(os.environ, NGN_TESTS="1", NGN_STATE_DIR=os.path.join(work, "state"), NGN_RUN_ID="atspi-%d" % os.getpid(),
250
+ NGN_TESTS_FAKE_SYSTEM_UI="1")
251
+ env.pop("GTK_A11Y", None)
252
+ log_path = os.path.join(work, "host.log")
253
+ log = open(log_path, "w")
254
+ command = [args.host, args.bundle, "--title", "AT-SPI check"] + (["--url", args.url] if args.url else [])
255
+ host = subprocess.Popen(command, stdout=log, stderr=subprocess.STDOUT, env=env)
256
+
257
+ def fail(message, tree=None):
258
+ print("atspi-check: " + message, file=sys.stderr)
259
+ print_tree(tree or [], sys.stderr)
260
+ print("--- host log ---", file=sys.stderr)
261
+ with open(log_path) as text:
262
+ sys.stderr.write(text.read())
263
+ return 1
264
+
265
+ try:
266
+ deadline = time.time() + args.seconds
267
+ tree = None
268
+ missing = args.role
269
+ while time.time() < deadline:
270
+ if host.poll() is not None:
271
+ return fail("the host exited (%d)" % host.returncode)
272
+ with open(log_path) as text:
273
+ drawn = "[ngn] first frame" in text.read()
274
+ tree = host_tree(host.pid) if drawn else None
275
+ missing = [role for role in args.role if not any(r.split(" (")[0] == role and n for _, r, n, _ in tree or [])]
276
+ missing += ["%s relation" % kind for kind in args.relation
277
+ if not any(k == kind and target for *_, relations in tree or [] for k, target in relations)]
278
+ if tree and not missing:
279
+ print_tree(tree, sys.stdout)
280
+ print("atspi-check: %d nodes, with %s" % (len(tree), ", ".join(args.role + args.relation) or "a window"))
281
+ checks = []
282
+ if args.heading is not None:
283
+ checks.append(lambda: check_heading(host, args.heading, deadline))
284
+ if args.announce:
285
+ checks.append(lambda: check_announce(host, args.announce, deadline))
286
+ if args.action:
287
+ node, action = action_target
288
+ checks.append(lambda node=node, action=action: check_announce(host, node, deadline, "custom." + action))
289
+ for check in checks:
290
+ failed = check()
291
+ if failed:
292
+ return fail(failed, host_tree(host.pid))
293
+ if args.tab:
294
+ return check_tab(host, deadline, fail)
295
+ return 0
296
+ time.sleep(0.5)
297
+ if not tree:
298
+ return fail("the host's window was not on AT-SPI within %ds" % args.seconds)
299
+ return fail("no named %s in the host's tree within %ds" % (", ".join(missing), args.seconds), tree)
300
+ finally:
301
+ host.terminate()
302
+ host.wait()
303
+ launcher.terminate()
304
+ launcher.wait()
305
+ log.close()
306
+ shutil.rmtree(work, ignore_errors=True)
307
+
308
+
309
+ if __name__ == "__main__":
310
+ sys.exit(main())
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env python3
2
+ """The pure parts of atspi-check.py: which action it invokes and how --action is read. They need no
3
+ AT-SPI, so pyatspi is stood in for. Run: python3 native/scripts/atspi-check.test.py"""
4
+ import importlib.util
5
+ import os
6
+ import sys
7
+ import types
8
+ import unittest
9
+
10
+ sys.modules.setdefault("pyatspi", types.SimpleNamespace(RELATION_LABELLED_BY=0, RELATION_DESCRIBED_BY=1))
11
+ spec = importlib.util.spec_from_file_location("atspi_check", os.path.join(os.path.dirname(os.path.abspath(__file__)), "atspi-check.py"))
12
+ check = importlib.util.module_from_spec(spec)
13
+ spec.loader.exec_module(check)
14
+
15
+
16
+ class PickAction(unittest.TestCase):
17
+ def test_default_prefers_the_press(self):
18
+ self.assertEqual(check.pick_action(["custom.a", "accessibility.press"]), 1)
19
+
20
+ def test_default_falls_back_to_a_native_controls_first_action(self):
21
+ self.assertEqual(check.pick_action(["activate"]), 0)
22
+
23
+ def test_default_finds_nothing_without_actions(self):
24
+ self.assertIsNone(check.pick_action([]))
25
+
26
+ def test_an_explicit_action_matches_exactly(self):
27
+ names = ["accessibility.press", "custom.mark-read", "custom.mark-read-2"]
28
+ self.assertEqual(check.pick_action(names, "custom.mark-read-2"), 2)
29
+ self.assertEqual(check.pick_action(names, "custom.mark-read"), 1)
30
+ self.assertIsNone(check.pick_action(names, "custom.mark read"))
31
+
32
+ def test_an_explicit_action_never_falls_back(self):
33
+ self.assertIsNone(check.pick_action(["activate"], "accessibility.press"))
34
+
35
+
36
+ class ParseActionArgument(unittest.TestCase):
37
+ def test_splits_at_the_last_equals(self):
38
+ self.assertEqual(check.parse_action_argument("Row=mark-read"), ("Row", "mark-read"))
39
+ self.assertEqual(check.parse_action_argument("a=b=c"), ("a=b", "c"))
40
+
41
+ def test_needs_both_halves(self):
42
+ for value in ("Row", "=x", "Row="):
43
+ with self.assertRaises(ValueError):
44
+ check.parse_action_argument(value)
45
+
46
+
47
+ if __name__ == "__main__":
48
+ unittest.main()
@@ -2,19 +2,22 @@
2
2
  # Builds the desktop host (or only the core and its tests) in the per-user cache, fetching the
3
3
  # pinned sources and building Hermes first when they are missing. Prints the build directory.
4
4
  #
5
- # build.sh [node_modules/react-native] [--backend appkit|none] [--runtime] [--universal]
5
+ # build.sh [node_modules/react-native] [--backend appkit|gtk|none] [--runtime] [--universal]
6
6
  # [--debug|--release] [--test | --no-tests] [--no-debug-info]
7
7
  # [--library <node_modules/library>]... [--build-dir <dir>]
8
8
  #
9
9
  # Without a path, react-native is resolved from the current directory.
10
10
  #
11
11
  # --backend none the toolkit-free core and its tests only: any OS, no Hermes
12
+ # --backend gtk the GTK 4 host, ngn-linux: Linux's, and on a Mac a dev loop over Homebrew's GTK
13
+ # (brew install gtk4 libadwaita)
12
14
  # --runtime with --backend none, the core's runtime half too: Hermes, ReactHost and the
13
15
  # runtime tests, still with no toolkit (what Linux builds until it has a backend)
14
16
  # --universal arm64 and x86_64 in one binary (default: this machine's architecture)
15
17
  # --debug a Debug build (default: RelWithDebInfo)
16
18
  # --release a Release build without the core tests, as a packaged app ships it
17
- # --test run the core tests after building, and the AppKit view tests when it built them
19
+ # --test run the core tests after building, and the AppKit or GTK view tests when it
20
+ # built them (the GTK ones need a display: xvfb-run on a Linux machine without one)
18
21
  # --no-tests leave the core tests out, as an app's build does: the published package has
19
22
  # none of their sources
20
23
  # --no-debug-info the default RelWithDebInfo build without its debug info, for a host that is
@@ -85,7 +88,9 @@ JOBS="${NGN_JOBS:-8}"
85
88
  RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_PKG")"
86
89
  CACHE="$("$here/cache-dir.sh" "$RN_VERSION")"
87
90
 
88
- "$here/fetch.sh" "$RN_PKG" >&2
91
+ fetch_args=()
92
+ [ "$backend" = "gtk" ] && fetch_args=(--curl)
93
+ "$here/fetch.sh" "$RN_PKG" ${fetch_args[@]+"${fetch_args[@]}"} >&2
89
94
 
90
95
  library_dirs=""
91
96
  for lib in ${libraries[@]+"${libraries[@]}"}; do
@@ -132,6 +137,11 @@ while IFS= read -r arg; do
132
137
  launcher_args+=("$arg")
133
138
  done < <("$here/compiler-launcher.sh" "${NGN_COMPILER_LAUNCHER:-}")
134
139
 
140
+ compiler_args=()
141
+ while IFS= read -r arg; do
142
+ compiler_args+=("$arg")
143
+ done < <("$here/compilers.sh")
144
+
135
145
  # RelWithDebInfo's flags, with or without -g, set either way: CMake keeps a -D in the build
136
146
  # directory's cache, so a build with debug info after one without would otherwise go without too.
137
147
  # Hermes builds as Release, which has none.
@@ -182,6 +192,8 @@ BUILD="${build_dir:-$host_dir/$variant-$arch_key-$config}"
182
192
  # One build at a time in it (build-lock.sh), held until this script and the ninja it runs end.
183
193
  . "$here/build-lock.sh"
184
194
  lock_build "$BUILD"
195
+ # Configured with GCC before the build named clang, it starts over (reset-for-compilers.sh).
196
+ "$here/reset-for-compilers.sh" "$BUILD" ${compiler_args[@]+"${compiler_args[@]}"}
185
197
  cmake --log-level=WARNING -G Ninja -S "$native_dir" -B "$BUILD" \
186
198
  -DCMAKE_BUILD_TYPE="$config" \
187
199
  -DCMAKE_OSX_ARCHITECTURES="$archs" \
@@ -192,6 +204,7 @@ cmake --log-level=WARNING -G Ninja -S "$native_dir" -B "$BUILD" \
192
204
  -DNGN_LIBRARIES="$library_dirs" \
193
205
  -DNGN_TESTS="$tests" \
194
206
  "${link_args[@]}" \
207
+ ${compiler_args[@]+"${compiler_args[@]}"} \
195
208
  ${launcher_args[@]+"${launcher_args[@]}"} \
196
209
  ${flags_args[@]+"${flags_args[@]}"} \
197
210
  ${hermes_args[@]+"${hermes_args[@]}"} >&2
@@ -210,5 +223,9 @@ if [ "$run_tests" = 1 ]; then
210
223
  if [ -x "$BUILD/appkit/ngn_appkit_tests" ]; then
211
224
  "$BUILD/appkit/ngn_appkit_tests" >&2
212
225
  fi
226
+ # The GTK view tests, which a build with the GTK backend has.
227
+ if [ -x "$BUILD/gtk/ngn_gtk_tests" ]; then
228
+ "$BUILD/gtk/ngn_gtk_tests" >&2
229
+ fi
213
230
  fi
214
231
  echo "$BUILD"
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env bash
2
+ # The CMake arguments that name the host's C and C++ compilers, one per line.
3
+ #
4
+ # compilers.sh [Darwin|Linux]
5
+ #
6
+ # Off macOS the host is clang's, as Hermes and ICU are (build-hermes.sh, build-icu.sh): React
7
+ # Native's headers have `#pragma mark`, which GCC's -Wall rejects under -Werror, and CMake takes
8
+ # the system's cc and c++, which on most distributions is GCC. CC and CXX choose another compiler:
9
+ # each set is left to CMake, which reads it from the environment with any flags it carries
10
+ # (`clang -pthread`), where -DCMAKE_C_COMPILER would take the whole of it as the program's name.
11
+ # On macOS, Xcode's clang is CMake's own default, so nothing is named.
12
+ set -euo pipefail
13
+ os="${1:-$(uname -s)}"
14
+ [ "$os" = "Darwin" ] && exit 0
15
+ [ -z "${CC:-}" ] && echo "-DCMAKE_C_COMPILER=clang"
16
+ [ -z "${CXX:-}" ] && echo "-DCMAKE_CXX_COMPILER=clang++"
17
+ exit 0
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+ # Checks a `.deb`'s Depends against what the GTK host links: in a clean Debian or Ubuntu container,
3
+ # installs only the packages named, then fails when the dynamic loader cannot find a library the
4
+ # host needs, directly or through another library. dpkg never reads the binary, so a library
5
+ # missing from bin/package-linux.mjs's DEB_DEPENDS fails here rather than on a user's machine.
6
+ #
7
+ # deb-depends-check.sh <ngn-linux> <package>...
8
+ #
9
+ # CI runs it in ubuntu:24.04 with the package names DEB_DEPENDS gives.
10
+ set -euo pipefail
11
+ host="${1:?usage: deb-depends-check.sh <ngn-linux> <package>...}"
12
+ shift
13
+ [ $# -gt 0 ] || { echo "deb-depends-check: no packages named" >&2; exit 2; }
14
+ export DEBIAN_FRONTEND=noninteractive
15
+ apt-get update -qq
16
+ apt-get install -y -qq --no-install-recommends "$@" > /dev/null
17
+ libraries=$(ldd "$host")
18
+ if grep 'not found' <<< "$libraries" >&2; then
19
+ echo "deb-depends-check: with only $* installed, the host cannot find the libraries above" >&2
20
+ exit 1
21
+ fi
22
+ echo "deb-depends-check: all $(wc -l <<< "$libraries") libraries the host loads are found with $*"
@@ -9,7 +9,9 @@
9
9
  # Native's Android build would normally download (glog, fmt, double-conversion, boost headers,
10
10
  # fast_float), nlohmann_json for the dev-server client, doctest for the core tests, on macOS
11
11
  # Sparkle's framework, which `package --format dmg` embeds for whole-app updates, and elsewhere ICU,
12
- # which Hermes's Unicode layer needs there (build-icu.sh builds it).
12
+ # which Hermes's Unicode layer needs there (build-icu.sh builds it), and curl, which the GTK host's
13
+ # HTTP and WebSocket client is built on (cmake/curl.cmake). `--curl` fetches curl on macOS too,
14
+ # for the GTK build there.
13
15
  # Each source records what it was fetched at, so a changed pin fetches it again. A download whose
14
16
  # checksum or commit does not match fails the script; nothing is ever used unverified.
15
17
  #
@@ -18,7 +20,11 @@
18
20
  set -euo pipefail
19
21
 
20
22
  here="$(cd "$(dirname "$0")" && pwd)"
21
- RN_PKG="$(cd "${1:?usage: fetch.sh <node_modules/react-native>}" && pwd)"
23
+ RN_PKG="$(cd "${1:?usage: fetch.sh <node_modules/react-native> [--curl]}" && pwd)"
24
+ with_curl=0
25
+ if [ "$(uname -s)" != "Darwin" ] || [ "${2:-}" = "--curl" ]; then
26
+ with_curl=1
27
+ fi
22
28
  RN_VERSION="$(node -p 'require(process.argv[1] + "/package.json").version' "$RN_PKG")"
23
29
 
24
30
  # --- Pins, per supported React Native version ----------------------------------------------------
@@ -55,6 +61,9 @@ ICU_URL=https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-
55
61
  ICU_SHA256=588e431f77327c39031ffbb8843c0e3bc122c211374485fa87dc5f3faff24061
56
62
  ICU_DATA_URL=https://github.com/unicode-org/icu/releases/download/release-77-1/icu4c-77_1-data.zip
57
63
  ICU_DATA_SHA256=1e08bfafa442260ccabf9a872d4eab12de813d42b90769df056bab032b37e1d3
64
+ # curl's release tarball; its SHA-256 matches the digest GitHub lists for the release's asset.
65
+ CURL_URL=https://curl.se/download/curl-8.23.0.tar.xz
66
+ CURL_SHA256=8dadd7d2536a314f982ad05a651b713f426bf7d02cc2c76cffb9796f2218e6c5
58
67
 
59
68
  if [ "$(cat "$RN_PKG/sdks/.hermesv1version")" != "$HERMES_TAG" ]; then
60
69
  echo "fetch.sh: react-native names Hermes $(cat "$RN_PKG/sdks/.hermesv1version"), pinned $HERMES_TAG" >&2
@@ -173,6 +182,18 @@ if [ "$(uname -s)" != "Darwin" ] && ! fresh icu "$ICU_SHA256-$ICU_DATA_SHA256";
173
182
  rm -rf "$SRC/.icu.tmp"
174
183
  stamp icu "$ICU_SHA256-$ICU_DATA_SHA256"
175
184
  fi
185
+
186
+ # curl without its test suite, which its build leaves out.
187
+ if [ "$with_curl" = 1 ] && ! fresh curl "$CURL_SHA256"; then
188
+ echo "==> curl"
189
+ rm -rf "$SRC/curl" "$SRC/.curl.tmp"
190
+ mkdir -p "$SRC/.curl.tmp/x"
191
+ download "$CURL_URL" "$CURL_SHA256" "$SRC/.curl.tmp/curl.tar.xz"
192
+ tar -xJf "$SRC/.curl.tmp/curl.tar.xz" -C "$SRC/.curl.tmp/x" --exclude='*/tests'
193
+ mv "$SRC/.curl.tmp/x/"curl-* "$SRC/curl"
194
+ rm -rf "$SRC/.curl.tmp"
195
+ stamp curl "$CURL_SHA256"
196
+ fi
176
197
  t1=$(date +%s)
177
198
 
178
199
  # React Native's own component codegen (FBReactNativeSpec), from the installed package.