@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.
Files changed (66) hide show
  1. package/native/CMakeLists.txt +47 -4
  2. package/native/appkit/CMakeLists.txt +2 -1
  3. package/native/appkit/cg-canvas.h +5 -0
  4. package/native/appkit/cg-canvas.mm +21 -6
  5. package/native/appkit/desktop-expo.h +6 -0
  6. package/native/appkit/desktop-expo.mm +5 -0
  7. package/native/appkit/host-view.mm +32 -0
  8. package/native/appkit/image-request.h +2 -10
  9. package/native/appkit/image-request.mm +0 -22
  10. package/native/appkit/image-view.mm +94 -6
  11. package/native/appkit/main.mm +130 -185
  12. package/native/appkit/split-view.mm +3 -9
  13. package/native/appkit/system-access.mm +3 -0
  14. package/native/appkit/system.mm +33 -48
  15. package/native/appkit/view-effects.h +27 -0
  16. package/native/appkit/view-effects.mm +90 -0
  17. package/native/cmake/runtime-dependencies.cmake +11 -1
  18. package/native/core/include/ngn/app-info.h +3 -2
  19. package/native/core/include/ngn/app-menus.h +5 -11
  20. package/native/core/include/ngn/default-menu.h +16 -6
  21. package/native/core/include/ngn/desktop-expo.h +0 -5
  22. package/native/core/include/ngn/desktop-modules.h +144 -0
  23. package/native/core/include/ngn/dev-server.h +12 -3
  24. package/native/core/include/ngn/host-os.h +45 -0
  25. package/native/core/include/ngn/host-views.h +25 -0
  26. package/native/core/include/ngn/image-source.h +18 -0
  27. package/native/core/include/ngn/launch-settings.h +9 -7
  28. package/native/core/include/ngn/module-registry.h +2 -0
  29. package/native/core/include/ngn/notifications.h +6 -0
  30. package/native/core/include/ngn/runtime.h +4 -1
  31. package/native/core/include/ngn/spawn-rules.h +3 -2
  32. package/native/core/include/ngn/split-view.h +12 -0
  33. package/native/core/include/ngn/system.h +47 -0
  34. package/native/core/include/ngn/undo.h +27 -0
  35. package/native/core/include/ngn/updates.h +3 -2
  36. package/native/core/include/ngn/view-filter.h +33 -0
  37. package/native/core/src/app-menus.cpp +9 -11
  38. package/native/core/src/default-menu.cpp +6 -2
  39. package/native/core/src/dev-server-helper.cpp +3 -2
  40. package/native/core/src/dev-server.cpp +22 -5
  41. package/native/core/src/host-os.cpp +20 -0
  42. package/native/core/src/host-views.cpp +25 -0
  43. package/native/core/src/image-source.cpp +30 -0
  44. package/native/core/src/launch-settings.cpp +10 -6
  45. package/native/core/src/module-registry.cpp +9 -0
  46. package/native/core/src/modules/app-info.cpp +4 -4
  47. package/native/core/src/modules/desktop-expo.cpp +0 -5
  48. package/native/core/src/modules/desktop-modules.cpp +132 -0
  49. package/native/core/src/modules/notifications.cpp +4 -4
  50. package/native/core/src/runtime.cpp +2 -0
  51. package/native/core/src/spawn-rules.cpp +1 -4
  52. package/native/core/src/split-view.cpp +10 -0
  53. package/native/core/src/system.cpp +52 -0
  54. package/native/core/src/undo-stacks.cpp +71 -0
  55. package/native/core/src/view-filter.cpp +114 -0
  56. package/native/scripts/build-hermes.sh +19 -7
  57. package/native/scripts/build-icu.sh +36 -0
  58. package/native/scripts/build-lock.sh +21 -0
  59. package/native/scripts/build.sh +40 -7
  60. package/native/scripts/fetch.sh +24 -2
  61. package/native/scripts/hermes-built.sh +5 -4
  62. package/native/scripts/hermes-target.sh +18 -0
  63. package/native/scripts/icu-filter.json +22 -0
  64. package/native/shim/openssl/sha.h +108 -3
  65. package/package.json +2 -2
  66. package/prebuilt.json +6 -6
@@ -0,0 +1,90 @@
1
+ #import "view-effects.h"
2
+
3
+ namespace ngn::appkit {
4
+
5
+ namespace {
6
+
7
+ CIFilter *colorMatrix(const std::array<double, 20> &m) {
8
+ CIFilter *filter = [CIFilter filterWithName:@"CIColorMatrix"];
9
+ // Row by row of the spec's 4 by 5 matrix: each output channel's weights, and the offsets as the bias.
10
+ [filter setValue:[CIVector vectorWithX:m[0] Y:m[1] Z:m[2] W:m[3]] forKey:@"inputRVector"];
11
+ [filter setValue:[CIVector vectorWithX:m[5] Y:m[6] Z:m[7] W:m[8]] forKey:@"inputGVector"];
12
+ [filter setValue:[CIVector vectorWithX:m[10] Y:m[11] Z:m[12] W:m[13]] forKey:@"inputBVector"];
13
+ [filter setValue:[CIVector vectorWithX:m[15] Y:m[16] Z:m[17] W:m[18]] forKey:@"inputAVector"];
14
+ [filter setValue:[CIVector vectorWithX:m[4] Y:m[9] Z:m[14] W:m[19]] forKey:@"inputBiasVector"];
15
+ return filter;
16
+ }
17
+
18
+ } // namespace
19
+
20
+ NSArray<CIFilter *> *layerFilters(const std::vector<FilterStep> &steps) {
21
+ NSMutableArray<CIFilter *> *filters = [NSMutableArray array];
22
+ for (const auto &step : steps) {
23
+ switch (step.type) {
24
+ case FilterStep::Type::ColorMatrix:
25
+ [filters addObject:colorMatrix(step.matrix)];
26
+ [filters addObject:[CIFilter filterWithName:@"CIColorClamp"]];
27
+ break;
28
+ case FilterStep::Type::Blur: {
29
+ CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
30
+ // Core Image's radius is the Gaussian's standard deviation, as CSS's blur() is.
31
+ [blur setValue:@(step.standardDeviation) forKey:kCIInputRadiusKey];
32
+ [filters addObject:blur];
33
+ break;
34
+ }
35
+ case FilterStep::Type::DropShadow:
36
+ break;
37
+ }
38
+ }
39
+ if (filters.count == 0) {
40
+ return nil;
41
+ }
42
+ // The steps run on sRGB values, as Chrome's do, between the conversions out of and back into the
43
+ // working space.
44
+ [filters insertObject:[CIFilter filterWithName:@"CILinearToSRGBToneCurve"] atIndex:0];
45
+ [filters addObject:[CIFilter filterWithName:@"CISRGBToneCurveToLinear"]];
46
+ return filters;
47
+ }
48
+
49
+ NSString *blendFilterName(facebook::react::BlendMode mode) {
50
+ using facebook::react::BlendMode;
51
+ switch (mode) {
52
+ case BlendMode::Multiply:
53
+ return @"multiplyBlendMode";
54
+ case BlendMode::Screen:
55
+ return @"screenBlendMode";
56
+ case BlendMode::Overlay:
57
+ return @"overlayBlendMode";
58
+ case BlendMode::Darken:
59
+ return @"darkenBlendMode";
60
+ case BlendMode::Lighten:
61
+ return @"lightenBlendMode";
62
+ case BlendMode::ColorDodge:
63
+ return @"colorDodgeBlendMode";
64
+ case BlendMode::ColorBurn:
65
+ return @"colorBurnBlendMode";
66
+ case BlendMode::HardLight:
67
+ return @"hardLightBlendMode";
68
+ case BlendMode::SoftLight:
69
+ return @"softLightBlendMode";
70
+ case BlendMode::Difference:
71
+ return @"differenceBlendMode";
72
+ case BlendMode::Exclusion:
73
+ return @"exclusionBlendMode";
74
+ case BlendMode::Hue:
75
+ return @"hueBlendMode";
76
+ case BlendMode::Saturation:
77
+ return @"saturationBlendMode";
78
+ case BlendMode::Color:
79
+ return @"colorBlendMode";
80
+ case BlendMode::Luminosity:
81
+ return @"luminosityBlendMode";
82
+ case BlendMode::PlusLighter:
83
+ return @"linearDodgeBlendMode";
84
+ case BlendMode::Normal:
85
+ return nil;
86
+ }
87
+ return nil;
88
+ }
89
+
90
+ } // namespace ngn::appkit
@@ -1,5 +1,6 @@
1
1
  # What the runtime half needs beyond the renderer: Hermes, built statically by
2
- # scripts/build-hermes.sh, and the one OpenSSL call React Native's dev-server helper makes.
2
+ # scripts/build-hermes.sh, with off macOS the static ICU it was built against, and the one OpenSSL
3
+ # call React Native's dev-server helper makes.
3
4
 
4
5
  if(IS_DIRECTORY "${NGN_HERMES_PREBUILT}")
5
6
  # React Native's prebuilt Hermes on macOS: a dynamic framework, which the binary finds beside
@@ -37,6 +38,15 @@ list(APPEND _hermes_link ${_hermes_context})
37
38
  if(APPLE)
38
39
  # Intl is built over Foundation, as in React Native's Apple builds.
39
40
  list(APPEND _hermes_link "-framework Foundation")
41
+ else()
42
+ # Its Unicode layer over the ICU scripts/build-icu.sh built beside it, data and all.
43
+ foreach(lib icui18n icuuc icudata)
44
+ if(NOT EXISTS ${NGN_HERMES_BUILD}/icu/lib/lib${lib}.a)
45
+ message(FATAL_ERROR "${NGN_HERMES_BUILD} has no ICU (icu/lib/lib${lib}.a); build through scripts/build.sh")
46
+ endif()
47
+ list(APPEND _hermes_link ${NGN_HERMES_BUILD}/icu/lib/lib${lib}.a)
48
+ endforeach()
49
+ list(APPEND _hermes_link ${CMAKE_DL_LIBS} pthread)
40
50
  endif()
41
51
  foreach(alias hermesvm libhermes)
42
52
  add_library(hermes-engine::${alias} INTERFACE IMPORTED GLOBAL)
@@ -6,7 +6,7 @@
6
6
  // (CFBundleDisplayName, else CFBundleName). A dev run's binary has no bundle: its id and name are
7
7
  // the app's own (app.json's), and its versions null.
8
8
  // - NgNativeDevice: brand and manufacturer "Apple", modelName (the Mac's marketing name, else its
9
- // model identifier), modelId ("Mac15,3"), osName "macOS", osVersion, osBuildId, deviceName,
9
+ // model identifier), modelId ("Mac15,3"), osName ("macOS"), osVersion, osBuildId, deviceName,
10
10
  // totalMemory, supportedCpuArchitectures, isDevice true (a Mac is never a simulator) and
11
11
  // deviceType 3, expo-device's DESKTOP.
12
12
  #pragma once
@@ -47,6 +47,7 @@ struct MachineFacts {
47
47
 
48
48
  // `appId` and `appName` stand in for what a bundle with no Info.plist does not have.
49
49
  std::shared_ptr<NativeModule> makeApplicationModule(BundleFacts bundle, std::string appId, std::string appName);
50
- std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine);
50
+ // `osName` is the host OS's name (HostOs).
51
+ std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine, std::string osName);
51
52
 
52
53
  } // namespace ngn
@@ -5,7 +5,8 @@
5
5
  // The bar the app sends is the whole merged bar, its defaults included. An item with a `menuRole`
6
6
  // is the OS's own command unless the app marks it `handled`; every other item is the app's, and
7
7
  // choosing it sends `menuSelect` with its id. Shortcuts match a key press before the menus see it;
8
- // one on an editing key (Cmd-Z, X, C, V, A) still goes on to a focused text input, which owns it.
8
+ // one on an editing key (the OS's primary modifier with Z, X, C, V or A: Cmd-Z on macOS) still goes
9
+ // on to a focused text input, which owns it.
9
10
  #pragma once
10
11
 
11
12
  #include "ngn/default-menu.h"
@@ -26,14 +27,6 @@ namespace ngn {
26
27
 
27
28
  using facebook::react::SurfaceId;
28
29
 
29
- // A key press: the key as the web names it (a character, or "ArrowLeft", "Enter", "F5"...) and the
30
- // modifiers held (MenuModifier).
31
- struct KeyChord {
32
- std::string key;
33
- unsigned modifiers{0};
34
- bool operator==(const KeyChord &) const = default;
35
- };
36
-
37
30
  // The entries of a menu as the app sends them (a context menu's, or one group's items).
38
31
  std::vector<MenuItem> parseMenu(const folly::dynamic &entries);
39
32
  // The app's whole bar, with the host's Developer menu before Help when `options.developer`.
@@ -46,9 +39,10 @@ enum class NavigationInput { MouseButton4, MouseButton5, SwipeLeft, SwipeRight }
46
39
 
47
40
  // The OS's back and forward inputs: mouse buttons 4 and 5, a swipe (right goes back in a
48
41
  // left-to-right layout and left in a right-to-left one, as a page follows the fingers and as Safari
49
- // swaps them), and Cmd-[ and Cmd-]. Cmd-Left stays with text editing.
42
+ // swaps them), and the OS's back and forward keys (Cmd-[ and Cmd-] on macOS, where Cmd-Left stays
43
+ // with text editing).
50
44
  std::optional<NavigationDirection> navigationFor(NavigationInput input, bool rightToLeft = false);
51
- std::optional<NavigationDirection> navigationFor(const KeyChord &chord);
45
+ std::optional<NavigationDirection> navigationFor(const KeyChord &chord, const HostOs &os);
52
46
 
53
47
  // A window's back and forward history, as the app's router reports it (`setHistory`): the titles
54
48
  // of the entries behind and ahead, nearest first.
@@ -1,9 +1,13 @@
1
- // The menu bar every desktop app gets at launch, before any JavaScript runs: the app menu with
2
- // Quit, File's Close Window and Print... (which prints the key window), the standard text editing commands, View's Back, Forward and Show Sidebar, the window commands and, for
3
- // a bundle from a dev server, the developer commands. A backend draws it and maps each command to
4
- // the toolkit's own. The app's own bar replaces it once the app sets one (app-menus.h).
1
+ // The menu bar every desktop app gets at launch, before any JavaScript runs: its OS's (HostOs's
2
+ // menuBar). On macOS, the app menu with Quit, File's Close Window and Print... (which prints the
3
+ // key window), the standard text editing commands, View's Back, Forward and Show Sidebar, the
4
+ // window commands and, for a bundle from a dev server, the developer commands. A backend draws it
5
+ // and maps each command to the toolkit's own. The app's own bar replaces it once the app sets one
6
+ // (app-menus.h).
5
7
  #pragma once
6
8
 
9
+ #include "ngn/host-os.h"
10
+
7
11
  #include <string>
8
12
  #include <vector>
9
13
 
@@ -42,8 +46,8 @@ enum class MenuCommand {
42
46
  AppItem,
43
47
  };
44
48
 
45
- // The key equivalent's modifiers, as a bitmask. Command is the platform's primary modifier
46
- // (Control off macOS).
49
+ // The key equivalent's modifiers, as a bitmask: Command is the web's `meta` key and Option its
50
+ // `alt`. Which one is the OS's primary modifier is HostOs's primaryModifier.
47
51
  enum MenuModifier : unsigned {
48
52
  Command = 1 << 0,
49
53
  Shift = 1 << 1,
@@ -81,9 +85,15 @@ struct DefaultMenuOptions {
81
85
  std::string appName;
82
86
  // Adds the Developer menu (Reload) for a bundle from a dev server.
83
87
  bool developer{false};
88
+ // The OS whose menu bar it is, and whose primary modifier and back and forward keys the app's
89
+ // menus and shortcuts follow.
90
+ HostOs os;
84
91
  };
85
92
 
93
+ // The OS's bar: `options.os.menuBar`.
86
94
  std::vector<MenuItem> defaultMenuBar(const DefaultMenuOptions &options);
95
+ // macOS's bar (HostOs's menuBar for macOS).
96
+ std::vector<MenuItem> macOSMenuBar(const DefaultMenuOptions &options);
87
97
 
88
98
  // The item with this command anywhere in `menus`, or null.
89
99
  const MenuItem *findMenuItem(const std::vector<MenuItem> &menus, MenuCommand command);
@@ -78,11 +78,6 @@ class PrefixedSecretStore final : public SecretStore {
78
78
  std::set<std::pair<std::string, std::string>> written_;
79
79
  };
80
80
 
81
- // Whether the app can use the Data Protection keychain: its signature has a Team ID, and an
82
- // entitlement that gives it a keychain access group (an application identifier, as a Mac App Store
83
- // build has, or keychain-access-groups). Without one the keychain refuses it (errSecMissingEntitlement).
84
- bool usesDataProtectionKeychain(const std::string &teamId, const std::set<std::string> &entitlements);
85
-
86
81
  // The service items go under when the call names none: the app's own.
87
82
  std::shared_ptr<NativeModule> makeSecureStoreModule(std::shared_ptr<SecretStore> store, std::string defaultService);
88
83
  bool secureStoreKeyValid(const std::string &key);
@@ -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;
@@ -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{};