@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,408 @@
|
|
|
1
|
+
// The photo picker of a host with no photo library (photo-library.h's makeFilePhotoPicker), and
|
|
2
|
+
// the two file readers it describes a pick with: an MP4 or QuickTime file's moov box, and a JPEG's
|
|
3
|
+
// EXIF.
|
|
4
|
+
#include "ngn/photo-library.h"
|
|
5
|
+
|
|
6
|
+
#include <chrono>
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <filesystem>
|
|
9
|
+
#include <fstream>
|
|
10
|
+
#include <map>
|
|
11
|
+
#include <thread>
|
|
12
|
+
|
|
13
|
+
namespace ngn {
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
namespace fs = std::filesystem;
|
|
18
|
+
|
|
19
|
+
// Big-endian reads of the file at `in`'s position.
|
|
20
|
+
uint64_t readBig(std::istream &in, int bytes) {
|
|
21
|
+
uint64_t value = 0;
|
|
22
|
+
for (int i = 0; i < bytes; i++) {
|
|
23
|
+
int c = in.get();
|
|
24
|
+
if (c == EOF) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
value = (value << 8) | static_cast<uint8_t>(c);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The boxes between `from` and `to`, each as its type, where its contents start, and where it ends.
|
|
33
|
+
struct Box {
|
|
34
|
+
std::string type;
|
|
35
|
+
uint64_t start{0};
|
|
36
|
+
uint64_t end{0};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
std::optional<Box> boxAt(std::istream &in, uint64_t at, uint64_t to) {
|
|
40
|
+
if (at + 8 > to) {
|
|
41
|
+
return std::nullopt;
|
|
42
|
+
}
|
|
43
|
+
in.clear();
|
|
44
|
+
in.seekg(static_cast<std::streamoff>(at));
|
|
45
|
+
uint64_t size = readBig(in, 4);
|
|
46
|
+
std::string type(4, '\0');
|
|
47
|
+
in.read(type.data(), 4);
|
|
48
|
+
uint64_t start = at + 8;
|
|
49
|
+
if (size == 1) {
|
|
50
|
+
size = readBig(in, 8);
|
|
51
|
+
start += 8;
|
|
52
|
+
} else if (size == 0) {
|
|
53
|
+
size = to - at;
|
|
54
|
+
}
|
|
55
|
+
// `at` is inside the parent (checked above), so `to - at` cannot wrap, and a size past it would.
|
|
56
|
+
if (!in || size < start - at || size > to - at) {
|
|
57
|
+
return std::nullopt;
|
|
58
|
+
}
|
|
59
|
+
return Box{type, start, at + size};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
std::optional<Box> child(std::istream &in, const Box &parent, const std::string &type) {
|
|
63
|
+
for (uint64_t at = parent.start; auto box = boxAt(in, at, parent.end); at = box->end) {
|
|
64
|
+
if (box->type == type) {
|
|
65
|
+
return box;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return std::nullopt;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A full box's version, read from its first byte, leaving `in` after its flags.
|
|
72
|
+
int versionAt(std::istream &in, const Box &box) {
|
|
73
|
+
in.clear();
|
|
74
|
+
in.seekg(static_cast<std::streamoff>(box.start));
|
|
75
|
+
int version = in.get();
|
|
76
|
+
in.ignore(3);
|
|
77
|
+
return version;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// expo's names for the EXIF tags of each IFD, as iOS answers them (the TIFF and Exif tags at the
|
|
81
|
+
// top level, the GPS ones with GPS before their names).
|
|
82
|
+
const std::map<uint16_t, const char *> &mainTags() {
|
|
83
|
+
static const std::map<uint16_t, const char *> tags{
|
|
84
|
+
{0x0100, "ImageWidth"}, {0x0101, "ImageLength"}, {0x010E, "ImageDescription"}, {0x010F, "Make"},
|
|
85
|
+
{0x0110, "Model"}, {0x0112, "Orientation"}, {0x011A, "XResolution"}, {0x011B, "YResolution"},
|
|
86
|
+
{0x0128, "ResolutionUnit"}, {0x0131, "Software"}, {0x0132, "DateTime"}, {0x013B, "Artist"},
|
|
87
|
+
{0x8298, "Copyright"}, {0x829A, "ExposureTime"}, {0x829D, "FNumber"}, {0x8822, "ExposureProgram"},
|
|
88
|
+
{0x8827, "ISOSpeedRatings"}, {0x9003, "DateTimeOriginal"}, {0x9004, "DateTimeDigitized"}, {0x9010, "OffsetTime"},
|
|
89
|
+
{0x9011, "OffsetTimeOriginal"}, {0x9012, "OffsetTimeDigitized"}, {0x9201, "ShutterSpeedValue"}, {0x9202, "ApertureValue"},
|
|
90
|
+
{0x9203, "BrightnessValue"}, {0x9204, "ExposureBiasValue"}, {0x9207, "MeteringMode"}, {0x9209, "Flash"},
|
|
91
|
+
{0x920A, "FocalLength"}, {0x9290, "SubsecTime"}, {0x9291, "SubsecTimeOriginal"}, {0x9292, "SubsecTimeDigitized"},
|
|
92
|
+
{0xA001, "ColorSpace"}, {0xA002, "PixelXDimension"}, {0xA003, "PixelYDimension"}, {0xA402, "ExposureMode"},
|
|
93
|
+
{0xA403, "WhiteBalance"}, {0xA404, "DigitalZoomRatio"}, {0xA405, "FocalLenIn35mmFilm"}, {0xA406, "SceneCaptureType"},
|
|
94
|
+
{0xA432, "LensSpecification"}, {0xA433, "LensMake"}, {0xA434, "LensModel"},
|
|
95
|
+
};
|
|
96
|
+
return tags;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const std::map<uint16_t, const char *> &gpsTags() {
|
|
100
|
+
static const std::map<uint16_t, const char *> tags{
|
|
101
|
+
{0x0001, "GPSLatitudeRef"}, {0x0002, "GPSLatitude"}, {0x0003, "GPSLongitudeRef"}, {0x0004, "GPSLongitude"},
|
|
102
|
+
{0x0005, "GPSAltitudeRef"}, {0x0006, "GPSAltitude"}, {0x0007, "GPSTimeStamp"}, {0x000C, "GPSSpeedRef"},
|
|
103
|
+
{0x000D, "GPSSpeed"}, {0x0010, "GPSImgDirectionRef"}, {0x0011, "GPSImgDirection"}, {0x001D, "GPSDateStamp"},
|
|
104
|
+
};
|
|
105
|
+
return tags;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// A TIFF structure inside the APP1 segment, read with its byte order.
|
|
109
|
+
struct Tiff {
|
|
110
|
+
const std::string &bytes;
|
|
111
|
+
size_t base;
|
|
112
|
+
bool little;
|
|
113
|
+
|
|
114
|
+
bool has(size_t at, size_t count) const {
|
|
115
|
+
return base + at + count <= bytes.size() && base + at + count >= base + at;
|
|
116
|
+
}
|
|
117
|
+
uint32_t read(size_t at, int size) const {
|
|
118
|
+
uint32_t value = 0;
|
|
119
|
+
for (int i = 0; i < size; i++) {
|
|
120
|
+
auto byte = static_cast<uint8_t>(bytes[base + at + (little ? size - 1 - i : i)]);
|
|
121
|
+
value = (value << 8) | byte;
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// One entry's value: a number, a string, or an array of numbers when it holds more than one.
|
|
128
|
+
folly::dynamic valueOf(const Tiff &tiff, size_t entry) {
|
|
129
|
+
static const int sizes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8};
|
|
130
|
+
uint32_t type = tiff.read(entry + 2, 2);
|
|
131
|
+
uint32_t count = tiff.read(entry + 4, 4);
|
|
132
|
+
if (type == 0 || type > 10 || count == 0 || count > 1 << 16) {
|
|
133
|
+
return nullptr;
|
|
134
|
+
}
|
|
135
|
+
size_t length = static_cast<size_t>(sizes[type]) * count;
|
|
136
|
+
size_t at = length <= 4 ? entry + 8 : tiff.read(entry + 8, 4);
|
|
137
|
+
if (!tiff.has(at, length)) {
|
|
138
|
+
return nullptr;
|
|
139
|
+
}
|
|
140
|
+
if (type == 2 || type == 7) {
|
|
141
|
+
std::string text = tiff.bytes.substr(tiff.base + at, length);
|
|
142
|
+
if (type == 2) {
|
|
143
|
+
text = text.substr(0, text.find('\0'));
|
|
144
|
+
}
|
|
145
|
+
return text;
|
|
146
|
+
}
|
|
147
|
+
folly::dynamic values = folly::dynamic::array();
|
|
148
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
149
|
+
size_t at_i = at + static_cast<size_t>(sizes[type]) * i;
|
|
150
|
+
switch (type) {
|
|
151
|
+
case 1:
|
|
152
|
+
case 6:
|
|
153
|
+
values.push_back(static_cast<int64_t>(type == 6 ? static_cast<int8_t>(tiff.read(at_i, 1)) : tiff.read(at_i, 1)));
|
|
154
|
+
break;
|
|
155
|
+
case 3:
|
|
156
|
+
case 8:
|
|
157
|
+
values.push_back(static_cast<int64_t>(type == 8 ? static_cast<int16_t>(tiff.read(at_i, 2)) : tiff.read(at_i, 2)));
|
|
158
|
+
break;
|
|
159
|
+
case 4:
|
|
160
|
+
case 9:
|
|
161
|
+
values.push_back(type == 9 ? static_cast<int64_t>(static_cast<int32_t>(tiff.read(at_i, 4))) : static_cast<int64_t>(tiff.read(at_i, 4)));
|
|
162
|
+
break;
|
|
163
|
+
default: {
|
|
164
|
+
// A rational: 5 unsigned, 10 signed.
|
|
165
|
+
// Each branch is a double before the conditional joins them, or a signed one would turn unsigned.
|
|
166
|
+
auto word = [&](size_t from) {
|
|
167
|
+
return type == 10 ? static_cast<double>(static_cast<int32_t>(tiff.read(from, 4))) : static_cast<double>(tiff.read(from, 4));
|
|
168
|
+
};
|
|
169
|
+
double num = word(at_i);
|
|
170
|
+
double den = word(at_i + 4);
|
|
171
|
+
values.push_back(den == 0 ? 0.0 : num / den);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return count == 1 ? values[0] : values;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// The entries of the IFD at `at` into `out`, with what its pointers to the Exif and GPS IFDs say.
|
|
179
|
+
void readIfd(const Tiff &tiff, size_t at, const std::map<uint16_t, const char *> &names, folly::dynamic &out, std::optional<size_t> *exif,
|
|
180
|
+
std::optional<size_t> *gps) {
|
|
181
|
+
if (!tiff.has(at, 2)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
uint32_t count = tiff.read(at, 2);
|
|
185
|
+
for (uint32_t i = 0; i < count; i++) {
|
|
186
|
+
size_t entry = at + 2 + 12 * static_cast<size_t>(i);
|
|
187
|
+
if (!tiff.has(entry, 12)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
auto tag = static_cast<uint16_t>(tiff.read(entry, 2));
|
|
191
|
+
if (tag == 0x8769 && exif) {
|
|
192
|
+
*exif = tiff.read(entry + 8, 4);
|
|
193
|
+
} else if (tag == 0x8825 && gps) {
|
|
194
|
+
*gps = tiff.read(entry + 8, 4);
|
|
195
|
+
} else if (auto name = names.find(tag); name != names.end()) {
|
|
196
|
+
auto value = valueOf(tiff, entry);
|
|
197
|
+
if (!value.isNull()) {
|
|
198
|
+
out[name->second] = std::move(value);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Degrees, minutes and seconds as degrees, as iOS gives GPSLatitude and GPSLongitude.
|
|
205
|
+
void toDegrees(folly::dynamic &exif, const char *key) {
|
|
206
|
+
auto *value = exif.get_ptr(key);
|
|
207
|
+
if (value && value->isArray() && value->size() == 3 && (*value)[0].isNumber()) {
|
|
208
|
+
*value = (*value)[0].asDouble() + (*value)[1].asDouble() / 60 + (*value)[2].asDouble() / 3600;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
class FilePhotoPicker final : public PhotoPicker, public std::enable_shared_from_this<FilePhotoPicker> {
|
|
213
|
+
public:
|
|
214
|
+
FilePhotoPicker(std::shared_ptr<FileDialogs> dialogs, std::string folder, std::function<std::optional<std::pair<double, double>>(const std::string &)> imageSize)
|
|
215
|
+
: dialogs_(std::move(dialogs)), folder_(std::move(folder)), imageSize_(std::move(imageSize)) {}
|
|
216
|
+
|
|
217
|
+
void pick(const folly::dynamic &options, std::function<void(std::optional<std::vector<Picked>>)> done) override {
|
|
218
|
+
auto kinds = mediaKindsOf(options);
|
|
219
|
+
bool multiple = options.getDefault("allowsMultipleSelection", false) == true;
|
|
220
|
+
auto limit = options.getDefault("selectionLimit", 0);
|
|
221
|
+
// 2^64 is the first double past size_t: a limit at or above it is no limit.
|
|
222
|
+
constexpr double pastSize = 18446744073709551616.0;
|
|
223
|
+
size_t most = multiple ? (limit.isNumber() && limit.asDouble() >= 1 ? (limit.asDouble() < pastSize ? static_cast<size_t>(limit.asDouble()) : 0) : 0) : 1;
|
|
224
|
+
FileDialogs::OpenRequest request{.multiple = multiple};
|
|
225
|
+
if (kinds.photos) {
|
|
226
|
+
request.types.emplace_back("image/*");
|
|
227
|
+
}
|
|
228
|
+
if (kinds.videos) {
|
|
229
|
+
request.types.emplace_back("video/*");
|
|
230
|
+
}
|
|
231
|
+
const char *noun = kinds.photos && kinds.videos ? "Images and Videos" : kinds.videos ? "Videos" : "Images";
|
|
232
|
+
request.filterName = noun;
|
|
233
|
+
request.title = kinds.photos && kinds.videos ? (multiple ? "Choose Images or Videos" : "Choose an Image or Video")
|
|
234
|
+
: kinds.videos ? (multiple ? "Choose Videos" : "Choose a Video")
|
|
235
|
+
: (multiple ? "Choose Images" : "Choose an Image");
|
|
236
|
+
dialogs_->openFiles(request, [self = shared_from_this(), most, done = std::move(done)](std::optional<std::vector<std::string>> paths) {
|
|
237
|
+
if (!paths) {
|
|
238
|
+
done(std::nullopt);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (most > 0 && paths->size() > most) {
|
|
242
|
+
paths->resize(most);
|
|
243
|
+
}
|
|
244
|
+
// Copied on a thread of its own: the panel answers on the UI thread, and a video can be large.
|
|
245
|
+
std::thread([self, paths = std::move(*paths), done = std::move(done)] {
|
|
246
|
+
std::vector<Picked> picked;
|
|
247
|
+
for (size_t i = 0; i < paths.size(); i++) {
|
|
248
|
+
if (auto one = self->describe(paths[i], i)) {
|
|
249
|
+
picked.push_back(std::move(*one));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
done(std::move(picked));
|
|
253
|
+
}).detach();
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private:
|
|
258
|
+
// The file copied into the caches, as the picker answers it; nothing when it cannot be copied.
|
|
259
|
+
std::optional<Picked> describe(const std::string &path, size_t index) {
|
|
260
|
+
std::error_code error;
|
|
261
|
+
fs::path source(path);
|
|
262
|
+
// A folder of its own per file keeps two files of one name apart.
|
|
263
|
+
auto folder = fs::path(folder_) / (std::to_string(std::chrono::system_clock::now().time_since_epoch().count()) + "-" + std::to_string(index));
|
|
264
|
+
fs::create_directories(folder, error);
|
|
265
|
+
auto at = folder / source.filename();
|
|
266
|
+
if (error || !fs::copy_file(source, at, fs::copy_options::overwrite_existing, error) || error) {
|
|
267
|
+
return std::nullopt;
|
|
268
|
+
}
|
|
269
|
+
Picked out;
|
|
270
|
+
out.uri = fileUri(at.string());
|
|
271
|
+
out.fileName = source.filename().string();
|
|
272
|
+
out.mimeType = mimeTypeOf(out.fileName);
|
|
273
|
+
auto size = fs::file_size(at, error);
|
|
274
|
+
out.fileSize = error ? 0 : static_cast<double>(size);
|
|
275
|
+
if (out.mimeType.starts_with("video/")) {
|
|
276
|
+
out.type = "video";
|
|
277
|
+
if (auto facts = isoVideoFacts(at.string())) {
|
|
278
|
+
out.width = facts->width;
|
|
279
|
+
out.height = facts->height;
|
|
280
|
+
out.duration = facts->duration;
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
out.type = "image";
|
|
284
|
+
if (auto measured = imageSize_ ? imageSize_(at.string()) : std::nullopt) {
|
|
285
|
+
out.width = measured->first;
|
|
286
|
+
out.height = measured->second;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
std::shared_ptr<FileDialogs> dialogs_;
|
|
293
|
+
std::string folder_;
|
|
294
|
+
std::function<std::optional<std::pair<double, double>>(const std::string &)> imageSize_;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
} // namespace
|
|
298
|
+
|
|
299
|
+
std::optional<VideoFacts> isoVideoFacts(const std::string &path) {
|
|
300
|
+
std::ifstream in(path, std::ios::binary);
|
|
301
|
+
if (!in) {
|
|
302
|
+
return std::nullopt;
|
|
303
|
+
}
|
|
304
|
+
in.seekg(0, std::ios::end);
|
|
305
|
+
Box file{"", 0, static_cast<uint64_t>(in.tellg())};
|
|
306
|
+
auto moov = child(in, file, "moov");
|
|
307
|
+
auto mvhd = moov ? child(in, *moov, "mvhd") : std::nullopt;
|
|
308
|
+
if (!mvhd) {
|
|
309
|
+
return std::nullopt;
|
|
310
|
+
}
|
|
311
|
+
VideoFacts facts;
|
|
312
|
+
int version = versionAt(in, *mvhd);
|
|
313
|
+
// Version, flags, two times, the time scale and the duration: all inside the box.
|
|
314
|
+
if (mvhd->end - mvhd->start < (version == 1 ? 32u : 20u)) {
|
|
315
|
+
return std::nullopt;
|
|
316
|
+
}
|
|
317
|
+
in.ignore(version == 1 ? 16 : 8);
|
|
318
|
+
double scale = static_cast<double>(readBig(in, 4));
|
|
319
|
+
double duration = static_cast<double>(readBig(in, version == 1 ? 8 : 4));
|
|
320
|
+
facts.duration = scale > 0 ? duration / scale * 1000 : 0;
|
|
321
|
+
for (uint64_t at = moov->start; auto box = boxAt(in, at, moov->end); at = box->end) {
|
|
322
|
+
auto tkhd = box->type == "trak" ? child(in, *box, "tkhd") : std::nullopt;
|
|
323
|
+
if (!tkhd) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
int v = versionAt(in, *tkhd);
|
|
327
|
+
// Up to the width and height, which are the box's last fields: a shorter box has no size.
|
|
328
|
+
if (tkhd->end - tkhd->start < (v == 1 ? 96u : 84u)) {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
// Times, track id, reserved and duration; then reserved, layer, group, volume and reserved.
|
|
332
|
+
in.ignore((v == 1 ? 32 : 20) + 16);
|
|
333
|
+
int32_t matrix[9];
|
|
334
|
+
for (auto &value : matrix) {
|
|
335
|
+
value = static_cast<int32_t>(readBig(in, 4));
|
|
336
|
+
}
|
|
337
|
+
double width = static_cast<double>(readBig(in, 4)) / 65536;
|
|
338
|
+
double height = static_cast<double>(readBig(in, 4)) / 65536;
|
|
339
|
+
// A sound track has no size.
|
|
340
|
+
if (!in || width <= 0 || height <= 0) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
// Turned a quarter, as a phone's portrait video is: its size as it plays.
|
|
344
|
+
bool turned = matrix[0] == 0 && matrix[4] == 0;
|
|
345
|
+
facts.width = turned ? height : width;
|
|
346
|
+
facts.height = turned ? width : height;
|
|
347
|
+
return facts;
|
|
348
|
+
}
|
|
349
|
+
return facts;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
folly::dynamic jpegExif(const std::string &bytes) {
|
|
353
|
+
if (bytes.size() < 4 || static_cast<uint8_t>(bytes[0]) != 0xFF || static_cast<uint8_t>(bytes[1]) != 0xD8) {
|
|
354
|
+
return nullptr;
|
|
355
|
+
}
|
|
356
|
+
for (size_t at = 2; at + 4 <= bytes.size();) {
|
|
357
|
+
if (static_cast<uint8_t>(bytes[at]) != 0xFF) {
|
|
358
|
+
return nullptr;
|
|
359
|
+
}
|
|
360
|
+
// Any number of 0xFF fill bytes may come before a marker's code.
|
|
361
|
+
while (at + 4 <= bytes.size() && static_cast<uint8_t>(bytes[at + 1]) == 0xFF) {
|
|
362
|
+
at++;
|
|
363
|
+
}
|
|
364
|
+
if (at + 4 > bytes.size()) {
|
|
365
|
+
return nullptr;
|
|
366
|
+
}
|
|
367
|
+
auto marker = static_cast<uint8_t>(bytes[at + 1]);
|
|
368
|
+
size_t length = (static_cast<uint8_t>(bytes[at + 2]) << 8) | static_cast<uint8_t>(bytes[at + 3]);
|
|
369
|
+
// The image data starts: no EXIF came before it.
|
|
370
|
+
if (marker == 0xDA || marker == 0xD9 || length < 2) {
|
|
371
|
+
return nullptr;
|
|
372
|
+
}
|
|
373
|
+
if (marker == 0xE1 && length >= 16 && bytes.compare(at + 4, 6, std::string("Exif\0\0", 6)) == 0) {
|
|
374
|
+
// The TIFF header: its byte order, 42, and where its first IFD is.
|
|
375
|
+
size_t base = at + 10;
|
|
376
|
+
std::string segment = bytes.substr(0, std::min(bytes.size(), at + 2 + length));
|
|
377
|
+
bool little = segment.compare(base, 2, "II") == 0;
|
|
378
|
+
if (!little && segment.compare(base, 2, "MM") != 0) {
|
|
379
|
+
return nullptr;
|
|
380
|
+
}
|
|
381
|
+
Tiff tiff{segment, base, little};
|
|
382
|
+
if (!tiff.has(0, 8) || tiff.read(2, 2) != 42) {
|
|
383
|
+
return nullptr;
|
|
384
|
+
}
|
|
385
|
+
folly::dynamic out = folly::dynamic::object();
|
|
386
|
+
std::optional<size_t> exif, gps;
|
|
387
|
+
readIfd(tiff, tiff.read(4, 4), mainTags(), out, &exif, &gps);
|
|
388
|
+
if (exif) {
|
|
389
|
+
readIfd(tiff, *exif, mainTags(), out, nullptr, nullptr);
|
|
390
|
+
}
|
|
391
|
+
if (gps) {
|
|
392
|
+
readIfd(tiff, *gps, gpsTags(), out, nullptr, nullptr);
|
|
393
|
+
toDegrees(out, "GPSLatitude");
|
|
394
|
+
toDegrees(out, "GPSLongitude");
|
|
395
|
+
}
|
|
396
|
+
return out;
|
|
397
|
+
}
|
|
398
|
+
at += 2 + length;
|
|
399
|
+
}
|
|
400
|
+
return nullptr;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
std::shared_ptr<PhotoPicker> makeFilePhotoPicker(std::shared_ptr<FileDialogs> dialogs, std::string folder,
|
|
404
|
+
std::function<std::optional<std::pair<double, double>>(const std::string &path)> imageSize) {
|
|
405
|
+
return std::make_shared<FilePhotoPicker>(std::move(dialogs), std::move(folder), std::move(imageSize));
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
} // namespace ngn
|
|
@@ -512,25 +512,21 @@ struct Notifications : NativeModule {
|
|
|
512
512
|
center->setBadge(static_cast<int>(args[0].asDouble()));
|
|
513
513
|
promise.resolve(true);
|
|
514
514
|
});
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
promise
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
promise.reject(error);
|
|
525
|
-
}
|
|
515
|
+
if (push) {
|
|
516
|
+
promise("getDevicePushTokenAsync", [push, os = events->os()](const folly::dynamic &, JsPromise promise) {
|
|
517
|
+
push->request([promise, os](std::optional<std::string> token, std::string error) {
|
|
518
|
+
if (token) {
|
|
519
|
+
promise.resolve(folly::dynamic::object("type", os)("data", *token));
|
|
520
|
+
} else {
|
|
521
|
+
promise.reject(error);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
526
524
|
});
|
|
527
|
-
|
|
528
|
-
promise("unregisterForNotificationsAsync", [push](const folly::dynamic &, JsPromise promise) {
|
|
529
|
-
if (push) {
|
|
525
|
+
promise("unregisterForNotificationsAsync", [push](const folly::dynamic &, JsPromise promise) {
|
|
530
526
|
push->unregister();
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
527
|
+
promise.resolve(nullptr);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
534
530
|
listeners();
|
|
535
531
|
subscription_ = events->listen([this](const folly::dynamic &event) { emit("ngNativeNotifications", event); });
|
|
536
532
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#include "ngn/photo-library.h"
|
|
2
2
|
|
|
3
|
+
#include "ngn/bytes.h"
|
|
3
4
|
#include "ngn/camera.h"
|
|
4
5
|
|
|
6
|
+
#include <fstream>
|
|
7
|
+
#include <iterator>
|
|
5
8
|
#include <mutex>
|
|
6
9
|
#include <set>
|
|
7
10
|
#include <stdexcept>
|
|
@@ -329,16 +332,25 @@ std::shared_ptr<NativeModule> makeMediaLibraryModule(std::shared_ptr<PhotoLibrar
|
|
|
329
332
|
return std::make_shared<MediaLibrary>(std::move(library), noPrompts, std::move(files));
|
|
330
333
|
}
|
|
331
334
|
|
|
332
|
-
std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary> library, bool noPrompts,
|
|
335
|
+
std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoPicker> picker, std::shared_ptr<PhotoLibrary> library, bool noPrompts,
|
|
336
|
+
std::optional<PickerCamera> camera) {
|
|
333
337
|
struct ImagePicker : NativeModule {
|
|
334
|
-
ImagePicker(std::shared_ptr<
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
permissions
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
ImagePicker(std::shared_ptr<PhotoPicker> photos, std::shared_ptr<PhotoLibrary> library, bool noPrompts, std::optional<PickerCamera> camera)
|
|
339
|
+
: NativeModule("NgNativeImagePicker") {
|
|
340
|
+
if (library) {
|
|
341
|
+
Permissions permissions{library, noPrompts};
|
|
342
|
+
promise("getMediaLibraryPermissionsAsync", [permissions](const folly::dynamic &args, JsPromise promise) {
|
|
343
|
+
permissions.get(flagArg(args, 0), std::move(promise));
|
|
344
|
+
});
|
|
345
|
+
promise("requestMediaLibraryPermissionsAsync", [permissions](const folly::dynamic &args, JsPromise promise) {
|
|
346
|
+
permissions.request(flagArg(args, 0), std::move(promise));
|
|
347
|
+
});
|
|
348
|
+
} else {
|
|
349
|
+
// An open panel over the user's files, which asks nothing first.
|
|
350
|
+
auto granted = [](const folly::dynamic &, JsPromise promise) { promise.resolve(permissionOf(Access::Granted)); };
|
|
351
|
+
promise("getMediaLibraryPermissionsAsync", granted);
|
|
352
|
+
promise("requestMediaLibraryPermissionsAsync", granted);
|
|
353
|
+
}
|
|
342
354
|
folly::dynamic canceled = folly::dynamic::object("canceled", true)("assets", nullptr);
|
|
343
355
|
if (camera) {
|
|
344
356
|
promise("getCameraPermissionsAsync", [hardware = camera->hardware](const folly::dynamic &, JsPromise promise) {
|
|
@@ -363,23 +375,40 @@ std::shared_ptr<NativeModule> makeImagePickerModule(std::shared_ptr<PhotoLibrary
|
|
|
363
375
|
return;
|
|
364
376
|
}
|
|
365
377
|
auto options = args.empty() || !args[0].isObject() ? folly::dynamic::object() : args[0];
|
|
366
|
-
|
|
378
|
+
bool base64 = options.getDefault("base64", false) == true;
|
|
379
|
+
bool exif = options.getDefault("exif", false) == true;
|
|
380
|
+
photos->pick(options, [promise, canceled, base64, exif](std::optional<std::vector<PhotoPicker::Picked>> picked) {
|
|
367
381
|
if (!picked || picked->empty()) {
|
|
368
382
|
promise.resolve(canceled);
|
|
369
383
|
return;
|
|
370
384
|
}
|
|
371
385
|
folly::dynamic assets = folly::dynamic::array();
|
|
372
386
|
for (const auto &asset : *picked) {
|
|
373
|
-
|
|
387
|
+
folly::dynamic item = folly::dynamic::object("uri", asset.uri)("assetId", asset.assetId ? folly::dynamic(*asset.assetId) : folly::dynamic(nullptr))(
|
|
374
388
|
"width", asset.width)("height", asset.height)("type", asset.type)("fileName", asset.fileName)("fileSize", asset.fileSize)(
|
|
375
|
-
"mimeType", asset.mimeType)("duration", orNull(asset.duration))("exif", nullptr)("base64", nullptr)
|
|
389
|
+
"mimeType", asset.mimeType)("duration", orNull(asset.duration))("exif", nullptr)("base64", nullptr);
|
|
390
|
+
// As a camera shot is answered: a video has neither, whatever was asked.
|
|
391
|
+
auto path = asset.type == "image" && (base64 || exif) ? pathOfUri(asset.uri) : std::nullopt;
|
|
392
|
+
if (path) {
|
|
393
|
+
std::ifstream in(*path, std::ios::binary);
|
|
394
|
+
// A file that has gone since it was picked is no empty one: base64 stays null.
|
|
395
|
+
const bool readable = static_cast<bool>(in);
|
|
396
|
+
std::string bytes = readable ? std::string{std::istreambuf_iterator<char>(in), {}} : std::string();
|
|
397
|
+
if (base64 && readable) {
|
|
398
|
+
item["base64"] = base64Encode(bytes);
|
|
399
|
+
}
|
|
400
|
+
if (exif) {
|
|
401
|
+
item["exif"] = asset.exif.isNull() ? jpegExif(bytes) : asset.exif;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
assets.push_back(std::move(item));
|
|
376
405
|
}
|
|
377
406
|
promise.resolve(folly::dynamic::object("canceled", false)("assets", std::move(assets)));
|
|
378
407
|
});
|
|
379
408
|
});
|
|
380
409
|
}
|
|
381
410
|
};
|
|
382
|
-
return std::make_shared<ImagePicker>(std::move(library), noPrompts, std::move(camera));
|
|
411
|
+
return std::make_shared<ImagePicker>(std::move(picker), std::move(library), noPrompts, std::move(camera));
|
|
383
412
|
}
|
|
384
413
|
|
|
385
414
|
} // namespace ngn
|
|
@@ -30,6 +30,95 @@ bool webUrl(const std::string &url) {
|
|
|
30
30
|
return (scheme == "http" || scheme == "https") && url.compare(colon, 3, "://") == 0 && url.size() > colon + 3;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
LinkAuthSession::LinkAuthSession(Hooks hooks) : hooks_(std::move(hooks)) {}
|
|
34
|
+
|
|
35
|
+
void LinkAuthSession::start(const Request &request, std::function<void(std::optional<std::string> url, std::string error)> done) {
|
|
36
|
+
uint64_t attempt = 0;
|
|
37
|
+
{
|
|
38
|
+
std::lock_guard lock(mutex_);
|
|
39
|
+
if (done_) {
|
|
40
|
+
done(std::nullopt, "another authentication session is already open");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
scheme_ = lower(request.callbackScheme);
|
|
44
|
+
done_ = std::move(done);
|
|
45
|
+
attempt = ++attempt_;
|
|
46
|
+
}
|
|
47
|
+
// Each callback below belongs to this attempt: one that arrives after the session ended and
|
|
48
|
+
// another began is stale, and does not touch the new one.
|
|
49
|
+
std::weak_ptr<LinkAuthSession> self = weak_from_this();
|
|
50
|
+
hooks_.openUrl(request.url, [self, attempt, url = request.url](bool opened) {
|
|
51
|
+
if (auto session = self.lock(); session && !opened) {
|
|
52
|
+
session->finish(attempt, std::nullopt, "no browser opened " + url);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (!hooks_.prompt) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
auto hide = hooks_.prompt([self, attempt] {
|
|
59
|
+
if (auto session = self.lock()) {
|
|
60
|
+
session->finish(attempt, std::nullopt, "");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
std::unique_lock lock(mutex_);
|
|
64
|
+
if (done_ && attempt_ == attempt) {
|
|
65
|
+
hidePrompt_ = std::move(hide);
|
|
66
|
+
} else {
|
|
67
|
+
// Ended before its prompt was up (the browser did not open, or a link came back at once), and
|
|
68
|
+
// maybe another session began since: this prompt is taken away without touching that one.
|
|
69
|
+
lock.unlock();
|
|
70
|
+
if (hide) {
|
|
71
|
+
hide();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
void LinkAuthSession::cancel() {
|
|
77
|
+
finish(std::nullopt, std::nullopt, "");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
bool LinkAuthSession::receive(const std::string &url) {
|
|
81
|
+
Ending ending;
|
|
82
|
+
{
|
|
83
|
+
std::lock_guard lock(mutex_);
|
|
84
|
+
auto colon = url.find(':');
|
|
85
|
+
if (!done_ || scheme_.empty() || colon == std::string::npos || lower(url.substr(0, colon)) != scheme_) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
ending = take();
|
|
89
|
+
}
|
|
90
|
+
end(std::move(ending), url, "");
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
LinkAuthSession::Ending LinkAuthSession::take() {
|
|
95
|
+
Ending ending;
|
|
96
|
+
ending.done.swap(done_);
|
|
97
|
+
ending.hide.swap(hidePrompt_);
|
|
98
|
+
return ending;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void LinkAuthSession::end(Ending ending, std::optional<std::string> url, std::string error) {
|
|
102
|
+
if (ending.hide) {
|
|
103
|
+
ending.hide();
|
|
104
|
+
}
|
|
105
|
+
if (ending.done) {
|
|
106
|
+
ending.done(std::move(url), std::move(error));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void LinkAuthSession::finish(std::optional<uint64_t> attempt, std::optional<std::string> url, std::string error) {
|
|
111
|
+
Ending ending;
|
|
112
|
+
{
|
|
113
|
+
std::lock_guard lock(mutex_);
|
|
114
|
+
if (attempt && *attempt != attempt_) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
ending = take();
|
|
118
|
+
}
|
|
119
|
+
end(std::move(ending), std::move(url), std::move(error));
|
|
120
|
+
}
|
|
121
|
+
|
|
33
122
|
std::shared_ptr<NativeModule> makeWebBrowserModule(std::shared_ptr<System> system, std::shared_ptr<AuthSession> sessions, bool noPrompts) {
|
|
34
123
|
struct WebBrowser : NativeModule {
|
|
35
124
|
std::shared_ptr<std::atomic<bool>> inSession = std::make_shared<std::atomic<bool>>(false);
|
|
@@ -134,6 +134,12 @@ void MountingManager::synchronouslyUpdateViewOnUIThread(Tag tag, const folly::dy
|
|
|
134
134
|
view.props = descriptor->cloneProps(context, view.props, RawProps(changed));
|
|
135
135
|
tree_.update(view);
|
|
136
136
|
backend_->updateProps(view);
|
|
137
|
+
// A nativeID or a relation changed this way is as real as one a commit brought: tell the backend
|
|
138
|
+
// now, not whenever a later commit touches the surface.
|
|
139
|
+
relations_.update(view);
|
|
140
|
+
for (const auto &[related, relations] : relations_.didMount(view.surfaceId)) {
|
|
141
|
+
backend_->setAccessibilityRelations(view.surfaceId, related, relations);
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
void MountingManager::ensureRoot(SurfaceId surfaceId, Tag tag) {
|
|
@@ -159,6 +165,7 @@ void MountingManager::apply(SurfaceId surfaceId, const ShadowViewMutationList &m
|
|
|
159
165
|
const auto &view = m.newChildShadowView;
|
|
160
166
|
tree_.create(view);
|
|
161
167
|
liveRegions_.update(view);
|
|
168
|
+
relations_.update(view);
|
|
162
169
|
safeAreas_->created(view);
|
|
163
170
|
backend_->createView(view);
|
|
164
171
|
svgs_.changed(tree_, view.tag);
|
|
@@ -178,6 +185,7 @@ void MountingManager::apply(SurfaceId surfaceId, const ShadowViewMutationList &m
|
|
|
178
185
|
svgs_.deleted(m.oldChildShadowView.tag);
|
|
179
186
|
expoUI_.deleted(m.oldChildShadowView.tag);
|
|
180
187
|
liveRegions_.remove(m.oldChildShadowView.tag);
|
|
188
|
+
relations_.remove(m.oldChildShadowView.tag);
|
|
181
189
|
tree_.destroy(m.oldChildShadowView.tag);
|
|
182
190
|
backend_->deleteView(surfaceId, m.oldChildShadowView.tag);
|
|
183
191
|
break;
|
|
@@ -214,6 +222,7 @@ void MountingManager::apply(SurfaceId surfaceId, const ShadowViewMutationList &m
|
|
|
214
222
|
backend_->updateProps(view);
|
|
215
223
|
reportDesktopProps(view, &old);
|
|
216
224
|
liveRegions_.update(view);
|
|
225
|
+
relations_.update(view);
|
|
217
226
|
sidebars_.propsChanged(tree_, view.tag);
|
|
218
227
|
tabs_->propsChanged(tree_, view.tag);
|
|
219
228
|
screens_->propsChanged(tree_, view.tag);
|
|
@@ -264,6 +273,9 @@ void MountingManager::apply(SurfaceId surfaceId, const ShadowViewMutationList &m
|
|
|
264
273
|
frontHeaders_[surfaceId] = header;
|
|
265
274
|
backend_->setFrontHeader(surfaceId, header);
|
|
266
275
|
}
|
|
276
|
+
for (const auto &[tag, relations] : relations_.didMount(surfaceId)) {
|
|
277
|
+
backend_->setAccessibilityRelations(surfaceId, tag, relations);
|
|
278
|
+
}
|
|
267
279
|
for (const auto &announcement : liveRegions_.didMount(surfaceId)) {
|
|
268
280
|
backend_->announce(surfaceId, announcement);
|
|
269
281
|
}
|