@ng-native/desktop 0.24.0 → 0.26.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/bin/package.mjs +65 -9
- package/bin/prebuilt.mjs +25 -4
- package/native/CMakeLists.txt +51 -4
- package/native/appkit/CMakeLists.txt +16 -2
- package/native/appkit/appkit-backend.mm +28 -3
- 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 +121 -4
- package/native/appkit/main.mm +130 -185
- package/native/appkit/scroll-view.mm +57 -16
- package/native/appkit/scrollers.h +22 -2
- package/native/appkit/scrollers.mm +221 -2
- package/native/appkit/split-view.h +4 -0
- package/native/appkit/split-view.mm +60 -12
- package/native/appkit/system-access.mm +3 -0
- package/native/appkit/system.mm +33 -48
- package/native/appkit/text-layout.h +6 -0
- package/native/appkit/text-layout.mm +147 -24
- package/native/appkit/view-effects.h +27 -0
- package/native/appkit/view-effects.mm +90 -0
- package/native/cmake/react-native.cmake +9 -0
- package/native/cmake/runtime-dependencies.cmake +32 -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/scrollers.h +5 -0
- 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/text-measurer.h +11 -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/app-modules.cpp +4 -2
- 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/scrollers.cpp +11 -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/text-layout-manager.cpp +13 -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 +46 -7
- package/native/scripts/fetch-hermes.sh +70 -0
- 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/scripts/make-prebuilt.mjs +13 -6
- package/native/scripts/prebuilt-host-cache.mjs +1 -1
- package/native/shim/openssl/sha.h +108 -3
- package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
- package/package.json +2 -2
- package/prebuilt.json +6 -6
|
@@ -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
|
|
@@ -377,8 +377,10 @@ std::shared_ptr<NativeModule> makeGestureHandlerModule(const CoreModuleServices
|
|
|
377
377
|
// Each call is already queued for the UI thread as it is made.
|
|
378
378
|
sync("flushOperations", [](const folly::dynamic &) { return folly::dynamic(nullptr); });
|
|
379
379
|
// The worklet runtime's `_setGestureStateSync` is not installed: a worklet's state manager
|
|
380
|
-
// reaches the handlers through Reanimated's setGestureState instead (worklet-host.h).
|
|
381
|
-
|
|
380
|
+
// reaches the handlers through Reanimated's setGestureState instead (worklet-host.h). The
|
|
381
|
+
// answer only decides whether the gesture handler warns, telling the app to report a bug,
|
|
382
|
+
// so it says the runtime is ready, as the gesture handler's own web module does.
|
|
383
|
+
sync("installUIRuntimeBindings", [](const folly::dynamic &) { return folly::dynamic(true); });
|
|
382
384
|
}
|
|
383
385
|
|
|
384
386
|
void send(const std::string &event, folly::dynamic body) const {
|
|
@@ -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.
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#include "ngn/scrollers.h"
|
|
2
2
|
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
|
|
3
6
|
using namespace facebook::react;
|
|
4
7
|
namespace yoga = facebook::yoga;
|
|
5
8
|
|
|
@@ -20,6 +23,14 @@ ScrollerVisibility scrollerVisibility(
|
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
float pagedOffset(float offset, float velocity, float page, float max) {
|
|
27
|
+
// ponytail: a flick is a fixed speed, as UIKit's paging roughly is; tune here if it feels off.
|
|
28
|
+
constexpr float flick = 0.3f;
|
|
29
|
+
float at = page > 0 ? offset / page : 0;
|
|
30
|
+
float index = velocity > flick ? std::floor(at) + 1 : velocity < -flick ? std::ceil(at) - 1 : std::round(at);
|
|
31
|
+
return std::clamp(index * page, 0.0f, std::max(0.0f, max));
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
ScrollerGutter scrollerGutter(ScrollerStyle style, float legacyWidth, const ScrollerVisibility &visibility) {
|
|
24
35
|
if (style == ScrollerStyle::Overlay) {
|
|
25
36
|
return {};
|
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
namespace ngn {
|
|
8
8
|
|
|
9
|
-
const std::vector<std::string> kSearchPath{
|
|
10
|
-
"/usr/bin", "/bin", "/usr/sbin", "/sbin", "/opt/homebrew/bin", "/usr/local/bin"};
|
|
11
|
-
|
|
12
9
|
namespace {
|
|
13
10
|
|
|
14
11
|
const std::set<std::string> kRefusedPrograms{
|
|
@@ -260,7 +257,7 @@ std::optional<std::string> resolveProgram(const std::string &program, const Prog
|
|
|
260
257
|
if (program[0] == '/') {
|
|
261
258
|
candidates.push_back(program);
|
|
262
259
|
} else {
|
|
263
|
-
for (const auto &dir :
|
|
260
|
+
for (const auto &dir : lookup.searchPath) {
|
|
264
261
|
candidates.push_back(dir + "/" + program);
|
|
265
262
|
}
|
|
266
263
|
}
|
|
@@ -25,6 +25,16 @@ SplitPaneProps::SplitPaneProps(const PropsParserContext &context, const SplitPan
|
|
|
25
25
|
paneMaxWidth(convertRawProp(context, rawProps, "paneMaxWidth", sourceProps.paneMaxWidth, Float{0})),
|
|
26
26
|
autosaveName(convertRawProp(context, rawProps, "autosaveName", sourceProps.autosaveName, std::string{})) {}
|
|
27
27
|
|
|
28
|
+
SidebarWidths sidebarWidths(const SplitPaneProps *props) {
|
|
29
|
+
constexpr Float minimum = 150;
|
|
30
|
+
constexpr Float maximum = 400;
|
|
31
|
+
SidebarWidths widths;
|
|
32
|
+
widths.minimum = props && props->paneMinWidth > 0 ? props->paneMinWidth : minimum;
|
|
33
|
+
widths.maximum = std::max(widths.minimum, props && props->paneMaxWidth > 0 ? props->paneMaxWidth : maximum);
|
|
34
|
+
widths.starting = std::min(std::max(kSidebarDefaultWidth, widths.minimum), widths.maximum);
|
|
35
|
+
return widths;
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
SidebarSectionProps::SidebarSectionProps(
|
|
29
39
|
const PropsParserContext &context,
|
|
30
40
|
const SidebarSectionProps &sourceProps,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#include "ngn/system.h"
|
|
2
|
+
|
|
3
|
+
#include <folly/json.h>
|
|
4
|
+
|
|
5
|
+
namespace ngn {
|
|
6
|
+
|
|
7
|
+
ColorSchemeOverride::ColorSchemeOverride(std::string systemScheme) : system_(std::move(systemScheme)) {}
|
|
8
|
+
|
|
9
|
+
std::string ColorSchemeOverride::current() const {
|
|
10
|
+
std::lock_guard lock(mutex_);
|
|
11
|
+
return override_.value_or(system_);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
void ColorSchemeOverride::set(std::optional<std::string> scheme) {
|
|
15
|
+
std::lock_guard lock(mutex_);
|
|
16
|
+
override_ = std::move(scheme);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void ColorSchemeOverride::systemChanged(std::string scheme) {
|
|
20
|
+
std::lock_guard lock(mutex_);
|
|
21
|
+
system_ = std::move(scheme);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
std::string ColorSchemeOverride::applied(const std::optional<std::string> &scheme) const {
|
|
25
|
+
std::lock_guard lock(mutex_);
|
|
26
|
+
return scheme.value_or(system_);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
JsonPreferences::JsonPreferences(std::shared_ptr<StringStore> store, const std::string &appId, bool sharedStore)
|
|
30
|
+
: store_(std::move(store)), prefix_(sharedStore ? appId + "." : std::string{}) {}
|
|
31
|
+
|
|
32
|
+
std::optional<folly::dynamic> JsonPreferences::get(const std::string &key) const {
|
|
33
|
+
auto json = store_->get(prefix_ + key);
|
|
34
|
+
if (!json) {
|
|
35
|
+
return std::nullopt;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
return folly::parseJson(*json);
|
|
39
|
+
} catch (...) {
|
|
40
|
+
return std::nullopt;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void JsonPreferences::set(const std::string &key, const std::optional<folly::dynamic> &value) const {
|
|
45
|
+
if (value) {
|
|
46
|
+
store_->set(prefix_ + key, folly::toJson(*value));
|
|
47
|
+
} else {
|
|
48
|
+
store_->remove(prefix_ + key);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} // namespace ngn
|
|
@@ -60,4 +60,17 @@ TextMeasurement TextLayoutManager::measure(
|
|
|
60
60
|
compute);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
LinesMeasurements TextLayoutManager::measureLines(
|
|
64
|
+
const AttributedStringBox &attributedStringBox,
|
|
65
|
+
const ParagraphAttributes ¶graphAttributes,
|
|
66
|
+
const Size &size) const {
|
|
67
|
+
auto measurer = contextContainer_
|
|
68
|
+
? contextContainer_->find<std::shared_ptr<const ngn::TextMeasurer>>(ngn::kTextMeasurerKey)
|
|
69
|
+
: std::nullopt;
|
|
70
|
+
if (!measurer || !*measurer) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
return (*measurer)->lines(attributedStringBox.getValue(), paragraphAttributes, size.width);
|
|
74
|
+
}
|
|
75
|
+
|
|
63
76
|
} // namespace facebook::react
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#include "ngn/undo.h"
|
|
2
|
+
|
|
3
|
+
namespace ngn {
|
|
4
|
+
|
|
5
|
+
namespace {
|
|
6
|
+
|
|
7
|
+
// Sets a flag for one action's run and puts back its earlier value however the run ends, so an
|
|
8
|
+
// action that throws does not leave later registrations going to the wrong stack, and an undo run
|
|
9
|
+
// inside another undo's action leaves the outer one still undoing.
|
|
10
|
+
struct Running {
|
|
11
|
+
bool &flag;
|
|
12
|
+
bool before;
|
|
13
|
+
explicit Running(bool &flag) : flag(flag), before(flag) {
|
|
14
|
+
flag = true;
|
|
15
|
+
}
|
|
16
|
+
~Running() {
|
|
17
|
+
flag = before;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
} // namespace
|
|
22
|
+
|
|
23
|
+
void UndoStacks::registerAction(const std::string &label, std::function<void()> action) {
|
|
24
|
+
if (undoing_) {
|
|
25
|
+
redos_.push_back({label, std::move(action)});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
undos_.push_back({label, std::move(action)});
|
|
29
|
+
if (!redoing_) {
|
|
30
|
+
redos_.clear();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
bool UndoStacks::undoing() const {
|
|
35
|
+
return undoing_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void UndoStacks::undo() {
|
|
39
|
+
if (undos_.empty()) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
auto action = std::move(undos_.back());
|
|
43
|
+
undos_.pop_back();
|
|
44
|
+
Running running(undoing_);
|
|
45
|
+
action.run();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void UndoStacks::redo() {
|
|
49
|
+
if (redos_.empty()) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
auto action = std::move(redos_.back());
|
|
53
|
+
redos_.pop_back();
|
|
54
|
+
Running running(redoing_);
|
|
55
|
+
action.run();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void UndoStacks::clear() {
|
|
59
|
+
undos_.clear();
|
|
60
|
+
redos_.clear();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
std::optional<std::string> UndoStacks::undoLabel() const {
|
|
64
|
+
return undos_.empty() ? std::nullopt : std::optional(undos_.back().label);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
std::optional<std::string> UndoStacks::redoLabel() const {
|
|
68
|
+
return redos_.empty() ? std::nullopt : std::optional(redos_.back().label);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} // namespace ngn
|