@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,196 @@
1
+ #include "ngn/crash-report.h"
2
+
3
+ #include <execinfo.h>
4
+ #include <fcntl.h>
5
+ #include <pwd.h>
6
+ #include <signal.h>
7
+ #include <sys/stat.h>
8
+ #include <unistd.h>
9
+
10
+ #include <cstdlib>
11
+ #include <cstring>
12
+ #include <filesystem>
13
+
14
+ namespace ngn {
15
+
16
+ namespace {
17
+
18
+ // What the handler reads, set before it is installed: it may only make async-signal-safe calls.
19
+ char gPath[4096];
20
+ char gProgram[256];
21
+
22
+ constexpr int kSignals[] = {SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGABRT};
23
+
24
+ const char *signalName(int signal) {
25
+ switch (signal) {
26
+ case SIGSEGV: return "SIGSEGV";
27
+ case SIGBUS: return "SIGBUS";
28
+ case SIGILL: return "SIGILL";
29
+ case SIGFPE: return "SIGFPE";
30
+ case SIGABRT: return "SIGABRT";
31
+ }
32
+ return "a fatal signal";
33
+ }
34
+
35
+ void put(int fd, const char *text) {
36
+ size_t length = std::strlen(text);
37
+ while (length > 0) {
38
+ ssize_t n = write(fd, text, length);
39
+ if (n <= 0) {
40
+ return;
41
+ }
42
+ text += n;
43
+ length -= static_cast<size_t>(n);
44
+ }
45
+ }
46
+
47
+ // The signal's number, written without the heap.
48
+ void putNumber(int fd, int value) {
49
+ char digits[16];
50
+ int at = sizeof digits;
51
+ digits[--at] = '\0';
52
+ unsigned v = value < 0 ? 0u : static_cast<unsigned>(value);
53
+ do {
54
+ digits[--at] = static_cast<char>('0' + v % 10);
55
+ v /= 10;
56
+ } while (v > 0 && at > 0);
57
+ put(fd, digits + at);
58
+ }
59
+
60
+ // The handler's time to write the report, which takes milliseconds.
61
+ constexpr unsigned kHandlerSeconds = 2;
62
+
63
+ volatile sig_atomic_t gSignal = 0;
64
+ // The report while the handler writes it, else -1.
65
+ volatile sig_atomic_t gReport = -1;
66
+
67
+ void heading(int fd, int signal) {
68
+ put(fd, gProgram);
69
+ put(fd, " crashed: ");
70
+ put(fd, signalName(signal));
71
+ put(fd, " (signal ");
72
+ putNumber(fd, signal);
73
+ put(fd, ")\nNative stack:\n");
74
+ }
75
+
76
+ void where() {
77
+ put(STDERR_FILENO, "The crash report is at ");
78
+ put(STDERR_FILENO, gPath);
79
+ put(STDERR_FILENO, "\n");
80
+ }
81
+
82
+ // The signal kills the process now, as it would have, whatever other handler called this one, and
83
+ // from inside a handler for another signal.
84
+ [[noreturn]] void dieOf(int signal) {
85
+ struct sigaction fallback{};
86
+ fallback.sa_handler = SIG_DFL;
87
+ sigemptyset(&fallback.sa_mask);
88
+ sigaction(signal, &fallback, nullptr);
89
+ sigset_t set;
90
+ sigemptyset(&set);
91
+ sigaddset(&set, signal);
92
+ sigprocmask(SIG_UNBLOCK, &set, nullptr);
93
+ raise(signal);
94
+ _exit(128 + signal);
95
+ }
96
+
97
+ // backtrace is not async-signal-safe: its unwinder takes the loader's lock, which the crashed
98
+ // thread or another one can hold, and opening the report can block too. So the handler has a
99
+ // bounded time, after which the process dies of its signal with what was written.
100
+ void onStuck(int) {
101
+ constexpr const char *stuck = "The native stack could not be read in time.\n";
102
+ if (gReport >= 0) {
103
+ put(gReport, stuck);
104
+ close(gReport);
105
+ }
106
+ put(STDERR_FILENO, stuck);
107
+ where();
108
+ dieOf(gSignal);
109
+ }
110
+
111
+ void onFatalSignal(int signal) {
112
+ gSignal = signal;
113
+ struct sigaction watchdog{};
114
+ watchdog.sa_handler = onStuck;
115
+ sigemptyset(&watchdog.sa_mask);
116
+ sigaction(SIGALRM, &watchdog, nullptr);
117
+ alarm(kHandlerSeconds);
118
+ heading(STDERR_FILENO, signal);
119
+ int fd = open(gPath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
120
+ if (fd >= 0) {
121
+ heading(fd, signal);
122
+ gReport = fd;
123
+ }
124
+ void *frames[64];
125
+ int count = backtrace(frames, 64);
126
+ if (fd >= 0) {
127
+ backtrace_symbols_fd(frames, count, fd);
128
+ }
129
+ backtrace_symbols_fd(frames, count, STDERR_FILENO);
130
+ alarm(0);
131
+ if (fd >= 0) {
132
+ gReport = -1;
133
+ close(fd);
134
+ }
135
+ where();
136
+ dieOf(signal);
137
+ }
138
+
139
+ } // namespace
140
+
141
+ std::optional<std::string> accountHomeDirectory() {
142
+ const passwd *account = getpwuid(getuid());
143
+ if (!account || !account->pw_dir || !*account->pw_dir) {
144
+ return std::nullopt;
145
+ }
146
+ return std::string(account->pw_dir);
147
+ }
148
+
149
+ std::string crashReportPath(
150
+ const std::string &appId,
151
+ const std::optional<std::string> &testStateDir,
152
+ const std::function<std::optional<std::string>(const std::string &name)> &env,
153
+ const std::function<std::optional<std::string>()> &accountHome) {
154
+ if (testStateDir) {
155
+ return *testStateDir + "/crash.txt";
156
+ }
157
+ std::string state;
158
+ if (auto xdg = env("XDG_STATE_HOME"); xdg && !xdg->empty()) {
159
+ state = *xdg;
160
+ } else {
161
+ auto home = env("HOME");
162
+ if (!home || home->empty()) {
163
+ home = accountHome();
164
+ }
165
+ if (!home || home->empty()) {
166
+ std::error_code ignored;
167
+ home = std::filesystem::temp_directory_path(ignored).string();
168
+ }
169
+ state = *home + "/.local/state";
170
+ }
171
+ return state + "/" + appId + "/crash.txt";
172
+ }
173
+
174
+ void installCrashReport(const std::string &path, const std::string &program) {
175
+ std::error_code ignored;
176
+ std::filesystem::create_directories(std::filesystem::path(path).parent_path(), ignored);
177
+ std::strncpy(gPath, path.c_str(), sizeof gPath - 1);
178
+ std::strncpy(gProgram, program.c_str(), sizeof gProgram - 1);
179
+ // backtrace loads its unwinder the first time it runs, which must not happen in the handler.
180
+ void *warm[1];
181
+ backtrace(warm, 1);
182
+ static char alternate[64 * 1024];
183
+ stack_t stack{};
184
+ stack.ss_sp = alternate;
185
+ stack.ss_size = sizeof alternate;
186
+ sigaltstack(&stack, nullptr);
187
+ struct sigaction action{};
188
+ action.sa_handler = onFatalSignal;
189
+ action.sa_flags = SA_ONSTACK | SA_RESETHAND;
190
+ sigemptyset(&action.sa_mask);
191
+ for (int signal : kSignals) {
192
+ sigaction(signal, &action, nullptr);
193
+ }
194
+ }
195
+
196
+ } // namespace ngn