@ng-native/desktop 0.0.0 → 0.24.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 +52 -0
- 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 +277 -0
- package/native/appkit/CMakeLists.txt +130 -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-sheet.h +59 -0
- package/native/appkit/camera-sheet.mm +344 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +134 -0
- package/native/appkit/camera.h +61 -0
- package/native/appkit/camera.mm +496 -0
- package/native/appkit/cg-canvas.h +24 -0
- package/native/appkit/cg-canvas.mm +663 -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 +632 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1228 -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 +1475 -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 +562 -0
- package/native/appkit/svg-view.h +18 -0
- package/native/appkit/svg-view.mm +103 -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/tab-walk.h +31 -0
- package/native/appkit/tab-walk.mm +64 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +81 -0
- package/native/appkit/text-input-field.mm +525 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +485 -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 +10 -0
- package/native/appkit/web-view-component.mm +62 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +401 -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 +151 -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 +121 -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 +222 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +108 -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/dom-web-view.h +53 -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 +134 -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 +163 -0
- package/native/core/include/ngn/safe-areas.h +82 -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/surface-metrics.h +51 -0
- package/native/core/include/ngn/svg.h +434 -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 +134 -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 +137 -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 +359 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +98 -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/dom-web-view.cpp +45 -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 +358 -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 +412 -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 +401 -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 +385 -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 +384 -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 +420 -0
- package/native/core/src/safe-areas.cpp +137 -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 +2190 -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 +139 -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 +175 -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/launch-probe.sh +60 -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 +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include "ngn/tracking.h"
|
|
2
|
+
|
|
3
|
+
namespace ngn {
|
|
4
|
+
|
|
5
|
+
namespace {
|
|
6
|
+
|
|
7
|
+
using Access = TrackingAuthority::Access;
|
|
8
|
+
|
|
9
|
+
folly::dynamic permissionOf(Access access) {
|
|
10
|
+
bool granted = access == Access::Granted;
|
|
11
|
+
bool askable = access == Access::NotDetermined;
|
|
12
|
+
return folly::dynamic::object("status", granted ? "granted" : askable ? "undetermined" : "denied")("granted", granted)(
|
|
13
|
+
"canAskAgain", askable)("expires", "never");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
} // namespace
|
|
17
|
+
|
|
18
|
+
std::shared_ptr<NativeModule> makeTrackingModule(std::shared_ptr<TrackingAuthority> authority, bool noPrompts) {
|
|
19
|
+
struct Tracking : NativeModule {
|
|
20
|
+
Tracking(std::shared_ptr<TrackingAuthority> authority, bool noPrompts) : NativeModule("NgNativeTrackingTransparency") {
|
|
21
|
+
sync("isAvailable", [](const folly::dynamic &) { return folly::dynamic(true); });
|
|
22
|
+
promise("getTrackingPermissionsAsync", [authority](const folly::dynamic &, JsPromise promise) {
|
|
23
|
+
promise.resolve(permissionOf(authority->access()));
|
|
24
|
+
});
|
|
25
|
+
promise("requestTrackingPermissionsAsync", [authority, noPrompts](const folly::dynamic &, JsPromise promise) {
|
|
26
|
+
auto access = authority->access();
|
|
27
|
+
if (noPrompts || access != Access::NotDetermined) {
|
|
28
|
+
promise.resolve(permissionOf(access));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
authority->requestAccess([promise](Access decided) { promise.resolve(permissionOf(decided)); });
|
|
32
|
+
});
|
|
33
|
+
sync("getAdvertisingId", [authority](const folly::dynamic &) {
|
|
34
|
+
if (authority->access() != Access::Granted) {
|
|
35
|
+
return folly::dynamic(nullptr);
|
|
36
|
+
}
|
|
37
|
+
auto id = authority->advertisingId();
|
|
38
|
+
bool zeros = id.find_first_not_of("0-") == std::string::npos;
|
|
39
|
+
return zeros ? folly::dynamic(nullptr) : folly::dynamic(id);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return std::make_shared<Tracking>(std::move(authority), noPrompts);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
} // namespace ngn
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#include "ngn/undo.h"
|
|
2
|
+
|
|
3
|
+
namespace ngn {
|
|
4
|
+
|
|
5
|
+
namespace {
|
|
6
|
+
|
|
7
|
+
struct Undo : NativeModule {
|
|
8
|
+
explicit Undo(std::shared_ptr<UndoManager> manager) : NativeModule("NgNativeUndo"), manager_(std::move(manager)) {
|
|
9
|
+
sync("register", [this](const folly::dynamic &args) {
|
|
10
|
+
if (args.size() >= 2 && args[0].isString() && args[1].isString()) {
|
|
11
|
+
add(args[0].asString(), args[1].asString());
|
|
12
|
+
}
|
|
13
|
+
return folly::dynamic(nullptr);
|
|
14
|
+
});
|
|
15
|
+
sync("undo", [this](const folly::dynamic &) {
|
|
16
|
+
manager_->undo();
|
|
17
|
+
return folly::dynamic(nullptr);
|
|
18
|
+
});
|
|
19
|
+
sync("redo", [this](const folly::dynamic &) {
|
|
20
|
+
manager_->redo();
|
|
21
|
+
return folly::dynamic(nullptr);
|
|
22
|
+
});
|
|
23
|
+
sync("clear", [this](const folly::dynamic &) {
|
|
24
|
+
manager_->clear();
|
|
25
|
+
return folly::dynamic(nullptr);
|
|
26
|
+
});
|
|
27
|
+
listeners();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
~Undo() override {
|
|
31
|
+
// The actions run into this module: a reloaded app gets a clean history.
|
|
32
|
+
*alive_ = false;
|
|
33
|
+
manager_->clear();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void add(const std::string &id, const std::string &label) {
|
|
37
|
+
std::weak_ptr<bool> alive = alive_;
|
|
38
|
+
manager_->registerAction(label, [this, alive, id, label] {
|
|
39
|
+
auto live = alive.lock();
|
|
40
|
+
if (!live || !*live) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
emit("ngNativeUndo", folly::dynamic::object("type", manager_->undoing() ? "undo" : "redo")("id", id));
|
|
44
|
+
// Its inverse, on the other stack.
|
|
45
|
+
add(id, label);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
std::shared_ptr<UndoManager> manager_;
|
|
50
|
+
std::shared_ptr<bool> alive_ = std::make_shared<bool>(true);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
} // namespace
|
|
54
|
+
|
|
55
|
+
std::shared_ptr<NativeModule> makeUndoModule(std::shared_ptr<UndoManager> manager) {
|
|
56
|
+
return std::make_shared<Undo>(std::move(manager));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
} // namespace ngn
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
#include "ngn/video.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/desktop-view-props.h"
|
|
4
|
+
|
|
5
|
+
#include <react/renderer/core/propsConversions.h>
|
|
6
|
+
|
|
7
|
+
#include <algorithm>
|
|
8
|
+
#include <map>
|
|
9
|
+
#include <mutex>
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
using folly::dynamic;
|
|
13
|
+
|
|
14
|
+
namespace ngn {
|
|
15
|
+
|
|
16
|
+
const char VideoViewComponentName[] = "ViewManagerAdapter_ExpoVideo_VideoView";
|
|
17
|
+
|
|
18
|
+
VideoViewProps::VideoViewProps(const PropsParserContext &context, const VideoViewProps &sourceProps, const RawProps &rawProps)
|
|
19
|
+
: ViewProps(context, sourceProps, rawProps),
|
|
20
|
+
HasDesktopProps{parseDesktopProps(context, sourceProps.desktop, rawProps)},
|
|
21
|
+
values(sourceProps.values) {
|
|
22
|
+
auto raw = rawProps.toDynamic();
|
|
23
|
+
if (!raw.isObject()) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const auto &[key, value] : raw.items()) {
|
|
27
|
+
if (value.isNull()) {
|
|
28
|
+
values.erase(key);
|
|
29
|
+
} else {
|
|
30
|
+
values[key] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
VideoViewModel videoViewModel(const dynamic &values) {
|
|
36
|
+
VideoViewModel model;
|
|
37
|
+
if (!values.isObject()) {
|
|
38
|
+
return model;
|
|
39
|
+
}
|
|
40
|
+
auto flag = [&](const char *key, bool fallback) {
|
|
41
|
+
auto found = values.find(key);
|
|
42
|
+
return found != values.items().end() && found->second.isBool() ? found->second.asBool() : fallback;
|
|
43
|
+
};
|
|
44
|
+
if (auto player = values.find("player"); player != values.items().end() && player->second.isNumber()) {
|
|
45
|
+
model.player = static_cast<int>(player->second.asDouble());
|
|
46
|
+
}
|
|
47
|
+
model.nativeControls = flag("nativeControls", true);
|
|
48
|
+
if (auto fit = values.find("contentFit"); fit != values.items().end() && fit->second.isString()) {
|
|
49
|
+
const auto &name = fit->second.getString();
|
|
50
|
+
model.contentFit = name == "cover" ? VideoViewModel::Fit::Cover : name == "fill" ? VideoViewModel::Fit::Fill : VideoViewModel::Fit::Contain;
|
|
51
|
+
}
|
|
52
|
+
if (auto options = values.find("fullscreenOptions"); options != values.items().end() && options->second.isObject()) {
|
|
53
|
+
auto enable = options->second.find("enable");
|
|
54
|
+
model.fullscreen = enable == options->second.items().end() || !enable->second.isBool() || enable->second.asBool();
|
|
55
|
+
}
|
|
56
|
+
model.pictureInPicture = flag("allowsPictureInPicture", false);
|
|
57
|
+
model.timecodes = flag("showsTimecodes", true);
|
|
58
|
+
model.frameAnalysis = flag("allowsVideoFrameAnalysis", true);
|
|
59
|
+
return model;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
namespace {
|
|
63
|
+
|
|
64
|
+
using Change = VideoPlayback::Change;
|
|
65
|
+
|
|
66
|
+
std::optional<std::string> stringArg(const dynamic &args, size_t at) {
|
|
67
|
+
return args.size() > at && args[at].isString() ? std::optional(args[at].asString()) : std::nullopt;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
std::optional<double> numberArg(const dynamic &args, size_t at) {
|
|
71
|
+
return args.size() > at && args[at].isNumber() ? std::optional(args[at].asDouble()) : std::nullopt;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
bool flagArg(const dynamic &args, size_t at) {
|
|
75
|
+
return args.size() > at && args[at].isBool() && args[at].asBool();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
struct Player {
|
|
79
|
+
std::unique_ptr<VideoPlayback> playback;
|
|
80
|
+
std::optional<std::string> source;
|
|
81
|
+
// Each source loaded counts, so a change a replaced source sends late is dropped.
|
|
82
|
+
int generation{0};
|
|
83
|
+
std::string status{"idle"};
|
|
84
|
+
bool playing{false};
|
|
85
|
+
// Whether sourceLoad went out for this source.
|
|
86
|
+
bool loaded{false};
|
|
87
|
+
double volume{1};
|
|
88
|
+
bool muted{false};
|
|
89
|
+
double rate{1};
|
|
90
|
+
bool loop{false};
|
|
91
|
+
bool preservesPitch{true};
|
|
92
|
+
double interval{0};
|
|
93
|
+
// Why the source is not loaded: a file outside the file boundary.
|
|
94
|
+
std::optional<std::string> refused;
|
|
95
|
+
// The pick holding a file source, open while the player holds it.
|
|
96
|
+
std::shared_ptr<FileAccess::Use> use;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// The player's state: a refused source has failed without the player loading it.
|
|
100
|
+
VideoState currentState(Player &player) {
|
|
101
|
+
if (player.refused) {
|
|
102
|
+
return VideoState{.load = VideoState::Load::Failed, .error = *player.refused};
|
|
103
|
+
}
|
|
104
|
+
return player.source ? player.playback->state() : VideoState{};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
struct Shared {
|
|
108
|
+
std::recursive_mutex mutex;
|
|
109
|
+
std::map<int, Player> players;
|
|
110
|
+
int next{0};
|
|
111
|
+
std::function<void(dynamic)> send;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
void send(Shared &shared, int id, const char *type, dynamic payload) {
|
|
115
|
+
if (shared.send) {
|
|
116
|
+
shared.send(dynamic::object("type", type)("id", id)("payload", std::move(payload)));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
dynamic sourceOf(const std::optional<std::string> &uri) {
|
|
121
|
+
return uri ? dynamic::object("uri", *uri) : dynamic(nullptr);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// expo-video's status, as its iOS observer reads AVPlayer: a source still loading or waiting for
|
|
125
|
+
// data is loading.
|
|
126
|
+
std::string statusOf(Player &player, const VideoState &state) {
|
|
127
|
+
if (!player.source) {
|
|
128
|
+
return "idle";
|
|
129
|
+
}
|
|
130
|
+
switch (state.load) {
|
|
131
|
+
case VideoState::Load::Failed: return "error";
|
|
132
|
+
case VideoState::Load::Loading: return "loading";
|
|
133
|
+
case VideoState::Load::Ready: return state.buffering ? "loading" : "readyToPlay";
|
|
134
|
+
}
|
|
135
|
+
return "loading";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Sends what changed since the last look: the status, the source's load, and whether it plays.
|
|
139
|
+
void refresh(Shared &shared, int id, Player &player) {
|
|
140
|
+
VideoState state = currentState(player);
|
|
141
|
+
auto status = statusOf(player, state);
|
|
142
|
+
if (status != player.status) {
|
|
143
|
+
dynamic payload = dynamic::object("status", status)("oldStatus", player.status);
|
|
144
|
+
if (status == "error") {
|
|
145
|
+
payload["error"] = dynamic::object("message", state.error);
|
|
146
|
+
}
|
|
147
|
+
player.status = status;
|
|
148
|
+
send(shared, id, "statusChange", std::move(payload));
|
|
149
|
+
}
|
|
150
|
+
if (status == "readyToPlay" && !player.loaded) {
|
|
151
|
+
player.loaded = true;
|
|
152
|
+
send(shared, id, "sourceLoad",
|
|
153
|
+
dynamic::object("videoSource", sourceOf(player.source))("duration", state.duration)("availableVideoTracks", dynamic::array())(
|
|
154
|
+
"availableSubtitleTracks", dynamic::array())("availableAudioTracks", dynamic::array()));
|
|
155
|
+
}
|
|
156
|
+
if (state.playing != player.playing) {
|
|
157
|
+
player.playing = state.playing;
|
|
158
|
+
send(shared, id, "playingChange", dynamic::object("isPlaying", state.playing)("oldIsPlaying", !state.playing));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
void changed(Shared &shared, int id, Player &player, Change change) {
|
|
163
|
+
switch (change) {
|
|
164
|
+
case Change::State: refresh(shared, id, player); return;
|
|
165
|
+
case Change::Time:
|
|
166
|
+
if (player.interval > 0) {
|
|
167
|
+
auto state = player.playback->state();
|
|
168
|
+
send(shared, id, "timeUpdate",
|
|
169
|
+
dynamic::object("currentTime", state.currentTime)("currentLiveTimestamp", nullptr)("currentOffsetFromLive", nullptr)(
|
|
170
|
+
"bufferedPosition", state.bufferedPosition));
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
case Change::Ended:
|
|
174
|
+
send(shared, id, "playToEnd", dynamic::object());
|
|
175
|
+
if (player.loop) {
|
|
176
|
+
player.playback->seek(0, [] {});
|
|
177
|
+
player.playback->play(player.rate);
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void load(const std::shared_ptr<Shared> &shared, const FileAccess *files, int id, Player &player, const std::optional<std::string> &uri) {
|
|
184
|
+
auto old = player.source;
|
|
185
|
+
player.source = uri;
|
|
186
|
+
player.loaded = false;
|
|
187
|
+
player.refused.reset();
|
|
188
|
+
player.use.reset();
|
|
189
|
+
// A file is played only inside the file boundary, and exactly the file checked.
|
|
190
|
+
std::optional<std::string> loading = uri;
|
|
191
|
+
if (uri) {
|
|
192
|
+
try {
|
|
193
|
+
auto source = readableSource(files, *uri);
|
|
194
|
+
loading = source.uri;
|
|
195
|
+
player.use = source.use;
|
|
196
|
+
} catch (const FileRefused &refused) {
|
|
197
|
+
player.refused = refused.what();
|
|
198
|
+
loading.reset();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
int generation = ++player.generation;
|
|
202
|
+
std::weak_ptr<Shared> weak = shared;
|
|
203
|
+
player.playback->load(loading, [weak, id, generation](Change change) {
|
|
204
|
+
auto alive = weak.lock();
|
|
205
|
+
if (!alive) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
std::lock_guard lock(alive->mutex);
|
|
209
|
+
auto found = alive->players.find(id);
|
|
210
|
+
if (found != alive->players.end() && found->second.generation == generation) {
|
|
211
|
+
changed(*alive, id, found->second, change);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
player.playback->setVolume(player.volume);
|
|
215
|
+
player.playback->setMuted(player.muted);
|
|
216
|
+
player.playback->setRate(player.rate);
|
|
217
|
+
player.playback->setPreservesPitch(player.preservesPitch);
|
|
218
|
+
player.playback->setTimeUpdates(player.interval);
|
|
219
|
+
if (old || uri) {
|
|
220
|
+
send(*shared, id, "sourceChange", dynamic::object("source", sourceOf(uri))("oldSource", sourceOf(old)));
|
|
221
|
+
}
|
|
222
|
+
refresh(*shared, id, player);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
dynamic stateOf(Player &player) {
|
|
226
|
+
VideoState state = currentState(player);
|
|
227
|
+
return dynamic::object("status", statusOf(player, state))("playing", state.playing)("currentTime", state.currentTime)(
|
|
228
|
+
"duration", state.duration)("bufferedPosition", state.bufferedPosition)("playbackRate", player.rate)("volume", player.volume)(
|
|
229
|
+
"muted", player.muted)("loop", player.loop)("preservesPitch", player.preservesPitch)("timeUpdateEventInterval", player.interval);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
} // namespace
|
|
233
|
+
|
|
234
|
+
std::shared_ptr<NativeModule> makeVideoModule(std::shared_ptr<VideoOutput> output, std::shared_ptr<FileAccess> files) {
|
|
235
|
+
struct Video : NativeModule {
|
|
236
|
+
std::shared_ptr<Shared> shared = std::make_shared<Shared>();
|
|
237
|
+
|
|
238
|
+
Video(std::shared_ptr<VideoOutput> output, std::shared_ptr<FileAccess> files) : NativeModule("NgNativeVideo") {
|
|
239
|
+
listeners();
|
|
240
|
+
shared->send = [this](dynamic body) { emit("ngNativeVideo", std::move(body)); };
|
|
241
|
+
auto state = shared;
|
|
242
|
+
// Each method on a player: the player, under the lock, or nothing for an id not held.
|
|
243
|
+
auto with = [state](const dynamic &args, auto fn) {
|
|
244
|
+
if (args.empty() || !args[0].isNumber()) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
int id = static_cast<int>(args[0].asDouble());
|
|
248
|
+
std::lock_guard lock(state->mutex);
|
|
249
|
+
if (auto found = state->players.find(id); found != state->players.end()) {
|
|
250
|
+
fn(id, found->second);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
// A setter's change event, sent only when the value changes, as expo-video's didSet does.
|
|
254
|
+
auto changeOf = [state](int id, const char *type, const char *key, const char *oldKey, auto before, auto after) {
|
|
255
|
+
if (before != after) {
|
|
256
|
+
send(*state, id, type, dynamic::object(key, after)(oldKey, before));
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
sync("createPlayer", [state, output, files](const dynamic &args) {
|
|
261
|
+
std::lock_guard lock(state->mutex);
|
|
262
|
+
int id = ++state->next;
|
|
263
|
+
auto &player = state->players[id];
|
|
264
|
+
player.playback = output->make(id);
|
|
265
|
+
load(state, files.get(), id, player, stringArg(args, 0));
|
|
266
|
+
return dynamic(id);
|
|
267
|
+
});
|
|
268
|
+
sync("replace", [state, with, files](const dynamic &args) {
|
|
269
|
+
with(args, [&](int id, Player &player) { load(state, files.get(), id, player, stringArg(args, 1)); });
|
|
270
|
+
return dynamic(nullptr);
|
|
271
|
+
});
|
|
272
|
+
sync("release", [state](const dynamic &args) {
|
|
273
|
+
if (!args.empty() && args[0].isNumber()) {
|
|
274
|
+
std::lock_guard lock(state->mutex);
|
|
275
|
+
state->players.erase(static_cast<int>(args[0].asDouble()));
|
|
276
|
+
}
|
|
277
|
+
return dynamic(nullptr);
|
|
278
|
+
});
|
|
279
|
+
sync("play", [with](const dynamic &args) {
|
|
280
|
+
with(args, [](int, Player &player) { player.playback->play(player.rate); });
|
|
281
|
+
return dynamic(nullptr);
|
|
282
|
+
});
|
|
283
|
+
sync("pause", [with](const dynamic &args) {
|
|
284
|
+
with(args, [](int, Player &player) { player.playback->pause(); });
|
|
285
|
+
return dynamic(nullptr);
|
|
286
|
+
});
|
|
287
|
+
sync("replay", [with](const dynamic &args) {
|
|
288
|
+
with(args, [](int, Player &player) {
|
|
289
|
+
player.playback->seek(0, [] {});
|
|
290
|
+
player.playback->play(player.rate);
|
|
291
|
+
});
|
|
292
|
+
return dynamic(nullptr);
|
|
293
|
+
});
|
|
294
|
+
sync("seekBy", [with](const dynamic &args) {
|
|
295
|
+
with(args, [&](int, Player &player) {
|
|
296
|
+
auto to = player.playback->state().currentTime + numberArg(args, 1).value_or(0);
|
|
297
|
+
player.playback->seek(std::max(0.0, to), [] {});
|
|
298
|
+
});
|
|
299
|
+
return dynamic(nullptr);
|
|
300
|
+
});
|
|
301
|
+
sync("setCurrentTime", [with](const dynamic &args) {
|
|
302
|
+
with(args, [&](int, Player &player) { player.playback->seek(std::max(0.0, numberArg(args, 1).value_or(0)), [] {}); });
|
|
303
|
+
return dynamic(nullptr);
|
|
304
|
+
});
|
|
305
|
+
sync("setPlaybackRate", [with, changeOf](const dynamic &args) {
|
|
306
|
+
with(args, [&](int id, Player &player) {
|
|
307
|
+
auto before = player.rate;
|
|
308
|
+
player.rate = std::clamp(numberArg(args, 1).value_or(1), 0.0, 16.0);
|
|
309
|
+
player.playback->setRate(player.rate);
|
|
310
|
+
changeOf(id, "playbackRateChange", "playbackRate", "oldPlaybackRate", before, player.rate);
|
|
311
|
+
});
|
|
312
|
+
return dynamic(nullptr);
|
|
313
|
+
});
|
|
314
|
+
sync("setVolume", [with, changeOf](const dynamic &args) {
|
|
315
|
+
with(args, [&](int id, Player &player) {
|
|
316
|
+
auto before = player.volume;
|
|
317
|
+
player.volume = std::clamp(numberArg(args, 1).value_or(1), 0.0, 1.0);
|
|
318
|
+
player.playback->setVolume(player.volume);
|
|
319
|
+
changeOf(id, "volumeChange", "volume", "oldVolume", before, player.volume);
|
|
320
|
+
});
|
|
321
|
+
return dynamic(nullptr);
|
|
322
|
+
});
|
|
323
|
+
sync("setMuted", [with, changeOf](const dynamic &args) {
|
|
324
|
+
with(args, [&](int id, Player &player) {
|
|
325
|
+
auto before = player.muted;
|
|
326
|
+
player.muted = flagArg(args, 1);
|
|
327
|
+
player.playback->setMuted(player.muted);
|
|
328
|
+
changeOf(id, "mutedChange", "muted", "oldMuted", before, player.muted);
|
|
329
|
+
});
|
|
330
|
+
return dynamic(nullptr);
|
|
331
|
+
});
|
|
332
|
+
sync("setLoop", [with](const dynamic &args) {
|
|
333
|
+
with(args, [&](int, Player &player) { player.loop = flagArg(args, 1); });
|
|
334
|
+
return dynamic(nullptr);
|
|
335
|
+
});
|
|
336
|
+
sync("setPreservesPitch", [with](const dynamic &args) {
|
|
337
|
+
with(args, [&](int, Player &player) {
|
|
338
|
+
player.preservesPitch = flagArg(args, 1);
|
|
339
|
+
player.playback->setPreservesPitch(player.preservesPitch);
|
|
340
|
+
});
|
|
341
|
+
return dynamic(nullptr);
|
|
342
|
+
});
|
|
343
|
+
sync("setTimeUpdateEventInterval", [with](const dynamic &args) {
|
|
344
|
+
with(args, [&](int, Player &player) {
|
|
345
|
+
player.interval = std::max(0.0, numberArg(args, 1).value_or(0));
|
|
346
|
+
player.playback->setTimeUpdates(player.interval);
|
|
347
|
+
});
|
|
348
|
+
return dynamic(nullptr);
|
|
349
|
+
});
|
|
350
|
+
sync("state", [with](const dynamic &args) {
|
|
351
|
+
dynamic out = nullptr;
|
|
352
|
+
with(args, [&](int, Player &player) { out = stateOf(player); });
|
|
353
|
+
return out;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
~Video() override {
|
|
358
|
+
std::lock_guard lock(shared->mutex);
|
|
359
|
+
shared->send = nullptr;
|
|
360
|
+
shared->players.clear();
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
return std::make_shared<Video>(std::move(output), std::move(files));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
} // namespace ngn
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#include "ngn/web-browser.h"
|
|
2
|
+
|
|
3
|
+
#include "ngn/processes.h"
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
#include <atomic>
|
|
7
|
+
#include <cctype>
|
|
8
|
+
|
|
9
|
+
namespace ngn {
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
std::string lower(std::string text) {
|
|
14
|
+
std::transform(text.begin(), text.end(), text.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
15
|
+
return text;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
folly::dynamic result(const char *type) {
|
|
19
|
+
return folly::dynamic::object("type", type);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace
|
|
23
|
+
|
|
24
|
+
bool webUrl(const std::string &url) {
|
|
25
|
+
auto colon = url.find(':');
|
|
26
|
+
if (colon == std::string::npos || !externalUrlAllowed(url)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
auto scheme = lower(url.substr(0, colon));
|
|
30
|
+
return (scheme == "http" || scheme == "https") && url.compare(colon, 3, "://") == 0 && url.size() > colon + 3;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
std::shared_ptr<NativeModule> makeWebBrowserModule(std::shared_ptr<System> system, std::shared_ptr<AuthSession> sessions, bool noPrompts) {
|
|
34
|
+
struct WebBrowser : NativeModule {
|
|
35
|
+
std::shared_ptr<std::atomic<bool>> inSession = std::make_shared<std::atomic<bool>>(false);
|
|
36
|
+
|
|
37
|
+
WebBrowser(std::shared_ptr<System> system, std::shared_ptr<AuthSession> sessions, bool noPrompts)
|
|
38
|
+
: NativeModule("NgNativeWebBrowser") {
|
|
39
|
+
promise("openBrowserAsync", [system](const folly::dynamic &args, JsPromise promise) {
|
|
40
|
+
std::string url = !args.empty() && args[0].isString() ? args[0].asString() : "";
|
|
41
|
+
if (!webUrl(url)) {
|
|
42
|
+
promise.reject("WebBrowser.openBrowserAsync: the url must use http or https: " + url);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
system->openUrl(url, [promise, url](bool opened) {
|
|
46
|
+
if (opened) {
|
|
47
|
+
promise.resolve(result("opened"));
|
|
48
|
+
} else {
|
|
49
|
+
promise.reject("WebBrowser.openBrowserAsync: no browser opened " + url);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
promise("dismissBrowser", [](const folly::dynamic &, JsPromise promise) { promise.resolve(result("dismiss")); });
|
|
54
|
+
auto busy = inSession;
|
|
55
|
+
promise("openAuthSessionAsync", [sessions, noPrompts, busy](const folly::dynamic &args, JsPromise promise) {
|
|
56
|
+
std::string url = !args.empty() && args[0].isString() ? args[0].asString() : "";
|
|
57
|
+
if (!webUrl(url)) {
|
|
58
|
+
promise.reject("WebBrowser.openAuthSessionAsync: the url must use http or https: " + url);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
std::string redirect = args.size() > 1 && args[1].isString() ? args[1].asString() : "";
|
|
62
|
+
auto colon = redirect.find(':');
|
|
63
|
+
bool ephemeral = false;
|
|
64
|
+
if (args.size() > 2 && args[2].isObject()) {
|
|
65
|
+
const auto *flag = args[2].get_ptr("preferEphemeralSession");
|
|
66
|
+
ephemeral = flag != nullptr && flag->isBool() && flag->asBool();
|
|
67
|
+
}
|
|
68
|
+
if (noPrompts || !sessions) {
|
|
69
|
+
promise.resolve(result("cancel"));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (busy->exchange(true)) {
|
|
73
|
+
promise.reject("WebBrowser.openAuthSessionAsync: another authentication session is already open");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
sessions->start(
|
|
77
|
+
{.url = url, .callbackScheme = colon == std::string::npos ? "" : lower(redirect.substr(0, colon)), .ephemeral = ephemeral},
|
|
78
|
+
[promise, busy](std::optional<std::string> ended, std::string error) {
|
|
79
|
+
busy->store(false);
|
|
80
|
+
if (!error.empty()) {
|
|
81
|
+
promise.reject("WebBrowser.openAuthSessionAsync: " + error);
|
|
82
|
+
} else if (ended) {
|
|
83
|
+
promise.resolve(folly::dynamic::object("type", "success")("url", *ended));
|
|
84
|
+
} else {
|
|
85
|
+
promise.resolve(result("cancel"));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
promise("dismissAuthSession", [sessions](const folly::dynamic &, JsPromise promise) {
|
|
90
|
+
if (sessions) {
|
|
91
|
+
sessions->cancel();
|
|
92
|
+
}
|
|
93
|
+
promise.resolve(nullptr);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return std::make_shared<WebBrowser>(std::move(system), std::move(sessions), noPrompts);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
} // namespace ngn
|