@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,258 @@
|
|
|
1
|
+
// The thread a runtime reloads on, apart from the runtime so nothing a run leaves behind touches it.
|
|
2
|
+
// One run at a time, on a worker that is always joined and never detached. A run's `then` runs on
|
|
3
|
+
// the UI queue once its worker has been joined, never on the worker, so a `then` that starts the
|
|
4
|
+
// next run or destroys the owner never has to join the thread it is on. A run asked for while one
|
|
5
|
+
// is live waits its turn and starts from the UI queue after that run's `then`. Once closed, it
|
|
6
|
+
// starts no run, and close returns only once the live run has been joined and its `then` has run:
|
|
7
|
+
// nothing reaches the owner after its close. Toolkit-free.
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <atomic>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <memory>
|
|
13
|
+
#include <mutex>
|
|
14
|
+
#include <optional>
|
|
15
|
+
#include <thread>
|
|
16
|
+
|
|
17
|
+
namespace ngn {
|
|
18
|
+
|
|
19
|
+
class ReloadThread {
|
|
20
|
+
public:
|
|
21
|
+
// Posts a task to the UI queue: the thread the owner lives on, which the run can need.
|
|
22
|
+
using Post = std::function<void(std::function<void()>)>;
|
|
23
|
+
// A run's last step, with whether its work ran: false when the run was refused or dropped.
|
|
24
|
+
using Then = std::function<void(bool ran)>;
|
|
25
|
+
|
|
26
|
+
explicit ReloadThread(Post post) : state_(std::make_shared<State>(std::move(post))) {}
|
|
27
|
+
ReloadThread(const ReloadThread &) = delete;
|
|
28
|
+
ReloadThread &operator=(const ReloadThread &) = delete;
|
|
29
|
+
~ReloadThread() {
|
|
30
|
+
close([] {});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Runs `work` on a worker thread, then `then(true)` on the UI queue once the worker has been
|
|
34
|
+
// joined. With a run live (or its `then` still to come), the run waits its turn: it starts from
|
|
35
|
+
// the UI queue after that one. Refused once closed, or with a run already waiting: `then(false)`
|
|
36
|
+
// on the calling thread, and false. Any thread, the worker's own included.
|
|
37
|
+
bool start(std::function<void()> work, Then then) {
|
|
38
|
+
{
|
|
39
|
+
std::lock_guard lock(state_->mutex);
|
|
40
|
+
if (!state_->closed) {
|
|
41
|
+
if (!state_->busy) {
|
|
42
|
+
spawn(state_, {std::move(work), std::move(then)});
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (!state_->waiting) {
|
|
46
|
+
state_->waiting = Run{std::move(work), std::move(then)};
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (then) {
|
|
52
|
+
then(false);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Starts no run from now on, and drops a waiting one (its `then(false)`). Waits for the live run,
|
|
58
|
+
// calling `service` until it ends (the UI thread's queue, which the run can need), joins it and
|
|
59
|
+
// runs its `then(true)` here if the UI queue has not yet. A `then` running on another thread is
|
|
60
|
+
// waited for too. From the live run's own work, it cannot join: the run's `then` joins it.
|
|
61
|
+
void close(const std::function<void()> &service) {
|
|
62
|
+
// A then run below can destroy this owner, so only this local reference to the state is used.
|
|
63
|
+
auto state = state_;
|
|
64
|
+
auto self = std::this_thread::get_id();
|
|
65
|
+
std::thread thread;
|
|
66
|
+
std::shared_ptr<std::atomic<bool>> finished;
|
|
67
|
+
{
|
|
68
|
+
std::unique_lock lock(state->mutex);
|
|
69
|
+
if (state->joiner == self) {
|
|
70
|
+
// Reentered on the thread a close is already ending the run on. From a callback that close
|
|
71
|
+
// runs there is nothing to wait for. From the UI queue it serves while it waits, this
|
|
72
|
+
// close waits for the run too, and runs the callbacks still owed before it returns, so
|
|
73
|
+
// they come before anything its caller tears down.
|
|
74
|
+
if (state->joinerInCallback) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
auto ending = state->joining;
|
|
78
|
+
lock.unlock();
|
|
79
|
+
while (ending && !*ending) {
|
|
80
|
+
service();
|
|
81
|
+
std::this_thread::yield();
|
|
82
|
+
}
|
|
83
|
+
runEnding(state);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
state->closed = true;
|
|
87
|
+
if (state->joiner == std::thread::id()) {
|
|
88
|
+
if (state->waiting) {
|
|
89
|
+
state->endingDropped = std::move(state->waiting);
|
|
90
|
+
state->waiting.reset();
|
|
91
|
+
}
|
|
92
|
+
if (state->thread.joinable() && state->thread.get_id() != self) {
|
|
93
|
+
thread = std::move(state->thread);
|
|
94
|
+
finished = state->finished;
|
|
95
|
+
state->endingThen = std::move(state->then);
|
|
96
|
+
state->then = nullptr;
|
|
97
|
+
}
|
|
98
|
+
// Until its callbacks have run, this close is the one ending the run: another close waits.
|
|
99
|
+
if (thread.joinable() || state->endingDropped) {
|
|
100
|
+
state->joiner = self;
|
|
101
|
+
state->joining = finished;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (thread.joinable()) {
|
|
106
|
+
while (!*finished) {
|
|
107
|
+
service();
|
|
108
|
+
std::this_thread::yield();
|
|
109
|
+
}
|
|
110
|
+
thread.join();
|
|
111
|
+
}
|
|
112
|
+
// Only the close ending the run runs its callbacks; another waits below until they have run.
|
|
113
|
+
bool ending;
|
|
114
|
+
{
|
|
115
|
+
std::lock_guard lock(state->mutex);
|
|
116
|
+
ending = state->joiner == self;
|
|
117
|
+
}
|
|
118
|
+
if (ending) {
|
|
119
|
+
runEnding(state);
|
|
120
|
+
}
|
|
121
|
+
{
|
|
122
|
+
std::lock_guard lock(state->mutex);
|
|
123
|
+
if (state->joiner == self) {
|
|
124
|
+
state->joiner = std::thread::id();
|
|
125
|
+
state->joining = nullptr;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// A `then` the UI queue is running on another thread, or a run another close is still ending
|
|
129
|
+
// (this close not called from either).
|
|
130
|
+
while (true) {
|
|
131
|
+
{
|
|
132
|
+
std::lock_guard lock(state->mutex);
|
|
133
|
+
bool thenDone = state->thenThread == std::thread::id() || state->thenThread == self;
|
|
134
|
+
bool joinDone = state->joiner == std::thread::id() || state->joiner == self;
|
|
135
|
+
if (thenDone && joinDone) {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
service();
|
|
140
|
+
std::this_thread::yield();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private:
|
|
145
|
+
struct Run {
|
|
146
|
+
std::function<void()> work;
|
|
147
|
+
Then then;
|
|
148
|
+
};
|
|
149
|
+
// Shared with the worker and the tasks it posts, so neither touches the owner.
|
|
150
|
+
struct State {
|
|
151
|
+
explicit State(Post post) : post(std::move(post)) {}
|
|
152
|
+
std::mutex mutex;
|
|
153
|
+
Post post;
|
|
154
|
+
std::thread thread;
|
|
155
|
+
std::shared_ptr<std::atomic<bool>> finished;
|
|
156
|
+
Then then;
|
|
157
|
+
// A run is live, or its `then` is still to run: a new run waits its turn.
|
|
158
|
+
bool busy{false};
|
|
159
|
+
std::optional<Run> waiting;
|
|
160
|
+
bool closed{false};
|
|
161
|
+
// The thread running a `then` from the UI queue, if one is.
|
|
162
|
+
std::thread::id thenThread;
|
|
163
|
+
// The thread whose close is ending the run (joining it, then running its and a dropped run's
|
|
164
|
+
// callbacks), if one is; the run it waits on; and whether it is inside one of those callbacks.
|
|
165
|
+
std::thread::id joiner;
|
|
166
|
+
std::shared_ptr<std::atomic<bool>> joining;
|
|
167
|
+
bool joinerInCallback{false};
|
|
168
|
+
// The callbacks the closing run still owes: the joined run's `then` and a dropped run's. Kept
|
|
169
|
+
// here so a close reentered from the UI queue can run them as well as the close that took them.
|
|
170
|
+
Then endingThen;
|
|
171
|
+
std::optional<Run> endingDropped;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// Runs the callbacks a close owes, the joined run's first, each once, whichever close gets to it.
|
|
175
|
+
static void runEnding(const std::shared_ptr<State> &state) {
|
|
176
|
+
while (true) {
|
|
177
|
+
Then then;
|
|
178
|
+
std::optional<Run> dropped;
|
|
179
|
+
{
|
|
180
|
+
std::lock_guard lock(state->mutex);
|
|
181
|
+
if (state->endingThen) {
|
|
182
|
+
then = std::move(state->endingThen);
|
|
183
|
+
state->endingThen = nullptr;
|
|
184
|
+
} else if (state->endingDropped) {
|
|
185
|
+
dropped = std::move(state->endingDropped);
|
|
186
|
+
state->endingDropped.reset();
|
|
187
|
+
} else {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
state->joinerInCallback = true;
|
|
191
|
+
}
|
|
192
|
+
if (then) {
|
|
193
|
+
then(true);
|
|
194
|
+
} else if (dropped->then) {
|
|
195
|
+
dropped->then(false);
|
|
196
|
+
}
|
|
197
|
+
std::lock_guard lock(state->mutex);
|
|
198
|
+
state->joinerInCallback = false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Under the state's lock.
|
|
203
|
+
static void spawn(const std::shared_ptr<State> &state, Run run) {
|
|
204
|
+
auto finished = std::make_shared<std::atomic<bool>>(false);
|
|
205
|
+
state->busy = true;
|
|
206
|
+
state->finished = finished;
|
|
207
|
+
state->then = std::move(run.then);
|
|
208
|
+
state->thread = std::thread([state, work = std::move(run.work), finished] {
|
|
209
|
+
work();
|
|
210
|
+
*finished = true;
|
|
211
|
+
// The worker's last step: everything after it (the join, `then`, the next run) is the UI
|
|
212
|
+
// queue's.
|
|
213
|
+
state->post([state] { finish(state); });
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// On the UI queue, once a run's work is done.
|
|
218
|
+
static void finish(const std::shared_ptr<State> &state) {
|
|
219
|
+
std::thread thread;
|
|
220
|
+
Then then;
|
|
221
|
+
{
|
|
222
|
+
std::lock_guard lock(state->mutex);
|
|
223
|
+
// A close may have joined the run and taken its `then` already.
|
|
224
|
+
thread = std::move(state->thread);
|
|
225
|
+
then = std::move(state->then);
|
|
226
|
+
state->then = nullptr;
|
|
227
|
+
state->thenThread = std::this_thread::get_id();
|
|
228
|
+
}
|
|
229
|
+
if (thread.joinable()) {
|
|
230
|
+
thread.join();
|
|
231
|
+
}
|
|
232
|
+
if (then) {
|
|
233
|
+
then(true);
|
|
234
|
+
}
|
|
235
|
+
std::optional<Run> dropped;
|
|
236
|
+
{
|
|
237
|
+
std::lock_guard lock(state->mutex);
|
|
238
|
+
state->thenThread = std::thread::id();
|
|
239
|
+
state->busy = false;
|
|
240
|
+
if (state->waiting) {
|
|
241
|
+
Run next = std::move(*state->waiting);
|
|
242
|
+
state->waiting.reset();
|
|
243
|
+
if (state->closed) {
|
|
244
|
+
dropped = std::move(next);
|
|
245
|
+
} else {
|
|
246
|
+
spawn(state, std::move(next));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (dropped && dropped->then) {
|
|
251
|
+
dropped->then(false);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
std::shared_ptr<State> state_;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
} // namespace ngn
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// One React Native runtime (ReactHost over Hermes) for every window of the app, with its surfaces.
|
|
2
|
+
// Toolkit-free: a backend supplies the mounting manager, the text measurer, its modules and the
|
|
3
|
+
// event beat, and owns the windows the surfaces mount into.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include "ngn/desktop-modal.h"
|
|
7
|
+
#include "ngn/dev-server.h"
|
|
8
|
+
#include "ngn/module-registry.h"
|
|
9
|
+
#include "ngn/mounting-manager.h"
|
|
10
|
+
#include "ngn/network.h"
|
|
11
|
+
#include "ngn/reload-thread.h"
|
|
12
|
+
#include "ngn/surface-book.h"
|
|
13
|
+
#include "ngn/native-controls.h"
|
|
14
|
+
#include "ngn/text-measurer.h"
|
|
15
|
+
|
|
16
|
+
#include <folly/dynamic.h>
|
|
17
|
+
#include <react/renderer/graphics/Size.h>
|
|
18
|
+
|
|
19
|
+
#include <atomic>
|
|
20
|
+
#include <functional>
|
|
21
|
+
#include <map>
|
|
22
|
+
#include <memory>
|
|
23
|
+
#include <mutex>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include <string>
|
|
26
|
+
#include <thread>
|
|
27
|
+
|
|
28
|
+
namespace facebook::react {
|
|
29
|
+
class ReactHost;
|
|
30
|
+
class RunLoopObserverManager;
|
|
31
|
+
} // namespace facebook::react
|
|
32
|
+
|
|
33
|
+
namespace facebook::jsi {
|
|
34
|
+
class Runtime;
|
|
35
|
+
} // namespace facebook::jsi
|
|
36
|
+
|
|
37
|
+
namespace ngn {
|
|
38
|
+
|
|
39
|
+
struct SurfaceMetrics {
|
|
40
|
+
facebook::react::Size size{};
|
|
41
|
+
// Device pixels per point.
|
|
42
|
+
float pointScale{2};
|
|
43
|
+
// The text size multiplier.
|
|
44
|
+
float fontScale{1};
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The OS's HTTP and WebSocket clients, which Networking, WebSocket and the dev server use.
|
|
48
|
+
struct NetworkClients {
|
|
49
|
+
std::shared_ptr<Http> http;
|
|
50
|
+
std::shared_ptr<WebSockets> webSockets;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// How the app and the machine are named to the dev server's inspector proxy: React Native
|
|
54
|
+
// DevTools and `/json/list` show the app as "<appId> (<deviceName>)".
|
|
55
|
+
struct DebuggerIdentity {
|
|
56
|
+
std::string appId{"ngn-desktop"};
|
|
57
|
+
std::string deviceName{"desktop"};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
class Runtime {
|
|
61
|
+
public:
|
|
62
|
+
// `bundle` is a path on disk or a Metro bundle URL. A URL turns dev mode on: the bundle loads
|
|
63
|
+
// from Metro, which can then reload the app (/message) and Fast Refresh it (the HMR client).
|
|
64
|
+
Runtime(
|
|
65
|
+
std::shared_ptr<MountingManager> mounting,
|
|
66
|
+
std::shared_ptr<const TextMeasurer> textMeasurer,
|
|
67
|
+
std::shared_ptr<const ControlMeasurer> controlMeasurer,
|
|
68
|
+
std::shared_ptr<ModuleRegistry> modules,
|
|
69
|
+
NetworkClients clients,
|
|
70
|
+
std::string bundle,
|
|
71
|
+
DebuggerIdentity identity = {});
|
|
72
|
+
~Runtime();
|
|
73
|
+
Runtime(const Runtime &) = delete;
|
|
74
|
+
Runtime &operator=(const Runtime &) = delete;
|
|
75
|
+
|
|
76
|
+
// A dev run's (with a dev server): each error React Native's error pipeline sees, fatal or soft,
|
|
77
|
+
// as its exception listeners get it (jsErrorFrom reads it), whether or not LogBox takes it, and
|
|
78
|
+
// each one logged with console.error or caught by ErrorUtils, with `source` "console"
|
|
79
|
+
// (jsErrorFromConsole reads it, red-box-errors.js sends it); and
|
|
80
|
+
// each start of a JavaScript instance, the first and every reload's, Metro's included. Both on
|
|
81
|
+
// the JavaScript thread. Set them before loadBundle.
|
|
82
|
+
std::function<void(const folly::dynamic &error)> onJsError;
|
|
83
|
+
std::function<void()> onInstanceStart;
|
|
84
|
+
// React Native DevTools paused the JavaScript (a breakpoint, `debugger`, a step), and the call
|
|
85
|
+
// that resumes it; then that it resumed. On the inspector's thread. Set them before loadBundle.
|
|
86
|
+
std::function<void(std::function<void()> resume)> onDebuggerPaused;
|
|
87
|
+
std::function<void()> onDebuggerResumed;
|
|
88
|
+
|
|
89
|
+
// Loads the bundle (JavaScript or Hermes bytecode). False if it could not be read or downloaded.
|
|
90
|
+
bool loadBundle();
|
|
91
|
+
// The dev server the bundle came from, or nothing for a bundle on disk.
|
|
92
|
+
const std::optional<DevServer> &devServer() const {
|
|
93
|
+
return devServer_;
|
|
94
|
+
}
|
|
95
|
+
// Tears the runtime down and starts it again on a fresh download of the bundle, with every
|
|
96
|
+
// running surface restarted. Runs off the calling thread; a second call while one runs is
|
|
97
|
+
// dropped. `done` gets whether the bundle loaded, on the UI thread once the reload's thread has
|
|
98
|
+
// ended (or on shutdown's thread, when shutdown joins it), so it may reload again or destroy the
|
|
99
|
+
// runtime: an explicit shutdown() touches nothing of it after such a `done`. One the destructor's
|
|
100
|
+
// shutdown runs must not destroy it again. It gets false, on the calling thread, once shutdown
|
|
101
|
+
// has begun.
|
|
102
|
+
void reload(std::function<void(bool)> done = nullptr);
|
|
103
|
+
// The same, on another bundle on disk: an update's (updates.h). Ignored for a dev server's bundle.
|
|
104
|
+
void reload(std::string bundle, std::function<void(bool)> done);
|
|
105
|
+
|
|
106
|
+
// An empty `moduleName` starts a surface that runs nothing: one the app renders into itself, such
|
|
107
|
+
// as a second window's.
|
|
108
|
+
void startSurface(SurfaceId surfaceId, const std::string &moduleName, const SurfaceMetrics &metrics);
|
|
109
|
+
void stopSurface(SurfaceId surfaceId);
|
|
110
|
+
void updateSurface(SurfaceId surfaceId, const SurfaceMetrics &metrics);
|
|
111
|
+
|
|
112
|
+
// The view `tag` on `surfaceId` and those under it, as the shadow tree last laid them out: what
|
|
113
|
+
// a sheet sizes itself by (desktop-modal.h). Nothing when it is not there. Any thread.
|
|
114
|
+
std::optional<SheetNode> sheetNode(SurfaceId surfaceId, Tag tag);
|
|
115
|
+
|
|
116
|
+
// The event beat: the backend calls it each time its UI thread's run loop is about to wait.
|
|
117
|
+
void beat();
|
|
118
|
+
// A frame of the running layout animations (layout-animations.h). UI thread.
|
|
119
|
+
void animationTick();
|
|
120
|
+
|
|
121
|
+
// Asks the dev server to open React Native DevTools on this app (its /open-debugger), as the
|
|
122
|
+
// dev menu's Open DevTools does on iOS. Nothing without a dev server.
|
|
123
|
+
void openDebugger();
|
|
124
|
+
|
|
125
|
+
// Stops every surface and tears the runtime down, before the process exits.
|
|
126
|
+
void shutdown();
|
|
127
|
+
|
|
128
|
+
private:
|
|
129
|
+
void createHost();
|
|
130
|
+
void installErrorListener(facebook::jsi::Runtime &runtime);
|
|
131
|
+
|
|
132
|
+
std::shared_ptr<MountingManager> mounting_;
|
|
133
|
+
std::shared_ptr<const TextMeasurer> textMeasurer_;
|
|
134
|
+
std::shared_ptr<const ControlMeasurer> controlMeasurer_;
|
|
135
|
+
std::shared_ptr<ModuleRegistry> modules_;
|
|
136
|
+
NetworkClients clients_;
|
|
137
|
+
std::string bundle_;
|
|
138
|
+
DebuggerIdentity identity_;
|
|
139
|
+
std::optional<DevServer> devServer_;
|
|
140
|
+
std::shared_ptr<facebook::react::RunLoopObserverManager> runLoop_;
|
|
141
|
+
// Guards host_, which a reload holds while it tears the runtime down and loads the bundle. The
|
|
142
|
+
// UI thread never waits on it during a reload: it writes to the book instead.
|
|
143
|
+
std::recursive_mutex mutex_;
|
|
144
|
+
std::atomic<bool> reloading_{false};
|
|
145
|
+
// The reload's thread, which uses this runtime until it ends: one at a time, each joined before
|
|
146
|
+
// the next starts, and closed by shutdown before it tears the runtime down (reload-thread.h).
|
|
147
|
+
ReloadThread reloader_;
|
|
148
|
+
// False once the destructor has run, so a shutdown whose reload `done` destroyed the runtime
|
|
149
|
+
// stops before it touches it again.
|
|
150
|
+
std::shared_ptr<bool> alive_ = std::make_shared<bool>(true);
|
|
151
|
+
std::unique_ptr<facebook::react::ReactHost> host_;
|
|
152
|
+
struct Surface {
|
|
153
|
+
std::string moduleName;
|
|
154
|
+
SurfaceMetrics metrics;
|
|
155
|
+
};
|
|
156
|
+
// Taken before mutex_ when both are, and never held by a reload while it holds mutex_.
|
|
157
|
+
std::mutex surfacesMutex_;
|
|
158
|
+
SurfaceBook<Surface> surfaces_;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
} // namespace ngn
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Safe-area insets, the same on every toolkit: each container (the window's content, a cover, a
|
|
2
|
+
// sidebar pane) reports its size and the insets its OS gives it (on macOS, the content view's
|
|
3
|
+
// safeAreaInsets: the title bar plus the toolbar when the content runs under them), and every
|
|
4
|
+
// safe-area view in it gets the part of those insets it overlaps, as a UIView's safeAreaInsets
|
|
5
|
+
// does on iOS.
|
|
6
|
+
//
|
|
7
|
+
// RNCSafeAreaProvider hears insetsChange with its insets and its frame in the container.
|
|
8
|
+
// RNCSafeAreaView and react-native-screens' RNSSafeAreaView get theirs through their state, which
|
|
9
|
+
// their shadow nodes turn into padding. Each is told only when its insets change.
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "ngn/view-tree.h"
|
|
13
|
+
|
|
14
|
+
#include <react/renderer/graphics/RectangleEdges.h>
|
|
15
|
+
|
|
16
|
+
#include <optional>
|
|
17
|
+
#include <unordered_map>
|
|
18
|
+
|
|
19
|
+
namespace ngn {
|
|
20
|
+
|
|
21
|
+
using facebook::react::EdgeInsets;
|
|
22
|
+
using facebook::react::Rect;
|
|
23
|
+
using facebook::react::Size;
|
|
24
|
+
|
|
25
|
+
struct ContainerInsets {
|
|
26
|
+
Size size;
|
|
27
|
+
EdgeInsets insets;
|
|
28
|
+
// How far the window controls reach into this container from its leading edge, for
|
|
29
|
+
// --safe-area-inset-titlebar-leading: their extent in a window's content with no sidebar and in
|
|
30
|
+
// the sidebar pane under them, and 0 in the content pane beside a sidebar, which they do not
|
|
31
|
+
// reach.
|
|
32
|
+
double titlebarLeading{0};
|
|
33
|
+
bool operator==(const ContainerInsets &) const = default;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// The part of a container's insets a view at `frame` (in the container's coordinates) overlaps.
|
|
37
|
+
EdgeInsets insetsWithin(const ContainerInsets &container, const Rect &frame);
|
|
38
|
+
|
|
39
|
+
class SafeAreas {
|
|
40
|
+
public:
|
|
41
|
+
virtual ~SafeAreas() = default;
|
|
42
|
+
|
|
43
|
+
void created(const ShadowView &view);
|
|
44
|
+
void deleted(Tag tag);
|
|
45
|
+
// A container's metrics, keyed by the tag its hit test starts from (the surface's root for the
|
|
46
|
+
// window's content).
|
|
47
|
+
void setContainer(Tag root, const ContainerInsets &metrics);
|
|
48
|
+
void removeContainer(Tag root);
|
|
49
|
+
|
|
50
|
+
// Brings every safe-area view up to date with the tree and the containers. True when it told
|
|
51
|
+
// any of them something new.
|
|
52
|
+
bool settle(const ViewTree &tree);
|
|
53
|
+
|
|
54
|
+
protected:
|
|
55
|
+
// Where the insets leave the core: the provider's event, and the views' state through the
|
|
56
|
+
// library's glue. Tests record them instead.
|
|
57
|
+
virtual void emitInsetsChange(const ViewTree::Node &provider, EdgeInsets insets, Rect frame, double titlebarLeading);
|
|
58
|
+
virtual void setStateInsets(const ViewTree::Node &view, EdgeInsets insets);
|
|
59
|
+
// The margin a view's mounted state adds for its insets, for a view that moves itself by them
|
|
60
|
+
// (library-glue.h); nothing for one that pads its content instead.
|
|
61
|
+
virtual std::optional<EdgeInsets> appliedMargin(const ViewTree::Node &view) const;
|
|
62
|
+
|
|
63
|
+
private:
|
|
64
|
+
enum class Kind { Provider, View };
|
|
65
|
+
struct Tracked {
|
|
66
|
+
Kind kind;
|
|
67
|
+
bool known{false};
|
|
68
|
+
EdgeInsets insets;
|
|
69
|
+
Rect frame;
|
|
70
|
+
// A provider's: the last titlebarLeading its event said.
|
|
71
|
+
double titlebarLeading{0};
|
|
72
|
+
};
|
|
73
|
+
std::unordered_map<Tag, Tracked> tracked_;
|
|
74
|
+
std::unordered_map<Tag, ContainerInsets> containers_;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
} // namespace ngn
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// NgNativeScreenCapture: what @ng-native/expo's ScreenCapture calls on expo-screen-capture, over a
|
|
2
|
+
// CaptureShield, which the AppKit backend implements with every window's NSWindow.sharingType.
|
|
3
|
+
//
|
|
4
|
+
// - isAvailableAsync(): whether there is a shield.
|
|
5
|
+
// - preventScreenCaptureAsync(key), allowScreenCaptureAsync(key): capture stays prevented while
|
|
6
|
+
// any key is held, `default` when none is given, as expo-screen-capture keeps its keys. The
|
|
7
|
+
// shield changes only as the first key is taken and the last released, and a reload, which
|
|
8
|
+
// ends the module, releases them all. Each resolves once the windows have the state it asks
|
|
9
|
+
// for.
|
|
10
|
+
// - enableAppSwitcherProtectionAsync(), disableAppSwitcherProtectionAsync(): resolve; macOS shows
|
|
11
|
+
// no snapshot of an app that is not in front.
|
|
12
|
+
// - getPermissionsAsync(), requestPermissionsAsync(): granted, as on iOS: nothing is asked.
|
|
13
|
+
#pragma once
|
|
14
|
+
|
|
15
|
+
#include "ngn/native-module.h"
|
|
16
|
+
|
|
17
|
+
#include <functional>
|
|
18
|
+
#include <memory>
|
|
19
|
+
|
|
20
|
+
namespace ngn {
|
|
21
|
+
|
|
22
|
+
class CaptureShield {
|
|
23
|
+
public:
|
|
24
|
+
virtual ~CaptureShield() = default;
|
|
25
|
+
// Marks every window of the app, and every one it opens after, as one whose content another
|
|
26
|
+
// process may not read, as far as the OS offers that (on macOS, NSWindowSharingNone; which
|
|
27
|
+
// capture tools honour it is the OS's to decide); or lets them be read again. `done` once every
|
|
28
|
+
// window has the new state, or a later request's, on any thread; it may be empty. Any thread: the
|
|
29
|
+
// windows keep the state of the request asked last.
|
|
30
|
+
virtual void setProtected(bool on, std::function<void()> done) = 0;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
std::shared_ptr<NativeModule> makeScreenCaptureModule(std::shared_ptr<CaptureShield> shield);
|
|
34
|
+
|
|
35
|
+
} // namespace ngn
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// react-native-screens' presented screens on a desktop: an RNSScreen whose `stackPresentation` is
|
|
2
|
+
// not `push` is presented over the stack rather than pushed onto it, the way <modal> is
|
|
3
|
+
// (desktop-modal.h): `modal`, `formSheet` and `pageSheet` as a sheet on the window,
|
|
4
|
+
// `fullScreenModal`, `transparentModal` and the contained ones as a cover in the window, and any
|
|
5
|
+
// with an `anchor` (the react tag of a view, which `present()` writes) as a popover at that view.
|
|
6
|
+
//
|
|
7
|
+
// The core registers RNSScreen with these props, with the library's event emitter, in place of the
|
|
8
|
+
// library's own (library-glue.h): the library's props drop `anchor`. Its state is SplitPaneState, the
|
|
9
|
+
// size the toolkit presents it at, which it takes in layout.
|
|
10
|
+
//
|
|
11
|
+
// A sheet draws the screen's header itself, since a sheet has no toolbar: the title is a heading
|
|
12
|
+
// at the top, and the bar buttons a row at the bottom right, the left ones (Cancel) first and
|
|
13
|
+
// bound to Escape, the right ones after, the last of them the default button on Return. A popover
|
|
14
|
+
// draws no header; its title is the popover's accessibility label.
|
|
15
|
+
#pragma once
|
|
16
|
+
|
|
17
|
+
#include "ngn/desktop-props.h"
|
|
18
|
+
#include "ngn/header-bar.h"
|
|
19
|
+
|
|
20
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
21
|
+
|
|
22
|
+
#include <optional>
|
|
23
|
+
#include <string>
|
|
24
|
+
#include <vector>
|
|
25
|
+
|
|
26
|
+
namespace ngn {
|
|
27
|
+
|
|
28
|
+
class ScreenProps final : public facebook::react::ViewProps {
|
|
29
|
+
public:
|
|
30
|
+
ScreenProps() = default;
|
|
31
|
+
ScreenProps(
|
|
32
|
+
const facebook::react::PropsParserContext &context,
|
|
33
|
+
const ScreenProps &sourceProps,
|
|
34
|
+
const facebook::react::RawProps &rawProps);
|
|
35
|
+
|
|
36
|
+
std::string stackPresentation{"push"};
|
|
37
|
+
// 0 for none.
|
|
38
|
+
int anchor{0};
|
|
39
|
+
// Whether the OS's back gesture may leave the screen (a back swipe, back-swipe.h).
|
|
40
|
+
bool gestureEnabled{true};
|
|
41
|
+
// How the screen arrives and leaves: `none` and `fade` change how a back swipe moves it.
|
|
42
|
+
std::string stackAnimation{"default"};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// How a screen with these props is presented, or nothing for one pushed onto its stack (or props
|
|
46
|
+
// that are not a screen's).
|
|
47
|
+
std::optional<ModalPresentation> screenPresentation(const facebook::react::Props &props);
|
|
48
|
+
|
|
49
|
+
// The heading's and the button row's heights in a sheet, in points.
|
|
50
|
+
constexpr facebook::react::Float kSheetHeadingHeight = 44;
|
|
51
|
+
constexpr facebook::react::Float kSheetButtonRowHeight = 52;
|
|
52
|
+
|
|
53
|
+
struct SheetButton {
|
|
54
|
+
std::string id;
|
|
55
|
+
std::string title;
|
|
56
|
+
// The first left item: Escape presses it. Only one button has it.
|
|
57
|
+
bool cancel{false};
|
|
58
|
+
// The last right item: Return presses it.
|
|
59
|
+
bool isDefault{false};
|
|
60
|
+
bool disabled{false};
|
|
61
|
+
bool operator==(const SheetButton &) const = default;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
struct SheetChrome {
|
|
65
|
+
// Empty for none.
|
|
66
|
+
std::string heading;
|
|
67
|
+
std::vector<SheetButton> buttons;
|
|
68
|
+
// What names the presentation, in a popover too, when the screen has no accessibility label of
|
|
69
|
+
// its own (presentationLabel, desktop-modal.h): the title.
|
|
70
|
+
std::string label;
|
|
71
|
+
bool operator==(const SheetChrome &) const = default;
|
|
72
|
+
|
|
73
|
+
facebook::react::Float top() const {
|
|
74
|
+
return heading.empty() ? 0 : kSheetHeadingHeight;
|
|
75
|
+
}
|
|
76
|
+
facebook::react::Float bottom() const {
|
|
77
|
+
return buttons.empty() ? 0 : kSheetButtonRowHeight;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// What a presented screen's header becomes inside its presentation. A popover's is only the label;
|
|
82
|
+
// a cover keeps the window's toolbar.
|
|
83
|
+
SheetChrome sheetChrome(const HeaderBar &header, ModalPresentation presentation);
|
|
84
|
+
|
|
85
|
+
} // namespace ngn
|