@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,71 @@
1
+ #include "ngn/dbus-menu.h"
2
+
3
+ namespace ngn {
4
+
5
+ namespace {
6
+
7
+ void addSeparator(std::vector<DbusMenuNode> &into, int &next) {
8
+ if (!into.empty() && !into.back().separator) {
9
+ into.push_back({.id = next++, .separator = true});
10
+ }
11
+ }
12
+
13
+ void addItems(const std::vector<MenuItem> &items, std::vector<DbusMenuNode> &into, int &next) {
14
+ for (const auto &item : items) {
15
+ if (item.separator) {
16
+ addSeparator(into, next);
17
+ } else if (item.inlineItems) {
18
+ addSeparator(into, next);
19
+ addItems(item.items, into, next);
20
+ addSeparator(into, next);
21
+ } else {
22
+ DbusMenuNode node{
23
+ .id = next++,
24
+ .label = dbusMenuLabel(item.title),
25
+ .enabled = !item.disabled,
26
+ .checked = item.checked,
27
+ .itemId = item.items.empty() ? item.id : std::string(),
28
+ .command = item.items.empty() && item.command != MenuCommand::None ? item.command : MenuCommand::AppItem,
29
+ };
30
+ addItems(item.items, node.children, next);
31
+ into.push_back(std::move(node));
32
+ }
33
+ }
34
+ if (!into.empty() && into.back().separator) {
35
+ into.pop_back();
36
+ }
37
+ }
38
+
39
+ } // namespace
40
+
41
+ DbusMenuNode dbusMenuLayout(const std::vector<MenuItem> &items) {
42
+ DbusMenuNode root;
43
+ int next = 1;
44
+ addItems(items, root.children, next);
45
+ return root;
46
+ }
47
+
48
+ const DbusMenuNode *findDbusMenuNode(const DbusMenuNode &root, int id) {
49
+ if (root.id == id) {
50
+ return &root;
51
+ }
52
+ for (const auto &child : root.children) {
53
+ if (const auto *found = findDbusMenuNode(child, id)) {
54
+ return found;
55
+ }
56
+ }
57
+ return nullptr;
58
+ }
59
+
60
+ std::string dbusMenuLabel(const std::string &title) {
61
+ std::string out;
62
+ for (char c : title) {
63
+ out += c;
64
+ if (c == '_') {
65
+ out += '_';
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+
71
+ } // namespace ngn
@@ -1,5 +1,7 @@
1
1
  #include "ngn/default-menu.h"
2
2
 
3
+ #include <cctype>
4
+
3
5
  namespace ngn {
4
6
 
5
7
  namespace {
@@ -85,6 +87,138 @@ std::vector<MenuItem> macOSMenuBar(const DefaultMenuOptions &options) {
85
87
  return bar;
86
88
  }
87
89
 
90
+ MenuPlacement linuxMenuPlacement(std::string_view currentDesktop) {
91
+ while (!currentDesktop.empty()) {
92
+ auto colon = currentDesktop.find(':');
93
+ if (currentDesktop.substr(0, colon) == "KDE") {
94
+ return MenuPlacement::MenuBar;
95
+ }
96
+ currentDesktop = colon == std::string_view::npos ? std::string_view() : currentDesktop.substr(colon + 1);
97
+ }
98
+ return MenuPlacement::PrimaryMenu;
99
+ }
100
+
101
+ std::vector<MenuItem> linuxMenuBar(const DefaultMenuOptions &options) {
102
+ const std::string &app = options.appName;
103
+ std::vector<MenuItem> bar{
104
+ menu("File", {item("Close Window", MenuCommand::CloseWindow, "w", Control), separator(), item("Print...", MenuCommand::Print, "p", Control)}),
105
+ menu(
106
+ "Edit",
107
+ {
108
+ item("Undo", MenuCommand::Undo, "z", Control),
109
+ item("Redo", MenuCommand::Redo, "z", Control | Shift),
110
+ separator(),
111
+ item("Cut", MenuCommand::Cut, "x", Control),
112
+ item("Copy", MenuCommand::Copy, "c", Control),
113
+ item("Paste", MenuCommand::Paste, "v", Control),
114
+ item("Delete", MenuCommand::Delete),
115
+ item("Select All", MenuCommand::SelectAll, "a", Control),
116
+ }),
117
+ menu(
118
+ "View",
119
+ {
120
+ item("Back", MenuCommand::Back, options.os.back.key, options.os.back.modifiers),
121
+ item("Forward", MenuCommand::Forward, options.os.forward.key, options.os.forward.modifiers),
122
+ separator(),
123
+ item("Show Sidebar", MenuCommand::ToggleSidebar, "F9", 0),
124
+ item("Full Screen", MenuCommand::ToggleFullScreen, "F11", 0),
125
+ }),
126
+ };
127
+ if (options.developer) {
128
+ bar.push_back(menu(
129
+ "Developer",
130
+ {
131
+ item("Reload", MenuCommand::Reload, "r", Control),
132
+ item("Open DevTools", MenuCommand::OpenDevTools, "i", Control | Shift),
133
+ }));
134
+ }
135
+ bar.push_back(menu(
136
+ app,
137
+ {
138
+ item("Keyboard Shortcuts", MenuCommand::KeyboardShortcuts, "?", Control | Shift),
139
+ separator(),
140
+ item("About " + app, MenuCommand::About),
141
+ separator(),
142
+ item("Quit", MenuCommand::Quit, "q", Control),
143
+ }));
144
+ return bar;
145
+ }
146
+
147
+ namespace {
148
+
149
+ void collectShortcuts(const std::vector<MenuItem> &items, std::vector<ShortcutEntry> &out) {
150
+ for (const auto &m : items) {
151
+ if (m.separator || m.disabled) {
152
+ continue;
153
+ }
154
+ if (!m.items.empty()) {
155
+ collectShortcuts(m.items, out);
156
+ } else if (!m.key.empty()) {
157
+ out.push_back({.title = m.title, .chord = {.key = m.key, .modifiers = m.modifiers}});
158
+ }
159
+ }
160
+ }
161
+
162
+ } // namespace
163
+
164
+ std::vector<ShortcutGroup> menuShortcuts(const std::vector<MenuItem> &menus) {
165
+ std::vector<ShortcutGroup> groups;
166
+ for (const auto &m : menus) {
167
+ // A disabled top-level menu is skipped as findMenuItem skips it: its keys select nothing.
168
+ if (m.separator || m.disabled) {
169
+ continue;
170
+ }
171
+ ShortcutGroup group{.title = m.title};
172
+ collectShortcuts(m.items, group.entries);
173
+ if (!group.entries.empty()) {
174
+ groups.push_back(std::move(group));
175
+ }
176
+ }
177
+ return groups;
178
+ }
179
+
180
+ namespace {
181
+
182
+ std::string lowerKey(std::string key) {
183
+ if (key.size() == 1) {
184
+ key[0] = static_cast<char>(std::tolower(static_cast<unsigned char>(key[0])));
185
+ }
186
+ return key;
187
+ }
188
+
189
+ } // namespace
190
+
191
+ const MenuItem *findMenuItem(const std::vector<MenuItem> &menus, const KeyChord &chord) {
192
+ for (const auto &m : menus) {
193
+ if (m.separator || m.disabled) {
194
+ continue;
195
+ }
196
+ if (m.items.empty() && !m.key.empty() && m.modifiers == chord.modifiers && lowerKey(m.key) == lowerKey(chord.key)) {
197
+ return &m;
198
+ }
199
+ if (auto found = findMenuItem(m.items, chord)) {
200
+ return found;
201
+ }
202
+ }
203
+ return nullptr;
204
+ }
205
+
206
+ bool isEditingCommand(MenuCommand command) {
207
+ switch (command) {
208
+ case MenuCommand::Undo:
209
+ case MenuCommand::Redo:
210
+ case MenuCommand::Cut:
211
+ case MenuCommand::Copy:
212
+ case MenuCommand::Paste:
213
+ case MenuCommand::PasteAndMatchStyle:
214
+ case MenuCommand::Delete:
215
+ case MenuCommand::SelectAll:
216
+ return true;
217
+ default:
218
+ return false;
219
+ }
220
+ }
221
+
88
222
  const MenuItem *findMenuItem(const std::vector<MenuItem> &menus, MenuCommand command) {
89
223
  for (const auto &m : menus) {
90
224
  if (m.command == command && !m.separator) {
@@ -21,6 +21,17 @@ void fromRawValue(const PropsParserContext &, const RawValue &value, ScrollbarGu
21
21
  result = keyword == "stable" ? ScrollbarGutter::Stable : ScrollbarGutter::Auto;
22
22
  }
23
23
 
24
+ AriaFields parseAriaFields(const PropsParserContext &context, const AriaFields &source, const RawProps &rawProps) {
25
+ return AriaFields{
26
+ .required = convertRawProp(context, rawProps, "accessibilityRequired", source.required, false),
27
+ .invalid = convertRawProp(context, rawProps, "accessibilityInvalid", source.invalid, false),
28
+ .posInSet = convertRawProp(context, rawProps, "accessibilityPosInSet", source.posInSet, {}),
29
+ .setSize = convertRawProp(context, rawProps, "accessibilitySetSize", source.setSize, {}),
30
+ .rowCount = convertRawProp(context, rawProps, "accessibilityRowCount", source.rowCount, {}),
31
+ .columnCount = convertRawProp(context, rawProps, "accessibilityColumnCount", source.columnCount, {}),
32
+ };
33
+ }
34
+
24
35
  DesktopProps parseDesktopProps(const PropsParserContext &context, const DesktopProps &source, const RawProps &rawProps) {
25
36
  return DesktopProps{
26
37
  .focusable = convertRawProp(context, rawProps, "focusable", source.focusable, {}),
@@ -38,6 +49,9 @@ DesktopProps parseDesktopProps(const PropsParserContext &context, const DesktopP
38
49
  .contextMenu = convertRawProp(context, rawProps, "contextMenu", source.contextMenu, folly::dynamic(nullptr)),
39
50
  .role = convertRawProp(context, rawProps, "role", source.role, std::string{}),
40
51
  .accessibilityLevel = convertRawProp(context, rawProps, "accessibilityLevel", source.accessibilityLevel, {}),
52
+ .accessibilityDescribedBy =
53
+ convertRawProp(context, rawProps, "accessibilityDescribedBy", source.accessibilityDescribedBy, {}),
54
+ .aria = parseAriaFields(context, source.aria, rawProps),
41
55
  };
42
56
  }
43
57
 
@@ -90,6 +90,25 @@ bool walked(const ViewTree &tree, Tag tag, Tag root, const ViewTree::Node *node)
90
90
  node->view.layoutMetrics.displayType != DisplayType::None;
91
91
  }
92
92
 
93
+ } // namespace
94
+
95
+ bool viewTakesFocus(const DesktopProps &props) {
96
+ return props.tabIndex.has_value() || props.focusable.value_or(false);
97
+ }
98
+
99
+ Tag focusContainer(const ViewTree &tree, Tag tag) {
100
+ Tag at = tag;
101
+ for (const auto *node = tree.find(at); node != nullptr; node = tree.find(at)) {
102
+ if (tree.isContainerRoot(at) || node->parent < 0) {
103
+ return at;
104
+ }
105
+ at = node->parent;
106
+ }
107
+ return tag;
108
+ }
109
+
110
+ namespace {
111
+
93
112
  // Whether the view takes the focus when the host moves it there, in Tab order or not: any
94
113
  // `tabIndex` does, as on the web.
95
114
  bool canFocus(const ViewTree::Node &node) {
@@ -1,5 +1,7 @@
1
1
  #include "ngn/header-bar.h"
2
2
 
3
+ #include <algorithm>
4
+
3
5
  namespace ngn {
4
6
 
5
7
  namespace {
@@ -101,4 +103,22 @@ std::optional<SearchBarCommand> searchBarCommand(const std::string &name, const
101
103
  return std::nullopt;
102
104
  }
103
105
 
106
+ HeaderLayout headerLayout(const HeaderBar &bar, std::vector<HeaderSubview> subviews, bool canGoBack) {
107
+ std::sort(subviews.begin(), subviews.end(), [](const HeaderSubview &a, const HeaderSubview &b) { return a.tag < b.tag; });
108
+ HeaderLayout layout;
109
+ for (const auto &subview : subviews) {
110
+ if (subview.type == "left") {
111
+ layout.left.push_back(subview.tag);
112
+ } else if (subview.type == "center") {
113
+ layout.center.push_back(subview.tag);
114
+ } else if (subview.type == "right") {
115
+ layout.right.push_back(subview.tag);
116
+ } else if (subview.type == "searchBar") {
117
+ layout.searchBars.push_back(subview.tag);
118
+ }
119
+ }
120
+ layout.back = canGoBack && !bar.hideBackButton && layout.left.empty() && bar.left.empty();
121
+ return layout;
122
+ }
123
+
104
124
  } // namespace ngn
@@ -8,6 +8,7 @@ HostOs macOS() {
8
8
  return {
9
9
  .id = "macos",
10
10
  .name = "macOS",
11
+ .deviceMaker = "Apple",
11
12
  .program = "ngn-macos",
12
13
  .primaryModifier = Command,
13
14
  .back = {.key = "[", .modifiers = Command},
@@ -17,4 +18,22 @@ HostOs macOS() {
17
18
  };
18
19
  }
19
20
 
21
+ // Ctrl for an app's shortcuts and the OS's own; Alt+Left and Alt+Right for back and forward, as
22
+ // GNOME's and KDE's apps have them, the other way round in a right-to-left locale, where back
23
+ // points right; no Homebrew on the search path.
24
+ HostOs linuxOs(bool rightToLeft) {
25
+ const char *back = rightToLeft ? "ArrowRight" : "ArrowLeft";
26
+ const char *forward = rightToLeft ? "ArrowLeft" : "ArrowRight";
27
+ return {
28
+ .id = "linux",
29
+ .name = "Linux",
30
+ .program = "ngn-linux",
31
+ .primaryModifier = Control,
32
+ .back = {.key = back, .modifiers = Option},
33
+ .forward = {.key = forward, .modifiers = Option},
34
+ .searchPath = {"/usr/local/bin", "/usr/bin", "/bin", "/usr/local/sbin", "/usr/sbin", "/sbin"},
35
+ .menuBar = linuxMenuBar,
36
+ };
37
+ }
38
+
20
39
  } // namespace ngn
@@ -0,0 +1,45 @@
1
+ #include "ngn/host-reload.h"
2
+
3
+ #include <map>
4
+ #include <mutex>
5
+
6
+ namespace ngn {
7
+
8
+ namespace {
9
+
10
+ std::mutex &routesMutex() {
11
+ static std::mutex mutex;
12
+ return mutex;
13
+ }
14
+
15
+ std::map<const void *, std::function<void()>> &routes() {
16
+ static std::map<const void *, std::function<void()>> routes;
17
+ return routes;
18
+ }
19
+
20
+ } // namespace
21
+
22
+ void routeHostReload(const void *host, std::function<void()> reload) {
23
+ std::lock_guard lock(routesMutex());
24
+ if (reload) {
25
+ routes()[host] = std::move(reload);
26
+ } else {
27
+ routes().erase(host);
28
+ }
29
+ }
30
+
31
+ bool reloadThroughRoute(const void *host) {
32
+ std::function<void()> reload;
33
+ {
34
+ std::lock_guard lock(routesMutex());
35
+ auto it = routes().find(host);
36
+ if (it == routes().end()) {
37
+ return false;
38
+ }
39
+ reload = it->second;
40
+ }
41
+ reload();
42
+ return true;
43
+ }
44
+
45
+ } // namespace ngn
@@ -4,6 +4,14 @@
4
4
 
5
5
  namespace ngn {
6
6
 
7
+ AccessibilitySettings linuxAccessibility(const LinuxAccessibilitySources &sources) {
8
+ return {
9
+ .screenReader = sources.screenReader,
10
+ .reduceMotion = sources.portalReducedMotion || sources.gtkReducedMotion || !sources.animations,
11
+ .increaseContrast = sources.highContrast || sources.portalContrast,
12
+ };
13
+ }
14
+
7
15
  void HostState::setInitialUrl(std::string url) {
8
16
  std::lock_guard lock(mutex_);
9
17
  initialUrl_ = std::move(url);
@@ -1,8 +1,11 @@
1
1
  #include "ngn/image-source.h"
2
2
 
3
+ #include "ngn/download.h"
4
+
3
5
  #include <cmath>
4
6
  #include <limits>
5
7
 
8
+ using facebook::react::ImageResizeMode;
6
9
  using facebook::react::ImageSource;
7
10
 
8
11
  namespace ngn {
@@ -27,4 +30,91 @@ bool sameImageRequest(const ImageSource &a, const ImageSource &b) {
27
30
  return a.uri == b.uri && a.cache == b.cache && a.method == b.method && a.headers == b.headers && a.body == b.body;
28
31
  }
29
32
 
33
+ const char *imageContentFit(ImageResizeMode mode) {
34
+ switch (mode) {
35
+ case ImageResizeMode::Cover:
36
+ return "cover";
37
+ case ImageResizeMode::Contain:
38
+ return "contain";
39
+ case ImageResizeMode::Center:
40
+ return "none";
41
+ default:
42
+ return "fill";
43
+ }
44
+ }
45
+
46
+ namespace {
47
+
48
+ // What a cacheable source is kept under: its uri, and its headers when it sends any, so a request
49
+ // with other credentials never answers with another's bytes.
50
+ std::string cacheKey(const ImageSource &source) {
51
+ std::string key = source.uri;
52
+ for (const auto &[name, value] : source.headers) {
53
+ key += '\n';
54
+ key += name;
55
+ key += ": ";
56
+ key += value;
57
+ }
58
+ return key;
59
+ }
60
+
61
+ } // namespace
62
+
63
+ void loadImageSource(
64
+ const std::shared_ptr<Http> &http,
65
+ const std::shared_ptr<ImageCache> &cache,
66
+ const FileAccess *files,
67
+ const ImageSource &source,
68
+ std::function<void(std::string, const std::string &)> done) {
69
+ using Cache = ImageSource::CacheStategy;
70
+ const std::string &uri = source.uri;
71
+ bool remote = uri.starts_with("http://") || uri.starts_with("https://");
72
+ std::string url = uri;
73
+ std::shared_ptr<FileAccess::Use> use;
74
+ if (uri.starts_with('/') || isFileScheme(uri)) {
75
+ try {
76
+ auto readable = readableSource(files, uri);
77
+ url = readable.uri;
78
+ use = std::move(readable.use);
79
+ } catch (const FileRefused &refused) {
80
+ done("", refused.what());
81
+ return;
82
+ }
83
+ } else if (!remote && !uri.starts_with("data:")) {
84
+ done("", "Invalid image URL: " + uri);
85
+ return;
86
+ }
87
+ bool cacheable = cache && remote && (source.method.empty() || source.method == "GET") && source.body.empty();
88
+ std::string key = cacheable ? cacheKey(source) : "";
89
+ if (cacheable && source.cache != Cache::Reload) {
90
+ if (auto found = cache->find(key, "memory")) {
91
+ done(std::move(found->first), "");
92
+ return;
93
+ }
94
+ }
95
+ if (source.cache == Cache::OnlyIfCached) {
96
+ done("", "The image at " + uri + " is not in the cache");
97
+ return;
98
+ }
99
+ HttpRequest request{.url = url, .body = source.body};
100
+ if (!source.method.empty()) {
101
+ request.method = source.method;
102
+ }
103
+ for (const auto &[name, value] : source.headers) {
104
+ request.headers.emplace_back(name, value);
105
+ }
106
+ // The pick holding a file stays open until it is read.
107
+ auto keep = cacheable ? cache : nullptr;
108
+ fetchBytes(http, std::move(request), [keep, key, uri, use, done](std::string body, const std::string &error) {
109
+ if (!error.empty()) {
110
+ done("", "Could not load the image at " + uri + " (" + error + ")");
111
+ return;
112
+ }
113
+ if (keep) {
114
+ keep->store(key, body, "memory");
115
+ }
116
+ done(std::move(body), "");
117
+ });
118
+ }
119
+
30
120
  } // namespace ngn
@@ -5,6 +5,8 @@
5
5
  #include "ngn/app-menus.h"
6
6
  #include "ngn/file-system.h"
7
7
 
8
+ #include <unordered_set>
9
+
8
10
  #include <react/renderer/components/view/TouchEventEmitter.h>
9
11
  #include <react/renderer/components/view/ViewProps.h>
10
12
 
@@ -392,14 +394,31 @@ DragItems dragItems(const std::vector<std::string> &urls, std::optional<std::str
392
394
  auto last = slash == std::string_view::npos ? path : path.substr(slash + 1);
393
395
  items.files.push_back({.uri = url, .name = percentDecoded(last)});
394
396
  }
395
- // The toolkit offers a dragged url as text too, and a file as its path.
397
+ // The toolkit offers a dragged url as text too, and a file as its path: several of them a line
398
+ // each (a file manager's drag of more than one file).
396
399
  if (items.text) {
400
+ // Each url, and each file url's decoded path, once: a drag of thousands of files stays linear.
401
+ std::unordered_set<std::string> offered;
397
402
  for (const auto &url : urls) {
398
- bool path = url.rfind("file://", 0) == 0 && percentDecoded(std::string_view(url).substr(7)) == *items.text;
399
- if (url == *items.text || path) {
400
- items.text.reset();
401
- break;
403
+ offered.insert(url);
404
+ if (url.rfind("file://", 0) == 0) {
405
+ offered.insert(percentDecoded(std::string_view(url).substr(7)));
406
+ }
407
+ }
408
+ auto repeats = [&offered](std::string_view line) { return offered.count(std::string(line)) > 0; };
409
+ bool onlyUrls = !urls.empty();
410
+ std::string_view rest = *items.text;
411
+ while (onlyUrls && !rest.empty()) {
412
+ auto end = rest.find('\n');
413
+ auto line = rest.substr(0, end);
414
+ if (!line.empty() && line.back() == '\r') {
415
+ line.remove_suffix(1);
402
416
  }
417
+ onlyUrls = line.empty() || repeats(line);
418
+ rest = end == std::string_view::npos ? std::string_view() : rest.substr(end + 1);
419
+ }
420
+ if (onlyUrls) {
421
+ items.text.reset();
403
422
  }
404
423
  }
405
424
  return items;
@@ -453,6 +472,9 @@ bool InputDispatcher::dragOver(const PointerInput &input, const DragItems &items
453
472
  if (!target) {
454
473
  return false;
455
474
  }
475
+ if (items.pending) {
476
+ return true;
477
+ }
456
478
  dropTarget_ = DropTarget{input.container, *target};
457
479
  if (const auto *node = tree_.find(*target)) {
458
480
  emitElementEvent(*node, "dropEnter", dropPayload(items));
@@ -1,5 +1,6 @@
1
1
  #include "ngn/input-script.h"
2
2
 
3
+ #include <set>
3
4
  #include <sstream>
4
5
 
5
6
  namespace ngn {
@@ -75,8 +76,8 @@ InputScript parseInputScript(const std::string &text) {
75
76
  if (!(words >> step.key)) {
76
77
  return fail("key needs a key");
77
78
  }
78
- if (step.key.size() != 1 && step.key != "escape" && step.key != "return" && step.key != "space" &&
79
- step.key != "tab" && step.key != "delete") {
79
+ static const std::set<std::string> named{"escape", "return", "space", "tab", "delete", "left", "right", "up", "down"};
80
+ if (step.key.size() != 1 && !named.count(step.key)) {
80
81
  return fail("unknown key " + step.key);
81
82
  }
82
83
  std::string modifier;
@@ -1,7 +1,12 @@
1
1
  #include "ngn/launch-settings.h"
2
2
 
3
+ #include <folly/json.h>
4
+
3
5
  #include <cctype>
4
6
  #include <filesystem>
7
+ #include <fstream>
8
+ #include <sstream>
9
+ #include <system_error>
5
10
 
6
11
  namespace ngn {
7
12
 
@@ -59,6 +64,24 @@ std::string LaunchSettings::setting(const std::string &plistKey, const std::stri
59
64
  return "";
60
65
  }
61
66
 
67
+ // A link (`scheme:...`) or a file's absolute path, as a launcher's `%U` gives them.
68
+ static bool isOpenArg(const std::string &arg) {
69
+ if (arg.starts_with("/")) {
70
+ return true;
71
+ }
72
+ auto colon = arg.find(':');
73
+ if (colon == std::string::npos || colon == 0 || !std::isalpha(static_cast<unsigned char>(arg[0]))) {
74
+ return false;
75
+ }
76
+ for (size_t i = 1; i < colon; ++i) {
77
+ char c = arg[i];
78
+ if (!std::isalnum(static_cast<unsigned char>(c)) && c != '+' && c != '-' && c != '.') {
79
+ return false;
80
+ }
81
+ }
82
+ return true;
83
+ }
84
+
62
85
  std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources, const HostOs &os) {
63
86
  LaunchSettings settings;
64
87
  settings.env = sources.env;
@@ -82,6 +105,16 @@ std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources,
82
105
  settings.module = plist("NGNModuleName").value_or("main");
83
106
  settings.title = plist("CFBundleName").value_or(settings.title);
84
107
  settings.appId = plist("CFBundleIdentifier").value_or("");
108
+ settings.capabilitiesJson = plist("NGNCapabilities").value_or("");
109
+ // A Linux launcher passes the links and files to open, and the bus its service switch. Nothing
110
+ // else on the command line is read.
111
+ for (const auto &arg : sources.args) {
112
+ if (arg == kDBusServiceArg) {
113
+ settings.dbusService = true;
114
+ } else if (isOpenArg(arg)) {
115
+ settings.openArgs.push_back(arg);
116
+ }
117
+ }
85
118
  return settings;
86
119
  }
87
120
 
@@ -111,6 +144,8 @@ std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources,
111
144
  settings.initialUrl = args[++i];
112
145
  } else if (arg == "--title" && hasValue) {
113
146
  settings.title = args[++i];
147
+ } else if (arg == kDBusServiceArg) {
148
+ settings.dbusService = true;
114
149
  } else if (settings.bundle.empty() && !arg.starts_with("--")) {
115
150
  settings.bundle = arg;
116
151
  } else {
@@ -123,6 +158,47 @@ std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources,
123
158
  return settings;
124
159
  }
125
160
 
161
+ std::variant<LaunchSources::Lookup, std::string> packagedMetadata(const std::string &folder) {
162
+ auto path = std::filesystem::path(folder) / "metadata.json";
163
+ // Only a file that is not there makes a dev run: one that is there and cannot be read is a broken
164
+ // package, which must not fall back to argv and the environment.
165
+ std::error_code error;
166
+ bool there = std::filesystem::exists(path, error);
167
+ if (error) {
168
+ return path.string() + " cannot be read: " + error.message();
169
+ }
170
+ if (!there) {
171
+ return LaunchSources::Lookup();
172
+ }
173
+ std::ifstream file(path);
174
+ if (!file) {
175
+ return path.string() + " cannot be read";
176
+ }
177
+ std::stringstream text;
178
+ text << file.rdbuf();
179
+ folly::dynamic metadata;
180
+ try {
181
+ metadata = folly::parseJson(text.str());
182
+ } catch (const std::exception &error) {
183
+ return path.string() + " is not JSON: " + error.what();
184
+ }
185
+ if (!metadata.isObject()) {
186
+ return path.string() + " is not a JSON object";
187
+ }
188
+ // A package always names its bundle: without one the host would take argv's, as a dev run does.
189
+ if (auto bundle = metadata.find("NGNBundleFile"); bundle == metadata.items().end() || !bundle->second.isString() ||
190
+ bundle->second.getString().empty()) {
191
+ return path.string() + " names no NGNBundleFile";
192
+ }
193
+ return LaunchSources::Lookup([metadata = std::move(metadata)](const std::string &key) -> std::optional<std::string> {
194
+ auto it = metadata.find(key);
195
+ if (it == metadata.items().end() || it->second.isNull()) {
196
+ return std::nullopt;
197
+ }
198
+ return it->second.isString() ? it->second.getString() : folly::toJson(it->second);
199
+ });
200
+ }
201
+
126
202
  UpdatesConfig updatesConfigFrom(
127
203
  const LaunchSettings &settings, const HostOs &os, const std::string &appData, const std::string &embeddedBundle) {
128
204
  UpdatesConfig config{