@ng-native/desktop 0.0.0-stage → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +51 -2
- package/app.plugin.cjs +17 -0
- package/bin/app-config.mjs +168 -0
- package/bin/autolink.mjs +224 -0
- package/bin/cli.mjs +158 -0
- package/bin/host.mjs +427 -0
- package/bin/ng-native-desktop.mjs +4 -0
- package/bin/package.mjs +971 -0
- package/bin/plist.mjs +68 -0
- package/bin/prebuilt.mjs +328 -0
- package/bin/toolchain.mjs +192 -0
- package/native/CMakeLists.txt +276 -0
- package/native/appkit/CMakeLists.txt +109 -0
- package/native/appkit/address-search.h +26 -0
- package/native/appkit/address-search.mm +277 -0
- package/native/appkit/animation-frames.h +14 -0
- package/native/appkit/animation-frames.mm +106 -0
- package/native/appkit/app-info.h +12 -0
- package/native/appkit/app-info.mm +98 -0
- package/native/appkit/app-updater.mm +128 -0
- package/native/appkit/app-windows.h +81 -0
- package/native/appkit/app-windows.mm +318 -0
- package/native/appkit/appkit-backend.h +73 -0
- package/native/appkit/appkit-backend.mm +276 -0
- package/native/appkit/apple-authentication.h +19 -0
- package/native/appkit/apple-authentication.mm +248 -0
- package/native/appkit/apple-button-view.h +10 -0
- package/native/appkit/apple-button-view.mm +37 -0
- package/native/appkit/apple-id-button.h +16 -0
- package/native/appkit/apple-id-button.mm +50 -0
- package/native/appkit/audio.h +16 -0
- package/native/appkit/audio.mm +275 -0
- package/native/appkit/battery.h +13 -0
- package/native/appkit/battery.mm +92 -0
- package/native/appkit/bookmarks.h +17 -0
- package/native/appkit/bookmarks.mm +145 -0
- package/native/appkit/calendar.h +25 -0
- package/native/appkit/calendar.mm +660 -0
- package/native/appkit/camera-view.h +15 -0
- package/native/appkit/camera-view.mm +130 -0
- package/native/appkit/camera.h +39 -0
- package/native/appkit/camera.mm +362 -0
- package/native/appkit/cg-canvas.h +17 -0
- package/native/appkit/cg-canvas.mm +518 -0
- package/native/appkit/component-view.h +17 -0
- package/native/appkit/crypto.h +19 -0
- package/native/appkit/crypto.mm +78 -0
- package/native/appkit/desktop-expo.h +29 -0
- package/native/appkit/desktop-expo.mm +385 -0
- package/native/appkit/expo-image-drawing.h +46 -0
- package/native/appkit/expo-image-drawing.mm +131 -0
- package/native/appkit/expo-image-view.h +15 -0
- package/native/appkit/expo-image-view.mm +182 -0
- package/native/appkit/expo-ui-renderer.h +68 -0
- package/native/appkit/expo-ui-renderer.mm +101 -0
- package/native/appkit/expo-ui-view.h +26 -0
- package/native/appkit/expo-ui-view.mm +134 -0
- package/native/appkit/expo-ui.swift +1284 -0
- package/native/appkit/file-system.h +16 -0
- package/native/appkit/file-system.mm +140 -0
- package/native/appkit/fonts.h +12 -0
- package/native/appkit/fonts.mm +48 -0
- package/native/appkit/geocoder.h +19 -0
- package/native/appkit/geocoder.mm +101 -0
- package/native/appkit/glass-effect.h +22 -0
- package/native/appkit/glass-effect.mm +63 -0
- package/native/appkit/glass-view.h +8 -0
- package/native/appkit/glass-view.mm +65 -0
- package/native/appkit/header-toolbar.h +60 -0
- package/native/appkit/header-toolbar.mm +629 -0
- package/native/appkit/host-view.h +54 -0
- package/native/appkit/host-view.mm +1200 -0
- package/native/appkit/image-manipulator.h +14 -0
- package/native/appkit/image-manipulator.mm +191 -0
- package/native/appkit/image-request.h +22 -0
- package/native/appkit/image-request.mm +62 -0
- package/native/appkit/image-view.h +8 -0
- package/native/appkit/image-view.mm +142 -0
- package/native/appkit/input-replay.h +25 -0
- package/native/appkit/input-replay.mm +418 -0
- package/native/appkit/language-model.h +14 -0
- package/native/appkit/language-model.mm +99 -0
- package/native/appkit/language-model.swift +472 -0
- package/native/appkit/local-authentication.h +15 -0
- package/native/appkit/local-authentication.mm +133 -0
- package/native/appkit/location.h +16 -0
- package/native/appkit/location.mm +214 -0
- package/native/appkit/main.mm +1515 -0
- package/native/appkit/map-view.h +15 -0
- package/native/appkit/map-view.mm +109 -0
- package/native/appkit/maps.h +35 -0
- package/native/appkit/maps.mm +343 -0
- package/native/appkit/menu-bar.h +22 -0
- package/native/appkit/menu-bar.mm +208 -0
- package/native/appkit/modal-focus.h +16 -0
- package/native/appkit/modal-focus.mm +26 -0
- package/native/appkit/modal-host-view.h +79 -0
- package/native/appkit/modal-host-view.mm +442 -0
- package/native/appkit/native-controls.h +22 -0
- package/native/appkit/native-controls.mm +431 -0
- package/native/appkit/network-state.h +12 -0
- package/native/appkit/network-state.mm +64 -0
- package/native/appkit/network.h +14 -0
- package/native/appkit/network.mm +396 -0
- package/native/appkit/notifications.h +19 -0
- package/native/appkit/notifications.mm +309 -0
- package/native/appkit/photo-library.h +33 -0
- package/native/appkit/photo-library.mm +548 -0
- package/native/appkit/pointer-buttons.h +32 -0
- package/native/appkit/presentation-label.h +15 -0
- package/native/appkit/presentation-label.mm +12 -0
- package/native/appkit/presented-screen.h +19 -0
- package/native/appkit/presented-screen.mm +181 -0
- package/native/appkit/printing.h +42 -0
- package/native/appkit/printing.mm +393 -0
- package/native/appkit/push.h +19 -0
- package/native/appkit/push.mm +81 -0
- package/native/appkit/red-box.h +26 -0
- package/native/appkit/red-box.mm +387 -0
- package/native/appkit/screen-capture.h +21 -0
- package/native/appkit/screen-capture.mm +92 -0
- package/native/appkit/scroll-view.h +13 -0
- package/native/appkit/scroll-view.mm +251 -0
- package/native/appkit/scrollers.h +25 -0
- package/native/appkit/scrollers.mm +43 -0
- package/native/appkit/search-field.h +34 -0
- package/native/appkit/search-field.mm +291 -0
- package/native/appkit/search-toolbar-item.h +19 -0
- package/native/appkit/search-toolbar-item.mm +269 -0
- package/native/appkit/share-picker.h +34 -0
- package/native/appkit/share-picker.mm +121 -0
- package/native/appkit/split-view.h +77 -0
- package/native/appkit/split-view.mm +1206 -0
- package/native/appkit/store-review.h +13 -0
- package/native/appkit/store-review.mm +28 -0
- package/native/appkit/surface-view.h +45 -0
- package/native/appkit/surface-view.mm +558 -0
- package/native/appkit/svg-view.h +17 -0
- package/native/appkit/svg-view.mm +57 -0
- package/native/appkit/symbol-drawing.h +24 -0
- package/native/appkit/symbol-drawing.mm +117 -0
- package/native/appkit/symbol-view.h +8 -0
- package/native/appkit/symbol-view.mm +33 -0
- package/native/appkit/system-access.h +34 -0
- package/native/appkit/system-access.mm +210 -0
- package/native/appkit/system.h +24 -0
- package/native/appkit/system.mm +403 -0
- package/native/appkit/test-launch.h +36 -0
- package/native/appkit/test-launch.mm +115 -0
- package/native/appkit/text-input-field.h +76 -0
- package/native/appkit/text-input-field.mm +444 -0
- package/native/appkit/text-layout.h +58 -0
- package/native/appkit/text-layout.mm +477 -0
- package/native/appkit/text-recognition.h +13 -0
- package/native/appkit/text-recognition.mm +102 -0
- package/native/appkit/tracking.h +13 -0
- package/native/appkit/tracking.mm +51 -0
- package/native/appkit/tray-and-dock.h +45 -0
- package/native/appkit/tray-and-dock.mm +130 -0
- package/native/appkit/undo.h +23 -0
- package/native/appkit/undo.mm +125 -0
- package/native/appkit/updates.h +17 -0
- package/native/appkit/updates.mm +71 -0
- package/native/appkit/video-view.h +10 -0
- package/native/appkit/video-view.mm +42 -0
- package/native/appkit/video.h +38 -0
- package/native/appkit/video.mm +404 -0
- package/native/appkit/web-browser.h +12 -0
- package/native/appkit/web-browser.mm +97 -0
- package/native/appkit/web-view-component.h +9 -0
- package/native/appkit/web-view-component.mm +56 -0
- package/native/appkit/web-view.h +31 -0
- package/native/appkit/web-view.mm +394 -0
- package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
- package/native/cmake/libraries/react-native-worklets.cmake +46 -0
- package/native/cmake/libraries.cmake +109 -0
- package/native/cmake/linked-modules.cmake +112 -0
- package/native/cmake/react-native.cmake +175 -0
- package/native/cmake/runtime-dependencies.cmake +34 -0
- package/native/cmake/swift.cmake +43 -0
- package/native/cmake/third-party.cmake +74 -0
- package/native/core/include/ngn/absent-views.h +27 -0
- package/native/core/include/ngn/accessibility.h +140 -0
- package/native/core/include/ngn/address-search.h +69 -0
- package/native/core/include/ngn/animation-frames.h +39 -0
- package/native/core/include/ngn/app-info.h +52 -0
- package/native/core/include/ngn/app-menus.h +146 -0
- package/native/core/include/ngn/app-windows.h +181 -0
- package/native/core/include/ngn/apple-authentication.h +116 -0
- package/native/core/include/ngn/asset.h +28 -0
- package/native/core/include/ngn/audio.h +125 -0
- package/native/core/include/ngn/back-swipe.h +112 -0
- package/native/core/include/ngn/battery.h +48 -0
- package/native/core/include/ngn/bytes.h +59 -0
- package/native/core/include/ngn/calendar.h +180 -0
- package/native/core/include/ngn/camera.h +128 -0
- package/native/core/include/ngn/control-sizes.h +111 -0
- package/native/core/include/ngn/core-modules.h +105 -0
- package/native/core/include/ngn/crypto.h +38 -0
- package/native/core/include/ngn/default-menu.h +91 -0
- package/native/core/include/ngn/desktop-expo.h +193 -0
- package/native/core/include/ngn/desktop-modal.h +109 -0
- package/native/core/include/ngn/desktop-props.h +75 -0
- package/native/core/include/ngn/desktop-view-props.h +110 -0
- package/native/core/include/ngn/dev-server.h +33 -0
- package/native/core/include/ngn/download.h +24 -0
- package/native/core/include/ngn/expo-image.h +192 -0
- package/native/core/include/ngn/expo-ui.h +133 -0
- package/native/core/include/ngn/file-system.h +274 -0
- package/native/core/include/ngn/focus-order.h +63 -0
- package/native/core/include/ngn/fonts.h +64 -0
- package/native/core/include/ngn/gestures.h +305 -0
- package/native/core/include/ngn/glass.h +67 -0
- package/native/core/include/ngn/header-bar.h +112 -0
- package/native/core/include/ngn/host-state.h +243 -0
- package/native/core/include/ngn/image-manipulator.h +70 -0
- package/native/core/include/ngn/input-dispatcher.h +211 -0
- package/native/core/include/ngn/input-script.h +56 -0
- package/native/core/include/ngn/input.h +112 -0
- package/native/core/include/ngn/key-value-store.h +41 -0
- package/native/core/include/ngn/language-model.h +69 -0
- package/native/core/include/ngn/launch-frame.h +47 -0
- package/native/core/include/ngn/launch-settings.h +98 -0
- package/native/core/include/ngn/layout-animations.h +24 -0
- package/native/core/include/ngn/library-components.h +13 -0
- package/native/core/include/ngn/library-glue.h +53 -0
- package/native/core/include/ngn/live-regions.h +54 -0
- package/native/core/include/ngn/local-authentication.h +74 -0
- package/native/core/include/ngn/location.h +89 -0
- package/native/core/include/ngn/maps.h +226 -0
- package/native/core/include/ngn/module-registry.h +51 -0
- package/native/core/include/ngn/mounting-backend.h +96 -0
- package/native/core/include/ngn/mounting-manager.h +155 -0
- package/native/core/include/ngn/native-controls.h +161 -0
- package/native/core/include/ngn/native-module.h +109 -0
- package/native/core/include/ngn/network-state.h +44 -0
- package/native/core/include/ngn/network.h +100 -0
- package/native/core/include/ngn/notifications.h +185 -0
- package/native/core/include/ngn/photo-library.h +130 -0
- package/native/core/include/ngn/printing.h +69 -0
- package/native/core/include/ngn/processes.h +114 -0
- package/native/core/include/ngn/red-box.h +119 -0
- package/native/core/include/ngn/reload-thread.h +258 -0
- package/native/core/include/ngn/runtime.h +161 -0
- package/native/core/include/ngn/safe-areas.h +77 -0
- package/native/core/include/ngn/screen-capture.h +35 -0
- package/native/core/include/ngn/screen-presentation.h +85 -0
- package/native/core/include/ngn/screen-stacks.h +80 -0
- package/native/core/include/ngn/scrollers.h +106 -0
- package/native/core/include/ngn/sharing.h +39 -0
- package/native/core/include/ngn/spawn-rules.h +78 -0
- package/native/core/include/ngn/splash-screen.h +41 -0
- package/native/core/include/ngn/split-view.h +270 -0
- package/native/core/include/ngn/sqlite.h +38 -0
- package/native/core/include/ngn/store-review.h +26 -0
- package/native/core/include/ngn/surface-book.h +101 -0
- package/native/core/include/ngn/svg.h +393 -0
- package/native/core/include/ngn/symbol.h +90 -0
- package/native/core/include/ngn/system.h +102 -0
- package/native/core/include/ngn/tabs-host.h +171 -0
- package/native/core/include/ngn/text-input.h +125 -0
- package/native/core/include/ngn/text-measurer.h +38 -0
- package/native/core/include/ngn/text-recognition.h +55 -0
- package/native/core/include/ngn/tracking.h +34 -0
- package/native/core/include/ngn/tray-and-dock.h +107 -0
- package/native/core/include/ngn/undo.h +37 -0
- package/native/core/include/ngn/updates.h +253 -0
- package/native/core/include/ngn/video.h +126 -0
- package/native/core/include/ngn/view-box.h +126 -0
- package/native/core/include/ngn/view-transform.h +26 -0
- package/native/core/include/ngn/view-tree.h +85 -0
- package/native/core/include/ngn/web-browser.h +45 -0
- package/native/core/include/ngn/web-view.h +133 -0
- package/native/core/include/ngn/worklet-host.h +98 -0
- package/native/core/src/absent-views.cpp +41 -0
- package/native/core/src/accessibility.cpp +374 -0
- package/native/core/src/animation-frames.cpp +49 -0
- package/native/core/src/app-menus.cpp +352 -0
- package/native/core/src/app-windows.cpp +444 -0
- package/native/core/src/back-swipe.cpp +91 -0
- package/native/core/src/bytes.cpp +158 -0
- package/native/core/src/control-sizes.cpp +232 -0
- package/native/core/src/default-menu.cpp +96 -0
- package/native/core/src/desktop-modal.cpp +162 -0
- package/native/core/src/desktop-view-props.cpp +80 -0
- package/native/core/src/dev-server-helper.cpp +152 -0
- package/native/core/src/dev-server.cpp +103 -0
- package/native/core/src/download.cpp +53 -0
- package/native/core/src/expo-image.cpp +548 -0
- package/native/core/src/expo-ui.cpp +203 -0
- package/native/core/src/focus-order.cpp +441 -0
- package/native/core/src/gestures.cpp +1806 -0
- package/native/core/src/glass.cpp +49 -0
- package/native/core/src/header-bar.cpp +104 -0
- package/native/core/src/host-services.cpp +50 -0
- package/native/core/src/host-state.cpp +61 -0
- package/native/core/src/input-dispatcher.cpp +727 -0
- package/native/core/src/input-script.cpp +123 -0
- package/native/core/src/key-value-store.cpp +169 -0
- package/native/core/src/launch-settings.cpp +148 -0
- package/native/core/src/layout-animations.cpp +62 -0
- package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
- package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
- package/native/core/src/libraries/react-native-worklets.cpp +192 -0
- package/native/core/src/libraries/rnscreens.cpp +125 -0
- package/native/core/src/libraries/rnsvg.cpp +345 -0
- package/native/core/src/libraries/safeareacontext.cpp +70 -0
- package/native/core/src/libraries/worklets-idle-frames.js +70 -0
- package/native/core/src/library-glue.cpp +35 -0
- package/native/core/src/live-regions.cpp +122 -0
- package/native/core/src/module-registry.cpp +50 -0
- package/native/core/src/modules/accessibility-manager.cpp +98 -0
- package/native/core/src/modules/address-search.cpp +219 -0
- package/native/core/src/modules/alert-manager.cpp +140 -0
- package/native/core/src/modules/app-info.cpp +74 -0
- package/native/core/src/modules/app-modules.cpp +405 -0
- package/native/core/src/modules/apple-authentication.cpp +188 -0
- package/native/core/src/modules/asset.cpp +111 -0
- package/native/core/src/modules/async-storage.cpp +192 -0
- package/native/core/src/modules/audio.cpp +541 -0
- package/native/core/src/modules/battery.cpp +88 -0
- package/native/core/src/modules/calendar.cpp +457 -0
- package/native/core/src/modules/camera.cpp +221 -0
- package/native/core/src/modules/core-modules.cpp +62 -0
- package/native/core/src/modules/crypto.cpp +117 -0
- package/native/core/src/modules/desktop-expo.cpp +527 -0
- package/native/core/src/modules/file-system.cpp +941 -0
- package/native/core/src/modules/fonts.cpp +163 -0
- package/native/core/src/modules/image-loader.cpp +105 -0
- package/native/core/src/modules/image-manipulator.cpp +305 -0
- package/native/core/src/modules/language-model.cpp +195 -0
- package/native/core/src/modules/local-authentication.cpp +140 -0
- package/native/core/src/modules/location.cpp +186 -0
- package/native/core/src/modules/maps.cpp +500 -0
- package/native/core/src/modules/network-state.cpp +72 -0
- package/native/core/src/modules/networking.cpp +387 -0
- package/native/core/src/modules/notifications.cpp +549 -0
- package/native/core/src/modules/photo-library.cpp +371 -0
- package/native/core/src/modules/printing.cpp +201 -0
- package/native/core/src/modules/screen-capture.cpp +71 -0
- package/native/core/src/modules/sharing.cpp +59 -0
- package/native/core/src/modules/splash-screen.cpp +70 -0
- package/native/core/src/modules/sqlite.cpp +421 -0
- package/native/core/src/modules/store-review.cpp +23 -0
- package/native/core/src/modules/text-recognition.cpp +107 -0
- package/native/core/src/modules/tracking.cpp +46 -0
- package/native/core/src/modules/undo.cpp +59 -0
- package/native/core/src/modules/video.cpp +366 -0
- package/native/core/src/modules/web-browser.cpp +100 -0
- package/native/core/src/modules/web-socket.cpp +266 -0
- package/native/core/src/mounting-manager.cpp +380 -0
- package/native/core/src/native-controls.cpp +129 -0
- package/native/core/src/native-module.cpp +250 -0
- package/native/core/src/network.cpp +219 -0
- package/native/core/src/posix-launcher.cpp +366 -0
- package/native/core/src/processes.cpp +324 -0
- package/native/core/src/red-box-errors.js +83 -0
- package/native/core/src/red-box.cpp +306 -0
- package/native/core/src/runtime.cpp +422 -0
- package/native/core/src/safe-areas.cpp +130 -0
- package/native/core/src/screen-presentation.cpp +61 -0
- package/native/core/src/screen-stacks.cpp +254 -0
- package/native/core/src/scrollers.cpp +181 -0
- package/native/core/src/spawn-rules.cpp +292 -0
- package/native/core/src/split-view.cpp +343 -0
- package/native/core/src/svg.cpp +1883 -0
- package/native/core/src/symbol.cpp +94 -0
- package/native/core/src/tabs-host.cpp +234 -0
- package/native/core/src/text-input.cpp +126 -0
- package/native/core/src/text-layout-manager.cpp +63 -0
- package/native/core/src/tray-and-dock.cpp +154 -0
- package/native/core/src/updates.cpp +965 -0
- package/native/core/src/view-box.cpp +788 -0
- package/native/core/src/view-transform.cpp +45 -0
- package/native/core/src/view-tree.cpp +234 -0
- package/native/core/src/web-view.cpp +143 -0
- package/native/core/src/worklet-host.cpp +10 -0
- package/native/scripts/build-hermes.sh +44 -0
- package/native/scripts/build.sh +171 -0
- package/native/scripts/cache-dir.sh +18 -0
- package/native/scripts/codegen-library.sh +193 -0
- package/native/scripts/compiler-launcher.sh +17 -0
- package/native/scripts/fetch.sh +174 -0
- package/native/scripts/hermes-built.sh +10 -0
- package/native/scripts/host-dir.sh +16 -0
- package/native/scripts/macos-target.sh +8 -0
- package/native/scripts/make-prebuilt.mjs +360 -0
- package/native/scripts/prebuilt-host-cache.mjs +158 -0
- package/native/shim/openssl/sha.h +22 -0
- package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
- package/package.json +70 -3
- package/prebuilt.json +33 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#import "push.h"
|
|
2
|
+
|
|
3
|
+
#import <AppKit/AppKit.h>
|
|
4
|
+
|
|
5
|
+
#include <optional>
|
|
6
|
+
|
|
7
|
+
namespace ngn::appkit {
|
|
8
|
+
|
|
9
|
+
namespace {
|
|
10
|
+
|
|
11
|
+
class AppKitPushRegistrar final : public PushRegistrar {
|
|
12
|
+
public:
|
|
13
|
+
void registerForRemoteNotifications() override {
|
|
14
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
15
|
+
[NSApp registerForRemoteNotifications];
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
void unregisterForRemoteNotifications() override {
|
|
19
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
20
|
+
[NSApp unregisterForRemoteNotifications];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// The whole string, U+0000 included: UTF8String alone stops at the first one.
|
|
26
|
+
std::string utf8Of(NSString *string) {
|
|
27
|
+
return std::string(string.UTF8String, [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// No value for what JSON cannot say, so its key or item is left out.
|
|
31
|
+
std::optional<folly::dynamic> jsonOf(id value) {
|
|
32
|
+
if (value == nil || value == NSNull.null) {
|
|
33
|
+
return folly::dynamic(nullptr);
|
|
34
|
+
}
|
|
35
|
+
if ([value isKindOfClass:NSString.class]) {
|
|
36
|
+
return folly::dynamic(utf8Of(value));
|
|
37
|
+
}
|
|
38
|
+
if ([value isKindOfClass:NSNumber.class]) {
|
|
39
|
+
NSNumber *number = value;
|
|
40
|
+
if (CFGetTypeID((__bridge CFTypeRef)number) == CFBooleanGetTypeID()) {
|
|
41
|
+
return folly::dynamic(static_cast<bool>(number.boolValue));
|
|
42
|
+
}
|
|
43
|
+
if (CFNumberIsFloatType((__bridge CFNumberRef)number)) {
|
|
44
|
+
return folly::dynamic(number.doubleValue);
|
|
45
|
+
}
|
|
46
|
+
return folly::dynamic(static_cast<int64_t>(number.longLongValue));
|
|
47
|
+
}
|
|
48
|
+
if ([value isKindOfClass:NSArray.class]) {
|
|
49
|
+
folly::dynamic out = folly::dynamic::array();
|
|
50
|
+
for (id item in (NSArray *)value) {
|
|
51
|
+
if (auto json = jsonOf(item)) {
|
|
52
|
+
out.push_back(std::move(*json));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
if ([value isKindOfClass:NSDictionary.class]) {
|
|
58
|
+
folly::dynamic out = folly::dynamic::object();
|
|
59
|
+
for (id key in (NSDictionary *)value) {
|
|
60
|
+
if ([key isKindOfClass:NSString.class]) {
|
|
61
|
+
if (auto json = jsonOf(((NSDictionary *)value)[key])) {
|
|
62
|
+
out[utf8Of(key)] = std::move(*json);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
return std::nullopt;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} // namespace
|
|
72
|
+
|
|
73
|
+
std::shared_ptr<PushRegistrar> makePushRegistrar() {
|
|
74
|
+
return std::make_shared<AppKitPushRegistrar>();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
folly::dynamic pushPayload(NSDictionary *userInfo) {
|
|
78
|
+
return [userInfo isKindOfClass:NSDictionary.class] ? *jsonOf(userInfo) : folly::dynamic::object();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// The OS half of the dev red box (the core's red-box.h): a red window over the app's, as React
|
|
2
|
+
// Native iOS's RCTRedBox covers its window, with the error's message, its stack, and Dismiss
|
|
3
|
+
// (Escape), Reload (Command-R), Copy and, with more than one error kept, the arrows between them.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include "ngn/red-box.h"
|
|
7
|
+
|
|
8
|
+
#include <functional>
|
|
9
|
+
#include <memory>
|
|
10
|
+
|
|
11
|
+
namespace ngn::appkit {
|
|
12
|
+
|
|
13
|
+
struct RedBoxActions {
|
|
14
|
+
std::function<void()> dismiss;
|
|
15
|
+
std::function<void()> reload;
|
|
16
|
+
std::function<void(int delta)> step;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
std::shared_ptr<RedBoxBackend> makeRedBoxWindow(RedBoxActions actions);
|
|
20
|
+
|
|
21
|
+
// React Native DevTools' pause, as React Native iOS overlays it: "Paused in debugger" and a
|
|
22
|
+
// resume button, over the top of the app's window while the JavaScript is paused. Any thread.
|
|
23
|
+
void showDebuggerPaused(std::function<void()> resume);
|
|
24
|
+
void hideDebuggerPaused();
|
|
25
|
+
|
|
26
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
#import "red-box.h"
|
|
2
|
+
|
|
3
|
+
#import <AppKit/AppKit.h>
|
|
4
|
+
|
|
5
|
+
#include <atomic>
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
NSString *string(const std::string &s) {
|
|
10
|
+
NSString *out = [NSString stringWithUTF8String:s.c_str()];
|
|
11
|
+
return out != nil ? out : @"";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
NSColor *red() {
|
|
15
|
+
// RCTRedBox's background.
|
|
16
|
+
return [NSColor colorWithSRGBRed:0.8 green:0 blue:0 alpha:1];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// The error as text, for Copy: its message, then each frame's method and place.
|
|
20
|
+
NSString *plainText(const ngn::JsError &error) {
|
|
21
|
+
NSMutableString *text = [string(error.message) mutableCopy];
|
|
22
|
+
[text appendString:@"\n\n"];
|
|
23
|
+
for (const auto &frame : ngn::shownFrames(error)) {
|
|
24
|
+
[text appendFormat:@"%@\n %@\n", string(frame.methodName.empty() ? "(anonymous)" : frame.methodName),
|
|
25
|
+
string(ngn::frameLocation(frame))];
|
|
26
|
+
}
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
NSAttributedString *stackText(const ngn::JsError &error) {
|
|
31
|
+
NSMutableAttributedString *out = [[NSMutableAttributedString alloc] init];
|
|
32
|
+
NSFont *method = [NSFont monospacedSystemFontOfSize:13 weight:NSFontWeightSemibold];
|
|
33
|
+
NSFont *place = [NSFont monospacedSystemFontOfSize:12 weight:NSFontWeightRegular];
|
|
34
|
+
NSDictionary *methodStyle = @{NSFontAttributeName : method, NSForegroundColorAttributeName : NSColor.whiteColor};
|
|
35
|
+
NSDictionary *placeStyle = @{
|
|
36
|
+
NSFontAttributeName : place,
|
|
37
|
+
NSForegroundColorAttributeName : [NSColor colorWithWhite:1 alpha:0.7],
|
|
38
|
+
};
|
|
39
|
+
for (const auto &frame : ngn::shownFrames(error)) {
|
|
40
|
+
NSString *name = string(frame.methodName.empty() ? "(anonymous)" : frame.methodName);
|
|
41
|
+
[out appendAttributedString:[[NSAttributedString alloc] initWithString:[name stringByAppendingString:@"\n"]
|
|
42
|
+
attributes:methodStyle]];
|
|
43
|
+
auto location = ngn::frameLocation(frame);
|
|
44
|
+
if (!location.empty()) {
|
|
45
|
+
[out appendAttributedString:[[NSAttributedString alloc]
|
|
46
|
+
initWithString:[NSString stringWithFormat:@" %@\n", string(location)]
|
|
47
|
+
attributes:placeStyle]];
|
|
48
|
+
}
|
|
49
|
+
[out appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n" attributes:placeStyle]];
|
|
50
|
+
}
|
|
51
|
+
if (!error.componentStack.empty()) {
|
|
52
|
+
[out appendAttributedString:[[NSAttributedString alloc] initWithString:string(error.componentStack)
|
|
53
|
+
attributes:placeStyle]];
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} // namespace
|
|
59
|
+
|
|
60
|
+
// The window: Escape dismisses it and Command-R reloads, as RCTRedBox's keys do.
|
|
61
|
+
@interface NGNRedBoxWindow : NSWindow
|
|
62
|
+
@property (nonatomic, copy) void (^onDismiss)(void);
|
|
63
|
+
@property (nonatomic, copy) void (^onReload)(void);
|
|
64
|
+
@end
|
|
65
|
+
|
|
66
|
+
@implementation NGNRedBoxWindow
|
|
67
|
+
- (BOOL)canBecomeKeyWindow {
|
|
68
|
+
return YES;
|
|
69
|
+
}
|
|
70
|
+
- (void)cancelOperation:(id)sender {
|
|
71
|
+
if (self.onDismiss) {
|
|
72
|
+
self.onDismiss();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
- (BOOL)performKeyEquivalent:(NSEvent *)event {
|
|
76
|
+
if ((event.modifierFlags & NSEventModifierFlagDeviceIndependentFlagsMask) == NSEventModifierFlagCommand &&
|
|
77
|
+
[event.charactersIgnoringModifiers isEqualToString:@"r"]) {
|
|
78
|
+
if (self.onReload) {
|
|
79
|
+
self.onReload();
|
|
80
|
+
}
|
|
81
|
+
return YES;
|
|
82
|
+
}
|
|
83
|
+
return [super performKeyEquivalent:event];
|
|
84
|
+
}
|
|
85
|
+
@end
|
|
86
|
+
|
|
87
|
+
@interface NGNRedBoxController : NSObject <NSWindowDelegate>
|
|
88
|
+
- (instancetype)initWithActions:(ngn::appkit::RedBoxActions)actions;
|
|
89
|
+
- (void)show:(const ngn::RedBoxContent &)content;
|
|
90
|
+
- (void)hide;
|
|
91
|
+
@end
|
|
92
|
+
|
|
93
|
+
@implementation NGNRedBoxController {
|
|
94
|
+
ngn::appkit::RedBoxActions _actions;
|
|
95
|
+
NGNRedBoxWindow *_window;
|
|
96
|
+
NSTextField *_message;
|
|
97
|
+
NSTextView *_stack;
|
|
98
|
+
NSTextField *_position;
|
|
99
|
+
NSButton *_previous;
|
|
100
|
+
NSButton *_next;
|
|
101
|
+
NSString *_copyText;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
- (instancetype)initWithActions:(ngn::appkit::RedBoxActions)actions {
|
|
105
|
+
if ((self = [super init])) {
|
|
106
|
+
_actions = std::move(actions);
|
|
107
|
+
}
|
|
108
|
+
return self;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
- (NSButton *)button:(NSString *)title action:(SEL)action {
|
|
112
|
+
NSButton *button = [NSButton buttonWithTitle:title target:self action:action];
|
|
113
|
+
button.bezelStyle = NSBezelStylePush;
|
|
114
|
+
button.translatesAutoresizingMaskIntoConstraints = NO;
|
|
115
|
+
return button;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
- (void)build {
|
|
119
|
+
_window = [[NGNRedBoxWindow alloc] initWithContentRect:NSMakeRect(0, 0, 760, 560)
|
|
120
|
+
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
|
121
|
+
NSWindowStyleMaskResizable
|
|
122
|
+
backing:NSBackingStoreBuffered
|
|
123
|
+
defer:YES];
|
|
124
|
+
_window.releasedWhenClosed = NO;
|
|
125
|
+
_window.delegate = self;
|
|
126
|
+
_window.backgroundColor = red();
|
|
127
|
+
_window.titlebarAppearsTransparent = YES;
|
|
128
|
+
_window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
|
|
129
|
+
_window.minSize = NSMakeSize(420, 300);
|
|
130
|
+
__weak NGNRedBoxController *weak = self;
|
|
131
|
+
_window.onDismiss = ^{
|
|
132
|
+
[weak dismiss:nil];
|
|
133
|
+
};
|
|
134
|
+
_window.onReload = ^{
|
|
135
|
+
[weak reload:nil];
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
NSView *content = _window.contentView;
|
|
139
|
+
_message = [NSTextField wrappingLabelWithString:@""];
|
|
140
|
+
_message.font = [NSFont systemFontOfSize:17 weight:NSFontWeightBold];
|
|
141
|
+
_message.textColor = NSColor.whiteColor;
|
|
142
|
+
_message.selectable = YES;
|
|
143
|
+
_message.translatesAutoresizingMaskIntoConstraints = NO;
|
|
144
|
+
[_message setContentCompressionResistancePriority:NSLayoutPriorityRequired
|
|
145
|
+
forOrientation:NSLayoutConstraintOrientationVertical];
|
|
146
|
+
|
|
147
|
+
NSScrollView *scroll = [[NSScrollView alloc] init];
|
|
148
|
+
scroll.translatesAutoresizingMaskIntoConstraints = NO;
|
|
149
|
+
scroll.drawsBackground = NO;
|
|
150
|
+
scroll.hasVerticalScroller = YES;
|
|
151
|
+
_stack = [[NSTextView alloc] init];
|
|
152
|
+
_stack.editable = NO;
|
|
153
|
+
_stack.selectable = YES;
|
|
154
|
+
_stack.drawsBackground = NO;
|
|
155
|
+
_stack.textContainerInset = NSMakeSize(0, 8);
|
|
156
|
+
_stack.autoresizingMask = NSViewWidthSizable;
|
|
157
|
+
scroll.documentView = _stack;
|
|
158
|
+
|
|
159
|
+
NSButton *dismiss = [self button:@"Dismiss (Esc)" action:@selector(dismiss:)];
|
|
160
|
+
NSButton *reload = [self button:@"Reload (⌘R)" action:@selector(reload:)];
|
|
161
|
+
reload.keyEquivalent = @"\r";
|
|
162
|
+
NSButton *copy = [self button:@"Copy" action:@selector(copyError:)];
|
|
163
|
+
_previous = [self button:@"◀" action:@selector(previous:)];
|
|
164
|
+
_next = [self button:@"▶" action:@selector(next:)];
|
|
165
|
+
_position = [NSTextField labelWithString:@""];
|
|
166
|
+
_position.textColor = [NSColor colorWithWhite:1 alpha:0.8];
|
|
167
|
+
_position.translatesAutoresizingMaskIntoConstraints = NO;
|
|
168
|
+
|
|
169
|
+
NSStackView *buttons = [NSStackView stackViewWithViews:@[ _previous, _position, _next ]];
|
|
170
|
+
NSStackView *actions = [NSStackView stackViewWithViews:@[ copy, dismiss, reload ]];
|
|
171
|
+
buttons.translatesAutoresizingMaskIntoConstraints = NO;
|
|
172
|
+
actions.translatesAutoresizingMaskIntoConstraints = NO;
|
|
173
|
+
|
|
174
|
+
for (NSView *view in @[ _message, scroll, buttons, actions ]) {
|
|
175
|
+
[content addSubview:view];
|
|
176
|
+
}
|
|
177
|
+
[NSLayoutConstraint activateConstraints:@[
|
|
178
|
+
[_message.topAnchor constraintEqualToAnchor:content.topAnchor constant:40],
|
|
179
|
+
[_message.leadingAnchor constraintEqualToAnchor:content.leadingAnchor constant:20],
|
|
180
|
+
[_message.trailingAnchor constraintEqualToAnchor:content.trailingAnchor constant:-20],
|
|
181
|
+
[scroll.topAnchor constraintEqualToAnchor:_message.bottomAnchor constant:12],
|
|
182
|
+
[scroll.leadingAnchor constraintEqualToAnchor:content.leadingAnchor constant:20],
|
|
183
|
+
[scroll.trailingAnchor constraintEqualToAnchor:content.trailingAnchor constant:-20],
|
|
184
|
+
[scroll.bottomAnchor constraintEqualToAnchor:actions.topAnchor constant:-12],
|
|
185
|
+
[actions.trailingAnchor constraintEqualToAnchor:content.trailingAnchor constant:-20],
|
|
186
|
+
[actions.bottomAnchor constraintEqualToAnchor:content.bottomAnchor constant:-16],
|
|
187
|
+
[buttons.leadingAnchor constraintEqualToAnchor:content.leadingAnchor constant:20],
|
|
188
|
+
[buttons.centerYAnchor constraintEqualToAnchor:actions.centerYAnchor],
|
|
189
|
+
]];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
- (void)show:(const ngn::RedBoxContent &)content {
|
|
193
|
+
if (_window == nil) {
|
|
194
|
+
[self build];
|
|
195
|
+
}
|
|
196
|
+
const auto &error = content.error;
|
|
197
|
+
_window.title = error.fatal ? @"JavaScript error" : @"JavaScript error (soft)";
|
|
198
|
+
_message.stringValue = string(error.message);
|
|
199
|
+
[_stack.textStorage setAttributedString:stackText(error)];
|
|
200
|
+
_copyText = plainText(error);
|
|
201
|
+
BOOL several = content.count > 1;
|
|
202
|
+
_previous.hidden = _next.hidden = _position.hidden = !several;
|
|
203
|
+
_position.stringValue = [NSString stringWithFormat:@"%zu of %zu", content.index + 1, content.count];
|
|
204
|
+
_previous.enabled = content.index > 0;
|
|
205
|
+
_next.enabled = content.index + 1 < content.count;
|
|
206
|
+
if (!_window.visible) {
|
|
207
|
+
// Over the window the app was using, as RCTRedBox covers its own.
|
|
208
|
+
NSWindow *app = NSApp.keyWindow != nil ? NSApp.keyWindow : NSApp.mainWindow;
|
|
209
|
+
if (app != nil && app != _window) {
|
|
210
|
+
NSRect frame = NSInsetRect(app.frame, 24, 24);
|
|
211
|
+
[_window setFrame:frame display:NO];
|
|
212
|
+
} else {
|
|
213
|
+
[_window center];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
[NSApp activateIgnoringOtherApps:YES];
|
|
217
|
+
[_window makeKeyAndOrderFront:nil];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
- (void)hide {
|
|
221
|
+
[_window orderOut:nil];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
- (void)dismiss:(id)sender {
|
|
225
|
+
if (_actions.dismiss) {
|
|
226
|
+
_actions.dismiss();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
- (void)reload:(id)sender {
|
|
231
|
+
if (_actions.reload) {
|
|
232
|
+
_actions.reload();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
- (void)copyError:(id)sender {
|
|
237
|
+
[NSPasteboard.generalPasteboard clearContents];
|
|
238
|
+
[NSPasteboard.generalPasteboard setString:(_copyText != nil ? _copyText : @"") forType:NSPasteboardTypeString];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
- (void)previous:(id)sender {
|
|
242
|
+
if (_actions.step) {
|
|
243
|
+
_actions.step(-1);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
- (void)next:(id)sender {
|
|
248
|
+
if (_actions.step) {
|
|
249
|
+
_actions.step(1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// The close button dismisses, as Escape does.
|
|
254
|
+
- (BOOL)windowShouldClose:(NSWindow *)sender {
|
|
255
|
+
[self dismiss:nil];
|
|
256
|
+
return NO;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@end
|
|
260
|
+
|
|
261
|
+
namespace ngn::appkit {
|
|
262
|
+
|
|
263
|
+
namespace {
|
|
264
|
+
|
|
265
|
+
class RedBoxWindow final : public RedBoxBackend {
|
|
266
|
+
public:
|
|
267
|
+
explicit RedBoxWindow(RedBoxActions actions) {
|
|
268
|
+
controller_ = [[NGNRedBoxController alloc] initWithActions:std::move(actions)];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
void show(const RedBoxContent &content) override {
|
|
272
|
+
NGNRedBoxController *controller = controller_;
|
|
273
|
+
auto copy = std::make_shared<RedBoxContent>(content);
|
|
274
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
275
|
+
[controller show:*copy];
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
void hide() override {
|
|
280
|
+
NGNRedBoxController *controller = controller_;
|
|
281
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
282
|
+
[controller hide];
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private:
|
|
287
|
+
NGNRedBoxController *controller_;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
} // namespace
|
|
291
|
+
|
|
292
|
+
std::shared_ptr<RedBoxBackend> makeRedBoxWindow(RedBoxActions actions) {
|
|
293
|
+
return std::make_shared<RedBoxWindow>(std::move(actions));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// The overlay, and the call that resumes the JavaScript. Main thread.
|
|
297
|
+
NSPanel *gPausedPanel;
|
|
298
|
+
std::function<void()> gResume;
|
|
299
|
+
// Moved on by each show and hide, from any thread: a show queued before a later hide finds it moved
|
|
300
|
+
// on and does nothing.
|
|
301
|
+
std::atomic<uint64_t> gPausedTurn{0};
|
|
302
|
+
|
|
303
|
+
} // namespace ngn::appkit
|
|
304
|
+
|
|
305
|
+
@interface NGNDebuggerResumeTarget : NSObject
|
|
306
|
+
@end
|
|
307
|
+
|
|
308
|
+
@implementation NGNDebuggerResumeTarget
|
|
309
|
+
+ (void)resume:(id)sender {
|
|
310
|
+
auto resume = std::move(ngn::appkit::gResume);
|
|
311
|
+
ngn::appkit::hideDebuggerPaused();
|
|
312
|
+
if (resume) {
|
|
313
|
+
resume();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
@end
|
|
317
|
+
|
|
318
|
+
namespace ngn::appkit {
|
|
319
|
+
|
|
320
|
+
void showDebuggerPaused(std::function<void()> resume) {
|
|
321
|
+
auto shared = std::make_shared<std::function<void()>>(std::move(resume));
|
|
322
|
+
uint64_t turn = ++gPausedTurn;
|
|
323
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
324
|
+
if (gPausedTurn != turn) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
gResume = *shared;
|
|
328
|
+
NSWindow *app = NSApp.mainWindow != nil ? NSApp.mainWindow : NSApp.windows.firstObject;
|
|
329
|
+
if (gPausedPanel == nil) {
|
|
330
|
+
gPausedPanel = [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 260, 40)
|
|
331
|
+
styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel
|
|
332
|
+
backing:NSBackingStoreBuffered
|
|
333
|
+
defer:YES];
|
|
334
|
+
gPausedPanel.releasedWhenClosed = NO;
|
|
335
|
+
gPausedPanel.opaque = NO;
|
|
336
|
+
gPausedPanel.backgroundColor = NSColor.clearColor;
|
|
337
|
+
gPausedPanel.hasShadow = YES;
|
|
338
|
+
NSVisualEffectView *pill = [[NSVisualEffectView alloc] initWithFrame:NSMakeRect(0, 0, 260, 40)];
|
|
339
|
+
pill.material = NSVisualEffectMaterialHUDWindow;
|
|
340
|
+
pill.state = NSVisualEffectStateActive;
|
|
341
|
+
pill.wantsLayer = YES;
|
|
342
|
+
pill.layer.cornerRadius = 20;
|
|
343
|
+
pill.layer.masksToBounds = YES;
|
|
344
|
+
NSTextField *label = [NSTextField labelWithString:@"Paused in debugger"];
|
|
345
|
+
label.font = [NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
|
|
346
|
+
label.frame = NSMakeRect(18, 11, 160, 18);
|
|
347
|
+
NSButton *resume = [NSButton buttonWithTitle:@"Resume"
|
|
348
|
+
target:NGNDebuggerResumeTarget.class
|
|
349
|
+
action:@selector(resume:)];
|
|
350
|
+
resume.bezelStyle = NSBezelStylePush;
|
|
351
|
+
resume.controlSize = NSControlSizeSmall;
|
|
352
|
+
resume.frame = NSMakeRect(176, 7, 72, 26);
|
|
353
|
+
[pill addSubview:label];
|
|
354
|
+
[pill addSubview:resume];
|
|
355
|
+
gPausedPanel.contentView = pill;
|
|
356
|
+
}
|
|
357
|
+
if (app != nil) {
|
|
358
|
+
NSRect frame = app.frame;
|
|
359
|
+
[gPausedPanel setFrameOrigin:NSMakePoint(NSMidX(frame) - 130, NSMaxY(frame) - 40 - 44)];
|
|
360
|
+
if (gPausedPanel.parentWindow != app) {
|
|
361
|
+
[gPausedPanel.parentWindow removeChildWindow:gPausedPanel];
|
|
362
|
+
[app addChildWindow:gPausedPanel ordered:NSWindowAbove];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
[gPausedPanel orderFront:nil];
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
void hideDebuggerPaused() {
|
|
370
|
+
uint64_t turn = ++gPausedTurn;
|
|
371
|
+
auto hide = ^{
|
|
372
|
+
// A show since has the panel now.
|
|
373
|
+
if (gPausedTurn != turn) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
gResume = nullptr;
|
|
377
|
+
[gPausedPanel.parentWindow removeChildWindow:gPausedPanel];
|
|
378
|
+
[gPausedPanel orderOut:nil];
|
|
379
|
+
};
|
|
380
|
+
if (NSThread.isMainThread) {
|
|
381
|
+
hide();
|
|
382
|
+
} else {
|
|
383
|
+
dispatch_async(dispatch_get_main_queue(), hide);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The OS half of NgNativeScreenCapture (the core's screen-capture.h): NSWindow.sharingType on every
|
|
2
|
+
// window of the app, NSWindowSharingNone while capture is prevented. That is the only control
|
|
3
|
+
// AppKit has; which capture tools honour it is the OS's to decide. A window opened while capture is prevented is kept out from its first update,
|
|
4
|
+
// and the host's own windows (AppWindows and modal sheets) from the moment they are made.
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "ngn/screen-capture.h"
|
|
8
|
+
|
|
9
|
+
#include <memory>
|
|
10
|
+
|
|
11
|
+
@class NSWindow;
|
|
12
|
+
|
|
13
|
+
namespace ngn::appkit {
|
|
14
|
+
|
|
15
|
+
// One per process: the windows are the process's.
|
|
16
|
+
std::shared_ptr<CaptureShield> captureShield();
|
|
17
|
+
|
|
18
|
+
// Applies the shield's state to a window the host has just made, before it is shown.
|
|
19
|
+
void shieldNewWindow(NSWindow *window);
|
|
20
|
+
|
|
21
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#include "screen-capture.h"
|
|
2
|
+
|
|
3
|
+
#import <AppKit/AppKit.h>
|
|
4
|
+
|
|
5
|
+
#include <atomic>
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <mutex>
|
|
8
|
+
|
|
9
|
+
namespace ngn::appkit {
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
|
|
13
|
+
std::atomic<bool> gProtected{false};
|
|
14
|
+
// Requests numbered in the order they set `gProtected`, under `gAsking`, and the latest one applied
|
|
15
|
+
// to the windows (main thread only).
|
|
16
|
+
std::mutex gAsking;
|
|
17
|
+
uint64_t gAsked = 0;
|
|
18
|
+
uint64_t gApplied = 0;
|
|
19
|
+
|
|
20
|
+
// `gProtected` is the state the latest request asked for; each request applies its own on the main
|
|
21
|
+
// thread unless a later one has applied already, so the last one asked is the one the windows keep,
|
|
22
|
+
// though one asked on the main thread applies ahead of an earlier one still queued.
|
|
23
|
+
void apply(NSWindow *window, bool on) {
|
|
24
|
+
NSWindowSharingType wanted = on ? NSWindowSharingNone : NSWindowSharingReadOnly;
|
|
25
|
+
if (window.sharingType != wanted) {
|
|
26
|
+
window.sharingType = wanted;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void applyToAll(bool on) {
|
|
31
|
+
for (NSWindow *window in NSApp.windows) {
|
|
32
|
+
apply(window, on);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
class WindowShield final : public CaptureShield {
|
|
37
|
+
public:
|
|
38
|
+
WindowShield() {
|
|
39
|
+
// Every window AppKit updates or shows, the system's panels and alerts among them, so one the
|
|
40
|
+
// host does not make itself is covered too.
|
|
41
|
+
for (NSNotificationName name in @[ NSWindowDidUpdateNotification, NSWindowDidChangeOcclusionStateNotification ]) {
|
|
42
|
+
[NSNotificationCenter.defaultCenter addObserverForName:name
|
|
43
|
+
object:nil
|
|
44
|
+
queue:nil
|
|
45
|
+
usingBlock:^(NSNotification *note) {
|
|
46
|
+
if (gProtected) {
|
|
47
|
+
apply(note.object, true);
|
|
48
|
+
}
|
|
49
|
+
}];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void setProtected(bool on, std::function<void()> done) override {
|
|
54
|
+
uint64_t request;
|
|
55
|
+
{
|
|
56
|
+
std::lock_guard<std::mutex> lock(gAsking);
|
|
57
|
+
request = ++gAsked;
|
|
58
|
+
gProtected = on;
|
|
59
|
+
}
|
|
60
|
+
auto finish = std::make_shared<std::function<void()>>(std::move(done));
|
|
61
|
+
auto apply = ^{
|
|
62
|
+
if (request > gApplied) {
|
|
63
|
+
gApplied = request;
|
|
64
|
+
applyToAll(on);
|
|
65
|
+
}
|
|
66
|
+
if (*finish) {
|
|
67
|
+
(*finish)();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// Off the main thread, applied there without blocking this thread on it.
|
|
71
|
+
if (NSThread.isMainThread) {
|
|
72
|
+
apply();
|
|
73
|
+
} else {
|
|
74
|
+
dispatch_async(dispatch_get_main_queue(), apply);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace
|
|
80
|
+
|
|
81
|
+
std::shared_ptr<CaptureShield> captureShield() {
|
|
82
|
+
static auto shield = std::make_shared<WindowShield>();
|
|
83
|
+
return shield;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void shieldNewWindow(NSWindow *window) {
|
|
87
|
+
if (gProtected) {
|
|
88
|
+
apply(window, true);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
} // namespace ngn::appkit
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// ScrollView as a real NSScrollView: the content container mounts into its document view, the
|
|
2
|
+
// wheel, trackpad momentum and scrollers are AppKit's, and each scroll reports onScroll, updates
|
|
3
|
+
// the view's state and tells the core's hit test the new offset.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#import "host-view.h"
|
|
7
|
+
|
|
8
|
+
#include <functional>
|
|
9
|
+
|
|
10
|
+
@interface NGNScrollView : NGNView
|
|
11
|
+
// Called on the main thread as the content scrolls, with the view's tag and its offset.
|
|
12
|
+
@property (class, nonatomic) std::function<void(NSInteger, CGPoint)> offsetChanged;
|
|
13
|
+
@end
|