@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.
- 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,82 @@
|
|
|
1
|
+
// A ScrollView on GTK: a GtkScrolledWindow filling the view, its content mounted into a document
|
|
2
|
+
// view the size of the content, as the macOS host mounts it into an NSScrollView's document view.
|
|
3
|
+
// The wheel, touchpad, kinetic scrolling and scroll bars are GTK's. Each scroll reports onScroll,
|
|
4
|
+
// updates the view's state and tells the core's hit test the new offset (onOffset).
|
|
5
|
+
//
|
|
6
|
+
// Scroll bars follow `gtk-overlay-scrolling`: overlay ones float over the content; classic ones take
|
|
7
|
+
// a strip of the view, which the core's scrollers.h lays the content out without.
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "view-widget.h"
|
|
11
|
+
|
|
12
|
+
#include "ngn/desktop-props.h"
|
|
13
|
+
#include "ngn/scrollers.h"
|
|
14
|
+
|
|
15
|
+
#include <react/renderer/graphics/Point.h>
|
|
16
|
+
#include <react/renderer/graphics/Size.h>
|
|
17
|
+
|
|
18
|
+
#include <folly/dynamic.h>
|
|
19
|
+
|
|
20
|
+
#include <gtk/gtk.h>
|
|
21
|
+
|
|
22
|
+
#include <atomic>
|
|
23
|
+
#include <functional>
|
|
24
|
+
#include <memory>
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include <string>
|
|
27
|
+
#include <vector>
|
|
28
|
+
|
|
29
|
+
namespace ngn::gtk {
|
|
30
|
+
|
|
31
|
+
struct ScrollBox {
|
|
32
|
+
GtkWidget *scrolled{nullptr};
|
|
33
|
+
// The view the content mounts into, the content's size.
|
|
34
|
+
GtkWidget *document{nullptr};
|
|
35
|
+
ViewData *view{nullptr};
|
|
36
|
+
facebook::react::Size content{};
|
|
37
|
+
bool showsVertical{true};
|
|
38
|
+
bool showsHorizontal{true};
|
|
39
|
+
bool enabled{true};
|
|
40
|
+
// GTK's own controllers on the scrolled window, turned off while scrolling is not enabled, and
|
|
41
|
+
// the phase each had as it was turned off.
|
|
42
|
+
std::vector<std::pair<GtkEventController *, GtkPropagationPhase>> controllers;
|
|
43
|
+
// The `contentOffset` prop last read, and one not yet applied: it waits for the content's size
|
|
44
|
+
// and the view's, and is applied once, as the prop arrives or changes.
|
|
45
|
+
std::optional<facebook::react::Point> offsetProp;
|
|
46
|
+
std::optional<facebook::react::Point> pendingOffset;
|
|
47
|
+
guint pendingSource{0};
|
|
48
|
+
// An offset the backend set, which the state already has.
|
|
49
|
+
bool settingOffset{false};
|
|
50
|
+
// The frame clock handler measuring the gutter again once a new scroll bar style applies.
|
|
51
|
+
gulong remeasure{0};
|
|
52
|
+
GdkFrameClock *remeasureClock{nullptr};
|
|
53
|
+
int remeasureFrames{0};
|
|
54
|
+
int steadyFrames{0};
|
|
55
|
+
float measuredWidth{-1};
|
|
56
|
+
// A new gutter's clone of the node not yet applied: React Native replaces a state update not
|
|
57
|
+
// yet applied with the next one, which then clones in its place. Read where updates apply.
|
|
58
|
+
std::shared_ptr<std::atomic<bool>> relayoutOwed{std::make_shared<std::atomic<bool>>(false)};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Told on the UI thread as a scroll view's content moves: its tag and its offset.
|
|
62
|
+
using ScrollOffsetChanged = std::function<void(facebook::react::Tag, facebook::react::Point)>;
|
|
63
|
+
void onScrollOffset(ScrollOffsetChanged changed);
|
|
64
|
+
|
|
65
|
+
// The scroller style in force, and the width a classic vertical scroll bar takes in `scrolled`.
|
|
66
|
+
ScrollerStyle scrollerStyle(GtkWidget *widget);
|
|
67
|
+
float classicScrollerWidth(GtkWidget *scrolled);
|
|
68
|
+
|
|
69
|
+
// Makes `view`'s scrolled window and document, children of `widget`.
|
|
70
|
+
void makeScrollView(GtkWidget *widget, ViewData &view);
|
|
71
|
+
void destroyScrollView(ViewData &view);
|
|
72
|
+
// The widget `view`'s children mount into: its document for a scroll view, else its own.
|
|
73
|
+
GtkWidget *contentWidget(GtkWidget *widget);
|
|
74
|
+
void applyScrollViewProps(ViewData &view);
|
|
75
|
+
void applyScrollViewState(ViewData &view);
|
|
76
|
+
// Shows the scroll bars the core says show, and lays the content out again when their gutter changed.
|
|
77
|
+
void updateScrollers(ViewData &view);
|
|
78
|
+
void allocateScrollView(ViewData &view, int width, int height);
|
|
79
|
+
// scrollTo and scrollToEnd.
|
|
80
|
+
void scrollViewCommand(ViewData &view, const std::string &name, const folly::dynamic &args);
|
|
81
|
+
|
|
82
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#include "secret-store.h"
|
|
2
|
+
|
|
3
|
+
#ifdef NGN_LIBSECRET
|
|
4
|
+
#include <libsecret/secret.h>
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
#include <stdexcept>
|
|
8
|
+
|
|
9
|
+
namespace ngn::gtk {
|
|
10
|
+
|
|
11
|
+
std::string secretLabel(const std::string &appId, const std::string &service, const std::string &key) {
|
|
12
|
+
// SecureStore's default service is the app's id, which the label already starts with.
|
|
13
|
+
if (service.empty() || service == appId) {
|
|
14
|
+
return appId + " " + key;
|
|
15
|
+
}
|
|
16
|
+
return appId + " " + service + " " + key;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
namespace {
|
|
20
|
+
|
|
21
|
+
bool listed(GVariant *names, const char *name) {
|
|
22
|
+
if (!names) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
GVariantIter *iter = nullptr;
|
|
26
|
+
const gchar *each = nullptr;
|
|
27
|
+
bool found = false;
|
|
28
|
+
g_variant_get(names, "(as)", &iter);
|
|
29
|
+
while (!found && g_variant_iter_next(iter, "&s", &each)) {
|
|
30
|
+
found = g_strcmp0(each, name) == 0;
|
|
31
|
+
}
|
|
32
|
+
g_variant_iter_free(iter);
|
|
33
|
+
g_variant_unref(names);
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#ifdef NGN_LIBSECRET
|
|
38
|
+
|
|
39
|
+
class LibsecretStore final : public SecretStore {
|
|
40
|
+
public:
|
|
41
|
+
explicit LibsecretStore(std::string appId) : name_(std::move(appId)) {
|
|
42
|
+
schema_ = {.name = name_.c_str(),
|
|
43
|
+
.flags = SECRET_SCHEMA_NONE,
|
|
44
|
+
.attributes = {{"service", SECRET_SCHEMA_ATTRIBUTE_STRING},
|
|
45
|
+
{"key", SECRET_SCHEMA_ATTRIBUTE_STRING},
|
|
46
|
+
{nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
std::optional<std::string> get(const std::string &service, const std::string &key) override {
|
|
50
|
+
GError *error = nullptr;
|
|
51
|
+
gchar *value = secret_password_lookup_sync(&schema_, nullptr, &error, "service", service.c_str(), "key", key.c_str(), nullptr);
|
|
52
|
+
fail(error);
|
|
53
|
+
if (!value) {
|
|
54
|
+
return std::nullopt;
|
|
55
|
+
}
|
|
56
|
+
std::string out = value;
|
|
57
|
+
secret_password_free(value);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void set(const std::string &service, const std::string &key, const std::string &value) override {
|
|
62
|
+
GError *error = nullptr;
|
|
63
|
+
auto label = secretLabel(name_, service, key);
|
|
64
|
+
secret_password_store_sync(&schema_, SECRET_COLLECTION_DEFAULT, label.c_str(), value.c_str(), nullptr, &error, "service",
|
|
65
|
+
service.c_str(), "key", key.c_str(), nullptr);
|
|
66
|
+
fail(error);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
void remove(const std::string &service, const std::string &key) override {
|
|
70
|
+
GError *error = nullptr;
|
|
71
|
+
secret_password_clear_sync(&schema_, nullptr, &error, "service", service.c_str(), "key", key.c_str(), nullptr);
|
|
72
|
+
fail(error);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private:
|
|
76
|
+
// A locked keyring the user would not unlock, or a Secret Service that went away.
|
|
77
|
+
static void fail(GError *error) {
|
|
78
|
+
if (error) {
|
|
79
|
+
std::string message = error->message;
|
|
80
|
+
g_error_free(error);
|
|
81
|
+
throw std::runtime_error(message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
std::string name_;
|
|
86
|
+
SecretSchema schema_{};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
#endif
|
|
90
|
+
|
|
91
|
+
} // namespace
|
|
92
|
+
|
|
93
|
+
bool secretServiceOn(GDBusConnection *bus) {
|
|
94
|
+
if (!bus) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
auto names = [bus](const char *method) {
|
|
98
|
+
return g_dbus_connection_call_sync(bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", method,
|
|
99
|
+
nullptr, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE, 2000, nullptr, nullptr);
|
|
100
|
+
};
|
|
101
|
+
return listed(names("ListNames"), "org.freedesktop.secrets") || listed(names("ListActivatableNames"), "org.freedesktop.secrets");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
std::shared_ptr<SecretStore> makeSecretStore(const std::string &appId, bool flatpak) {
|
|
105
|
+
#ifdef NGN_LIBSECRET
|
|
106
|
+
if (!flatpak) {
|
|
107
|
+
GDBusConnection *bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);
|
|
108
|
+
bool on = secretServiceOn(bus);
|
|
109
|
+
g_clear_object(&bus);
|
|
110
|
+
if (!on) {
|
|
111
|
+
return nullptr;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return std::make_shared<LibsecretStore>(appId);
|
|
115
|
+
#else
|
|
116
|
+
return nullptr;
|
|
117
|
+
#endif
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SecureStore's secrets on Linux: the Secret Service (GNOME Keyring, KWallet) through libsecret.
|
|
2
|
+
// Inside a Flatpak with the Secret portal, libsecret may keep them in the app's own encrypted file
|
|
3
|
+
// instead, with its key from the portal. Outside one, with no Secret Service to reach, there is no
|
|
4
|
+
// store and SecureStore is absent.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "ngn/desktop-expo.h"
|
|
8
|
+
|
|
9
|
+
#include <gio/gio.h>
|
|
10
|
+
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
namespace ngn::gtk {
|
|
15
|
+
|
|
16
|
+
// Whether `bus` has a Secret Service running or one it can start (org.freedesktop.secrets).
|
|
17
|
+
bool secretServiceOn(GDBusConnection *bus);
|
|
18
|
+
|
|
19
|
+
// The label a secret is kept under, which the keyring's app (Seahorse, KWallet) lists it by.
|
|
20
|
+
std::string secretLabel(const std::string &appId, const std::string &service, const std::string &key);
|
|
21
|
+
|
|
22
|
+
// The app's secrets, under a schema named for `appId` with the attributes `service` and `key`;
|
|
23
|
+
// null when no Secret Service is reachable (outside a Flatpak) or libsecret is not built in (the
|
|
24
|
+
// dev loop on a Mac).
|
|
25
|
+
std::shared_ptr<SecretStore> makeSecretStore(const std::string &appId, bool flatpak);
|
|
26
|
+
|
|
27
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#include "settings-portal.h"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cstring>
|
|
5
|
+
#include <memory>
|
|
6
|
+
|
|
7
|
+
namespace ngn::gtk {
|
|
8
|
+
|
|
9
|
+
GVariant *portalValue(GVariant *value) {
|
|
10
|
+
GVariant *inner = value ? g_variant_ref(value) : nullptr;
|
|
11
|
+
while (inner && g_variant_is_of_type(inner, G_VARIANT_TYPE_VARIANT)) {
|
|
12
|
+
GVariant *next = g_variant_get_variant(inner);
|
|
13
|
+
g_variant_unref(inner);
|
|
14
|
+
inner = next;
|
|
15
|
+
}
|
|
16
|
+
return inner;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
SettingsPortal::SettingsPortal(
|
|
20
|
+
std::vector<std::string> keys, std::function<void(const std::string &, GVariant *)> changed, GDBusConnection *connection)
|
|
21
|
+
: keys_(std::move(keys)), changed_(std::move(changed)), cancellable_(g_cancellable_new()) {
|
|
22
|
+
auto ready = +[](GObject *, GAsyncResult *result, gpointer data) {
|
|
23
|
+
GDBusProxy *proxy = g_dbus_proxy_new_finish(result, nullptr);
|
|
24
|
+
if (!proxy) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
auto *self = static_cast<SettingsPortal *>(data);
|
|
28
|
+
self->proxy_ = proxy;
|
|
29
|
+
// A portal that restarts need not say its values again: read them as a new owner appears, and
|
|
30
|
+
// let go of the old one's as it goes.
|
|
31
|
+
g_signal_connect_swapped(proxy, "notify::g-name-owner", G_CALLBACK(+[](SettingsPortal *self) { self->ownerChanged(); }), self);
|
|
32
|
+
auto signal = +[](SettingsPortal *self, const char *, const char *name, GVariant *params) {
|
|
33
|
+
const char *ns = nullptr;
|
|
34
|
+
const char *key = nullptr;
|
|
35
|
+
GVariant *value = nullptr;
|
|
36
|
+
if (std::strcmp(name, "SettingChanged") == 0 && g_variant_is_of_type(params, G_VARIANT_TYPE("(ssv)"))) {
|
|
37
|
+
g_variant_get(params, "(&s&sv)", &ns, &key, &value);
|
|
38
|
+
if (std::strcmp(ns, "org.freedesktop.appearance") == 0 &&
|
|
39
|
+
std::find(self->keys_.begin(), self->keys_.end(), key) != self->keys_.end()) {
|
|
40
|
+
self->changed_(key, value);
|
|
41
|
+
}
|
|
42
|
+
g_variant_unref(value);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
g_signal_connect_swapped(proxy, "g-signal", G_CALLBACK(signal), self);
|
|
46
|
+
self->readAll();
|
|
47
|
+
};
|
|
48
|
+
const char *name = "org.freedesktop.portal.Desktop";
|
|
49
|
+
const char *path = "/org/freedesktop/portal/desktop";
|
|
50
|
+
const char *interface = "org.freedesktop.portal.Settings";
|
|
51
|
+
if (connection) {
|
|
52
|
+
g_dbus_proxy_new(connection, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, nullptr, name, path, interface, cancellable_, ready, this);
|
|
53
|
+
} else {
|
|
54
|
+
g_dbus_proxy_new_for_bus(
|
|
55
|
+
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, nullptr, name, path, interface, cancellable_, ready, this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
SettingsPortal::~SettingsPortal() {
|
|
60
|
+
g_cancellable_cancel(cancellable_);
|
|
61
|
+
g_clear_object(&cancellable_);
|
|
62
|
+
if (proxy_) {
|
|
63
|
+
g_signal_handlers_disconnect_by_data(proxy_, this);
|
|
64
|
+
g_clear_object(&proxy_);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void SettingsPortal::readAll() {
|
|
69
|
+
for (const auto &key : keys_) {
|
|
70
|
+
read(key, false);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
void SettingsPortal::ownerChanged() {
|
|
75
|
+
// Replies asked of the last owner are no longer this one's to give.
|
|
76
|
+
generation_++;
|
|
77
|
+
char *owner = g_dbus_proxy_get_name_owner(proxy_);
|
|
78
|
+
if (owner) {
|
|
79
|
+
g_free(owner);
|
|
80
|
+
readAll();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const auto &key : keys_) {
|
|
84
|
+
changed_(key, nullptr);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
namespace {
|
|
89
|
+
|
|
90
|
+
// A read of one key, for the owner it was asked of.
|
|
91
|
+
struct PortalRead {
|
|
92
|
+
SettingsPortal *self;
|
|
93
|
+
std::string key;
|
|
94
|
+
unsigned generation;
|
|
95
|
+
bool legacy;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
} // namespace
|
|
99
|
+
|
|
100
|
+
void SettingsPortal::read(const std::string &key, bool legacy) {
|
|
101
|
+
g_dbus_proxy_call(
|
|
102
|
+
proxy_, legacy ? "Read" : "ReadOne", g_variant_new("(ss)", "org.freedesktop.appearance", key.c_str()), G_DBUS_CALL_FLAGS_NONE, -1,
|
|
103
|
+
cancellable_,
|
|
104
|
+
+[](GObject *proxy, GAsyncResult *result, gpointer data) {
|
|
105
|
+
std::unique_ptr<PortalRead> call(static_cast<PortalRead *>(data));
|
|
106
|
+
GError *error = nullptr;
|
|
107
|
+
GVariant *reply = g_dbus_proxy_call_finish(G_DBUS_PROXY(proxy), result, &error);
|
|
108
|
+
if (!reply) {
|
|
109
|
+
bool cancelled = g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
|
|
110
|
+
bool unknown = g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
|
|
111
|
+
g_error_free(error);
|
|
112
|
+
// Only ReadOne's missing method asks the older Read: if that fails too, the portal has no
|
|
113
|
+
// such setting, and nothing is heard.
|
|
114
|
+
if (!cancelled && unknown && !call->legacy && call->generation == call->self->generation_) {
|
|
115
|
+
call->self->read(call->key, true);
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (call->generation == call->self->generation_) {
|
|
120
|
+
GVariant *value = g_variant_get_child_value(reply, 0);
|
|
121
|
+
call->self->changed_(call->key, value);
|
|
122
|
+
g_variant_unref(value);
|
|
123
|
+
}
|
|
124
|
+
g_variant_unref(reply);
|
|
125
|
+
},
|
|
126
|
+
new PortalRead{this, key, generation_, legacy});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The desktop's settings portal (org.freedesktop.portal.Settings) for keys of its
|
|
2
|
+
// org.freedesktop.appearance namespace: each is read once the portal answers, with ReadOne where
|
|
3
|
+
// the portal has it (version 2) and Read on an older one, and followed through SettingChanged. A
|
|
4
|
+
// session with no portal says nothing. A portal that restarts is read again as its new owner appears,
|
|
5
|
+
// and its keys are let go of (heard with a null value) as its owner goes. A reply asked of an earlier
|
|
6
|
+
// owner is dropped. On the GTK thread; replies after it goes find nothing to call.
|
|
7
|
+
#pragma once
|
|
8
|
+
|
|
9
|
+
#include <gio/gio.h>
|
|
10
|
+
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
namespace ngn::gtk {
|
|
16
|
+
|
|
17
|
+
class SettingsPortal {
|
|
18
|
+
public:
|
|
19
|
+
// `changed` hears a key and its value (as ReadOne gives it), at start and on each change, and a
|
|
20
|
+
// null value when the portal's owner goes. The portal is on the session bus, or on `connection`
|
|
21
|
+
// where a test gives one.
|
|
22
|
+
SettingsPortal(
|
|
23
|
+
std::vector<std::string> keys, std::function<void(const std::string &key, GVariant *value)> changed,
|
|
24
|
+
GDBusConnection *connection = nullptr);
|
|
25
|
+
~SettingsPortal();
|
|
26
|
+
SettingsPortal(const SettingsPortal &) = delete;
|
|
27
|
+
SettingsPortal &operator=(const SettingsPortal &) = delete;
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
// Asks for one key: with ReadOne, or with the older Read when `legacy`.
|
|
31
|
+
void read(const std::string &key, bool legacy);
|
|
32
|
+
void readAll();
|
|
33
|
+
// The portal's owner appeared, changed or went.
|
|
34
|
+
void ownerChanged();
|
|
35
|
+
|
|
36
|
+
std::vector<std::string> keys_;
|
|
37
|
+
std::function<void(const std::string &, GVariant *)> changed_;
|
|
38
|
+
GCancellable *cancellable_{nullptr};
|
|
39
|
+
GDBusProxy *proxy_{nullptr};
|
|
40
|
+
// Counts the owners the portal has had: a reply asked of an earlier one is dropped.
|
|
41
|
+
unsigned generation_{0};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// A portal value without the extra variant the older Read wraps it in: a new reference.
|
|
45
|
+
GVariant *portalValue(GVariant *value);
|
|
46
|
+
|
|
47
|
+
} // namespace ngn::gtk
|