@ng-native/desktop 0.25.0 → 0.26.1
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/native/CMakeLists.txt +47 -4
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/cg-canvas.h +5 -0
- package/native/appkit/cg-canvas.mm +21 -6
- package/native/appkit/desktop-expo.h +6 -0
- package/native/appkit/desktop-expo.mm +5 -0
- package/native/appkit/host-view.mm +32 -0
- package/native/appkit/image-request.h +2 -10
- package/native/appkit/image-request.mm +0 -22
- package/native/appkit/image-view.mm +94 -6
- package/native/appkit/main.mm +130 -185
- package/native/appkit/split-view.mm +3 -9
- package/native/appkit/system-access.mm +3 -0
- package/native/appkit/system.mm +33 -48
- package/native/appkit/view-effects.h +27 -0
- package/native/appkit/view-effects.mm +90 -0
- package/native/cmake/runtime-dependencies.cmake +11 -1
- package/native/core/include/ngn/app-info.h +3 -2
- package/native/core/include/ngn/app-menus.h +5 -11
- package/native/core/include/ngn/default-menu.h +16 -6
- package/native/core/include/ngn/desktop-expo.h +0 -5
- package/native/core/include/ngn/desktop-modules.h +144 -0
- package/native/core/include/ngn/dev-server.h +12 -3
- package/native/core/include/ngn/host-os.h +45 -0
- package/native/core/include/ngn/host-views.h +25 -0
- package/native/core/include/ngn/image-source.h +18 -0
- package/native/core/include/ngn/launch-settings.h +9 -7
- package/native/core/include/ngn/module-registry.h +2 -0
- package/native/core/include/ngn/notifications.h +6 -0
- package/native/core/include/ngn/runtime.h +4 -1
- package/native/core/include/ngn/spawn-rules.h +3 -2
- package/native/core/include/ngn/split-view.h +12 -0
- package/native/core/include/ngn/system.h +47 -0
- package/native/core/include/ngn/undo.h +27 -0
- package/native/core/include/ngn/updates.h +3 -2
- package/native/core/include/ngn/view-filter.h +33 -0
- package/native/core/src/app-menus.cpp +9 -11
- package/native/core/src/default-menu.cpp +6 -2
- package/native/core/src/dev-server-helper.cpp +3 -2
- package/native/core/src/dev-server.cpp +22 -5
- package/native/core/src/host-os.cpp +20 -0
- package/native/core/src/host-views.cpp +25 -0
- package/native/core/src/image-source.cpp +30 -0
- package/native/core/src/launch-settings.cpp +10 -6
- package/native/core/src/module-registry.cpp +9 -0
- package/native/core/src/modules/app-info.cpp +4 -4
- package/native/core/src/modules/desktop-expo.cpp +0 -5
- package/native/core/src/modules/desktop-modules.cpp +132 -0
- package/native/core/src/modules/notifications.cpp +4 -4
- package/native/core/src/runtime.cpp +2 -0
- package/native/core/src/spawn-rules.cpp +1 -4
- package/native/core/src/split-view.cpp +10 -0
- package/native/core/src/system.cpp +52 -0
- package/native/core/src/undo-stacks.cpp +71 -0
- package/native/core/src/view-filter.cpp +114 -0
- package/native/scripts/build-hermes.sh +19 -7
- package/native/scripts/build-icu.sh +36 -0
- package/native/scripts/build-lock.sh +21 -0
- package/native/scripts/build.sh +40 -7
- package/native/scripts/fetch.sh +24 -2
- package/native/scripts/hermes-built.sh +5 -4
- package/native/scripts/hermes-target.sh +18 -0
- package/native/scripts/icu-filter.json +22 -0
- package/native/shim/openssl/sha.h +108 -3
- package/package.json +2 -2
- package/prebuilt.json +6 -6
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
#include <folly/dynamic.h>
|
|
8
8
|
|
|
9
9
|
#include <functional>
|
|
10
|
+
#include <memory>
|
|
11
|
+
#include <mutex>
|
|
10
12
|
#include <optional>
|
|
11
13
|
#include <string>
|
|
12
14
|
#include <vector>
|
|
@@ -99,4 +101,49 @@ class System {
|
|
|
99
101
|
virtual std::string appDataDirectory() = 0;
|
|
100
102
|
};
|
|
101
103
|
|
|
104
|
+
// The colour scheme a backend's System answers: the app's override while one holds, the system's
|
|
105
|
+
// own otherwise. Any thread.
|
|
106
|
+
class ColorSchemeOverride {
|
|
107
|
+
public:
|
|
108
|
+
explicit ColorSchemeOverride(std::string systemScheme);
|
|
109
|
+
// What System::colorScheme answers.
|
|
110
|
+
std::string current() const;
|
|
111
|
+
// The app's override, or none to follow the system again.
|
|
112
|
+
void set(std::optional<std::string> scheme);
|
|
113
|
+
// The system's own scheme changed (or was read again), override or not.
|
|
114
|
+
void systemChanged(std::string scheme);
|
|
115
|
+
// What a change to `scheme` applied, as System::setColorScheme tells it: that scheme, or the
|
|
116
|
+
// system's for none. Not the latest override, which a later change may have set already.
|
|
117
|
+
std::string applied(const std::optional<std::string> &scheme) const;
|
|
118
|
+
|
|
119
|
+
private:
|
|
120
|
+
mutable std::mutex mutex_;
|
|
121
|
+
std::string system_;
|
|
122
|
+
std::optional<std::string> override_;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Strings that persist across launches, the backend's (NSUserDefaults on macOS). Any thread.
|
|
126
|
+
class StringStore {
|
|
127
|
+
public:
|
|
128
|
+
virtual ~StringStore() = default;
|
|
129
|
+
virtual std::optional<std::string> get(const std::string &key) = 0;
|
|
130
|
+
virtual void set(const std::string &key, const std::string &value) = 0;
|
|
131
|
+
virtual void remove(const std::string &key) = 0;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// System::preference and setPreference over a string store: each value as JSON, and each key
|
|
135
|
+
// prefixed with the app's id when the store is shared with other apps (on macOS, a bare host
|
|
136
|
+
// binary's defaults, which every app run with it reads). A stored value that is not JSON reads as
|
|
137
|
+
// nothing.
|
|
138
|
+
class JsonPreferences {
|
|
139
|
+
public:
|
|
140
|
+
JsonPreferences(std::shared_ptr<StringStore> store, const std::string &appId, bool sharedStore);
|
|
141
|
+
std::optional<folly::dynamic> get(const std::string &key) const;
|
|
142
|
+
void set(const std::string &key, const std::optional<folly::dynamic> &value) const;
|
|
143
|
+
|
|
144
|
+
private:
|
|
145
|
+
std::shared_ptr<StringStore> store_;
|
|
146
|
+
std::string prefix_;
|
|
147
|
+
};
|
|
148
|
+
|
|
102
149
|
} // namespace ngn
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
#include <functional>
|
|
16
16
|
#include <memory>
|
|
17
|
+
#include <optional>
|
|
17
18
|
#include <string>
|
|
19
|
+
#include <vector>
|
|
18
20
|
|
|
19
21
|
namespace ngn {
|
|
20
22
|
|
|
@@ -32,6 +34,31 @@ class UndoManager {
|
|
|
32
34
|
virtual void clear() = 0;
|
|
33
35
|
};
|
|
34
36
|
|
|
37
|
+
// Those rules over two stacks, for a toolkit with no undo manager of its own (macOS keeps
|
|
38
|
+
// NSUndoManager, which its Edit menu and text inputs share). Each action is a step of its own.
|
|
39
|
+
// Called on the toolkit's main thread, as the toolkit's undo manager is.
|
|
40
|
+
class UndoStacks final : public UndoManager {
|
|
41
|
+
public:
|
|
42
|
+
void registerAction(const std::string &label, std::function<void()> action) override;
|
|
43
|
+
bool undoing() const override;
|
|
44
|
+
void undo() override;
|
|
45
|
+
void redo() override;
|
|
46
|
+
void clear() override;
|
|
47
|
+
// The label of the action undo or redo would run, for Edit > Undo and Edit > Redo, or none.
|
|
48
|
+
std::optional<std::string> undoLabel() const;
|
|
49
|
+
std::optional<std::string> redoLabel() const;
|
|
50
|
+
|
|
51
|
+
private:
|
|
52
|
+
struct Action {
|
|
53
|
+
std::string label;
|
|
54
|
+
std::function<void()> run;
|
|
55
|
+
};
|
|
56
|
+
std::vector<Action> undos_;
|
|
57
|
+
std::vector<Action> redos_;
|
|
58
|
+
bool undoing_{false};
|
|
59
|
+
bool redoing_{false};
|
|
60
|
+
};
|
|
61
|
+
|
|
35
62
|
std::shared_ptr<NativeModule> makeUndoModule(std::shared_ptr<UndoManager> manager);
|
|
36
63
|
|
|
37
64
|
} // namespace ngn
|
|
@@ -57,8 +57,9 @@ struct UpdatesConfig {
|
|
|
57
57
|
// The server's manifest URL (Expo's `updates.url`). Empty turns updates off.
|
|
58
58
|
std::string url;
|
|
59
59
|
std::string runtimeVersion;
|
|
60
|
-
// The `expo-platform` header
|
|
61
|
-
|
|
60
|
+
// The `expo-platform` header: the OS's id (HostOs) unless the app names another. EAS Update
|
|
61
|
+
// refuses `macos`; a self-hosted server serves it.
|
|
62
|
+
std::string platform;
|
|
62
63
|
// The certificate a manifest must be signed by, as PEM, with its `keyid` and `alg`
|
|
63
64
|
// (Expo's `updates.codeSigningCertificate` and `codeSigningMetadata`). Empty: no code signing.
|
|
64
65
|
std::string certificatePem;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// A view's CSS `filter` as the steps a toolkit applies to what the view draws, its children
|
|
2
|
+
// included: colour matrices from the Filter Effects spec's equivalents, a Gaussian blur, and a drop
|
|
3
|
+
// shadow. The GTK host maps each step to a GSK node, and the macOS host to a Core Image filter on
|
|
4
|
+
// the view's layer, which draws every step but the drop shadow.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <react/renderer/graphics/Filter.h>
|
|
8
|
+
|
|
9
|
+
#include <array>
|
|
10
|
+
#include <cstdint>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
namespace ngn {
|
|
14
|
+
|
|
15
|
+
struct FilterStep {
|
|
16
|
+
enum class Type { ColorMatrix, Blur, DropShadow };
|
|
17
|
+
Type type{Type::ColorMatrix};
|
|
18
|
+
// ColorMatrix: a 4x5 matrix by rows (r, g, b, a) over unpremultiplied sRGB, its last column an
|
|
19
|
+
// offset in 0 to 1, as SVG's feColorMatrix. The result is clamped to 0 to 1 after each step.
|
|
20
|
+
std::array<double, 20> matrix{1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0};
|
|
21
|
+
// Blur and DropShadow: the Gaussian's standard deviation, in points.
|
|
22
|
+
double standardDeviation{0};
|
|
23
|
+
// DropShadow: its offset and colour, drawn under the view from its alpha.
|
|
24
|
+
double offsetX{0}, offsetY{0};
|
|
25
|
+
uint32_t argb{0xff000000};
|
|
26
|
+
bool operator==(const FilterStep &) const = default;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// The steps in the list's order, the first applied first. A function that changes nothing
|
|
30
|
+
// (brightness(1), blur(0), ...) is left out.
|
|
31
|
+
std::vector<FilterStep> filterSteps(const std::vector<facebook::react::FilterFunction> &filter);
|
|
32
|
+
|
|
33
|
+
} // namespace ngn
|
|
@@ -96,9 +96,9 @@ const char *directionName(NavigationDirection direction) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// The keys a focused text input owns.
|
|
99
|
-
bool editingChord(const KeyChord &chord) {
|
|
99
|
+
bool editingChord(const KeyChord &chord, const HostOs &os) {
|
|
100
100
|
static const std::vector<std::string> keys{"z", "x", "c", "v", "a"};
|
|
101
|
-
return chord.modifiers ==
|
|
101
|
+
return chord.modifiers == os.primaryModifier && std::find(keys.begin(), keys.end(), chord.key) != keys.end();
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
} // namespace
|
|
@@ -145,8 +145,9 @@ std::vector<MenuItem> parseMenuBar(const folly::dynamic &groups, const DefaultMe
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
// Cmd-W closes the window (or the sheet in front) whatever the
|
|
149
|
-
// Close Window, as the default bar has it, when the app's bar
|
|
148
|
+
// Close Window's key (Cmd-W on macOS) closes the window (or the sheet in front) whatever the
|
|
149
|
+
// app's bar has: the File menu's Close Window, as the OS's default bar has it, when the app's bar
|
|
150
|
+
// has no close item.
|
|
150
151
|
if (findMenuItem(bar, MenuCommand::CloseWindow) == nullptr) {
|
|
151
152
|
auto close = *findMenuItem(defaultMenuBar(options), MenuCommand::CloseWindow);
|
|
152
153
|
auto file = std::find_if(bar.begin(), bar.end(), [](const MenuItem &m) { return m.title == "File"; });
|
|
@@ -183,14 +184,11 @@ std::optional<NavigationDirection> navigationFor(NavigationInput input, bool rig
|
|
|
183
184
|
return std::nullopt;
|
|
184
185
|
}
|
|
185
186
|
|
|
186
|
-
std::optional<NavigationDirection> navigationFor(const KeyChord &chord) {
|
|
187
|
-
if (chord
|
|
188
|
-
return std::nullopt;
|
|
189
|
-
}
|
|
190
|
-
if (chord.key == "[") {
|
|
187
|
+
std::optional<NavigationDirection> navigationFor(const KeyChord &chord, const HostOs &os) {
|
|
188
|
+
if (chord == os.back) {
|
|
191
189
|
return NavigationDirection::Back;
|
|
192
190
|
}
|
|
193
|
-
if (chord
|
|
191
|
+
if (chord == os.forward) {
|
|
194
192
|
return NavigationDirection::Forward;
|
|
195
193
|
}
|
|
196
194
|
return std::nullopt;
|
|
@@ -246,7 +244,7 @@ bool MenuHost::keyDown(const KeyChord &pressed, bool textInputFocused) {
|
|
|
246
244
|
return false;
|
|
247
245
|
}
|
|
248
246
|
send(folly::dynamic::object("type", "shortcut")("id", *id)("textInputFocused", textInputFocused));
|
|
249
|
-
return !(textInputFocused && editingChord(chord));
|
|
247
|
+
return !(textInputFocused && editingChord(chord, options_.os));
|
|
250
248
|
}
|
|
251
249
|
|
|
252
250
|
void MenuHost::navigate(NavigationDirection direction, std::optional<SurfaceId> surface, int steps) {
|
|
@@ -20,6 +20,10 @@ MenuItem menu(std::string title, std::vector<MenuItem> items, MenuRole role = Me
|
|
|
20
20
|
} // namespace
|
|
21
21
|
|
|
22
22
|
std::vector<MenuItem> defaultMenuBar(const DefaultMenuOptions &options) {
|
|
23
|
+
return options.os.menuBar(options);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
std::vector<MenuItem> macOSMenuBar(const DefaultMenuOptions &options) {
|
|
23
27
|
const std::string &app = options.appName;
|
|
24
28
|
std::vector<MenuItem> bar{
|
|
25
29
|
menu(
|
|
@@ -53,8 +57,8 @@ std::vector<MenuItem> defaultMenuBar(const DefaultMenuOptions &options) {
|
|
|
53
57
|
menu(
|
|
54
58
|
"View",
|
|
55
59
|
{
|
|
56
|
-
item("Back", MenuCommand::Back,
|
|
57
|
-
item("Forward", MenuCommand::Forward,
|
|
60
|
+
item("Back", MenuCommand::Back, options.os.back.key, options.os.back.modifiers),
|
|
61
|
+
item("Forward", MenuCommand::Forward, options.os.forward.key, options.os.forward.modifiers),
|
|
58
62
|
separator(),
|
|
59
63
|
item("Show Sidebar", MenuCommand::ToggleSidebar, "s", Command | Control),
|
|
60
64
|
item("Enter Full Screen", MenuCommand::ToggleFullScreen, "f", Command | Control),
|
|
@@ -122,10 +122,11 @@ std::string DevServerHelper::getBundleUrl() const {
|
|
|
122
122
|
return sourcePath_;
|
|
123
123
|
}
|
|
124
124
|
return fmt::format(
|
|
125
|
-
"http://{}:{}/{}.bundle?platform=
|
|
125
|
+
"http://{}:{}/{}.bundle?platform={}&dev=true&minify=false&app={}",
|
|
126
126
|
devServerHost_,
|
|
127
127
|
devServerPort_,
|
|
128
128
|
sourcePath_,
|
|
129
|
+
ngn::devServerOs(),
|
|
129
130
|
appId_);
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -146,7 +147,7 @@ void DevServerHelper::setupHMRClient() const {
|
|
|
146
147
|
if (!server) {
|
|
147
148
|
return;
|
|
148
149
|
}
|
|
149
|
-
javaScriptModuleCallback_("HMRClient", "setup", server->hmrSetupArgs());
|
|
150
|
+
javaScriptModuleCallback_("HMRClient", "setup", server->hmrSetupArgs(ngn::devServerOs()));
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
} // namespace facebook::react
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#include "ngn/dev-server.h"
|
|
2
2
|
|
|
3
3
|
#include <charconv>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
#include <utility>
|
|
4
6
|
|
|
5
7
|
namespace ngn {
|
|
6
8
|
|
|
@@ -85,9 +87,6 @@ std::optional<DevServer> DevServer::fromBundleUrl(const std::string &url) {
|
|
|
85
87
|
}
|
|
86
88
|
server.entry = path;
|
|
87
89
|
server.platform = queryValue(query, "platform");
|
|
88
|
-
if (server.platform.empty()) {
|
|
89
|
-
server.platform = "macos";
|
|
90
|
-
}
|
|
91
90
|
server.bundleUrl = url;
|
|
92
91
|
return server;
|
|
93
92
|
}
|
|
@@ -96,8 +95,26 @@ std::string DevServer::packagerConnectionUrl() const {
|
|
|
96
95
|
return (scheme == "https" ? "wss://" : "ws://") + host + ":" + std::to_string(port) + "/message";
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
folly::dynamic DevServer::hmrSetupArgs() const {
|
|
100
|
-
return folly::dynamic::array(platform, entry, host, port, true, scheme);
|
|
98
|
+
folly::dynamic DevServer::hmrSetupArgs(const std::string &os) const {
|
|
99
|
+
return folly::dynamic::array(platform.empty() ? os : platform, entry, host, port, true, scheme);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
namespace {
|
|
103
|
+
std::string &hostOs() {
|
|
104
|
+
static std::string os;
|
|
105
|
+
return os;
|
|
106
|
+
}
|
|
107
|
+
} // namespace
|
|
108
|
+
|
|
109
|
+
const std::string &devServerOs() {
|
|
110
|
+
return hostOs();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void setDevServerOs(std::string os) {
|
|
114
|
+
if (os.empty()) {
|
|
115
|
+
throw std::invalid_argument("The dev server needs the host OS's id, and DebuggerIdentity::os is empty");
|
|
116
|
+
}
|
|
117
|
+
hostOs() = std::move(os);
|
|
101
118
|
}
|
|
102
119
|
|
|
103
120
|
} // namespace ngn
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#include "ngn/host-os.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/default-menu.h"
|
|
4
|
+
|
|
5
|
+
namespace ngn {
|
|
6
|
+
|
|
7
|
+
HostOs macOS() {
|
|
8
|
+
return {
|
|
9
|
+
.id = "macos",
|
|
10
|
+
.name = "macOS",
|
|
11
|
+
.program = "ngn-macos",
|
|
12
|
+
.primaryModifier = Command,
|
|
13
|
+
.back = {.key = "[", .modifiers = Command},
|
|
14
|
+
.forward = {.key = "]", .modifiers = Command},
|
|
15
|
+
.searchPath = {"/usr/bin", "/bin", "/usr/sbin", "/sbin", "/opt/homebrew/bin", "/usr/local/bin"},
|
|
16
|
+
.menuBar = macOSMenuBar,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
} // namespace ngn
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include "ngn/host-views.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/worklet-host.h"
|
|
4
|
+
|
|
5
|
+
namespace ngn {
|
|
6
|
+
|
|
7
|
+
HostViews makeHostViews(
|
|
8
|
+
std::shared_ptr<MountingBackend> backend, std::shared_ptr<DesktopPropsSink> desktopProps, Gestures::Schedule schedule) {
|
|
9
|
+
HostViews views;
|
|
10
|
+
views.mounting = std::make_shared<MountingManager>(std::move(backend), std::move(desktopProps));
|
|
11
|
+
views.input = std::make_unique<InputDispatcher>(views.mounting->tree());
|
|
12
|
+
views.gestures = std::make_shared<Gestures>(views.mounting->tree(), std::move(schedule));
|
|
13
|
+
views.input->setGestures(views.gestures.get());
|
|
14
|
+
// A worklet gesture's events go to Reanimated's handlers on the UI runtime, and a worklet's
|
|
15
|
+
// state manager comes back to the recognisers, while Reanimated is running.
|
|
16
|
+
views.gestures->onWorkletEvent = [](const std::string &name, Tag view, const folly::dynamic &body) {
|
|
17
|
+
workletHost().reanimatedEvent.call(name, view, body);
|
|
18
|
+
};
|
|
19
|
+
workletHost().setGestureState = [gestures = views.gestures](int handlerTag, int state) {
|
|
20
|
+
gestures->setState(handlerTag, state);
|
|
21
|
+
};
|
|
22
|
+
return views;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace ngn
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#include "ngn/image-source.h"
|
|
2
|
+
|
|
3
|
+
#include <cmath>
|
|
4
|
+
#include <limits>
|
|
5
|
+
|
|
6
|
+
using facebook::react::ImageSource;
|
|
7
|
+
|
|
8
|
+
namespace ngn {
|
|
9
|
+
|
|
10
|
+
std::optional<ImageSource> pickImageSource(const std::vector<ImageSource> &sources, double screenScale) {
|
|
11
|
+
std::optional<ImageSource> best;
|
|
12
|
+
double distance = std::numeric_limits<double>::infinity();
|
|
13
|
+
for (const auto &source : sources) {
|
|
14
|
+
if (source.uri.empty()) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
double d = std::abs(source.scale - screenScale);
|
|
18
|
+
if (d < distance) {
|
|
19
|
+
distance = d;
|
|
20
|
+
best = source;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return best;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
bool sameImageRequest(const ImageSource &a, const ImageSource &b) {
|
|
27
|
+
return a.uri == b.uri && a.cache == b.cache && a.method == b.method && a.headers == b.headers && a.body == b.body;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace ngn
|
|
@@ -7,8 +7,10 @@ namespace ngn {
|
|
|
7
7
|
|
|
8
8
|
namespace {
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
std::string usage(const HostOs &os) {
|
|
11
|
+
return "usage: " + os.program +
|
|
12
|
+
" <bundle> [--module <name>] [--title <title>] [--app-id <id>] [--capabilities <json>] [--url <link>]";
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
bool is(const LaunchSources &sources, const char *name, const char *value) {
|
|
14
16
|
auto found = sources.env ? sources.env(name) : std::nullopt;
|
|
@@ -57,7 +59,7 @@ std::string LaunchSettings::setting(const std::string &plistKey, const std::stri
|
|
|
57
59
|
return "";
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources) {
|
|
62
|
+
std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources, const HostOs &os) {
|
|
61
63
|
LaunchSettings settings;
|
|
62
64
|
settings.env = sources.env;
|
|
63
65
|
settings.plist = sources.plist;
|
|
@@ -112,19 +114,21 @@ std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources)
|
|
|
112
114
|
} else if (settings.bundle.empty() && !arg.starts_with("--")) {
|
|
113
115
|
settings.bundle = arg;
|
|
114
116
|
} else {
|
|
115
|
-
return
|
|
117
|
+
return usage(os);
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
if (settings.bundle.empty()) {
|
|
119
|
-
return
|
|
121
|
+
return usage(os);
|
|
120
122
|
}
|
|
121
123
|
return settings;
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
UpdatesConfig updatesConfigFrom(
|
|
126
|
+
UpdatesConfig updatesConfigFrom(
|
|
127
|
+
const LaunchSettings &settings, const HostOs &os, const std::string &appData, const std::string &embeddedBundle) {
|
|
125
128
|
UpdatesConfig config{
|
|
126
129
|
.url = settings.setting("NGNUpdatesURL", "NGN_UPDATES_URL"),
|
|
127
130
|
.runtimeVersion = settings.setting("NGNRuntimeVersion", "NGN_RUNTIME_VERSION"),
|
|
131
|
+
.platform = os.id,
|
|
128
132
|
.certificatePem = settings.setting("NGNUpdatesCodeSigningCertificate", "NGN_UPDATES_CODE_SIGNING_CERTIFICATE"),
|
|
129
133
|
.directory = std::filesystem::path(appData) / "updates",
|
|
130
134
|
.embeddedBundle = embeddedBundle,
|
|
@@ -12,6 +12,15 @@ void ModuleRegistry::add(const std::string &name, Factory factory) {
|
|
|
12
12
|
factories_[name] = std::move(factory);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
std::vector<std::string> ModuleRegistry::names() const {
|
|
16
|
+
std::vector<std::string> names;
|
|
17
|
+
names.reserve(factories_.size());
|
|
18
|
+
for (const auto &entry : factories_) {
|
|
19
|
+
names.push_back(entry.first);
|
|
20
|
+
}
|
|
21
|
+
return names;
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
void ModuleRegistry::addProvider(std::shared_ptr<ModuleProvider> provider) {
|
|
16
25
|
providers_.push_back(std::move(provider));
|
|
17
26
|
}
|
|
@@ -38,9 +38,9 @@ std::shared_ptr<NativeModule> makeApplicationModule(BundleFacts bundle, std::str
|
|
|
38
38
|
return std::make_shared<Application>(std::move(bundle), std::move(appId), std::move(appName));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine) {
|
|
41
|
+
std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine, std::string osName) {
|
|
42
42
|
struct Device : NativeModule {
|
|
43
|
-
|
|
43
|
+
Device(const MachineFacts &machine, const std::string &osName) : NativeModule("NgNativeDevice") {
|
|
44
44
|
folly::dynamic architectures = folly::dynamic::array();
|
|
45
45
|
for (const auto &architecture : machine.architectures) {
|
|
46
46
|
architectures.push_back(architecture);
|
|
@@ -53,7 +53,7 @@ std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine) {
|
|
|
53
53
|
{"designName", nullptr},
|
|
54
54
|
{"productName", nullptr},
|
|
55
55
|
{"deviceYearClass", nullptr},
|
|
56
|
-
{"osName",
|
|
56
|
+
{"osName", osName},
|
|
57
57
|
{"osVersion", orNull(machine.osVersion)},
|
|
58
58
|
{"osBuildId", orNull(machine.osBuildId)},
|
|
59
59
|
{"osInternalBuildId", orNull(machine.osBuildId)},
|
|
@@ -68,7 +68,7 @@ std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
return std::make_shared<Device>(machine);
|
|
71
|
+
return std::make_shared<Device>(machine, osName);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
} // namespace ngn
|
|
@@ -128,11 +128,6 @@ void MovingSecretStore::removeOld(const std::string &service, const std::string
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
bool usesDataProtectionKeychain(const std::string &teamId, const std::set<std::string> &entitlements) {
|
|
132
|
-
return !teamId.empty() &&
|
|
133
|
-
(entitlements.contains("com.apple.application-identifier") || entitlements.contains("keychain-access-groups"));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
131
|
std::shared_ptr<NativeModule> makeSecureStoreModule(std::shared_ptr<SecretStore> store, std::string defaultService) {
|
|
137
132
|
struct SecureStore : NativeModule {
|
|
138
133
|
SecureStore(std::shared_ptr<SecretStore> store, std::string service) : NativeModule("NgNativeSecureStore") {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#include "ngn/desktop-modules.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/asset.h"
|
|
4
|
+
#include "ngn/sqlite.h"
|
|
5
|
+
#include "ngn/web-view.h"
|
|
6
|
+
|
|
7
|
+
namespace ngn {
|
|
8
|
+
|
|
9
|
+
DesktopModules addDesktopModules(ModuleRegistry ®istry, const DesktopModuleSources &s) {
|
|
10
|
+
// One launcher for the process: a reload gets a new module over it.
|
|
11
|
+
DesktopModules made{
|
|
12
|
+
.launcher = makePosixLauncher(),
|
|
13
|
+
.notificationEvents = std::make_shared<NotificationEvents>(s.os.id),
|
|
14
|
+
// The fonts loaded stay registered for the process, so their names outlast a reload too.
|
|
15
|
+
.fonts = std::make_shared<FontLibrary>(),
|
|
16
|
+
.cameraViews = std::make_shared<CameraViews>(),
|
|
17
|
+
.mapViews = std::make_shared<MapViews>(),
|
|
18
|
+
};
|
|
19
|
+
auto notifications = s.notifications(made.notificationEvents);
|
|
20
|
+
made.push = std::make_shared<PushTokens>(s.push, made.notificationEvents);
|
|
21
|
+
|
|
22
|
+
addModule(registry, "NgNativeWindows", [windows = s.windows] { return makeWindowsModule(windows); });
|
|
23
|
+
addModule(registry, "NgNativeMenus", [menus = s.menus] { return makeMenusModule(menus); });
|
|
24
|
+
addModule(registry, "NgNativeTray", [tray = s.tray] { return makeTrayModule(tray); });
|
|
25
|
+
addModule(registry, "NgNativeDock", [dock = s.dock] { return makeDockModule(dock); });
|
|
26
|
+
addModule(registry, "NgNativeProcesses", [launcher = made.launcher, processes = s.processes] {
|
|
27
|
+
return makeProcessesModule(launcher, processes);
|
|
28
|
+
});
|
|
29
|
+
addModule(registry, "NgNativeShell", [shell = s.shell, files = s.files] { return makeShellModule(shell, files); });
|
|
30
|
+
// The desktop Expo modules (DESKTOP_MODULES in @ng-native/expo).
|
|
31
|
+
addModule(registry, "NgNativeSecureStore", [secrets = s.secrets, service = s.appId] {
|
|
32
|
+
return makeSecureStoreModule(secrets, service);
|
|
33
|
+
});
|
|
34
|
+
addModule(registry, "NgNativeClipboard", [system = s.system, state = s.state] {
|
|
35
|
+
return makeDesktopClipboardModule(system, state);
|
|
36
|
+
});
|
|
37
|
+
addModule(registry, "NgNativeNotifications", [notifications, events = made.notificationEvents, push = made.push] {
|
|
38
|
+
return makeNotificationsModule(notifications, events, push);
|
|
39
|
+
});
|
|
40
|
+
addModule(registry, "NgNativeUndo", [undo = s.undo] { return makeUndoModule(undo); });
|
|
41
|
+
addModule(registry, "NgNativeKeepAwake", [awake = std::make_shared<KeepAwakeTags>(s.sleep)] {
|
|
42
|
+
return makeKeepAwakeModule(awake);
|
|
43
|
+
});
|
|
44
|
+
addModule(registry, "NgNativeHaptics", [haptics = s.haptics] { return makeHapticsModule(haptics); });
|
|
45
|
+
addModule(registry, "NgNativeFileSystem", [files = s.files, watcher = s.fileWatcher] {
|
|
46
|
+
return makeFileSystemModule(files, watcher);
|
|
47
|
+
});
|
|
48
|
+
addModule(registry, "NgNativeDocumentPicker", [dialogs = s.fileDialogs, caches = s.caches, files = s.files] {
|
|
49
|
+
return makeDocumentPickerModule(dialogs, caches, files);
|
|
50
|
+
});
|
|
51
|
+
// expo-sqlite keeps its databases in the app's documents, under SQLite; here, in its data.
|
|
52
|
+
addModule(registry, "NgNativeSqlite", [databases = s.system->appDataDirectory() + "/SQLite", files = s.files] {
|
|
53
|
+
return makeSqliteModule(databases, files);
|
|
54
|
+
});
|
|
55
|
+
addModule(registry, "NgNativeLocation", [location = s.location, noPrompts = s.noPrompts, geocoder = s.geocoder] {
|
|
56
|
+
return makeLocationModule(location, noPrompts, geocoder);
|
|
57
|
+
});
|
|
58
|
+
addModule(registry, "NgNativeLocalAuthentication", [authenticator = s.authenticator] {
|
|
59
|
+
return makeLocalAuthenticationModule(authenticator);
|
|
60
|
+
});
|
|
61
|
+
addModule(registry, "NgNativeApplication", [bundle = s.bundle, appId = s.appId, appName = s.appName] {
|
|
62
|
+
return makeApplicationModule(bundle, appId, appName);
|
|
63
|
+
});
|
|
64
|
+
addModule(registry, "NgNativeDevice", [machine = s.machine, os = s.os.name] { return makeDeviceModule(machine, os); });
|
|
65
|
+
addModule(registry, "NgNativeNetwork", [monitor = s.pathMonitor] { return makeNetworkModule(monitor); });
|
|
66
|
+
addModule(registry, "NgNativeBattery", [power = s.power] { return makeBatteryModule(power); });
|
|
67
|
+
addModule(registry, "NgNativeFont", [registrar = s.fontRegistrar, fonts = made.fonts, http = s.http, caches = s.caches, files = s.files] {
|
|
68
|
+
return makeFontModule(registrar, fonts, http, caches + "/fonts", files);
|
|
69
|
+
});
|
|
70
|
+
addModule(registry, "NgNativeWebBrowser", [system = s.system, sessions = s.authSession, noPrompts = s.noPrompts] {
|
|
71
|
+
return makeWebBrowserModule(system, sessions, noPrompts);
|
|
72
|
+
});
|
|
73
|
+
addModule(registry, "NgNativeTextRecognition", [reader = s.textReader, files = s.files] {
|
|
74
|
+
return makeTextRecognitionModule(reader, files);
|
|
75
|
+
});
|
|
76
|
+
addModule(registry, "NgNativeCalendar", [calendars = s.calendars, noPrompts = s.noPrompts] {
|
|
77
|
+
return makeCalendarModule(calendars, noPrompts);
|
|
78
|
+
});
|
|
79
|
+
// Players and recorders end with the runtime: a reload stops what the app played.
|
|
80
|
+
addModule(registry, "NgNativeAudio", [output = s.audioOutput, input = s.audioInput, caches = s.caches, noPrompts = s.noPrompts, files = s.files] {
|
|
81
|
+
return makeAudioModule(output, input, caches + "/Audio", noPrompts, files);
|
|
82
|
+
});
|
|
83
|
+
addModule(registry, "NgNativeVideo", [output = s.videoOutput, files = s.files] { return makeVideoModule(output, files); });
|
|
84
|
+
addModule(registry, "NgNativeLocalLlm", [engine = s.languageModel] { return makeLocalLlmModule(engine); });
|
|
85
|
+
addModule(registry, "NgNativeScreenCapture", [shield = s.captureShield] { return makeScreenCaptureModule(shield); });
|
|
86
|
+
addModule(registry, "NgNativeSplashScreen", [splash = s.splash] { return makeSplashScreenModule(splash); });
|
|
87
|
+
addModule(registry, "NgNativeMediaLibrary", [photos = s.photos, noPrompts = s.noPrompts, files = s.files] {
|
|
88
|
+
return makeMediaLibraryModule(photos, noPrompts, files);
|
|
89
|
+
});
|
|
90
|
+
addModule(registry, "NgNativeImagePicker", [photos = s.photos, noPrompts = s.noPrompts, camera = PickerCamera{.hardware = s.cameraHardware, .microphone = s.audioInput, .sheet = s.cameraSheet, .folder = s.caches + "/ImagePicker"}] {
|
|
91
|
+
return makeImagePickerModule(photos, noPrompts, camera);
|
|
92
|
+
});
|
|
93
|
+
addModule(registry, "NgNativeTrackingTransparency", [tracking = s.tracking, noPrompts = s.noPrompts] {
|
|
94
|
+
return makeTrackingModule(tracking, noPrompts);
|
|
95
|
+
});
|
|
96
|
+
addModule(registry, "NgNativeAddressSearch", [lookup = s.addressLookup] { return makeAddressSearchModule(lookup); });
|
|
97
|
+
addModule(registry, "NgNativeAsset", [http = s.http, caches = s.caches, files = s.files] {
|
|
98
|
+
return makeAssetModule(http, caches, files);
|
|
99
|
+
});
|
|
100
|
+
addModule(registry, "NgNativeSymbol", [measurer = s.symbolMeasurer] { return makeSymbolModule(measurer); });
|
|
101
|
+
addModule(registry, "NgNativeSharing", [picker = s.sharePicker, noPrompts = s.noPrompts, files = s.files] {
|
|
102
|
+
return makeSharingModule(picker, noPrompts, files);
|
|
103
|
+
});
|
|
104
|
+
addModule(registry, "NgNativeImageManipulator", [codec = s.imageCodec, http = s.http, caches = s.caches, files = s.files] {
|
|
105
|
+
return makeImageManipulatorModule(codec, http, caches + "/ImageManipulator", files);
|
|
106
|
+
});
|
|
107
|
+
addModule(registry, "NgNativeCamera", [hardware = s.cameraHardware, views = made.cameraViews, caches = s.caches, noPrompts = s.noPrompts] {
|
|
108
|
+
return makeCameraModule(hardware, views, caches + "/Camera", noPrompts);
|
|
109
|
+
});
|
|
110
|
+
addModule(registry, "NgNativeMaps", [views = made.mapViews] { return makeMapsModule(views); });
|
|
111
|
+
addModule(registry, "NgNativeAppleAuthentication", [provider = s.appleId, noPrompts = s.noPrompts] {
|
|
112
|
+
return makeAppleAuthenticationModule(provider, noPrompts);
|
|
113
|
+
});
|
|
114
|
+
addModule(registry, "NgNativePrint", [system = s.printSystem, http = s.http, caches = s.caches, files = s.files, noPrompts = s.noPrompts] {
|
|
115
|
+
return makePrintModule(system, http, caches + "/Print", files, noPrompts);
|
|
116
|
+
});
|
|
117
|
+
// react-native-webview's navigation answers; harmless in a host built without the library.
|
|
118
|
+
addModule(registry, "RNCWebViewModule", [] { return makeWebViewModule(sharedNavigationLocks()); });
|
|
119
|
+
addModule(registry, "NgNativeStoreReview", [prompt = s.reviewPrompt, noPrompts = s.noPrompts] {
|
|
120
|
+
return makeStoreReviewModule(prompt, noPrompts);
|
|
121
|
+
});
|
|
122
|
+
addModule(registry, "NgNativeCrypto", [crypto = s.crypto] { return makeCryptoModule(crypto); });
|
|
123
|
+
addModule(registry, "NgNativeLocalization", [locales = s.locales, regionCode = s.regionCode] {
|
|
124
|
+
return makeLocalizationModule(locales, regionCode());
|
|
125
|
+
});
|
|
126
|
+
addModule(registry, "NgNativeUpdates", [updates = s.updates, fromDevServer = s.fromDevServer, reload = s.reload, appUpdater = s.appUpdater] {
|
|
127
|
+
return makeUpdatesModule(updates, fromDevServer, reload, appUpdater);
|
|
128
|
+
});
|
|
129
|
+
return made;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
} // namespace ngn
|
|
@@ -365,7 +365,7 @@ void NotificationEvents::responded(double date, const NotificationRequest &reque
|
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
void NotificationEvents::tokenChanged(const std::string &token) {
|
|
368
|
-
send(folly::dynamic::object("type", "token")("token", folly::dynamic::object("type",
|
|
368
|
+
send(folly::dynamic::object("type", "token")("token", folly::dynamic::object("type", os_)("data", token)));
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
std::optional<folly::dynamic> NotificationEvents::lastResponse() const {
|
|
@@ -512,14 +512,14 @@ struct Notifications : NativeModule {
|
|
|
512
512
|
center->setBadge(static_cast<int>(args[0].asDouble()));
|
|
513
513
|
promise.resolve(true);
|
|
514
514
|
});
|
|
515
|
-
promise("getDevicePushTokenAsync", [push](const folly::dynamic &, JsPromise promise) {
|
|
515
|
+
promise("getDevicePushTokenAsync", [push, os = events->os()](const folly::dynamic &, JsPromise promise) {
|
|
516
516
|
if (!push) {
|
|
517
517
|
promise.reject("Remote notifications are not available in this build of the desktop host.");
|
|
518
518
|
return;
|
|
519
519
|
}
|
|
520
|
-
push->request([promise](std::optional<std::string> token, std::string error) {
|
|
520
|
+
push->request([promise, os](std::optional<std::string> token, std::string error) {
|
|
521
521
|
if (token) {
|
|
522
|
-
promise.resolve(folly::dynamic::object("type",
|
|
522
|
+
promise.resolve(folly::dynamic::object("type", os)("data", *token));
|
|
523
523
|
} else {
|
|
524
524
|
promise.reject(error);
|
|
525
525
|
}
|
|
@@ -90,6 +90,8 @@ Runtime::Runtime(
|
|
|
90
90
|
runLoop_(std::make_shared<RunLoopObserverManager>()),
|
|
91
91
|
// The mounting manager, not this runtime: the reload thread's tasks may run after it is gone.
|
|
92
92
|
reloader_([mounting = mounting_](std::function<void()> task) { mounting->runOnUiThread(std::move(task)); }) {
|
|
93
|
+
// First, so an empty OS id throws before the mounting manager holds a callback into this runtime.
|
|
94
|
+
setDevServerOs(identity_.os);
|
|
93
95
|
// As React Native iOS's surface presenter does after each mount: the UIManager's mount hooks
|
|
94
96
|
// (Reanimated's, which holds its own commits while React's are unmounted, and the observers')
|
|
95
97
|
// learn the views are there. UI thread; skipped while a reload holds the host.
|