@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.
- package/README.md +6 -3
- package/bin/app-config.mjs +1 -0
- package/bin/archive.mjs +166 -0
- package/bin/autolink.mjs +61 -30
- package/bin/cli.mjs +127 -27
- package/bin/host.mjs +255 -58
- package/bin/package-linux.mjs +1394 -0
- package/bin/package.mjs +171 -35
- package/bin/plist.mjs +6 -2
- package/bin/png-icon.mjs +315 -0
- package/bin/prebuilt.mjs +147 -26
- package/bin/toolchain.mjs +258 -19
- package/native/CMakeLists.txt +64 -6
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/appkit-backend.h +1 -0
- package/native/appkit/appkit-backend.mm +13 -0
- package/native/appkit/header-toolbar.mm +28 -25
- package/native/appkit/host-view.h +10 -0
- package/native/appkit/host-view.mm +146 -40
- package/native/appkit/input-replay.h +6 -0
- package/native/appkit/input-replay.mm +21 -12
- package/native/appkit/main.mm +11 -7
- package/native/appkit/native-controls.mm +13 -1
- package/native/appkit/split-view.mm +7 -13
- package/native/appkit/text-input-field.h +4 -0
- package/native/appkit/text-input-field.mm +20 -1
- package/native/cmake/curl.cmake +79 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
- package/native/cmake/libraries/react-native-worklets.cmake +5 -0
- package/native/cmake/linked-modules.cmake +20 -4
- package/native/cmake/react-native.cmake +18 -1
- package/native/core/include/ngn/accent-colors.h +38 -0
- package/native/core/include/ngn/accessibility-relations.h +65 -0
- package/native/core/include/ngn/accessibility.h +26 -0
- package/native/core/include/ngn/animated-frame-loop.h +56 -0
- package/native/core/include/ngn/app-info.h +24 -8
- package/native/core/include/ngn/app-menus.h +14 -1
- package/native/core/include/ngn/app-windows.h +15 -2
- package/native/core/include/ngn/aria-role.h +96 -0
- package/native/core/include/ngn/audio.h +2 -0
- package/native/core/include/ngn/camera.h +9 -0
- package/native/core/include/ngn/control-sizes.h +7 -2
- package/native/core/include/ngn/crash-report.h +31 -0
- package/native/core/include/ngn/curl-network.h +93 -0
- package/native/core/include/ngn/dbus-menu.h +39 -0
- package/native/core/include/ngn/default-menu.h +36 -0
- package/native/core/include/ngn/desktop-expo.h +7 -1
- package/native/core/include/ngn/desktop-modules.h +22 -0
- package/native/core/include/ngn/desktop-props.h +21 -1
- package/native/core/include/ngn/desktop-view-props.h +6 -0
- package/native/core/include/ngn/focus-order.h +10 -0
- package/native/core/include/ngn/header-bar.h +22 -0
- package/native/core/include/ngn/host-os.h +6 -0
- package/native/core/include/ngn/host-reload.h +21 -0
- package/native/core/include/ngn/host-state.h +23 -0
- package/native/core/include/ngn/image-source.h +26 -1
- package/native/core/include/ngn/input-script.h +3 -3
- package/native/core/include/ngn/input.h +4 -1
- package/native/core/include/ngn/launch-frame.h +21 -0
- package/native/core/include/ngn/launch-settings.h +23 -5
- package/native/core/include/ngn/mounting-backend.h +5 -0
- package/native/core/include/ngn/mounting-manager.h +1 -0
- package/native/core/include/ngn/native-controls.h +26 -5
- package/native/core/include/ngn/notification-schedule.h +74 -0
- package/native/core/include/ngn/notifications.h +2 -1
- package/native/core/include/ngn/openssl-update-crypto.h +15 -0
- package/native/core/include/ngn/photo-library.h +60 -20
- package/native/core/include/ngn/posix-locale.h +43 -0
- package/native/core/include/ngn/runtime.h +5 -0
- package/native/core/include/ngn/safe-areas.h +14 -2
- package/native/core/include/ngn/split-view.h +78 -0
- package/native/core/include/ngn/surface-metrics.h +7 -0
- package/native/core/include/ngn/system.h +14 -0
- package/native/core/include/ngn/text-input.h +13 -0
- package/native/core/include/ngn/text-units.h +38 -0
- package/native/core/include/ngn/updates.h +14 -2
- package/native/core/include/ngn/view-box.h +40 -0
- package/native/core/include/ngn/view-transform.h +15 -0
- package/native/core/include/ngn/web-browser.h +46 -0
- package/native/core/src/accent-colors.cpp +88 -0
- package/native/core/src/accessibility-relations.cpp +138 -0
- package/native/core/src/accessibility.cpp +50 -0
- package/native/core/src/animated-frame-loop.cpp +166 -0
- package/native/core/src/app-menus.cpp +26 -9
- package/native/core/src/app-windows.cpp +27 -6
- package/native/core/src/aria-role.cpp +127 -0
- package/native/core/src/control-sizes.cpp +9 -5
- package/native/core/src/crash-report.cpp +196 -0
- package/native/core/src/curl-network.cpp +1562 -0
- package/native/core/src/dbus-menu.cpp +71 -0
- package/native/core/src/default-menu.cpp +134 -0
- package/native/core/src/desktop-view-props.cpp +14 -0
- package/native/core/src/focus-order.cpp +19 -0
- package/native/core/src/header-bar.cpp +20 -0
- package/native/core/src/host-os.cpp +19 -0
- package/native/core/src/host-reload.cpp +45 -0
- package/native/core/src/host-state.cpp +8 -0
- package/native/core/src/image-source.cpp +90 -0
- package/native/core/src/input-dispatcher.cpp +27 -5
- package/native/core/src/input-script.cpp +3 -2
- package/native/core/src/launch-settings.cpp +76 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
- package/native/core/src/modules/app-info.cpp +55 -6
- package/native/core/src/modules/app-modules.cpp +1 -1
- package/native/core/src/modules/audio.cpp +4 -2
- package/native/core/src/modules/camera.cpp +8 -11
- package/native/core/src/modules/desktop-expo.cpp +10 -5
- package/native/core/src/modules/desktop-modules.cpp +106 -41
- package/native/core/src/modules/file-photo-picker.cpp +408 -0
- package/native/core/src/modules/notifications.cpp +13 -17
- package/native/core/src/modules/photo-library.cpp +42 -13
- package/native/core/src/modules/web-browser.cpp +89 -0
- package/native/core/src/mounting-manager.cpp +12 -0
- package/native/core/src/native-controls.cpp +42 -1
- package/native/core/src/notification-schedule.cpp +429 -0
- package/native/core/src/openssl-update-crypto.cpp +83 -0
- package/native/core/src/posix-locale.cpp +192 -0
- package/native/core/src/runtime.cpp +30 -1
- package/native/core/src/safe-areas.cpp +19 -4
- package/native/core/src/spawn-rules.cpp +4 -1
- package/native/core/src/split-view.cpp +93 -0
- package/native/core/src/system.cpp +19 -0
- package/native/core/src/text-input.cpp +18 -1
- package/native/core/src/text-units.cpp +99 -0
- package/native/core/src/updates.cpp +76 -17
- package/native/core/src/view-box.cpp +75 -40
- package/native/core/src/view-transform.cpp +28 -0
- package/native/docker/Dockerfile +38 -0
- package/native/docker/Dockerfile.fedora +36 -0
- package/native/docker/glibc-floor.sh +49 -0
- package/native/gtk/CMakeLists.txt +137 -0
- package/native/gtk/accent-colour.cpp +57 -0
- package/native/gtk/accent-colour.h +41 -0
- package/native/gtk/accessibility-settings.cpp +159 -0
- package/native/gtk/accessibility-settings.h +62 -0
- package/native/gtk/accessible-text.cpp +151 -0
- package/native/gtk/accessible-text.h +49 -0
- package/native/gtk/accessible.cpp +306 -0
- package/native/gtk/accessible.h +75 -0
- package/native/gtk/alerts.cpp +267 -0
- package/native/gtk/alerts.h +30 -0
- package/native/gtk/animation-frames.cpp +159 -0
- package/native/gtk/animation-frames.h +20 -0
- package/native/gtk/app-info.cpp +91 -0
- package/native/gtk/app-info.h +25 -0
- package/native/gtk/app-windows.cpp +439 -0
- package/native/gtk/app-windows.h +150 -0
- package/native/gtk/audio.cpp +370 -0
- package/native/gtk/audio.h +54 -0
- package/native/gtk/auth-session.cpp +73 -0
- package/native/gtk/auth-session.h +16 -0
- package/native/gtk/battery.cpp +110 -0
- package/native/gtk/battery.h +19 -0
- package/native/gtk/box-paint.cpp +262 -0
- package/native/gtk/box-paint.h +32 -0
- package/native/gtk/cairo-canvas.cpp +755 -0
- package/native/gtk/cairo-canvas.h +49 -0
- package/native/gtk/camera.cpp +909 -0
- package/native/gtk/camera.h +69 -0
- package/native/gtk/capture.cpp +46 -0
- package/native/gtk/capture.h +19 -0
- package/native/gtk/clock-format.cpp +151 -0
- package/native/gtk/clock-format.h +36 -0
- package/native/gtk/crypto.cpp +75 -0
- package/native/gtk/crypto.h +14 -0
- package/native/gtk/dbus-properties.cpp +131 -0
- package/native/gtk/dbus-properties.h +61 -0
- package/native/gtk/drag-and-drop.cpp +339 -0
- package/native/gtk/drag-and-drop.h +30 -0
- package/native/gtk/file-dialogs.cpp +239 -0
- package/native/gtk/file-dialogs.h +21 -0
- package/native/gtk/file-system.cpp +212 -0
- package/native/gtk/file-system.h +25 -0
- package/native/gtk/focus.cpp +282 -0
- package/native/gtk/focus.h +37 -0
- package/native/gtk/fonts.cpp +89 -0
- package/native/gtk/fonts.h +22 -0
- package/native/gtk/gst-frames.cpp +150 -0
- package/native/gtk/gst-frames.h +47 -0
- package/native/gtk/gst-playback.cpp +496 -0
- package/native/gtk/gst-playback.h +81 -0
- package/native/gtk/gtk-backend.cpp +690 -0
- package/native/gtk/gtk-backend.h +134 -0
- package/native/gtk/host-sources.cpp +354 -0
- package/native/gtk/host-sources.h +46 -0
- package/native/gtk/image-manipulator.cpp +254 -0
- package/native/gtk/image-manipulator.h +30 -0
- package/native/gtk/image-view.cpp +256 -0
- package/native/gtk/image-view.h +54 -0
- package/native/gtk/input-replay.cpp +299 -0
- package/native/gtk/input-replay.h +36 -0
- package/native/gtk/launcher-badge.cpp +29 -0
- package/native/gtk/launcher-badge.h +21 -0
- package/native/gtk/locales.cpp +131 -0
- package/native/gtk/locales.h +23 -0
- package/native/gtk/location.cpp +274 -0
- package/native/gtk/location.h +19 -0
- package/native/gtk/main.cpp +1092 -0
- package/native/gtk/menus.cpp +447 -0
- package/native/gtk/menus.h +100 -0
- package/native/gtk/native-controls.cpp +831 -0
- package/native/gtk/native-controls.h +58 -0
- package/native/gtk/network-state.cpp +72 -0
- package/native/gtk/network-state.h +24 -0
- package/native/gtk/notifications.cpp +235 -0
- package/native/gtk/notifications.h +30 -0
- package/native/gtk/pango-text.cpp +274 -0
- package/native/gtk/pango-text.h +73 -0
- package/native/gtk/portal.cpp +451 -0
- package/native/gtk/portal.h +71 -0
- package/native/gtk/printing.cpp +338 -0
- package/native/gtk/printing.h +34 -0
- package/native/gtk/proxy-resolver.cpp +74 -0
- package/native/gtk/proxy-resolver.h +20 -0
- package/native/gtk/screens.cpp +1461 -0
- package/native/gtk/screens.h +274 -0
- package/native/gtk/scroll-view.cpp +414 -0
- package/native/gtk/scroll-view.h +82 -0
- package/native/gtk/secret-store.cpp +120 -0
- package/native/gtk/secret-store.h +27 -0
- package/native/gtk/settings-portal.cpp +129 -0
- package/native/gtk/settings-portal.h +47 -0
- package/native/gtk/split-view.cpp +1105 -0
- package/native/gtk/split-view.h +195 -0
- package/native/gtk/status-notifier.cpp +487 -0
- package/native/gtk/status-notifier.h +43 -0
- package/native/gtk/surface-input.cpp +251 -0
- package/native/gtk/surface-input.h +57 -0
- package/native/gtk/system-access.cpp +295 -0
- package/native/gtk/system-access.h +37 -0
- package/native/gtk/text-field.cpp +827 -0
- package/native/gtk/text-field.h +78 -0
- package/native/gtk/video.cpp +527 -0
- package/native/gtk/video.h +47 -0
- package/native/gtk/view-widget.cpp +431 -0
- package/native/gtk/view-widget.h +105 -0
- package/native/gtk/window-scale.cpp +95 -0
- package/native/gtk/window-scale.h +35 -0
- package/native/scripts/atspi-check.py +310 -0
- package/native/scripts/atspi-check.test.py +48 -0
- package/native/scripts/build.sh +20 -3
- package/native/scripts/compilers.sh +17 -0
- package/native/scripts/deb-depends-check.sh +22 -0
- package/native/scripts/fetch.sh +23 -2
- package/native/scripts/launch-cell.sh +157 -0
- package/native/scripts/launch-probe.sh +14 -3
- package/native/scripts/make-prebuilt.mjs +133 -44
- package/native/scripts/prebuilt-host-cache.mjs +71 -40
- package/native/scripts/reset-for-compilers.sh +44 -0
- package/native/scripts/start-xvfb.sh +35 -0
- package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
- package/native/shim/worklets/linux-reanimated-props.h +14 -0
- package/native/shim/worklets/linux-worklets.h +23 -0
- package/package.json +6 -3
- package/prebuilt.json +70 -6
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#include "animation-frames.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/worklet-host.h"
|
|
4
|
+
|
|
5
|
+
#include <gtk/gtk.h>
|
|
6
|
+
|
|
7
|
+
namespace ngn::gtk {
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
// The window whose frame clock drives the frames, while a tick callback is on it; else a timer at
|
|
11
|
+
// 60 Hz while no window is shown. GTK's frame clock stops for a window that is not mapped, so a
|
|
12
|
+
// window going away or hiding hands the frames to another, as a display link moves screens on a Mac.
|
|
13
|
+
struct Driver {
|
|
14
|
+
GtkWidget *window = nullptr;
|
|
15
|
+
guint tick = 0;
|
|
16
|
+
gulong unmapped = 0;
|
|
17
|
+
guint timer = 0;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Driver &driver() {
|
|
21
|
+
static Driver d;
|
|
22
|
+
return d;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
double nowMs() {
|
|
26
|
+
return static_cast<double>(g_get_monotonic_time()) / 1000.0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The active window when it is shown, else any shown window, else none.
|
|
30
|
+
GtkWidget *shownWindow() {
|
|
31
|
+
GtkWidget *found = nullptr;
|
|
32
|
+
GListModel *windows = gtk_window_get_toplevels();
|
|
33
|
+
guint count = g_list_model_get_n_items(windows);
|
|
34
|
+
for (guint i = 0; i < count; ++i) {
|
|
35
|
+
auto *window = GTK_WIDGET(g_list_model_get_item(windows, i));
|
|
36
|
+
g_object_unref(window);
|
|
37
|
+
if (!gtk_widget_get_mapped(window)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (gtk_window_is_active(GTK_WINDOW(window))) {
|
|
41
|
+
return window;
|
|
42
|
+
}
|
|
43
|
+
if (!found) {
|
|
44
|
+
found = window;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return found;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void stopTick() {
|
|
51
|
+
Driver &d = driver();
|
|
52
|
+
if (!d.window) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
g_signal_handler_disconnect(d.window, d.unmapped);
|
|
56
|
+
gtk_widget_remove_tick_callback(d.window, d.tick);
|
|
57
|
+
g_object_remove_weak_pointer(G_OBJECT(d.window), reinterpret_cast<gpointer *>(&d.window));
|
|
58
|
+
d.window = nullptr;
|
|
59
|
+
d.tick = 0;
|
|
60
|
+
d.unmapped = 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void stopTimer() {
|
|
64
|
+
Driver &d = driver();
|
|
65
|
+
if (d.timer != 0) {
|
|
66
|
+
g_source_remove(d.timer);
|
|
67
|
+
d.timer = 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
gboolean onTick(GtkWidget *, GdkFrameClock *clock, gpointer) {
|
|
72
|
+
// The frame clock's time is GLib's monotonic clock, the one `now` reads.
|
|
73
|
+
workletHost().frames.frame(static_cast<double>(gdk_frame_clock_get_frame_time(clock)) / 1000.0);
|
|
74
|
+
if (workletHost().frames.wanted()) {
|
|
75
|
+
return G_SOURCE_CONTINUE;
|
|
76
|
+
}
|
|
77
|
+
Driver &d = driver();
|
|
78
|
+
g_signal_handler_disconnect(d.window, d.unmapped);
|
|
79
|
+
g_object_remove_weak_pointer(G_OBJECT(d.window), reinterpret_cast<gpointer *>(&d.window));
|
|
80
|
+
d.window = nullptr;
|
|
81
|
+
d.tick = 0;
|
|
82
|
+
d.unmapped = 0;
|
|
83
|
+
return G_SOURCE_REMOVE;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
gboolean onTimer(gpointer) {
|
|
87
|
+
workletHost().frames.frame(nowMs());
|
|
88
|
+
Driver &d = driver();
|
|
89
|
+
d.timer = 0;
|
|
90
|
+
// A window shown since takes the frames over; or the timer runs again while they are wanted.
|
|
91
|
+
updateAnimationFrames();
|
|
92
|
+
return G_SOURCE_REMOVE;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
void onUnmapped(GtkWidget *, gpointer) {
|
|
96
|
+
stopTick();
|
|
97
|
+
updateAnimationFrames();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
} // namespace
|
|
101
|
+
|
|
102
|
+
void updateAnimationFrames() {
|
|
103
|
+
Driver &d = driver();
|
|
104
|
+
if (!workletHost().frames.wanted()) {
|
|
105
|
+
// The tick callback removes itself after the frame that leaves nothing waiting; a clear()
|
|
106
|
+
// between frames stops them here.
|
|
107
|
+
stopTick();
|
|
108
|
+
stopTimer();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (d.window) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (GtkWidget *window = shownWindow()) {
|
|
115
|
+
stopTimer();
|
|
116
|
+
d.window = window;
|
|
117
|
+
g_object_add_weak_pointer(G_OBJECT(window), reinterpret_cast<gpointer *>(&d.window));
|
|
118
|
+
d.tick = gtk_widget_add_tick_callback(window, onTick, nullptr, nullptr);
|
|
119
|
+
d.unmapped = g_signal_connect(window, "unmap", G_CALLBACK(onUnmapped), nullptr);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (d.timer == 0) {
|
|
123
|
+
d.timer = g_timeout_add(16, onTimer, nullptr);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
void installWorkletHost(std::shared_ptr<MountingManager> mounting, std::shared_ptr<GtkBackend> backend) {
|
|
128
|
+
auto &host = workletHost();
|
|
129
|
+
std::weak_ptr<GtkBackend> weakBackend = backend;
|
|
130
|
+
host.runOnUiThread = [weakBackend](std::function<void()> task) {
|
|
131
|
+
if (auto backend = weakBackend.lock()) {
|
|
132
|
+
backend->runOnUiThread(std::move(task));
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
host.isUiThread = [weakBackend] {
|
|
136
|
+
auto backend = weakBackend.lock();
|
|
137
|
+
return backend && backend->onUiThread();
|
|
138
|
+
};
|
|
139
|
+
host.now = nowMs;
|
|
140
|
+
host.frames.onWanted = [weakBackend](bool) {
|
|
141
|
+
// Read again on the UI thread: a start and a stop from two threads may arrive in either order.
|
|
142
|
+
if (auto backend = weakBackend.lock()) {
|
|
143
|
+
backend->runOnUiThread(updateAnimationFrames);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
std::weak_ptr<MountingManager> weak = mounting;
|
|
147
|
+
host.synchronouslyUpdateView = [weak](Tag tag, const folly::dynamic &props) {
|
|
148
|
+
if (auto mounting = weak.lock()) {
|
|
149
|
+
mounting->synchronouslyUpdateViewOnUIThread(tag, props);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
host.readMountedProps = [weak](Tag tag) -> facebook::react::Props::Shared {
|
|
153
|
+
auto mounting = weak.lock();
|
|
154
|
+
const auto *node = mounting ? mounting->tree().find(tag) : nullptr;
|
|
155
|
+
return node ? node->view.props : nullptr;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The GTK half of the worklet host (ngn/worklet-host.h), as appkit/animation-frames.h is AppKit's:
|
|
2
|
+
// GTK's main thread as the UI thread, a window's frame clock driving the animation frames while
|
|
3
|
+
// they are wanted, and the synchronous view updates of the mounting manager.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include "gtk-backend.h"
|
|
7
|
+
|
|
8
|
+
#include "ngn/mounting-manager.h"
|
|
9
|
+
|
|
10
|
+
#include <memory>
|
|
11
|
+
|
|
12
|
+
namespace ngn::gtk {
|
|
13
|
+
|
|
14
|
+
void installWorkletHost(std::shared_ptr<MountingManager> mounting, std::shared_ptr<GtkBackend> backend);
|
|
15
|
+
|
|
16
|
+
// Starts or stops the frames as the host's `frames.wanted()` says. UI thread. The installed host
|
|
17
|
+
// calls it each time that changes; a test calls it to drive the frames itself.
|
|
18
|
+
void updateAnimationFrames();
|
|
19
|
+
|
|
20
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#include "app-info.h"
|
|
2
|
+
|
|
3
|
+
#include <glib.h>
|
|
4
|
+
|
|
5
|
+
#include <sys/utsname.h>
|
|
6
|
+
#include <unistd.h>
|
|
7
|
+
|
|
8
|
+
#include <algorithm>
|
|
9
|
+
#include <cctype>
|
|
10
|
+
#include <fstream>
|
|
11
|
+
#include <map>
|
|
12
|
+
#include <sstream>
|
|
13
|
+
|
|
14
|
+
namespace ngn::gtk {
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
|
|
18
|
+
std::optional<std::string> fileText(const std::string &path) {
|
|
19
|
+
std::ifstream in(path);
|
|
20
|
+
if (!in) {
|
|
21
|
+
return std::nullopt;
|
|
22
|
+
}
|
|
23
|
+
std::stringstream text;
|
|
24
|
+
text << in.rdbuf();
|
|
25
|
+
return text.str();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A DMI field, trimmed, or nothing for the placeholders firmware leaves unfilled.
|
|
29
|
+
std::optional<std::string> dmiField(const std::string &root, const char *name) {
|
|
30
|
+
auto text = fileText(root + "/sys/class/dmi/id/" + name);
|
|
31
|
+
if (!text) {
|
|
32
|
+
return std::nullopt;
|
|
33
|
+
}
|
|
34
|
+
auto first = text->find_first_not_of(" \t\n");
|
|
35
|
+
auto last = text->find_last_not_of(" \t\n");
|
|
36
|
+
if (first == std::string::npos) {
|
|
37
|
+
return std::nullopt;
|
|
38
|
+
}
|
|
39
|
+
std::string value = text->substr(first, last - first + 1);
|
|
40
|
+
std::string folded = value;
|
|
41
|
+
std::transform(folded.begin(), folded.end(), folded.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
42
|
+
for (const char *placeholder : {"to be filled by o.e.m.", "system manufacturer", "system product name", "default string", "not specified"}) {
|
|
43
|
+
if (folded == placeholder) {
|
|
44
|
+
return std::nullopt;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The distribution's os-release. A Flatpak's /etc/os-release is its runtime's: the host's is under
|
|
51
|
+
// /run/host.
|
|
52
|
+
std::map<std::string, std::string> osRelease(const std::string &root) {
|
|
53
|
+
std::optional<std::string> release;
|
|
54
|
+
for (const char *path : {"/run/host/os-release", "/etc/os-release", "/usr/lib/os-release"}) {
|
|
55
|
+
if ((release = fileText(root + path))) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return osReleaseFields(release.value_or(""));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
} // namespace
|
|
63
|
+
|
|
64
|
+
DistroRelease distroRelease(const std::string &root) {
|
|
65
|
+
auto fields = osRelease(root);
|
|
66
|
+
auto name = fields.find("NAME");
|
|
67
|
+
return {.name = name == fields.end() || name->second.empty() ? "Linux" : name->second, .versionId = fields["VERSION_ID"]};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
MachineFacts machineFacts(const std::string &root) {
|
|
71
|
+
struct utsname name {};
|
|
72
|
+
uname(&name);
|
|
73
|
+
std::string machine = name.machine;
|
|
74
|
+
// The name the macOS host gives the same CPUs.
|
|
75
|
+
if (machine == "aarch64") {
|
|
76
|
+
machine = "arm64";
|
|
77
|
+
}
|
|
78
|
+
auto fields = osRelease(root);
|
|
79
|
+
long pages = sysconf(_SC_PHYS_PAGES), pageSize = sysconf(_SC_PAGESIZE);
|
|
80
|
+
return {
|
|
81
|
+
.manufacturer = dmiField(root, "sys_vendor"),
|
|
82
|
+
.modelId = dmiField(root, "product_name").value_or(""),
|
|
83
|
+
.osVersion = fields["VERSION_ID"],
|
|
84
|
+
.osBuildId = name.release,
|
|
85
|
+
.deviceName = std::string(g_get_host_name()),
|
|
86
|
+
.totalMemory = pages > 0 && pageSize > 0 ? static_cast<uint64_t>(pages) * static_cast<uint64_t>(pageSize) : 0,
|
|
87
|
+
.architectures = {machine},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The OS half of NgNativeDevice on Linux (the core's app-info.h): the firmware's maker and product
|
|
2
|
+
// (DMI, under /sys/class/dmi/id), the distribution's os-release (the host's, from inside a
|
|
3
|
+
// Flatpak), the kernel's release, the host name, memory and the CPU's architecture.
|
|
4
|
+
// NgNativeApplication's facts are the package's metadata.json (bundleFactsOf).
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "ngn/app-info.h"
|
|
8
|
+
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
namespace ngn::gtk {
|
|
12
|
+
|
|
13
|
+
// `root` stands for / in the paths read, for the tests.
|
|
14
|
+
MachineFacts machineFacts(const std::string &root = "");
|
|
15
|
+
|
|
16
|
+
// The distribution as PlatformConstants names it (Platform.constants on Linux): os-release's NAME
|
|
17
|
+
// ("Ubuntu", or "Linux" where it has none, as os-release defaults it) and VERSION_ID ("24.04", or
|
|
18
|
+
// empty on a rolling release, which has none). Read as machineFacts reads it.
|
|
19
|
+
struct DistroRelease {
|
|
20
|
+
std::string name;
|
|
21
|
+
std::string versionId;
|
|
22
|
+
};
|
|
23
|
+
DistroRelease distroRelease(const std::string &root = "");
|
|
24
|
+
|
|
25
|
+
} // namespace ngn::gtk
|