@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,274 @@
|
|
|
1
|
+
#include "location.h"
|
|
2
|
+
|
|
3
|
+
#include "portal.h"
|
|
4
|
+
|
|
5
|
+
#include <atomic>
|
|
6
|
+
#include <map>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace ngn::gtk {
|
|
11
|
+
|
|
12
|
+
namespace {
|
|
13
|
+
|
|
14
|
+
using Authorization = LocationSource::Authorization;
|
|
15
|
+
using Fix = LocationSource::Fix;
|
|
16
|
+
|
|
17
|
+
constexpr const char *kLocation = "org.freedesktop.portal.Location";
|
|
18
|
+
// How long a single fix may take before it is given up.
|
|
19
|
+
constexpr guint kFixTimeoutSeconds = 30;
|
|
20
|
+
|
|
21
|
+
std::optional<double> known(GVariant *location, const char *key, double unknownBelow) {
|
|
22
|
+
double value = 0;
|
|
23
|
+
if (!g_variant_lookup(location, key, "d", &value) || value < unknownBelow) {
|
|
24
|
+
return std::nullopt;
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// LocationUpdated's a{sv}: the portal marks an unknown altitude with -DBL_MAX, and an unknown
|
|
30
|
+
// speed or heading with -1.
|
|
31
|
+
Fix fixOf(GVariant *location) {
|
|
32
|
+
Fix fix;
|
|
33
|
+
g_variant_lookup(location, "Latitude", "d", &fix.latitude);
|
|
34
|
+
g_variant_lookup(location, "Longitude", "d", &fix.longitude);
|
|
35
|
+
fix.accuracy = known(location, "Accuracy", 0);
|
|
36
|
+
fix.altitude = known(location, "Altitude", -1e300);
|
|
37
|
+
fix.speed = known(location, "Speed", 0);
|
|
38
|
+
fix.heading = known(location, "Heading", 0);
|
|
39
|
+
guint64 seconds = 0, micros = 0;
|
|
40
|
+
if (g_variant_lookup(location, "Timestamp", "(tt)", &seconds, µs)) {
|
|
41
|
+
fix.timestamp = static_cast<double>(seconds) * 1000 + static_cast<double>(micros) / 1000;
|
|
42
|
+
} else {
|
|
43
|
+
fix.timestamp = static_cast<double>(g_get_real_time()) / 1000;
|
|
44
|
+
}
|
|
45
|
+
return fix;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class PortalLocation final : public LocationSource, public std::enable_shared_from_this<PortalLocation> {
|
|
49
|
+
public:
|
|
50
|
+
~PortalLocation() override {
|
|
51
|
+
if (unsubscribe_) {
|
|
52
|
+
unsubscribe_();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Authorization authorization() override {
|
|
57
|
+
return static_cast<Authorization>(status_.load());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void requestAuthorization(std::function<void(Authorization)> done) override {
|
|
61
|
+
if (authorization() != Authorization::NotDetermined) {
|
|
62
|
+
done(authorization());
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
auto self = shared_from_this();
|
|
66
|
+
onMain([self, done = std::move(done)] {
|
|
67
|
+
// A session started and closed again: the portal asks, and remembers the answer itself.
|
|
68
|
+
auto session = std::make_shared<std::string>();
|
|
69
|
+
self->start(portalAccuracyOf(0), 0, session, [self, session, done](bool started, std::string) {
|
|
70
|
+
if (started) {
|
|
71
|
+
portal::closeSession(*session);
|
|
72
|
+
}
|
|
73
|
+
done(self->authorization());
|
|
74
|
+
}, nullptr);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void currentFix(double accuracy, std::function<void(std::optional<Fix>, std::string)> done) override {
|
|
79
|
+
auto self = shared_from_this();
|
|
80
|
+
onMain([self, accuracy, done = std::move(done)] {
|
|
81
|
+
struct Shot {
|
|
82
|
+
bool answered{false};
|
|
83
|
+
// Filled as CreateSession returns the path, which can be before Start has answered.
|
|
84
|
+
std::shared_ptr<std::string> session;
|
|
85
|
+
guint timeout{0};
|
|
86
|
+
std::function<void(std::optional<Fix>, std::string)> done;
|
|
87
|
+
// Drops the session's listener.
|
|
88
|
+
std::function<void()> forget;
|
|
89
|
+
void answer(std::optional<Fix> fix, std::string error) {
|
|
90
|
+
if (answered) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
answered = true;
|
|
94
|
+
forget();
|
|
95
|
+
if (timeout != 0) {
|
|
96
|
+
g_source_remove(timeout);
|
|
97
|
+
timeout = 0;
|
|
98
|
+
}
|
|
99
|
+
if (!session->empty()) {
|
|
100
|
+
portal::closeSession(*session);
|
|
101
|
+
}
|
|
102
|
+
done(std::move(fix), std::move(error));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
auto shot = std::make_shared<Shot>();
|
|
106
|
+
shot->done = done;
|
|
107
|
+
auto session = std::make_shared<std::string>();
|
|
108
|
+
shot->session = session;
|
|
109
|
+
shot->forget = [self, session] { self->fixes_.erase(*session); };
|
|
110
|
+
self->start(portalAccuracyOf(accuracy), 0, session, [shot](bool started, std::string error) {
|
|
111
|
+
if (!started) {
|
|
112
|
+
shot->answer(std::nullopt, error);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// A fix that came before Start answered has been answered, and its session closed.
|
|
116
|
+
if (shot->answered) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
auto *held = new std::shared_ptr<Shot>(shot);
|
|
120
|
+
shot->timeout = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, kFixTimeoutSeconds, +[](gpointer data) -> gboolean {
|
|
121
|
+
auto &shot = *static_cast<std::shared_ptr<Shot> *>(data);
|
|
122
|
+
shot->timeout = 0;
|
|
123
|
+
shot->answer(std::nullopt, "The location request timed out");
|
|
124
|
+
return G_SOURCE_REMOVE;
|
|
125
|
+
}, held, +[](gpointer data) { delete static_cast<std::shared_ptr<Shot> *>(data); });
|
|
126
|
+
}, [shot](const Fix &fix) { shot->answer(fix, ""); });
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
int watch(double accuracy, double distance, std::function<void(const Fix &)> fix) override {
|
|
131
|
+
int id = ++next_;
|
|
132
|
+
auto self = shared_from_this();
|
|
133
|
+
onMain([self, id, accuracy, distance, fix = std::move(fix)] {
|
|
134
|
+
auto session = std::make_shared<std::string>();
|
|
135
|
+
self->watches_[id] = session;
|
|
136
|
+
self->start(portalAccuracyOf(accuracy), distance, session, [self, id, session](bool started, std::string) {
|
|
137
|
+
// Stopped before it started: it ends now.
|
|
138
|
+
if (!self->watches_.count(id)) {
|
|
139
|
+
self->fixes_.erase(*session);
|
|
140
|
+
if (started) {
|
|
141
|
+
portal::closeSession(*session);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, fix, [self, id] { return self->watches_.count(id) == 0; });
|
|
145
|
+
});
|
|
146
|
+
return id;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void stopWatching(int handle) override {
|
|
150
|
+
auto self = shared_from_this();
|
|
151
|
+
onMain([self, handle] {
|
|
152
|
+
auto it = self->watches_.find(handle);
|
|
153
|
+
if (it == self->watches_.end()) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!it->second->empty()) {
|
|
157
|
+
portal::closeSession(*it->second);
|
|
158
|
+
self->fixes_.erase(*it->second);
|
|
159
|
+
}
|
|
160
|
+
self->watches_.erase(it);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private:
|
|
165
|
+
static void onMain(std::function<void()> fn) {
|
|
166
|
+
auto *heap = new std::function<void()>(std::move(fn));
|
|
167
|
+
g_main_context_invoke(nullptr, +[](gpointer data) -> gboolean {
|
|
168
|
+
std::unique_ptr<std::function<void()>> fn(static_cast<std::function<void()> *>(data));
|
|
169
|
+
(*fn)();
|
|
170
|
+
return G_SOURCE_REMOVE;
|
|
171
|
+
}, heap);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// A session of the Location portal, its path into `session` as it is made: `started` hears
|
|
175
|
+
// whether the portal started it (and so whether access was given), `fix` each update, `stopped`
|
|
176
|
+
// (when given) whether the caller has gone by the time the session is made, and the session is
|
|
177
|
+
// then closed unstarted and `fix` never installed. Main context.
|
|
178
|
+
void start(unsigned accuracy, double distance, std::shared_ptr<std::string> session, std::function<void(bool, std::string)> started,
|
|
179
|
+
std::function<void(const Fix &)> fix, std::function<bool()> stopped = nullptr) {
|
|
180
|
+
if (!unsubscribe_) {
|
|
181
|
+
std::weak_ptr<PortalLocation> weak = weak_from_this();
|
|
182
|
+
unsubscribe_ = portal::subscribe(kLocation, "LocationUpdated", [weak](GVariant *parameters) {
|
|
183
|
+
auto self = weak.lock();
|
|
184
|
+
if (!self) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const gchar *path = nullptr;
|
|
188
|
+
GVariant *location = nullptr;
|
|
189
|
+
g_variant_get(parameters, "(&o@a{sv})", &path, &location);
|
|
190
|
+
auto it = self->fixes_.find(path);
|
|
191
|
+
if (it != self->fixes_.end()) {
|
|
192
|
+
auto heard = it->second;
|
|
193
|
+
heard(fixOf(location));
|
|
194
|
+
}
|
|
195
|
+
g_variant_unref(location);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
GVariantBuilder *options = g_variant_builder_new(G_VARIANT_TYPE_VARDICT);
|
|
199
|
+
static std::atomic<int> tokens{0};
|
|
200
|
+
auto token = "ngnlocation" + std::to_string(++tokens);
|
|
201
|
+
g_variant_builder_add(options, "{sv}", "session_handle_token", g_variant_new_string(token.c_str()));
|
|
202
|
+
g_variant_builder_add(options, "{sv}", "distance-threshold", g_variant_new_uint32(distance > 0 ? static_cast<guint32>(distance) : 0));
|
|
203
|
+
g_variant_builder_add(options, "{sv}", "time-threshold", g_variant_new_uint32(0));
|
|
204
|
+
g_variant_builder_add(options, "{sv}", "accuracy", g_variant_new_uint32(accuracy));
|
|
205
|
+
auto self = shared_from_this();
|
|
206
|
+
portal::request(
|
|
207
|
+
kLocation, "CreateSession", g_variant_new("()"), options, nullptr,
|
|
208
|
+
[self, session, started, fix, stopped](portal::Outcome outcome, GVariant *) {
|
|
209
|
+
if (outcome != portal::Outcome::Done || session->empty()) {
|
|
210
|
+
if (outcome == portal::Outcome::Absent) {
|
|
211
|
+
self->status_ = static_cast<int>(Authorization::Restricted);
|
|
212
|
+
}
|
|
213
|
+
started(false, outcome == portal::Outcome::Absent ? "No Location portal answers on this desktop" : "The location session could not be made");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (stopped && stopped()) {
|
|
217
|
+
portal::closeSession(*session);
|
|
218
|
+
started(false, "The location watch was stopped");
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (fix) {
|
|
222
|
+
self->fixes_[*session] = fix;
|
|
223
|
+
}
|
|
224
|
+
portal::parentHandle(portal::frontWindow(), [self, session, started](const std::string &handle, std::function<void()> drop) {
|
|
225
|
+
portal::request(kLocation, "Start", g_variant_new("(os)", session->c_str(), handle.c_str()), g_variant_builder_new(G_VARIANT_TYPE_VARDICT),
|
|
226
|
+
nullptr, [self, session, started, drop](portal::Outcome outcome, GVariant *) {
|
|
227
|
+
drop();
|
|
228
|
+
bool ok = outcome == portal::Outcome::Done;
|
|
229
|
+
self->status_ = static_cast<int>(ok ? Authorization::Granted
|
|
230
|
+
: outcome == portal::Outcome::Absent ? Authorization::Restricted
|
|
231
|
+
: Authorization::Denied);
|
|
232
|
+
if (!ok) {
|
|
233
|
+
self->fixes_.erase(*session);
|
|
234
|
+
portal::closeSession(*session);
|
|
235
|
+
}
|
|
236
|
+
started(ok, ok ? "" : "Not authorized to use location services");
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
},
|
|
240
|
+
false, [session](const std::string &path) { *session = path; });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
std::atomic<int> status_{static_cast<int>(Authorization::NotDetermined)};
|
|
244
|
+
std::atomic<int> next_{0};
|
|
245
|
+
// Main context only.
|
|
246
|
+
std::function<void()> unsubscribe_;
|
|
247
|
+
std::map<std::string, std::function<void(const Fix &)>> fixes_;
|
|
248
|
+
std::map<int, std::shared_ptr<std::string>> watches_;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
} // namespace
|
|
252
|
+
|
|
253
|
+
unsigned portalAccuracyOf(double metres) {
|
|
254
|
+
// The portal's levels: 1 country, 2 city, 3 neighbourhood, 4 street, 5 exact.
|
|
255
|
+
if (metres <= 0 || metres <= 10) {
|
|
256
|
+
return 5;
|
|
257
|
+
}
|
|
258
|
+
if (metres <= 100) {
|
|
259
|
+
return 4;
|
|
260
|
+
}
|
|
261
|
+
if (metres <= 1000) {
|
|
262
|
+
return 3;
|
|
263
|
+
}
|
|
264
|
+
if (metres <= 10000) {
|
|
265
|
+
return 2;
|
|
266
|
+
}
|
|
267
|
+
return 1;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
std::shared_ptr<LocationSource> makeLocationSource() {
|
|
271
|
+
return std::make_shared<PortalLocation>();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
} // namespace ngn::gtk
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The OS half of NgNativeLocation on Linux (the core's location.h): the Location portal, which asks
|
|
2
|
+
// GeoClue, inside a sandbox and outside one. Each fix and each watch is a portal session of its
|
|
3
|
+
// own; the portal decides on access as a session starts, so authorization is what the last start
|
|
4
|
+
// was answered, not determined until one has been. Where no Location portal answers, location is
|
|
5
|
+
// restricted. Geocoding is absent: there is no geocoder to ask.
|
|
6
|
+
#pragma once
|
|
7
|
+
|
|
8
|
+
#include "ngn/location.h"
|
|
9
|
+
|
|
10
|
+
#include <memory>
|
|
11
|
+
|
|
12
|
+
namespace ngn::gtk {
|
|
13
|
+
|
|
14
|
+
// The portal accuracy level (0 none to 5 exact) for an accuracy in metres; 0 or less is exact.
|
|
15
|
+
unsigned portalAccuracyOf(double metres);
|
|
16
|
+
|
|
17
|
+
std::shared_ptr<LocationSource> makeLocationSource();
|
|
18
|
+
|
|
19
|
+
} // namespace ngn::gtk
|