@ng-native/desktop 0.0.0 → 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 +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 +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 +73 -1
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// NgNativeAddressSearch: @ng-native/expo's AddressSearch, the same module the iOS app has, over an
|
|
2
|
+
// AddressLookup, which the AppKit backend implements with MapKit's MKLocalSearchCompleter and
|
|
3
|
+
// MKLocalSearch. Neither needs a permission.
|
|
4
|
+
//
|
|
5
|
+
// - complete(session, query, {region, pointsOfInterest}): [{id, title, subtitle}]. Each session
|
|
6
|
+
// has a completer of its own; a newer query in a session settles the one before with []. What
|
|
7
|
+
// the completer reports for the query after that goes out as `ngNativeAddressSearch` on
|
|
8
|
+
// DeviceEventEmitter: {session, query, suggestions}. A failure rejects with MapKit's reason.
|
|
9
|
+
// - resolve(id): {line1, locality?, town, postcode, region?, country, countryCode, coordinates}
|
|
10
|
+
// for a suggestion of its session's latest answer, or null for one no longer current or a place
|
|
11
|
+
// MapKit cannot find.
|
|
12
|
+
// - end(session): drops the session, settling its query with [].
|
|
13
|
+
#pragma once
|
|
14
|
+
|
|
15
|
+
#include "ngn/native-module.h"
|
|
16
|
+
|
|
17
|
+
#include <functional>
|
|
18
|
+
#include <memory>
|
|
19
|
+
#include <optional>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <vector>
|
|
22
|
+
|
|
23
|
+
namespace ngn {
|
|
24
|
+
|
|
25
|
+
struct AddressCompletion {
|
|
26
|
+
std::string title;
|
|
27
|
+
std::string subtitle;
|
|
28
|
+
// The OS's own completion, handed back to look it up.
|
|
29
|
+
std::shared_ptr<void> handle;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
struct PostalAddressParts {
|
|
33
|
+
std::string line1;
|
|
34
|
+
std::optional<std::string> locality;
|
|
35
|
+
std::string town;
|
|
36
|
+
std::string postcode;
|
|
37
|
+
std::optional<std::string> region;
|
|
38
|
+
std::string country;
|
|
39
|
+
std::string countryCode;
|
|
40
|
+
double latitude{0};
|
|
41
|
+
double longitude{0};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// One session's completer. Its callbacks may come on any thread, more than once per query, and
|
|
45
|
+
// for a query before the latest; the module keeps only what is for the latest.
|
|
46
|
+
class AddressCompleter {
|
|
47
|
+
public:
|
|
48
|
+
struct Callbacks {
|
|
49
|
+
std::function<void(const std::string &query, std::vector<AddressCompletion> completions)> results;
|
|
50
|
+
std::function<void(const std::string &query, const std::string &reason)> failed;
|
|
51
|
+
};
|
|
52
|
+
virtual ~AddressCompleter() = default;
|
|
53
|
+
// `region` is an ISO 3166-1 alpha-2 code, or empty for anywhere.
|
|
54
|
+
virtual void complete(const std::string &query, const std::string ®ion, bool pointsOfInterest) = 0;
|
|
55
|
+
virtual void cancel() = 0;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
class AddressLookup {
|
|
59
|
+
public:
|
|
60
|
+
virtual ~AddressLookup() = default;
|
|
61
|
+
virtual std::unique_ptr<AddressCompleter> makeCompleter(AddressCompleter::Callbacks callbacks) = 0;
|
|
62
|
+
// The address of a completion: answers once, on any thread, with the address, or nothing and
|
|
63
|
+
// the reason (empty for a place that cannot be found).
|
|
64
|
+
virtual void lookup(std::shared_ptr<void> completion, std::function<void(std::optional<PostalAddressParts>, std::string error)> done) = 0;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
std::shared_ptr<NativeModule> makeAddressSearchModule(std::shared_ptr<AddressLookup> lookup);
|
|
68
|
+
|
|
69
|
+
} // namespace ngn
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Frame callbacks for animations that run on the UI thread: react-native-worklets'
|
|
2
|
+
// requestAnimationFrame and Reanimated's frames. What React Native iOS's AnimationFrameQueue and
|
|
3
|
+
// REANodesManager do over a CADisplayLink, without the display link: the backend drives `frame`
|
|
4
|
+
// from its own (CVDisplayLink, NSView.displayLink) while `wanted`, and stops it after the frame
|
|
5
|
+
// that leaves nothing waiting, so an app with nothing animating takes no frames at all.
|
|
6
|
+
#pragma once
|
|
7
|
+
|
|
8
|
+
#include <functional>
|
|
9
|
+
#include <mutex>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace ngn {
|
|
13
|
+
|
|
14
|
+
class AnimationFrames {
|
|
15
|
+
public:
|
|
16
|
+
// Gets the frame's timestamp in milliseconds, on the clock the backend's `now` reads.
|
|
17
|
+
using Callback = std::function<void(double timestampMs)>;
|
|
18
|
+
|
|
19
|
+
// Any thread. The callback runs on the next frame, once.
|
|
20
|
+
void request(Callback callback);
|
|
21
|
+
// UI thread: a display frame. Runs the callbacks waiting when it starts; one they request runs
|
|
22
|
+
// on the frame after.
|
|
23
|
+
void frame(double timestampMs);
|
|
24
|
+
// Any thread. Drops what waits, as the runtime that asked goes away.
|
|
25
|
+
void clear();
|
|
26
|
+
bool wanted() const;
|
|
27
|
+
|
|
28
|
+
// Told, on the thread that changed it, each time frames start or stop being wanted.
|
|
29
|
+
std::function<void(bool wanted)> onWanted;
|
|
30
|
+
|
|
31
|
+
private:
|
|
32
|
+
void setWanted(bool wanted, std::unique_lock<std::mutex> &lock);
|
|
33
|
+
|
|
34
|
+
mutable std::mutex mutex_;
|
|
35
|
+
std::vector<Callback> waiting_;
|
|
36
|
+
bool wanted_{false};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
} // namespace ngn
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// NgNativeApplication and NgNativeDevice: the constants @ng-native/expo's AppInfo reads off
|
|
2
|
+
// expo-application and expo-device, as properties.
|
|
3
|
+
//
|
|
4
|
+
// - NgNativeApplication: nativeApplicationVersion (CFBundleShortVersionString),
|
|
5
|
+
// nativeBuildVersion (CFBundleVersion), applicationId (CFBundleIdentifier) and applicationName
|
|
6
|
+
// (CFBundleDisplayName, else CFBundleName). A dev run's binary has no bundle: its id and name are
|
|
7
|
+
// the app's own (app.json's), and its versions null.
|
|
8
|
+
// - NgNativeDevice: brand and manufacturer "Apple", modelName (the Mac's marketing name, else its
|
|
9
|
+
// model identifier), modelId ("Mac15,3"), osName "macOS", osVersion, osBuildId, deviceName,
|
|
10
|
+
// totalMemory, supportedCpuArchitectures, isDevice true (a Mac is never a simulator) and
|
|
11
|
+
// deviceType 3, expo-device's DESKTOP.
|
|
12
|
+
#pragma once
|
|
13
|
+
|
|
14
|
+
#include "ngn/native-module.h"
|
|
15
|
+
|
|
16
|
+
#include <cstdint>
|
|
17
|
+
#include <memory>
|
|
18
|
+
#include <optional>
|
|
19
|
+
#include <string>
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
namespace ngn {
|
|
23
|
+
|
|
24
|
+
struct BundleFacts {
|
|
25
|
+
std::optional<std::string> version;
|
|
26
|
+
std::optional<std::string> build;
|
|
27
|
+
std::optional<std::string> id;
|
|
28
|
+
std::optional<std::string> displayName;
|
|
29
|
+
std::optional<std::string> name;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
struct MachineFacts {
|
|
33
|
+
// "MacBook Pro (14-inch, Nov 2023)"; nothing where the Mac does not say.
|
|
34
|
+
std::optional<std::string> marketingName;
|
|
35
|
+
// "Mac15,3"
|
|
36
|
+
std::string modelId;
|
|
37
|
+
// "26.1"
|
|
38
|
+
std::string osVersion;
|
|
39
|
+
// "25B78"
|
|
40
|
+
std::string osBuildId;
|
|
41
|
+
// The name the user gave the Mac.
|
|
42
|
+
std::optional<std::string> deviceName;
|
|
43
|
+
uint64_t totalMemory{0};
|
|
44
|
+
// "arm64", "x86_64"
|
|
45
|
+
std::vector<std::string> architectures;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// `appId` and `appName` stand in for what a bundle with no Info.plist does not have.
|
|
49
|
+
std::shared_ptr<NativeModule> makeApplicationModule(BundleFacts bundle, std::string appId, std::string appName);
|
|
50
|
+
std::shared_ptr<NativeModule> makeDeviceModule(MachineFacts machine);
|
|
51
|
+
|
|
52
|
+
} // namespace ngn
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// The app's menus and shortcuts: the `NgNativeMenus` module, the menu bar and context menu entries
|
|
2
|
+
// as the app sends them (`NativeMenuEntry` in @ng-native/device), the shortcuts it listens for, and
|
|
3
|
+
// the OS's back and forward inputs mapped to `navigate`.
|
|
4
|
+
//
|
|
5
|
+
// The bar the app sends is the whole merged bar, its defaults included. An item with a `menuRole`
|
|
6
|
+
// is the OS's own command unless the app marks it `handled`; every other item is the app's, and
|
|
7
|
+
// choosing it sends `menuSelect` with its id. Shortcuts match a key press before the menus see it;
|
|
8
|
+
// one on an editing key (Cmd-Z, X, C, V, A) still goes on to a focused text input, which owns it.
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "ngn/default-menu.h"
|
|
12
|
+
#include "ngn/host-state.h"
|
|
13
|
+
#include "ngn/native-module.h"
|
|
14
|
+
|
|
15
|
+
#include <react/renderer/core/ReactPrimitives.h>
|
|
16
|
+
|
|
17
|
+
#include <functional>
|
|
18
|
+
#include <map>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <mutex>
|
|
21
|
+
#include <optional>
|
|
22
|
+
#include <string>
|
|
23
|
+
#include <vector>
|
|
24
|
+
|
|
25
|
+
namespace ngn {
|
|
26
|
+
|
|
27
|
+
using facebook::react::SurfaceId;
|
|
28
|
+
|
|
29
|
+
// A key press: the key as the web names it (a character, or "ArrowLeft", "Enter", "F5"...) and the
|
|
30
|
+
// modifiers held (MenuModifier).
|
|
31
|
+
struct KeyChord {
|
|
32
|
+
std::string key;
|
|
33
|
+
unsigned modifiers{0};
|
|
34
|
+
bool operator==(const KeyChord &) const = default;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// The entries of a menu as the app sends them (a context menu's, or one group's items).
|
|
38
|
+
std::vector<MenuItem> parseMenu(const folly::dynamic &entries);
|
|
39
|
+
// The app's whole bar, with the host's Developer menu before Help when `options.developer`.
|
|
40
|
+
std::vector<MenuItem> parseMenuBar(const folly::dynamic &groups, const DefaultMenuOptions &options);
|
|
41
|
+
// `{ key, meta, ctrl, alt, shift }`, as `parseShortcut` reads a shortcut for macOS.
|
|
42
|
+
KeyChord parseChord(const folly::dynamic &chord);
|
|
43
|
+
|
|
44
|
+
enum class NavigationDirection { Back, Forward };
|
|
45
|
+
enum class NavigationInput { MouseButton4, MouseButton5, SwipeLeft, SwipeRight };
|
|
46
|
+
|
|
47
|
+
// The OS's back and forward inputs: mouse buttons 4 and 5, a swipe (right goes back, as a page
|
|
48
|
+
// follows the fingers), and Cmd-[ and Cmd-]. Cmd-Left stays with text editing.
|
|
49
|
+
std::optional<NavigationDirection> navigationFor(NavigationInput input);
|
|
50
|
+
std::optional<NavigationDirection> navigationFor(const KeyChord &chord);
|
|
51
|
+
|
|
52
|
+
// A window's back and forward history, as the app's router reports it (`setHistory`): the titles
|
|
53
|
+
// of the entries behind and ahead, nearest first.
|
|
54
|
+
struct WindowHistory {
|
|
55
|
+
std::vector<std::string> back;
|
|
56
|
+
std::vector<std::string> forward;
|
|
57
|
+
bool operator==(const WindowHistory &) const = default;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// The back and forward chevrons leading a window's toolbar.
|
|
61
|
+
struct HistoryButtons {
|
|
62
|
+
bool shown{false};
|
|
63
|
+
bool backEnabled{false};
|
|
64
|
+
bool forwardEnabled{false};
|
|
65
|
+
// Whether a click goes through the window's history (`navigate`), rather than popping the stack
|
|
66
|
+
// in front (an app that reports no history).
|
|
67
|
+
bool fromHistory{false};
|
|
68
|
+
bool operator==(const HistoryButtons &) const = default;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// The pair shows when the window has history, or, for an app that reports none, when the stack in
|
|
72
|
+
// front has a screen below (back only). The header's `hideBackButton` hides it, and its own left
|
|
73
|
+
// items replace it.
|
|
74
|
+
HistoryButtons historyButtons(const std::optional<WindowHistory> &history, bool stackCanGoBack, bool hidden);
|
|
75
|
+
|
|
76
|
+
// The list a long press or a secondary click on a chevron shows: the entries that way, nearest
|
|
77
|
+
// first, each with how many steps it is.
|
|
78
|
+
struct HistoryMenuItem {
|
|
79
|
+
std::string title;
|
|
80
|
+
int steps{1};
|
|
81
|
+
bool operator==(const HistoryMenuItem &) const = default;
|
|
82
|
+
};
|
|
83
|
+
std::vector<HistoryMenuItem> historyMenu(const WindowHistory &history, NavigationDirection direction);
|
|
84
|
+
|
|
85
|
+
class MenuBackend {
|
|
86
|
+
public:
|
|
87
|
+
virtual ~MenuBackend() = default;
|
|
88
|
+
// Draw `bar` as the menu bar, in place of the one before. Any thread.
|
|
89
|
+
virtual void setMenuBar(std::vector<MenuItem> bar) = 0;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
class MenuHost {
|
|
93
|
+
public:
|
|
94
|
+
using Listener = std::function<void(const folly::dynamic &event)>;
|
|
95
|
+
|
|
96
|
+
// Draws the default menu bar at once.
|
|
97
|
+
MenuHost(std::shared_ptr<MenuBackend> backend, DefaultMenuOptions options);
|
|
98
|
+
|
|
99
|
+
const DefaultMenuOptions &options() const {
|
|
100
|
+
return options_;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// --- what the app sends ---
|
|
104
|
+
void setMenuBar(const folly::dynamic &groups);
|
|
105
|
+
void setShortcuts(const folly::dynamic &shortcuts);
|
|
106
|
+
|
|
107
|
+
// --- what the OS reports ---
|
|
108
|
+
// A menu bar item was chosen in the window on `surface` (the key window's, or nothing). Print
|
|
109
|
+
// with no handler of the app's prints that window (`printWindow`).
|
|
110
|
+
void choose(const MenuItem &item, std::optional<SurfaceId> surface);
|
|
111
|
+
// What File > Print does when the app has no print item of its own: prints the window on the
|
|
112
|
+
// surface, or the key window when it has none. Set once by the host.
|
|
113
|
+
std::function<void(std::optional<SurfaceId> surface)> printWindow;
|
|
114
|
+
// A key press, before the menus and the focused view see it. True when the app's shortcut takes
|
|
115
|
+
// it, and the press goes no further.
|
|
116
|
+
bool keyDown(const KeyChord &chord, bool textInputFocused);
|
|
117
|
+
// Back or forward `steps` entries (one, but for a pick from the history menu).
|
|
118
|
+
void navigate(NavigationDirection direction, std::optional<SurfaceId> surface, int steps = 1);
|
|
119
|
+
|
|
120
|
+
// --- the windows' history, as the app reports it ---
|
|
121
|
+
void setHistory(SurfaceId surface, WindowHistory history);
|
|
122
|
+
// Nothing for a window the app reported none for.
|
|
123
|
+
std::optional<WindowHistory> history(SurfaceId surface) const;
|
|
124
|
+
// A window closed: its history goes with it.
|
|
125
|
+
void forgetHistory(SurfaceId surface);
|
|
126
|
+
// Told, on the thread `setHistory` came on, of a window whose history changed. Set once.
|
|
127
|
+
std::function<void(SurfaceId)> historyChanged;
|
|
128
|
+
|
|
129
|
+
std::shared_ptr<void> listen(Listener listener);
|
|
130
|
+
|
|
131
|
+
private:
|
|
132
|
+
void send(const folly::dynamic &event);
|
|
133
|
+
|
|
134
|
+
std::shared_ptr<MenuBackend> backend_;
|
|
135
|
+
DefaultMenuOptions options_;
|
|
136
|
+
mutable std::mutex mutex_;
|
|
137
|
+
std::vector<std::pair<std::string, KeyChord>> shortcuts_;
|
|
138
|
+
std::map<SurfaceId, WindowHistory> histories_;
|
|
139
|
+
// A dropped handle waits for its listener's call in progress, so a module going with a reload
|
|
140
|
+
// is never called after.
|
|
141
|
+
Listeners<folly::dynamic> listeners_;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
std::shared_ptr<NativeModule> makeMenusModule(std::shared_ptr<MenuHost> host);
|
|
145
|
+
|
|
146
|
+
} // namespace ngn
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Several windows on one runtime: the `NgNativeWindows` module and the rules every desktop backend
|
|
2
|
+
// shares. Each window has a surface of its own, which the app renders into; the app's own surface
|
|
3
|
+
// (1) is never shown.
|
|
4
|
+
//
|
|
5
|
+
// The host never closes a window or quits on its own. The close button, Cmd-W, Cmd-Q and a logout
|
|
6
|
+
// become `closeRequest` and `quitRequest` events on `ngNativeWindows`, and the window closes or the
|
|
7
|
+
// app quits when the app says so (`close(surface)`, `answerQuit(proceed)`). With no app listening
|
|
8
|
+
// (a bundle that failed to load), they do what the OS would.
|
|
9
|
+
//
|
|
10
|
+
// Window frames autosave under the window's key (`main`, a route outlet, a `restoreKey`) in the
|
|
11
|
+
// app's preferences, and a window opened again with that key comes back where it was. A reload
|
|
12
|
+
// keeps the windows with a key for the reloaded app to claim, and closes the rest.
|
|
13
|
+
#pragma once
|
|
14
|
+
|
|
15
|
+
#include "ngn/host-state.h"
|
|
16
|
+
#include "ngn/native-module.h"
|
|
17
|
+
#include "ngn/system.h"
|
|
18
|
+
|
|
19
|
+
#include <react/renderer/core/ReactPrimitives.h>
|
|
20
|
+
|
|
21
|
+
#include <map>
|
|
22
|
+
#include <memory>
|
|
23
|
+
#include <mutex>
|
|
24
|
+
#include <optional>
|
|
25
|
+
#include <string>
|
|
26
|
+
#include <vector>
|
|
27
|
+
|
|
28
|
+
namespace ngn {
|
|
29
|
+
|
|
30
|
+
using facebook::react::SurfaceId;
|
|
31
|
+
|
|
32
|
+
enum class TitleBar { Default, Transparent, Hidden };
|
|
33
|
+
|
|
34
|
+
// A window's content rectangle in the OS's screen coordinates, in points.
|
|
35
|
+
struct WindowFrame {
|
|
36
|
+
double x{0};
|
|
37
|
+
double y{0};
|
|
38
|
+
double width{0};
|
|
39
|
+
double height{0};
|
|
40
|
+
bool operator==(const WindowFrame &) const = default;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
constexpr double kDefaultWindowWidth = 1040;
|
|
44
|
+
constexpr double kDefaultWindowHeight = 720;
|
|
45
|
+
|
|
46
|
+
// What the app asked to open (`NativeWindowRequest`). Sizes are content sizes in points.
|
|
47
|
+
struct WindowRequest {
|
|
48
|
+
std::optional<std::string> key;
|
|
49
|
+
std::string title;
|
|
50
|
+
std::optional<double> width;
|
|
51
|
+
std::optional<double> height;
|
|
52
|
+
std::optional<double> minWidth;
|
|
53
|
+
std::optional<double> minHeight;
|
|
54
|
+
std::optional<double> maxWidth;
|
|
55
|
+
std::optional<double> maxHeight;
|
|
56
|
+
bool resizable{true};
|
|
57
|
+
TitleBar titleBar{TitleBar::Default};
|
|
58
|
+
bool fullScreen{false};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
WindowRequest windowRequest(const folly::dynamic &request);
|
|
62
|
+
|
|
63
|
+
// Where a window opens: its saved frame (`restored`), or the size it asked for with the origin left
|
|
64
|
+
// to the backend, which cascades it.
|
|
65
|
+
struct WindowPlacement {
|
|
66
|
+
WindowFrame frame;
|
|
67
|
+
bool restored{false};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
enum class QuitReply {
|
|
71
|
+
// Quit now: nothing is listening, or the app already agreed.
|
|
72
|
+
Now,
|
|
73
|
+
// The app was asked; the backend waits for `replyToQuit`.
|
|
74
|
+
Later,
|
|
75
|
+
Cancel,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// What a backend does with windows. Called on any thread; the backend moves to its UI thread.
|
|
79
|
+
class WindowBackend {
|
|
80
|
+
public:
|
|
81
|
+
virtual ~WindowBackend() = default;
|
|
82
|
+
// Make the window for `surface` and start the surface. `opened` is called once the surface can
|
|
83
|
+
// take commits. The window shows when the surface's first frame mounts.
|
|
84
|
+
virtual void openWindow(
|
|
85
|
+
SurfaceId surface,
|
|
86
|
+
const WindowRequest &request,
|
|
87
|
+
const WindowPlacement &placement,
|
|
88
|
+
std::function<void()> opened) = 0;
|
|
89
|
+
// Close the window without asking, and stop its surface.
|
|
90
|
+
virtual void closeWindow(SurfaceId surface) = 0;
|
|
91
|
+
virtual void focusWindow(SurfaceId surface) = 0;
|
|
92
|
+
virtual void setWindowTitle(SurfaceId surface, const std::string &title) = 0;
|
|
93
|
+
// Start quitting as the OS's quit command does, which comes back through `quitRequested`.
|
|
94
|
+
virtual void beginQuit() = 0;
|
|
95
|
+
// Answer a quit that `quitRequested` deferred.
|
|
96
|
+
virtual void replyToQuit(bool proceed) = 0;
|
|
97
|
+
// Run `task` on the UI thread after `seconds`.
|
|
98
|
+
virtual void after(double seconds, std::function<void()> task) = 0;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
class WindowHost {
|
|
102
|
+
public:
|
|
103
|
+
// Events for the app: what the module sends as `ngNativeWindows`.
|
|
104
|
+
using Listener = std::function<void(const folly::dynamic &event)>;
|
|
105
|
+
|
|
106
|
+
WindowHost(std::shared_ptr<WindowBackend> backend, std::shared_ptr<System> system);
|
|
107
|
+
|
|
108
|
+
// --- what the app asks (any thread) ---
|
|
109
|
+
void open(const WindowRequest &request, std::function<void(SurfaceId)> done);
|
|
110
|
+
void close(SurfaceId surface);
|
|
111
|
+
void focus(SurfaceId surface);
|
|
112
|
+
void setTitle(SurfaceId surface, const std::string &title);
|
|
113
|
+
void quit();
|
|
114
|
+
void answerQuit(bool proceed);
|
|
115
|
+
|
|
116
|
+
// --- what the OS reports (the backend's UI thread) ---
|
|
117
|
+
// The close button or Cmd-W. True to let the OS close the window now: the app is not listening,
|
|
118
|
+
// or the window is not one of the app's.
|
|
119
|
+
bool closeRequested(SurfaceId surface);
|
|
120
|
+
// The OS's quit command or a logout.
|
|
121
|
+
QuitReply quitRequested();
|
|
122
|
+
// SIGTERM. The app is asked to run only its `willQuit` hooks, with no `canClose` guard, and
|
|
123
|
+
// `done` runs on its `answerQuit` (either answer) or after kTerminateSeconds, whichever is first;
|
|
124
|
+
// it ends the process. A SIGTERM takes over a Cmd-Q still asking: that quit's no (a guard
|
|
125
|
+
// refusing) is replied to the OS and the SIGTERM waits on, so `willQuit` still runs. With no app
|
|
126
|
+
// listening, `done` runs at once. A second SIGTERM while waiting asks nothing more. `done` runs once, on the thread that answered, the backend's timer or the caller.
|
|
127
|
+
void terminateRequested(std::function<void()> done);
|
|
128
|
+
static constexpr double kTerminateSeconds = 2;
|
|
129
|
+
// The key window, or none when the app has none.
|
|
130
|
+
void focused(std::optional<SurfaceId> surface);
|
|
131
|
+
void resized(SurfaceId surface, const WindowFrame &frame, double scale);
|
|
132
|
+
void moved(SurfaceId surface, const WindowFrame &frame);
|
|
133
|
+
// The app was opened again, or its Dock icon clicked.
|
|
134
|
+
void reopen(bool hasVisibleWindows);
|
|
135
|
+
|
|
136
|
+
// --- reloads ---
|
|
137
|
+
// A runtime's module starts listening. After the first, the app has reloaded (from the menu or
|
|
138
|
+
// the dev server): the windows with no key close, and the rest wait for the app to `open` their
|
|
139
|
+
// key again, for `kClaimSeconds`, before they close too.
|
|
140
|
+
std::shared_ptr<void> attach(Listener listener);
|
|
141
|
+
static constexpr double kClaimSeconds = 5;
|
|
142
|
+
|
|
143
|
+
std::vector<SurfaceId> surfaces() const;
|
|
144
|
+
std::optional<SurfaceId> focusedSurface() const;
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
private:
|
|
148
|
+
struct Window {
|
|
149
|
+
std::optional<std::string> key;
|
|
150
|
+
bool kept{false};
|
|
151
|
+
};
|
|
152
|
+
void send(const folly::dynamic &event);
|
|
153
|
+
bool isTerminating() const;
|
|
154
|
+
void finishTerminate();
|
|
155
|
+
void autosave(SurfaceId surface, const WindowFrame &frame);
|
|
156
|
+
void reloading();
|
|
157
|
+
// The windows the reload `reload` kept that the app has not asked for again close.
|
|
158
|
+
void dropUnclaimed(uint64_t reload);
|
|
159
|
+
WindowPlacement placement(const WindowRequest &request);
|
|
160
|
+
|
|
161
|
+
std::shared_ptr<WindowBackend> backend_;
|
|
162
|
+
std::shared_ptr<System> system_;
|
|
163
|
+
mutable std::mutex mutex_;
|
|
164
|
+
std::map<SurfaceId, Window> windows_;
|
|
165
|
+
SurfaceId next_{11};
|
|
166
|
+
std::optional<SurfaceId> focused_;
|
|
167
|
+
bool quitAsked_{false};
|
|
168
|
+
bool quitAgreed_{false};
|
|
169
|
+
std::optional<std::function<void()>> terminating_;
|
|
170
|
+
bool attached_{false};
|
|
171
|
+
// Counts the reloads, so a claim timer only drops the windows of the reload that set it.
|
|
172
|
+
uint64_t reloads_{0};
|
|
173
|
+
// A dropped handle waits for its listener's call in progress, so a module going with a reload
|
|
174
|
+
// is never called after.
|
|
175
|
+
Listeners<folly::dynamic> listeners_;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// The `NgNativeWindows` module over `host`, one per runtime.
|
|
179
|
+
std::shared_ptr<NativeModule> makeWindowsModule(std::shared_ptr<WindowHost> host);
|
|
180
|
+
|
|
181
|
+
} // namespace ngn
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// NgNativeAppleAuthentication: expo-apple-authentication's native module on a desktop host, over an
|
|
2
|
+
// AppleIdProvider the AppKit backend implements with AuthenticationServices.
|
|
3
|
+
//
|
|
4
|
+
// - isAvailableAsync(): whether the app can sign in with Apple at all: its signature carries the
|
|
5
|
+
// `com.apple.developer.applesignin` entitlement. A development host has none, so it answers false.
|
|
6
|
+
// - requestAsync({requestedScopes, requestedOperation, user, state, nonce}): Apple's sheet, and the
|
|
7
|
+
// credential in expo's shape: {user, email, fullName, realUserStatus, state, authorizationCode,
|
|
8
|
+
// identityToken}. It rejects as `CODE: message` with expo's codes: an unknown scope or operation
|
|
9
|
+
// (ERR_INVALID_SCOPE, ERR_INVALID_OPERATION), no entitlement (ERR_REQUEST_NOT_HANDLED, without
|
|
10
|
+
// asking AuthenticationServices), `noPrompts` (ERR_REQUEST_NOT_INTERACTIVE, with no sheet), and
|
|
11
|
+
// each ASAuthorizationError as on iOS.
|
|
12
|
+
// - getCredentialStateAsync(user): 0 revoked, 1 authorized, 2 not found, 3 transferred.
|
|
13
|
+
// - formatFullName(fullName, style): the name for the user's locale, in `default`, `short`,
|
|
14
|
+
// `medium`, `long` or `abbreviated` style. Synchronous.
|
|
15
|
+
// The OS's word that the user revoked the app's credential arrives as an `ngNativeAppleAuthentication`
|
|
16
|
+
// event, {type: 'revoked'}.
|
|
17
|
+
//
|
|
18
|
+
// `<apple-sign-in-button>` is expo's button view (ViewManagerAdapter_ExpoAppleAuthentication), a
|
|
19
|
+
// Fabric component of the desktop's own that the AppKit backend draws as ASAuthorizationAppleIDButton,
|
|
20
|
+
// with expo's `buttonType`, `buttonStyle` and `cornerRadius`, sending `buttonPress` on a click.
|
|
21
|
+
#pragma once
|
|
22
|
+
|
|
23
|
+
#include "ngn/desktop-props.h"
|
|
24
|
+
#include "ngn/native-module.h"
|
|
25
|
+
|
|
26
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
27
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
28
|
+
#include <react/renderer/components/view/ViewProps.h>
|
|
29
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
30
|
+
|
|
31
|
+
#include <functional>
|
|
32
|
+
#include <memory>
|
|
33
|
+
#include <optional>
|
|
34
|
+
#include <string>
|
|
35
|
+
#include <vector>
|
|
36
|
+
|
|
37
|
+
namespace ngn {
|
|
38
|
+
|
|
39
|
+
class AppleIdProvider {
|
|
40
|
+
public:
|
|
41
|
+
enum class CredentialState { Revoked = 0, Authorized = 1, NotFound = 2, Transferred = 3 };
|
|
42
|
+
enum class Scope { FullName = 0, Email = 1 };
|
|
43
|
+
// ASAuthorization's OpenID operations, by expo's numbers.
|
|
44
|
+
enum class Operation { Implicit = 0, Login = 1, Refresh = 2, Logout = 3 };
|
|
45
|
+
|
|
46
|
+
struct Name {
|
|
47
|
+
std::optional<std::string> namePrefix;
|
|
48
|
+
std::optional<std::string> givenName;
|
|
49
|
+
std::optional<std::string> middleName;
|
|
50
|
+
std::optional<std::string> familyName;
|
|
51
|
+
std::optional<std::string> nameSuffix;
|
|
52
|
+
std::optional<std::string> nickname;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
struct Request {
|
|
56
|
+
std::vector<Scope> scopes;
|
|
57
|
+
Operation operation{Operation::Implicit};
|
|
58
|
+
std::optional<std::string> user;
|
|
59
|
+
std::optional<std::string> state;
|
|
60
|
+
std::optional<std::string> nonce;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
struct Credential {
|
|
64
|
+
std::optional<std::string> user;
|
|
65
|
+
std::optional<std::string> email;
|
|
66
|
+
std::optional<Name> fullName;
|
|
67
|
+
// expo's UserDetectionStatus: 0 unsupported, 1 unknown, 2 likely real.
|
|
68
|
+
int realUserStatus{0};
|
|
69
|
+
std::optional<std::string> state;
|
|
70
|
+
std::optional<std::string> authorizationCode;
|
|
71
|
+
std::optional<std::string> identityToken;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// ASAuthorizationError's codes.
|
|
75
|
+
enum class Failure { Unknown, Canceled, InvalidResponse, NotHandled, Failed, NotInteractive, MatchedExcludedCredential, NoWindow };
|
|
76
|
+
|
|
77
|
+
virtual ~AppleIdProvider() = default;
|
|
78
|
+
// Whether the app is signed with the Sign in with Apple entitlement.
|
|
79
|
+
virtual bool entitled() = 0;
|
|
80
|
+
// Shows Apple's sheet over the key window and answers once, on any thread.
|
|
81
|
+
virtual void perform(const Request &request, std::function<void(std::optional<Credential>, Failure)> done) = 0;
|
|
82
|
+
virtual void credentialState(const std::string &user, std::function<void(CredentialState)> done) = 0;
|
|
83
|
+
// `style` is expo's: default, short, medium, long or abbreviated.
|
|
84
|
+
virtual std::string formatName(const Name &name, const std::string &style) = 0;
|
|
85
|
+
// Calls `revoked`, on any thread, each time the OS says the app's credential was revoked, until
|
|
86
|
+
// the function it answers is called.
|
|
87
|
+
virtual std::function<void()> watchRevocations(std::function<void()> revoked) = 0;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// expo's `CODE: message` for a failure, as ExpoModulesCore names its exceptions on iOS.
|
|
91
|
+
std::string appleAuthenticationFailure(AppleIdProvider::Failure failure);
|
|
92
|
+
|
|
93
|
+
std::shared_ptr<NativeModule> makeAppleAuthenticationModule(std::shared_ptr<AppleIdProvider> provider, bool noPrompts);
|
|
94
|
+
|
|
95
|
+
extern const char AppleButtonComponentName[];
|
|
96
|
+
|
|
97
|
+
class AppleButtonProps final : public facebook::react::ViewProps, public HasDesktopProps {
|
|
98
|
+
public:
|
|
99
|
+
AppleButtonProps() = default;
|
|
100
|
+
AppleButtonProps(
|
|
101
|
+
const facebook::react::PropsParserContext &context,
|
|
102
|
+
const AppleButtonProps &sourceProps,
|
|
103
|
+
const facebook::react::RawProps &rawProps);
|
|
104
|
+
// expo's enums, which are AuthenticationServices' own: sign in 0, continue 1, sign up 2; white 0,
|
|
105
|
+
// white outline 1, black 2. Out of range is the default, as on iOS.
|
|
106
|
+
int buttonType{0};
|
|
107
|
+
int buttonStyle{0};
|
|
108
|
+
// In points; expo sets 0 when none is given.
|
|
109
|
+
double cornerRadius{0};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
using AppleButtonShadowNode =
|
|
113
|
+
facebook::react::ConcreteViewShadowNode<AppleButtonComponentName, AppleButtonProps, facebook::react::ViewEventEmitter>;
|
|
114
|
+
using AppleButtonComponentDescriptor = facebook::react::ConcreteComponentDescriptor<AppleButtonShadowNode>;
|
|
115
|
+
|
|
116
|
+
} // namespace ngn
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// NgNativeAsset: what @ng-native/expo's `assets()` needs of expo-asset on a desktop OS, where
|
|
2
|
+
// expo-asset is an empty module: an asset's file on this Mac, downloaded first when the dev server
|
|
3
|
+
// serves it. The desktop loader resolves each module to its source as an image is, and builds
|
|
4
|
+
// expo's Asset over the answer.
|
|
5
|
+
//
|
|
6
|
+
// - downloadAsync(uri, hash, type): the file:// uri of the asset's file. A `file:` uri or a path
|
|
7
|
+
// (a packaged app's asset) is answered as it is when the file is there. An `http(s):` url is
|
|
8
|
+
// downloaded into `<caches>/ExponentAsset-<hash>.<type>`, as expo-asset names it, and a file
|
|
9
|
+
// already there for that hash is not downloaded again. Without a hash the name is the url's.
|
|
10
|
+
// A hash or type other than letters, digits, `_` and `-` is refused, so neither leaves the caches.
|
|
11
|
+
//
|
|
12
|
+
// A file is answered only where `files` lets the app read (FileAccess::readFor: its own folders,
|
|
13
|
+
// picks, declared paths and a packaged app's bundle), and anything else is refused before the
|
|
14
|
+
// file is looked at, so the answer never says whether a file outside is there.
|
|
15
|
+
#pragma once
|
|
16
|
+
|
|
17
|
+
#include "ngn/file-system.h"
|
|
18
|
+
#include "ngn/native-module.h"
|
|
19
|
+
#include "ngn/network.h"
|
|
20
|
+
|
|
21
|
+
#include <memory>
|
|
22
|
+
#include <string>
|
|
23
|
+
|
|
24
|
+
namespace ngn {
|
|
25
|
+
|
|
26
|
+
std::shared_ptr<NativeModule> makeAssetModule(std::shared_ptr<Http> http, std::string caches, std::shared_ptr<FileAccess> files);
|
|
27
|
+
|
|
28
|
+
} // namespace ngn
|