@ng-native/desktop 0.0.0-stage → 0.23.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/LICENSE +21 -0
- package/README.md +51 -2
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +276 -0
- package/native/appkit/CMakeLists.txt +109 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +130 -0
- package/native/appkit/camera.h +39 -0
- package/native/appkit/camera.mm +362 -0
- package/native/appkit/cg-canvas.h +17 -0
- package/native/appkit/cg-canvas.mm +518 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +629 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1200 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1515 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +558 -0
- package/native/appkit/svg-view.h +17 -0
- package/native/appkit/svg-view.mm +57 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +76 -0
- package/native/appkit/text-input-field.mm +444 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +477 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +9 -0
- package/native/appkit/web-view-component.mm +56 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +394 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +146 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +112 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +128 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +105 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +130 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +161 -0
- package/native/core/include/ngn/safe-areas.h +77 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/svg.h +393 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +125 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +133 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +352 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +91 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +345 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +405 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +221 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +371 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +380 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +422 -0
- package/native/core/src/safe-areas.cpp +130 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +1883 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +126 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +171 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +70 -3
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#include "ngn/input-script.h"
|
|
2
|
+
|
|
3
|
+
#include <sstream>
|
|
4
|
+
|
|
5
|
+
namespace ngn {
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
std::optional<GesturePhase> phaseNamed(const std::string &name, bool &ok) {
|
|
10
|
+
ok = true;
|
|
11
|
+
if (name == "began") {
|
|
12
|
+
return GesturePhase::Began;
|
|
13
|
+
}
|
|
14
|
+
if (name == "changed") {
|
|
15
|
+
return GesturePhase::Changed;
|
|
16
|
+
}
|
|
17
|
+
if (name == "ended") {
|
|
18
|
+
return GesturePhase::Ended;
|
|
19
|
+
}
|
|
20
|
+
ok = name.empty();
|
|
21
|
+
return std::nullopt;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
} // namespace
|
|
25
|
+
|
|
26
|
+
InputScript parseInputScript(const std::string &text) {
|
|
27
|
+
InputScript script;
|
|
28
|
+
std::istringstream lines(text);
|
|
29
|
+
std::string line;
|
|
30
|
+
int number = 0;
|
|
31
|
+
while (std::getline(lines, line)) {
|
|
32
|
+
++number;
|
|
33
|
+
if (auto hash = line.find('#'); hash != std::string::npos) {
|
|
34
|
+
line.erase(hash);
|
|
35
|
+
}
|
|
36
|
+
std::istringstream words(line);
|
|
37
|
+
std::string verb;
|
|
38
|
+
if (!(words >> verb)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
auto fail = [&](const std::string &why) {
|
|
42
|
+
script.steps.clear();
|
|
43
|
+
script.error = "line " + std::to_string(number) + ": " + why;
|
|
44
|
+
return script;
|
|
45
|
+
};
|
|
46
|
+
InputStep step{};
|
|
47
|
+
std::string phase;
|
|
48
|
+
if (verb == "wait") {
|
|
49
|
+
step.kind = InputStep::Kind::Wait;
|
|
50
|
+
if (!(words >> step.amount) || step.amount < 0) {
|
|
51
|
+
return fail("wait needs a number of milliseconds");
|
|
52
|
+
}
|
|
53
|
+
} else if (verb == "move" || verb == "down" || verb == "drag" || verb == "up" || verb == "secondary") {
|
|
54
|
+
step.kind = verb == "move" ? InputStep::Kind::Move
|
|
55
|
+
: verb == "down" ? InputStep::Kind::Down
|
|
56
|
+
: verb == "drag" ? InputStep::Kind::Drag
|
|
57
|
+
: verb == "up" ? InputStep::Kind::Up
|
|
58
|
+
: InputStep::Kind::Secondary;
|
|
59
|
+
if (!(words >> step.x >> step.y)) {
|
|
60
|
+
return fail(verb + " needs x and y");
|
|
61
|
+
}
|
|
62
|
+
} else if (verb == "scroll") {
|
|
63
|
+
step.kind = InputStep::Kind::Scroll;
|
|
64
|
+
if (!(words >> step.x >> step.y >> step.amount >> step.dy)) {
|
|
65
|
+
return fail("scroll needs x, y, dx and dy");
|
|
66
|
+
}
|
|
67
|
+
words >> phase;
|
|
68
|
+
} else if (verb == "magnify" || verb == "rotate") {
|
|
69
|
+
step.kind = verb == "magnify" ? InputStep::Kind::Magnify : InputStep::Kind::Rotate;
|
|
70
|
+
if (!(words >> step.x >> step.y >> step.amount >> phase) || phase.empty()) {
|
|
71
|
+
return fail(verb + " needs x, y, an amount and a phase");
|
|
72
|
+
}
|
|
73
|
+
} else if (verb == "key") {
|
|
74
|
+
step.kind = InputStep::Kind::Key;
|
|
75
|
+
if (!(words >> step.key)) {
|
|
76
|
+
return fail("key needs a key");
|
|
77
|
+
}
|
|
78
|
+
if (step.key.size() != 1 && step.key != "escape" && step.key != "return" && step.key != "space" &&
|
|
79
|
+
step.key != "tab" && step.key != "delete") {
|
|
80
|
+
return fail("unknown key " + step.key);
|
|
81
|
+
}
|
|
82
|
+
std::string modifier;
|
|
83
|
+
while (words >> modifier) {
|
|
84
|
+
if (modifier == "cmd") {
|
|
85
|
+
step.modifiers |= InputStep::Command;
|
|
86
|
+
} else if (modifier == "shift") {
|
|
87
|
+
step.modifiers |= InputStep::Shift;
|
|
88
|
+
} else if (modifier == "option") {
|
|
89
|
+
step.modifiers |= InputStep::Option;
|
|
90
|
+
} else if (modifier == "ctrl") {
|
|
91
|
+
step.modifiers |= InputStep::Control;
|
|
92
|
+
} else {
|
|
93
|
+
return fail("unknown modifier " + modifier);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} else if (verb == "choose" || verb == "type") {
|
|
97
|
+
step.kind = verb == "choose" ? InputStep::Kind::Choose : InputStep::Kind::Type;
|
|
98
|
+
std::string rest;
|
|
99
|
+
std::getline(words, rest);
|
|
100
|
+
auto first = rest.find_first_not_of(" \t");
|
|
101
|
+
auto last = rest.find_last_not_of(" \t\r");
|
|
102
|
+
if (first == std::string::npos) {
|
|
103
|
+
return fail(verb == "choose" ? "choose needs an item's title" : "type needs some text");
|
|
104
|
+
}
|
|
105
|
+
step.key = rest.substr(first, last - first + 1);
|
|
106
|
+
} else {
|
|
107
|
+
return fail("unknown step " + verb);
|
|
108
|
+
}
|
|
109
|
+
bool ok = true;
|
|
110
|
+
step.phase = phaseNamed(phase, ok);
|
|
111
|
+
if (!ok) {
|
|
112
|
+
return fail("unknown phase " + phase);
|
|
113
|
+
}
|
|
114
|
+
std::string extra;
|
|
115
|
+
if (words >> extra) {
|
|
116
|
+
return fail("unexpected " + extra);
|
|
117
|
+
}
|
|
118
|
+
script.steps.push_back(step);
|
|
119
|
+
}
|
|
120
|
+
return script;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} // namespace ngn
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#include "ngn/key-value-store.h"
|
|
2
|
+
|
|
3
|
+
#include <folly/json.h>
|
|
4
|
+
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <cstdio>
|
|
7
|
+
#include <filesystem>
|
|
8
|
+
#include <fstream>
|
|
9
|
+
#include <sstream>
|
|
10
|
+
|
|
11
|
+
namespace ngn {
|
|
12
|
+
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
void mergeInto(folly::dynamic &into, const folly::dynamic &from) {
|
|
16
|
+
for (const auto &[k, v] : from.items()) {
|
|
17
|
+
if (v.isObject() && into.count(k) && into[k].isObject()) {
|
|
18
|
+
mergeInto(into[k], v);
|
|
19
|
+
} else {
|
|
20
|
+
into[k] = v;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
std::optional<folly::dynamic> parse(const std::string &json) {
|
|
26
|
+
try {
|
|
27
|
+
return folly::parseJson(json);
|
|
28
|
+
} catch (...) {
|
|
29
|
+
return std::nullopt;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
} // namespace
|
|
34
|
+
|
|
35
|
+
KeyValueStore::KeyValueStore(std::string directory) : directory_(std::move(directory)) {}
|
|
36
|
+
|
|
37
|
+
std::string KeyValueStore::path(const std::string &db) const {
|
|
38
|
+
// A database name becomes a file name: anything but letters, digits, dot, dash and underscore
|
|
39
|
+
// turns into an underscore, so a name cannot leave the directory. A hash of the whole name
|
|
40
|
+
// follows, so names that read the same that way (a/b and a_b), or only differ in case on a
|
|
41
|
+
// case-insensitive disk, keep files of their own.
|
|
42
|
+
std::string name;
|
|
43
|
+
for (char c : db) {
|
|
44
|
+
name += std::isalnum(static_cast<unsigned char>(c)) || c == '.' || c == '-' || c == '_' ? c : '_';
|
|
45
|
+
}
|
|
46
|
+
if (name.empty() || name[0] == '.') {
|
|
47
|
+
name = "_" + name;
|
|
48
|
+
}
|
|
49
|
+
// 64-bit FNV-1a.
|
|
50
|
+
uint64_t hash = 0xcbf29ce484222325ULL;
|
|
51
|
+
for (unsigned char c : db) {
|
|
52
|
+
hash = (hash ^ c) * 0x100000001b3ULL;
|
|
53
|
+
}
|
|
54
|
+
char hex[17];
|
|
55
|
+
std::snprintf(hex, sizeof hex, "%016llx", static_cast<unsigned long long>(hash));
|
|
56
|
+
return directory_ + "/" + name + "-" + hex + ".json";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
std::map<std::string, std::string> &KeyValueStore::load(const std::string &db) {
|
|
60
|
+
auto it = dbs_.find(db);
|
|
61
|
+
if (it != dbs_.end()) {
|
|
62
|
+
return it->second;
|
|
63
|
+
}
|
|
64
|
+
auto &values = dbs_[db];
|
|
65
|
+
std::ifstream in(path(db));
|
|
66
|
+
if (in) {
|
|
67
|
+
std::stringstream text;
|
|
68
|
+
text << in.rdbuf();
|
|
69
|
+
if (auto json = parse(text.str()); json && json->isObject()) {
|
|
70
|
+
for (const auto &[k, v] : json->items()) {
|
|
71
|
+
if (k.isString() && v.isString()) {
|
|
72
|
+
values[k.asString()] = v.asString();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return values;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
bool KeyValueStore::save(const std::string &db, std::map<std::string, std::string> values) {
|
|
81
|
+
folly::dynamic json = folly::dynamic::object();
|
|
82
|
+
for (const auto &[k, v] : values) {
|
|
83
|
+
json[k] = v;
|
|
84
|
+
}
|
|
85
|
+
std::error_code error;
|
|
86
|
+
std::filesystem::create_directories(directory_, error);
|
|
87
|
+
std::string target = path(db);
|
|
88
|
+
std::string temp = target + ".tmp";
|
|
89
|
+
std::ofstream out(temp, std::ios::binary | std::ios::trunc);
|
|
90
|
+
if (!out) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
out << folly::toJson(json);
|
|
94
|
+
// Closed and checked first: a write that fails as it is flushed leaves the old file in place.
|
|
95
|
+
out.close();
|
|
96
|
+
if (!out || std::rename(temp.c_str(), target.c_str()) != 0) {
|
|
97
|
+
std::filesystem::remove(temp, error);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
// Kept only once written, so a change that could not be saved is not read back.
|
|
101
|
+
dbs_[db] = std::move(values);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
std::vector<std::optional<std::string>> KeyValueStore::get(const std::string &db, const std::vector<std::string> &keys) {
|
|
106
|
+
std::lock_guard lock(mutex_);
|
|
107
|
+
auto &values = load(db);
|
|
108
|
+
std::vector<std::optional<std::string>> out;
|
|
109
|
+
for (const auto &key : keys) {
|
|
110
|
+
auto it = values.find(key);
|
|
111
|
+
out.push_back(it == values.end() ? std::nullopt : std::optional<std::string>(it->second));
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
bool KeyValueStore::set(const std::string &db, const std::vector<std::pair<std::string, std::optional<std::string>>> &values) {
|
|
117
|
+
std::lock_guard lock(mutex_);
|
|
118
|
+
auto stored = load(db);
|
|
119
|
+
for (const auto &[k, v] : values) {
|
|
120
|
+
if (v) {
|
|
121
|
+
stored[k] = *v;
|
|
122
|
+
} else {
|
|
123
|
+
stored.erase(k);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return save(db, std::move(stored));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
bool KeyValueStore::merge(const std::string &db, const std::vector<std::pair<std::string, std::string>> &values) {
|
|
130
|
+
std::lock_guard lock(mutex_);
|
|
131
|
+
auto stored = load(db);
|
|
132
|
+
for (const auto &[k, v] : values) {
|
|
133
|
+
auto it = stored.find(k);
|
|
134
|
+
auto incoming = parse(v);
|
|
135
|
+
auto existing = it == stored.end() ? std::nullopt : parse(it->second);
|
|
136
|
+
if (incoming && existing && incoming->isObject() && existing->isObject()) {
|
|
137
|
+
mergeInto(*existing, *incoming);
|
|
138
|
+
stored[k] = folly::toJson(*existing);
|
|
139
|
+
} else {
|
|
140
|
+
stored[k] = v;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return save(db, std::move(stored));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
bool KeyValueStore::remove(const std::string &db, const std::vector<std::string> &keys) {
|
|
147
|
+
std::lock_guard lock(mutex_);
|
|
148
|
+
auto stored = load(db);
|
|
149
|
+
for (const auto &k : keys) {
|
|
150
|
+
stored.erase(k);
|
|
151
|
+
}
|
|
152
|
+
return save(db, std::move(stored));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
std::vector<std::string> KeyValueStore::keys(const std::string &db) {
|
|
156
|
+
std::lock_guard lock(mutex_);
|
|
157
|
+
std::vector<std::string> out;
|
|
158
|
+
for (const auto &[k, _] : load(db)) {
|
|
159
|
+
out.push_back(k);
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
bool KeyValueStore::clear(const std::string &db) {
|
|
165
|
+
std::lock_guard lock(mutex_);
|
|
166
|
+
return save(db, {});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
} // namespace ngn
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#include "ngn/launch-settings.h"
|
|
2
|
+
|
|
3
|
+
#include <cctype>
|
|
4
|
+
#include <filesystem>
|
|
5
|
+
|
|
6
|
+
namespace ngn {
|
|
7
|
+
|
|
8
|
+
namespace {
|
|
9
|
+
|
|
10
|
+
const char *kUsage =
|
|
11
|
+
"usage: ngn-macos <bundle> [--module <name>] [--title <title>] [--app-id <id>] [--capabilities <json>] [--url <link>]";
|
|
12
|
+
|
|
13
|
+
bool is(const LaunchSources &sources, const char *name, const char *value) {
|
|
14
|
+
auto found = sources.env ? sources.env(name) : std::nullopt;
|
|
15
|
+
return found && *found == value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// A test launch from the environment, nothing when NGN_TESTS is not 1, or why it is unusable.
|
|
19
|
+
std::variant<std::optional<TestLaunch>, std::string> testLaunch(const LaunchSources &sources) {
|
|
20
|
+
if (!is(sources, "NGN_TESTS", "1")) {
|
|
21
|
+
return std::optional<TestLaunch>();
|
|
22
|
+
}
|
|
23
|
+
auto dir = sources.env("NGN_STATE_DIR").value_or("");
|
|
24
|
+
auto runId = sources.env("NGN_RUN_ID").value_or("");
|
|
25
|
+
if (dir.empty() || dir.front() != '/') {
|
|
26
|
+
return std::string("NGN_TESTS=1 needs NGN_STATE_DIR, an absolute path: \"") + dir + "\"";
|
|
27
|
+
}
|
|
28
|
+
bool plain = !runId.empty() && runId.size() <= 64;
|
|
29
|
+
for (char c : runId) {
|
|
30
|
+
plain = plain && (std::isalnum(static_cast<unsigned char>(c)) || c == '-');
|
|
31
|
+
}
|
|
32
|
+
if (!plain) {
|
|
33
|
+
return std::string("NGN_TESTS=1 needs NGN_RUN_ID, letters, digits and dashes: \"") + runId + "\"";
|
|
34
|
+
}
|
|
35
|
+
while (dir.size() > 1 && dir.back() == '/') {
|
|
36
|
+
dir.pop_back();
|
|
37
|
+
}
|
|
38
|
+
return std::optional<TestLaunch>(
|
|
39
|
+
TestLaunch{.stateDir = dir, .runId = runId, .fakeSystemUI = is(sources, "NGN_TESTS_FAKE_SYSTEM_UI", "1")});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
} // namespace
|
|
43
|
+
|
|
44
|
+
bool isStaleTestService(const std::string &service, const TestLaunch &own) {
|
|
45
|
+
return service.starts_with("ngn-test-") && !service.starts_with(own.keychainPrefix());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
std::string LaunchSettings::setting(const std::string &plistKey, const std::string &envName) const {
|
|
49
|
+
if (auto value = plist ? plist(plistKey) : std::nullopt) {
|
|
50
|
+
return *value;
|
|
51
|
+
}
|
|
52
|
+
if (!packaged && env) {
|
|
53
|
+
if (auto value = env(envName)) {
|
|
54
|
+
return *value;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
std::variant<LaunchSettings, std::string> launchSettings(LaunchSources sources) {
|
|
61
|
+
LaunchSettings settings;
|
|
62
|
+
settings.env = sources.env;
|
|
63
|
+
settings.plist = sources.plist;
|
|
64
|
+
auto plist = [&](const char *key) { return sources.plist ? sources.plist(key) : std::nullopt; };
|
|
65
|
+
// Only ever takes a prompt away, so a packaged app reads it too.
|
|
66
|
+
settings.noPrompts = is(sources, "NGN_NO_PROMPTS", "1");
|
|
67
|
+
|
|
68
|
+
if (auto file = plist("NGNBundleFile")) {
|
|
69
|
+
// Packaged: argv and the environment are never read.
|
|
70
|
+
std::filesystem::path relative(*file);
|
|
71
|
+
bool inside = !file->empty() && relative.is_relative();
|
|
72
|
+
for (const auto &part : relative) {
|
|
73
|
+
inside = inside && part != "..";
|
|
74
|
+
}
|
|
75
|
+
if (!inside) {
|
|
76
|
+
return std::string("NGNBundleFile must name a file inside the app's Resources: ") + *file;
|
|
77
|
+
}
|
|
78
|
+
settings.packaged = true;
|
|
79
|
+
settings.bundle = (std::filesystem::path(sources.resourcePath) / relative).string();
|
|
80
|
+
settings.module = plist("NGNModuleName").value_or("main");
|
|
81
|
+
settings.title = plist("CFBundleName").value_or(settings.title);
|
|
82
|
+
settings.appId = plist("CFBundleIdentifier").value_or("");
|
|
83
|
+
return settings;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
auto test = testLaunch(sources);
|
|
87
|
+
if (auto *problem = std::get_if<std::string>(&test)) {
|
|
88
|
+
return *problem;
|
|
89
|
+
}
|
|
90
|
+
settings.test = std::get<std::optional<TestLaunch>>(test);
|
|
91
|
+
settings.noPrompts = settings.noPrompts || (settings.test && settings.test->fakeSystemUI);
|
|
92
|
+
settings.inputScript = sources.env ? sources.env("NGN_INPUT_SCRIPT").value_or("") : "";
|
|
93
|
+
settings.logRotors = is(sources, "NGN_LOG_ROTORS", "1");
|
|
94
|
+
settings.logCommits = is(sources, "NGN_LOG_COMMITS", "1");
|
|
95
|
+
if (auto capabilities = sources.env ? sources.env("NGN_DESKTOP_CAPABILITIES") : std::nullopt) {
|
|
96
|
+
settings.capabilitiesJson = *capabilities;
|
|
97
|
+
}
|
|
98
|
+
const auto &args = sources.args;
|
|
99
|
+
for (size_t i = 0; i < args.size(); i++) {
|
|
100
|
+
const auto &arg = args[i];
|
|
101
|
+
bool hasValue = i + 1 < args.size();
|
|
102
|
+
if (arg == "--module" && hasValue) {
|
|
103
|
+
settings.module = args[++i];
|
|
104
|
+
} else if (arg == "--app-id" && hasValue) {
|
|
105
|
+
settings.appId = args[++i];
|
|
106
|
+
} else if (arg == "--capabilities" && hasValue) {
|
|
107
|
+
settings.capabilitiesJson = args[++i];
|
|
108
|
+
} else if (arg == "--url" && hasValue) {
|
|
109
|
+
settings.initialUrl = args[++i];
|
|
110
|
+
} else if (arg == "--title" && hasValue) {
|
|
111
|
+
settings.title = args[++i];
|
|
112
|
+
} else if (settings.bundle.empty() && !arg.starts_with("--")) {
|
|
113
|
+
settings.bundle = arg;
|
|
114
|
+
} else {
|
|
115
|
+
return std::string(kUsage);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (settings.bundle.empty()) {
|
|
119
|
+
return std::string(kUsage);
|
|
120
|
+
}
|
|
121
|
+
return settings;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
UpdatesConfig updatesConfigFrom(const LaunchSettings &settings, const std::string &appData, const std::string &embeddedBundle) {
|
|
125
|
+
UpdatesConfig config{
|
|
126
|
+
.url = settings.setting("NGNUpdatesURL", "NGN_UPDATES_URL"),
|
|
127
|
+
.runtimeVersion = settings.setting("NGNRuntimeVersion", "NGN_RUNTIME_VERSION"),
|
|
128
|
+
.certificatePem = settings.setting("NGNUpdatesCodeSigningCertificate", "NGN_UPDATES_CODE_SIGNING_CERTIFICATE"),
|
|
129
|
+
.directory = std::filesystem::path(appData) / "updates",
|
|
130
|
+
.embeddedBundle = embeddedBundle,
|
|
131
|
+
};
|
|
132
|
+
if (auto platform = settings.setting("NGNUpdatesPlatform", "NGN_UPDATES_PLATFORM"); !platform.empty()) {
|
|
133
|
+
config.platform = platform;
|
|
134
|
+
}
|
|
135
|
+
if (auto keyId = settings.setting("NGNUpdatesCodeSigningKeyId", "NGN_UPDATES_CODE_SIGNING_KEY_ID"); !keyId.empty()) {
|
|
136
|
+
config.keyId = keyId;
|
|
137
|
+
}
|
|
138
|
+
if (auto alg = settings.setting("NGNUpdatesCodeSigningAlg", "NGN_UPDATES_CODE_SIGNING_ALG"); !alg.empty()) {
|
|
139
|
+
config.algorithm = alg;
|
|
140
|
+
}
|
|
141
|
+
// A server needs a runtime version to match against; without one, updates are off.
|
|
142
|
+
if (config.runtimeVersion.empty()) {
|
|
143
|
+
config.url.clear();
|
|
144
|
+
}
|
|
145
|
+
return config;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
} // namespace ngn
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#include "ngn/layout-animations.h"
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/animations/LayoutAnimationDriver.h>
|
|
4
|
+
|
|
5
|
+
#include <mutex>
|
|
6
|
+
|
|
7
|
+
using namespace facebook::react;
|
|
8
|
+
|
|
9
|
+
namespace ngn {
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
std::mutex gMutex;
|
|
14
|
+
std::function<void(bool)> gRunning;
|
|
15
|
+
|
|
16
|
+
class Status final : public LayoutAnimationStatusDelegate {
|
|
17
|
+
public:
|
|
18
|
+
void onAnimationStarted() override {
|
|
19
|
+
report(true);
|
|
20
|
+
}
|
|
21
|
+
void onAllAnimationsComplete() override {
|
|
22
|
+
report(false);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
static void report(bool running) {
|
|
27
|
+
std::function<void(bool)> handler;
|
|
28
|
+
{
|
|
29
|
+
std::lock_guard lock(gMutex);
|
|
30
|
+
handler = gRunning;
|
|
31
|
+
}
|
|
32
|
+
if (handler) {
|
|
33
|
+
handler(running);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Status gStatus;
|
|
39
|
+
// The driver of the newest scheduler. ReactHost destroys a scheduler before it makes the next, so
|
|
40
|
+
// the one replaced here has no scheduler left to outlive.
|
|
41
|
+
std::shared_ptr<LayoutAnimationDriver> gDriver;
|
|
42
|
+
|
|
43
|
+
} // namespace
|
|
44
|
+
|
|
45
|
+
std::unique_ptr<Scheduler> makeScheduler(const SchedulerToolbox &toolbox, SchedulerDelegate *delegate) {
|
|
46
|
+
auto context = toolbox.contextContainer;
|
|
47
|
+
gDriver = std::make_shared<LayoutAnimationDriver>(toolbox.runtimeExecutor, context, &gStatus);
|
|
48
|
+
auto scheduler = std::make_unique<Scheduler>(toolbox, gDriver.get(), delegate);
|
|
49
|
+
// The driver interpolates the frames each surface mounts, as RCTScheduler sets it up.
|
|
50
|
+
std::weak_ptr<LayoutAnimationDriver> driver = gDriver;
|
|
51
|
+
scheduler->uiManagerShouldAddOnSurfaceStartCallback([driver](const ShadowTree &tree) {
|
|
52
|
+
tree.getMountingCoordinator()->setMountingOverrideDelegate(driver);
|
|
53
|
+
});
|
|
54
|
+
return scheduler;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void onLayoutAnimationsRunning(std::function<void(bool)> handler) {
|
|
58
|
+
std::lock_guard lock(gMutex);
|
|
59
|
+
gRunning = std::move(handler);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
} // namespace ngn
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The core's reading of react-native-webview's props into a WebViewConfig (web-view.h), compiled
|
|
2
|
+
// into the host only with the library (cmake/libraries.cmake).
|
|
3
|
+
//
|
|
4
|
+
// RNCWebView is registered as the desktop's own component: the library's props, parsed by its
|
|
5
|
+
// codegen, beside `originWhitelist`, which the library's codegen props leave to its JavaScript.
|
|
6
|
+
// Its events go out by name, as the library's iOS view sends them.
|
|
7
|
+
#include "ngn/library-glue.h"
|
|
8
|
+
#include "ngn/web-view.h"
|
|
9
|
+
|
|
10
|
+
#include <react/renderer/components/RNCWebViewSpec/Props.h>
|
|
11
|
+
#include <react/renderer/components/RNCWebViewSpec/ShadowNodes.h>
|
|
12
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
13
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
14
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/core/propsConversions.h>
|
|
16
|
+
|
|
17
|
+
using namespace facebook::react;
|
|
18
|
+
|
|
19
|
+
namespace ngn {
|
|
20
|
+
|
|
21
|
+
namespace {
|
|
22
|
+
|
|
23
|
+
class DesktopWebViewProps final : public ViewProps {
|
|
24
|
+
public:
|
|
25
|
+
DesktopWebViewProps() = default;
|
|
26
|
+
DesktopWebViewProps(const PropsParserContext &context, const DesktopWebViewProps &source, const RawProps &raw)
|
|
27
|
+
: ViewProps(context, source, raw),
|
|
28
|
+
library(context, source.library, raw),
|
|
29
|
+
originWhitelist(convertRawProp(context, raw, "originWhitelist", source.originWhitelist, {})) {}
|
|
30
|
+
|
|
31
|
+
RNCWebViewProps library;
|
|
32
|
+
std::optional<std::vector<std::string>> originWhitelist;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
using DesktopWebViewShadowNode = ConcreteViewShadowNode<RNCWebViewComponentName, DesktopWebViewProps, ViewEventEmitter>;
|
|
36
|
+
|
|
37
|
+
std::optional<WebViewConfig> webViewConfig(const Props &props) {
|
|
38
|
+
const auto *own = dynamic_cast<const DesktopWebViewProps *>(&props);
|
|
39
|
+
if (own == nullptr) {
|
|
40
|
+
return std::nullopt;
|
|
41
|
+
}
|
|
42
|
+
const auto &p = own->library;
|
|
43
|
+
WebViewConfig config;
|
|
44
|
+
config.source = {
|
|
45
|
+
.uri = p.newSource.uri,
|
|
46
|
+
.method = p.newSource.method,
|
|
47
|
+
.body = p.newSource.body,
|
|
48
|
+
.html = p.newSource.html,
|
|
49
|
+
.baseUrl = p.newSource.baseUrl,
|
|
50
|
+
};
|
|
51
|
+
for (const auto &header : p.newSource.headers) {
|
|
52
|
+
config.source.headers.emplace_back(header.name, header.value);
|
|
53
|
+
}
|
|
54
|
+
config.injectedJavaScript = p.injectedJavaScript;
|
|
55
|
+
config.injectedJavaScriptBeforeContentLoaded = p.injectedJavaScriptBeforeContentLoaded;
|
|
56
|
+
config.injectedJavaScriptForMainFrameOnly = p.injectedJavaScriptForMainFrameOnly;
|
|
57
|
+
config.injectedJavaScriptBeforeContentLoadedForMainFrameOnly = p.injectedJavaScriptBeforeContentLoadedForMainFrameOnly;
|
|
58
|
+
config.injectedJavaScriptObject = p.injectedJavaScriptObject;
|
|
59
|
+
config.messagingEnabled = p.messagingEnabled;
|
|
60
|
+
config.javaScriptEnabled = p.javaScriptEnabled;
|
|
61
|
+
config.javaScriptCanOpenWindowsAutomatically = p.javaScriptCanOpenWindowsAutomatically;
|
|
62
|
+
config.hasOnOpenWindowEvent = p.hasOnOpenWindowEvent;
|
|
63
|
+
config.incognito = p.incognito;
|
|
64
|
+
config.webviewDebuggingEnabled = p.webviewDebuggingEnabled;
|
|
65
|
+
config.allowsBackForwardNavigationGestures = p.allowsBackForwardNavigationGestures;
|
|
66
|
+
config.userAgent = p.userAgent;
|
|
67
|
+
config.applicationNameForUserAgent = p.applicationNameForUserAgent;
|
|
68
|
+
config.originWhitelist = own->originWhitelist;
|
|
69
|
+
return config;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
} // namespace
|
|
73
|
+
|
|
74
|
+
void installGlue_RNCWebViewSpec() {
|
|
75
|
+
auto &glue = libraryGlue();
|
|
76
|
+
glue.webViewConfig = webViewConfig;
|
|
77
|
+
glue.components.push_back(concreteComponentDescriptorProvider<ConcreteComponentDescriptor<DesktopWebViewShadowNode>>());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
} // namespace ngn
|