@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.
Files changed (85) hide show
  1. package/bin/package.mjs +65 -9
  2. package/bin/prebuilt.mjs +25 -4
  3. package/native/CMakeLists.txt +51 -4
  4. package/native/appkit/CMakeLists.txt +16 -2
  5. package/native/appkit/appkit-backend.mm +28 -3
  6. package/native/appkit/cg-canvas.h +5 -0
  7. package/native/appkit/cg-canvas.mm +21 -6
  8. package/native/appkit/desktop-expo.h +6 -0
  9. package/native/appkit/desktop-expo.mm +5 -0
  10. package/native/appkit/host-view.mm +32 -0
  11. package/native/appkit/image-request.h +2 -10
  12. package/native/appkit/image-request.mm +0 -22
  13. package/native/appkit/image-view.mm +121 -4
  14. package/native/appkit/main.mm +130 -185
  15. package/native/appkit/scroll-view.mm +57 -16
  16. package/native/appkit/scrollers.h +22 -2
  17. package/native/appkit/scrollers.mm +221 -2
  18. package/native/appkit/split-view.h +4 -0
  19. package/native/appkit/split-view.mm +60 -12
  20. package/native/appkit/system-access.mm +3 -0
  21. package/native/appkit/system.mm +33 -48
  22. package/native/appkit/text-layout.h +6 -0
  23. package/native/appkit/text-layout.mm +147 -24
  24. package/native/appkit/view-effects.h +27 -0
  25. package/native/appkit/view-effects.mm +90 -0
  26. package/native/cmake/react-native.cmake +9 -0
  27. package/native/cmake/runtime-dependencies.cmake +32 -1
  28. package/native/core/include/ngn/app-info.h +3 -2
  29. package/native/core/include/ngn/app-menus.h +5 -11
  30. package/native/core/include/ngn/default-menu.h +16 -6
  31. package/native/core/include/ngn/desktop-expo.h +0 -5
  32. package/native/core/include/ngn/desktop-modules.h +144 -0
  33. package/native/core/include/ngn/dev-server.h +12 -3
  34. package/native/core/include/ngn/host-os.h +45 -0
  35. package/native/core/include/ngn/host-views.h +25 -0
  36. package/native/core/include/ngn/image-source.h +18 -0
  37. package/native/core/include/ngn/launch-settings.h +9 -7
  38. package/native/core/include/ngn/module-registry.h +2 -0
  39. package/native/core/include/ngn/notifications.h +6 -0
  40. package/native/core/include/ngn/runtime.h +4 -1
  41. package/native/core/include/ngn/scrollers.h +5 -0
  42. package/native/core/include/ngn/spawn-rules.h +3 -2
  43. package/native/core/include/ngn/split-view.h +12 -0
  44. package/native/core/include/ngn/system.h +47 -0
  45. package/native/core/include/ngn/text-measurer.h +11 -0
  46. package/native/core/include/ngn/undo.h +27 -0
  47. package/native/core/include/ngn/updates.h +3 -2
  48. package/native/core/include/ngn/view-filter.h +33 -0
  49. package/native/core/src/app-menus.cpp +9 -11
  50. package/native/core/src/default-menu.cpp +6 -2
  51. package/native/core/src/dev-server-helper.cpp +3 -2
  52. package/native/core/src/dev-server.cpp +22 -5
  53. package/native/core/src/host-os.cpp +20 -0
  54. package/native/core/src/host-views.cpp +25 -0
  55. package/native/core/src/image-source.cpp +30 -0
  56. package/native/core/src/launch-settings.cpp +10 -6
  57. package/native/core/src/module-registry.cpp +9 -0
  58. package/native/core/src/modules/app-info.cpp +4 -4
  59. package/native/core/src/modules/app-modules.cpp +4 -2
  60. package/native/core/src/modules/desktop-expo.cpp +0 -5
  61. package/native/core/src/modules/desktop-modules.cpp +132 -0
  62. package/native/core/src/modules/notifications.cpp +4 -4
  63. package/native/core/src/runtime.cpp +2 -0
  64. package/native/core/src/scrollers.cpp +11 -0
  65. package/native/core/src/spawn-rules.cpp +1 -4
  66. package/native/core/src/split-view.cpp +10 -0
  67. package/native/core/src/system.cpp +52 -0
  68. package/native/core/src/text-layout-manager.cpp +13 -0
  69. package/native/core/src/undo-stacks.cpp +71 -0
  70. package/native/core/src/view-filter.cpp +114 -0
  71. package/native/scripts/build-hermes.sh +19 -7
  72. package/native/scripts/build-icu.sh +36 -0
  73. package/native/scripts/build-lock.sh +21 -0
  74. package/native/scripts/build.sh +46 -7
  75. package/native/scripts/fetch-hermes.sh +70 -0
  76. package/native/scripts/fetch.sh +24 -2
  77. package/native/scripts/hermes-built.sh +5 -4
  78. package/native/scripts/hermes-target.sh +18 -0
  79. package/native/scripts/icu-filter.json +22 -0
  80. package/native/scripts/make-prebuilt.mjs +13 -6
  81. package/native/scripts/prebuilt-host-cache.mjs +1 -1
  82. package/native/shim/openssl/sha.h +108 -3
  83. package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
  84. package/package.json +2 -2
  85. package/prebuilt.json +6 -6
@@ -0,0 +1,144 @@
1
+ // The desktop host's own modules (NgNativeWindows to NgNativeUpdates, and react-native-webview's
2
+ // RNCWebViewModule), registered once for every backend. A backend makes what only its toolkit can
3
+ // answer (the Keychain, the pasteboard, the notification centre) and passes it in; the core makes
4
+ // the objects its modules share and gives back those the backend's views need too.
5
+ //
6
+ // Each module is made again on every reload, over the same sources: they live for the process.
7
+ #pragma once
8
+
9
+ #include "ngn/address-search.h"
10
+ #include "ngn/app-info.h"
11
+ #include "ngn/app-menus.h"
12
+ #include "ngn/app-windows.h"
13
+ #include "ngn/apple-authentication.h"
14
+ #include "ngn/audio.h"
15
+ #include "ngn/battery.h"
16
+ #include "ngn/calendar.h"
17
+ #include "ngn/camera.h"
18
+ #include "ngn/crypto.h"
19
+ #include "ngn/desktop-expo.h"
20
+ #include "ngn/file-system.h"
21
+ #include "ngn/fonts.h"
22
+ #include "ngn/host-os.h"
23
+ #include "ngn/image-manipulator.h"
24
+ #include "ngn/language-model.h"
25
+ #include "ngn/local-authentication.h"
26
+ #include "ngn/location.h"
27
+ #include "ngn/maps.h"
28
+ #include "ngn/module-registry.h"
29
+ #include "ngn/network-state.h"
30
+ #include "ngn/network.h"
31
+ #include "ngn/notifications.h"
32
+ #include "ngn/photo-library.h"
33
+ #include "ngn/printing.h"
34
+ #include "ngn/processes.h"
35
+ #include "ngn/screen-capture.h"
36
+ #include "ngn/sharing.h"
37
+ #include "ngn/splash-screen.h"
38
+ #include "ngn/store-review.h"
39
+ #include "ngn/symbol.h"
40
+ #include "ngn/system.h"
41
+ #include "ngn/text-recognition.h"
42
+ #include "ngn/tracking.h"
43
+ #include "ngn/tray-and-dock.h"
44
+ #include "ngn/undo.h"
45
+ #include "ngn/updates.h"
46
+ #include "ngn/video.h"
47
+ #include "ngn/web-browser.h"
48
+
49
+ #include <functional>
50
+ #include <memory>
51
+ #include <string>
52
+
53
+ namespace ngn {
54
+
55
+ // What the backend passes in: the host's state and folders, the app's hosts it made with its
56
+ // windows and menus, and one source for each module that reaches the OS.
57
+ struct DesktopModuleSources {
58
+ // The OS the host runs on: Device's osName, and a device push token's type.
59
+ HostOs os;
60
+ std::shared_ptr<System> system;
61
+ std::shared_ptr<HostState> state;
62
+ std::shared_ptr<Http> http;
63
+ // The one set of rules for every path JavaScript names (file-system.h).
64
+ std::shared_ptr<FileAccess> files;
65
+ // The app's id, which names its secrets' service, and its name, as Application gives them.
66
+ std::string appId;
67
+ std::string appName;
68
+ // The app's caches folder: each module that writes a file JavaScript reads back has one in it.
69
+ std::string caches;
70
+ // No system prompt is ever shown (launch-settings.h): a permission not decided reads as denied.
71
+ bool noPrompts{false};
72
+
73
+ std::shared_ptr<WindowHost> windows;
74
+ std::shared_ptr<MenuHost> menus;
75
+ std::shared_ptr<TrayHost> tray;
76
+ std::shared_ptr<DockHost> dock;
77
+
78
+ ProcessesSetup processes;
79
+ std::shared_ptr<ShellOpener> shell;
80
+ std::shared_ptr<SecretStore> secrets;
81
+ std::shared_ptr<SleepPreventer> sleep;
82
+ std::shared_ptr<HapticPlayer> haptics;
83
+ // The notification centre, made over the events the core makes for it and for push.
84
+ std::function<std::shared_ptr<NotificationCenter>(std::shared_ptr<NotificationEvents>)> notifications;
85
+ std::shared_ptr<PushRegistrar> push;
86
+ std::shared_ptr<UndoManager> undo;
87
+ std::shared_ptr<FileDialogs> fileDialogs;
88
+ std::shared_ptr<FileWatcher> fileWatcher;
89
+ std::shared_ptr<LocationSource> location;
90
+ std::shared_ptr<Geocoder> geocoder;
91
+ std::shared_ptr<Authenticator> authenticator;
92
+ BundleFacts bundle;
93
+ MachineFacts machine;
94
+ std::shared_ptr<PathMonitor> pathMonitor;
95
+ std::shared_ptr<PowerSource> power;
96
+ std::shared_ptr<FontRegistrar> fontRegistrar;
97
+ std::shared_ptr<AuthSession> authSession;
98
+ std::shared_ptr<TextReader> textReader;
99
+ std::shared_ptr<CalendarStore> calendars;
100
+ std::shared_ptr<AudioOutput> audioOutput;
101
+ std::shared_ptr<AudioInput> audioInput;
102
+ std::shared_ptr<VideoOutput> videoOutput;
103
+ std::shared_ptr<LanguageModelEngine> languageModel;
104
+ std::shared_ptr<CaptureShield> captureShield;
105
+ std::shared_ptr<SplashGate> splash;
106
+ std::shared_ptr<PhotoLibrary> photos;
107
+ std::shared_ptr<CameraHardware> cameraHardware;
108
+ std::shared_ptr<CameraSheet> cameraSheet;
109
+ std::shared_ptr<TrackingAuthority> tracking;
110
+ std::shared_ptr<AddressLookup> addressLookup;
111
+ std::shared_ptr<SymbolMeasurer> symbolMeasurer;
112
+ std::shared_ptr<SharePicker> sharePicker;
113
+ std::shared_ptr<ImageCodec> imageCodec;
114
+ std::shared_ptr<AppleIdProvider> appleId;
115
+ std::shared_ptr<PrintSystem> printSystem;
116
+ std::shared_ptr<ReviewPrompt> reviewPrompt;
117
+ std::shared_ptr<CryptoSource> crypto;
118
+ std::shared_ptr<LocaleSource> locales;
119
+ // The region the system is set to, read again as each runtime's Localization module starts.
120
+ std::function<std::string()> regionCode;
121
+
122
+ // The Expo Updates client, whether the bundle came from a dev server, how the module's reload
123
+ // runs the bundle it names, and the whole-app updater, when the backend has one.
124
+ std::shared_ptr<UpdatesClient> updates;
125
+ bool fromDevServer{false};
126
+ std::function<void(const std::string &bundle, std::function<void(bool)> done)> reload;
127
+ std::shared_ptr<AppUpdater> appUpdater;
128
+ };
129
+
130
+ // The core objects the modules share that the backend needs as well: the launcher it kills the
131
+ // app's programs with as it quits, where it hears push answers and silent pushes, the fonts its
132
+ // text draws with, and the registries its camera and map views join.
133
+ struct DesktopModules {
134
+ std::shared_ptr<ProcessLauncher> launcher;
135
+ std::shared_ptr<NotificationEvents> notificationEvents;
136
+ std::shared_ptr<PushTokens> push;
137
+ std::shared_ptr<FontLibrary> fonts;
138
+ std::shared_ptr<CameraViews> cameraViews;
139
+ std::shared_ptr<MapViews> mapViews;
140
+ };
141
+
142
+ DesktopModules addDesktopModules(ModuleRegistry &registry, const DesktopModuleSources &sources);
143
+
144
+ } // namespace ngn
@@ -21,13 +21,22 @@ struct DevServer {
21
21
  uint32_t port{0};
22
22
  // The bundle's path without its leading slash and `.bundle`, as HMRClient.setup takes it.
23
23
  std::string entry;
24
- // The `platform` query parameter; `macos` when the URL has none.
24
+ // The `platform` query parameter; empty when the URL has none.
25
25
  std::string platform;
26
26
 
27
27
  // Where Metro sends reload and dev menu messages.
28
28
  std::string packagerConnectionUrl() const;
29
- // HMRClient.setup(platform, bundleEntry, host, port, isEnabled, scheme).
30
- folly::dynamic hmrSetupArgs() const;
29
+ // HMRClient.setup(platform, bundleEntry, host, port, isEnabled, scheme), the platform `os` (the
30
+ // host OS's id, HostOs) when the URL names none.
31
+ folly::dynamic hmrSetupArgs(const std::string &os) const;
31
32
  };
32
33
 
34
+ // The OS id the HMR client is set up for when the bundle URL names none. ReactHost makes React
35
+ // Native's DevServerHelper (dev-server-helper.cpp) with no way to pass it one, so the runtime sets
36
+ // it for the process before it makes its ReactHost, through setDevServerOs.
37
+ const std::string &devServerOs();
38
+ // Sets devServerOs. An empty id throws std::invalid_argument: the HMR client would be set up for
39
+ // no platform, and the core names no OS of its own to fall back on.
40
+ void setDevServerOs(std::string os);
41
+
33
42
  } // namespace ngn
@@ -0,0 +1,45 @@
1
+ // The OS the desktop host runs on, as the core needs to know it: the values that differ from one
2
+ // desktop OS to the next. A backend passes its OS's in as it builds the host, so the core itself
3
+ // names none of them.
4
+ #pragma once
5
+
6
+ #include <string>
7
+ #include <vector>
8
+
9
+ namespace ngn {
10
+
11
+ struct MenuItem;
12
+ struct DefaultMenuOptions;
13
+
14
+ // A key press: the key as the web names it (a character, or "ArrowLeft", "Enter", "F5"...) and the
15
+ // modifiers held (MenuModifier, default-menu.h).
16
+ struct KeyChord {
17
+ std::string key;
18
+ unsigned modifiers{0};
19
+ bool operator==(const KeyChord &) const = default;
20
+ };
21
+
22
+ struct HostOs {
23
+ // What `Platform.OS` reports ("macos"): the Metro `platform` a bundle URL without one is for, the
24
+ // `expo-platform` header Expo Updates sends by default, and a device push token's `type`.
25
+ std::string id;
26
+ // What Device's `osName` reports ("macOS").
27
+ std::string name;
28
+ // The host binary's name, for its usage line.
29
+ std::string program;
30
+ // The modifier an app's shortcuts and the OS's own commands use (MenuModifier): the one a
31
+ // `mod+` shortcut means, and the one that makes Z, X, C, V and A a focused text input's.
32
+ unsigned primaryModifier{0};
33
+ // The key presses that go back and forward through a window's history.
34
+ KeyChord back;
35
+ KeyChord forward;
36
+ // Where a bare program name a spawn capability declares is looked for, in order.
37
+ std::vector<std::string> searchPath;
38
+ // The menu bar an app has before its own (default-menu.h). It has a Close Window item, and with
39
+ // `options.developer` a menu holding Reload: an app's bar takes both from it (parseMenuBar).
40
+ std::vector<MenuItem> (*menuBar)(const DefaultMenuOptions &options){nullptr};
41
+ };
42
+
43
+ HostOs macOS();
44
+
45
+ } // namespace ngn
@@ -0,0 +1,25 @@
1
+ // The view side every desktop host builds over its backend: the mounting manager, the input
2
+ // dispatcher over its view tree, and react-native-gesture-handler's recognisers, which the
3
+ // dispatcher feeds and Reanimated's worklet gestures reach through the worklet host both ways.
4
+ // The backend adds what only its toolkit has: the views, the timers and the UI thread.
5
+ #pragma once
6
+
7
+ #include "ngn/gestures.h"
8
+ #include "ngn/input-dispatcher.h"
9
+ #include "ngn/mounting-manager.h"
10
+
11
+ #include <memory>
12
+
13
+ namespace ngn {
14
+
15
+ struct HostViews {
16
+ std::shared_ptr<MountingManager> mounting;
17
+ std::unique_ptr<InputDispatcher> input;
18
+ std::shared_ptr<Gestures> gestures;
19
+ };
20
+
21
+ // `schedule` runs the recognisers' timers on the UI thread.
22
+ HostViews makeHostViews(
23
+ std::shared_ptr<MountingBackend> backend, std::shared_ptr<DesktopPropsSink> desktopProps, Gestures::Schedule schedule);
24
+
25
+ } // namespace ngn
@@ -0,0 +1,18 @@
1
+ // Which of an Image's sources it loads, and whether a new one is a new load: the same on every
2
+ // toolkit, which then makes the request (appkit/image-request.h on macOS).
3
+ #pragma once
4
+
5
+ #include <react/renderer/imagemanager/primitives.h>
6
+
7
+ #include <optional>
8
+ #include <vector>
9
+
10
+ namespace ngn {
11
+
12
+ // The source with a uri whose scale is nearest `screenScale`, as React Native iOS picks, or none.
13
+ std::optional<facebook::react::ImageSource> pickImageSource(
14
+ const std::vector<facebook::react::ImageSource> &sources, double screenScale);
15
+ // Whether two sources load the same thing: ImageSource's own == compares only the uri.
16
+ bool sameImageRequest(const facebook::react::ImageSource &a, const facebook::react::ImageSource &b);
17
+
18
+ } // namespace ngn
@@ -5,6 +5,7 @@
5
5
  // it run another bundle, as another app, or take updates from another server.
6
6
  #pragma once
7
7
 
8
+ #include "ngn/host-os.h"
8
9
  #include "ngn/updates.h"
9
10
 
10
11
  #include <functional>
@@ -83,16 +84,17 @@ struct LaunchSettings {
83
84
  LaunchSources::Lookup plist;
84
85
  };
85
86
 
86
- // The settings, or the usage line when a dev run's argv names no bundle or is malformed, or why a
87
- // test launch's environment is unusable (NGN_TESTS=1 without an absolute NGN_STATE_DIR, or with a
88
- // run id that is not letters, digits and dashes).
89
- std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources);
87
+ // The settings, or the usage line (naming `os`'s program) when a dev run's argv names no bundle or
88
+ // is malformed, or why a test launch's environment is unusable (NGN_TESTS=1 without an absolute
89
+ // NGN_STATE_DIR, or with a run id that is not letters, digits and dashes).
90
+ std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources, const HostOs &os);
90
91
 
91
92
  // The Expo Updates client's settings: NGNUpdatesURL, NGNRuntimeVersion, NGNUpdatesPlatform,
92
93
  // NGNUpdatesCodeSigningCertificate (PEM), NGNUpdatesCodeSigningKeyId and
93
94
  // NGNUpdatesCodeSigningAlg, and in a dev run NGN_UPDATES_URL and the rest, as `setting` reads
94
- // them. Updates are kept in `appData`/updates; `embeddedBundle` runs without one. Off (no url)
95
- // without a runtime version.
96
- UpdatesConfig updatesConfigFrom(const LaunchSettings &settings, const std::string &appData, const std::string &embeddedBundle);
95
+ // them. The platform is `os`'s id without NGNUpdatesPlatform. Updates are kept in `appData`/updates;
96
+ // `embeddedBundle` runs without one. Off (no url) without a runtime version.
97
+ UpdatesConfig updatesConfigFrom(
98
+ const LaunchSettings &settings, const HostOs &os, const std::string &appData, const std::string &embeddedBundle);
97
99
 
98
100
  } // namespace ngn
@@ -35,6 +35,8 @@ class ModuleRegistry {
35
35
  // A core module. A second registration under one name replaces the first.
36
36
  void add(const std::string &name, Factory factory);
37
37
  void addProvider(std::shared_ptr<ModuleProvider> provider);
38
+ // The names the core modules were added under, sorted.
39
+ std::vector<std::string> names() const;
38
40
 
39
41
  std::shared_ptr<facebook::react::TurboModule> module(
40
42
  const std::string &name,
@@ -160,6 +160,11 @@ std::string pushFailure(const std::string &message);
160
160
  // the response that launched the app waits for getLastNotificationResponseAsync.
161
161
  class NotificationEvents {
162
162
  public:
163
+ // `os` is the host OS's id (HostOs), a device push token's `type`.
164
+ explicit NotificationEvents(std::string os) : os_(std::move(os)) {}
165
+ const std::string &os() const {
166
+ return os_;
167
+ }
163
168
  void received(double date, const NotificationRequest &request);
164
169
  void responded(double date, const NotificationRequest &request);
165
170
  // A new device token, in hex, while the app runs.
@@ -169,6 +174,7 @@ class NotificationEvents {
169
174
 
170
175
  private:
171
176
  void send(const folly::dynamic &event);
177
+ std::string os_;
172
178
  mutable std::mutex mutex_;
173
179
  std::optional<folly::dynamic> lastResponse_;
174
180
  // A dropped handle waits for its listener's call in progress, so a module going with a reload
@@ -48,6 +48,9 @@ struct NetworkClients {
48
48
  struct DebuggerIdentity {
49
49
  std::string appId{"ngn-desktop"};
50
50
  std::string deviceName{"desktop"};
51
+ // The host OS's id (HostOs): the platform the HMR client is set up for when the bundle URL
52
+ // names none. Required: the runtime throws std::invalid_argument when it is empty.
53
+ std::string os;
51
54
  };
52
55
 
53
56
  class Runtime {
@@ -61,7 +64,7 @@ class Runtime {
61
64
  std::shared_ptr<ModuleRegistry> modules,
62
65
  NetworkClients clients,
63
66
  std::string bundle,
64
- DebuggerIdentity identity = {});
67
+ DebuggerIdentity identity);
65
68
  ~Runtime();
66
69
  Runtime(const Runtime &) = delete;
67
70
  Runtime &operator=(const Runtime &) = delete;
@@ -53,6 +53,11 @@ ScrollerVisibility scrollerVisibility(
53
53
  // The gutter the visible scrollers take: their width for legacy scrollers, nothing for overlay.
54
54
  ScrollerGutter scrollerGutter(ScrollerStyle style, float legacyWidth, const ScrollerVisibility &visibility);
55
55
 
56
+ // Where a scroll view with `pagingEnabled` settles along one axis when a drag ends at `offset`,
57
+ // moving at `velocity` (points a millisecond, positive further into the content): the nearest page,
58
+ // or the next one in the drag's direction when it was flicked, within [0, `max`].
59
+ float pagedOffset(float offset, float velocity, float page, float max);
60
+
56
61
  // `style` with `gutter` added to the padding Yoga reads for the right and bottom edges in
57
62
  // `direction`. A percentage or `auto` there is left alone.
58
63
  facebook::yoga::Style withGutter(
@@ -42,8 +42,6 @@ class SpawnRuleError : public std::runtime_error {
42
42
  using std::runtime_error::runtime_error;
43
43
  };
44
44
 
45
- extern const std::vector<std::string> kSearchPath;
46
-
47
45
  // Why `program` cannot be declared, or nothing when it can.
48
46
  std::optional<std::string> programProblem(const std::string &program);
49
47
 
@@ -65,6 +63,9 @@ struct ProgramLookup {
65
63
  std::function<bool(const std::string &path)> isExecutable;
66
64
  // A developer tool stub that only runs xcrun, with no Command Line Tools to run.
67
65
  std::function<bool(const std::string &path)> isStub;
66
+ // Where a bare name is looked for, in order: the host OS's searchPath (HostOs), never the
67
+ // inherited PATH.
68
+ std::vector<std::string> searchPath;
68
69
  };
69
70
 
70
71
  // Where a declared program runs from, pinned once at startup, or nothing when it is absent.
@@ -56,6 +56,18 @@ class SplitPaneProps final : public facebook::react::ViewProps {
56
56
  std::string autosaveName;
57
57
  };
58
58
 
59
+ // The narrowest and widest a sidebar is dragged to, and the width it starts at when its toolkit's
60
+ // autosave holds none: the app's bounds, or 150 and 400 where it sets none, with the widest never
61
+ // below the narrowest.
62
+ struct SidebarWidths {
63
+ facebook::react::Float minimum{0};
64
+ facebook::react::Float maximum{0};
65
+ facebook::react::Float starting{0};
66
+ bool operator==(const SidebarWidths &) const = default;
67
+ };
68
+ // `props` is the sidebar's, or null before it has any.
69
+ SidebarWidths sidebarWidths(const SplitPaneProps *props);
70
+
59
71
  // The size the toolkit gives a pane, or a custom row's width (height unused). Zero until it reports.
60
72
  struct SplitPaneState {
61
73
  facebook::react::Size size{};
@@ -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
@@ -8,6 +8,7 @@
8
8
  #include <react/renderer/attributedstring/AttributedString.h>
9
9
  #include <react/renderer/attributedstring/ParagraphAttributes.h>
10
10
  #include <react/renderer/graphics/Size.h>
11
+ #include <react/renderer/textlayoutmanager/TextMeasureCache.h>
11
12
  #include <react/utils/ContextContainer.h>
12
13
 
13
14
  #include <memory>
@@ -24,6 +25,16 @@ class TextMeasurer {
24
25
  const facebook::react::AttributedString &text,
25
26
  const facebook::react::ParagraphAttributes &paragraph,
26
27
  facebook::react::Float maxWidth) const = 0;
28
+
29
+ // The lines the text lays out in at `width`, each with its frame and its first font's metrics,
30
+ // y measured from the top of the text: what a baseline and onTextLayout read. None by default,
31
+ // which reads as a baseline at the top.
32
+ virtual facebook::react::LinesMeasurements lines(
33
+ const facebook::react::AttributedString &text,
34
+ const facebook::react::ParagraphAttributes &paragraph,
35
+ facebook::react::Float width) const {
36
+ return {};
37
+ }
27
38
  };
28
39
 
29
40
  // The ContextContainer key the core's TextLayoutManager reads the measurer from.
@@ -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. EAS Update refuses `macos`; a self-hosted server serves it.
61
- std::string platform{"macos"};
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 == Command && std::find(keys.begin(), keys.end(), chord.key) != keys.end();
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 app's bar has: the File menu's
149
- // Close Window, as the default bar has it, when the app's bar has no close item.
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.modifiers != Command) {
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.key == "]") {
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),