@native-sdk/cli 0.0.0 → 0.4.1
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 +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +45 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,2232 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const canvas = @import("canvas");
|
|
3
|
+
const geometry = @import("geometry");
|
|
4
|
+
const platform_info = @import("platform_info");
|
|
5
|
+
const security = @import("../security/root.zig");
|
|
6
|
+
const types = @import("types.zig");
|
|
7
|
+
|
|
8
|
+
const default_gpu_frame_interval_ns = types.default_gpu_frame_interval_ns;
|
|
9
|
+
const default_gpu_first_frame_latency_budget_ns = types.default_gpu_first_frame_latency_budget_ns;
|
|
10
|
+
const Error = types.Error;
|
|
11
|
+
const WebEngine = types.WebEngine;
|
|
12
|
+
const PlatformFeature = types.PlatformFeature;
|
|
13
|
+
const WebViewSourceKind = types.WebViewSourceKind;
|
|
14
|
+
const WebViewAssetSource = types.WebViewAssetSource;
|
|
15
|
+
const WebViewSource = types.WebViewSource;
|
|
16
|
+
const WindowId = types.WindowId;
|
|
17
|
+
const WindowTitlebarStyle = types.WindowTitlebarStyle;
|
|
18
|
+
const ViewId = types.ViewId;
|
|
19
|
+
const max_windows = types.max_windows;
|
|
20
|
+
const max_window_label_bytes = types.max_window_label_bytes;
|
|
21
|
+
const max_window_title_bytes = types.max_window_title_bytes;
|
|
22
|
+
const max_window_source_bytes = types.max_window_source_bytes;
|
|
23
|
+
const max_webviews = types.max_webviews;
|
|
24
|
+
const max_webview_label_bytes = types.max_webview_label_bytes;
|
|
25
|
+
const max_webview_url_bytes = types.max_webview_url_bytes;
|
|
26
|
+
const max_external_url_bytes = types.max_external_url_bytes;
|
|
27
|
+
const max_reveal_path_bytes = types.max_reveal_path_bytes;
|
|
28
|
+
const max_recent_document_path_bytes = types.max_recent_document_path_bytes;
|
|
29
|
+
const max_notification_title_bytes = types.max_notification_title_bytes;
|
|
30
|
+
const max_notification_subtitle_bytes = types.max_notification_subtitle_bytes;
|
|
31
|
+
const max_notification_body_bytes = types.max_notification_body_bytes;
|
|
32
|
+
const max_clipboard_mime_type_bytes = types.max_clipboard_mime_type_bytes;
|
|
33
|
+
const max_clipboard_data_bytes = types.max_clipboard_data_bytes;
|
|
34
|
+
const max_credential_service_bytes = types.max_credential_service_bytes;
|
|
35
|
+
const max_credential_account_bytes = types.max_credential_account_bytes;
|
|
36
|
+
const max_credential_secret_bytes = types.max_credential_secret_bytes;
|
|
37
|
+
const max_tray_items = types.max_tray_items;
|
|
38
|
+
const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
|
|
39
|
+
const max_tray_title_bytes = types.max_tray_title_bytes;
|
|
40
|
+
const max_tray_tooltip_bytes = types.max_tray_tooltip_bytes;
|
|
41
|
+
const max_tray_item_label_bytes = types.max_tray_item_label_bytes;
|
|
42
|
+
const max_tray_item_command_bytes = types.max_tray_item_command_bytes;
|
|
43
|
+
const max_drop_paths_bytes = types.max_drop_paths_bytes;
|
|
44
|
+
const max_drop_paths = types.max_drop_paths;
|
|
45
|
+
const max_window_event_name_bytes = types.max_window_event_name_bytes;
|
|
46
|
+
const max_window_event_detail_bytes = types.max_window_event_detail_bytes;
|
|
47
|
+
const max_views = types.max_views;
|
|
48
|
+
const max_view_label_bytes = types.max_view_label_bytes;
|
|
49
|
+
const max_view_role_bytes = types.max_view_role_bytes;
|
|
50
|
+
const max_view_accessibility_label_bytes = types.max_view_accessibility_label_bytes;
|
|
51
|
+
const max_view_text_bytes = types.max_view_text_bytes;
|
|
52
|
+
const max_view_command_bytes = types.max_view_command_bytes;
|
|
53
|
+
const max_menus = types.max_menus;
|
|
54
|
+
const max_menu_items = types.max_menu_items;
|
|
55
|
+
const max_menu_title_bytes = types.max_menu_title_bytes;
|
|
56
|
+
const max_menu_item_label_bytes = types.max_menu_item_label_bytes;
|
|
57
|
+
const max_menu_command_bytes = types.max_menu_command_bytes;
|
|
58
|
+
const max_menu_key_bytes = types.max_menu_key_bytes;
|
|
59
|
+
const max_shortcuts = types.max_shortcuts;
|
|
60
|
+
const max_shortcut_id_bytes = types.max_shortcut_id_bytes;
|
|
61
|
+
const max_shortcut_key_bytes = types.max_shortcut_key_bytes;
|
|
62
|
+
const max_widget_accessibility_nodes = types.max_widget_accessibility_nodes;
|
|
63
|
+
const max_gpu_surface_packet_json_bytes = types.max_gpu_surface_packet_json_bytes;
|
|
64
|
+
const ShortcutModifiers = types.ShortcutModifiers;
|
|
65
|
+
const Shortcut = types.Shortcut;
|
|
66
|
+
const ShortcutEvent = types.ShortcutEvent;
|
|
67
|
+
const Menu = types.Menu;
|
|
68
|
+
const MenuItem = types.MenuItem;
|
|
69
|
+
const validateShortcut = types.validateShortcut;
|
|
70
|
+
const validateMenus = types.validateMenus;
|
|
71
|
+
const validateMenuItem = types.validateMenuItem;
|
|
72
|
+
const isValidShortcutKey = types.isValidShortcutKey;
|
|
73
|
+
const WindowRestorePolicy = types.WindowRestorePolicy;
|
|
74
|
+
const WindowOptions = types.WindowOptions;
|
|
75
|
+
const WindowState = types.WindowState;
|
|
76
|
+
const WindowInfo = types.WindowInfo;
|
|
77
|
+
const WindowCreateOptions = types.WindowCreateOptions;
|
|
78
|
+
const WebViewOptions = types.WebViewOptions;
|
|
79
|
+
const WebViewInfo = types.WebViewInfo;
|
|
80
|
+
const ViewKind = types.ViewKind;
|
|
81
|
+
const GpuSurfaceBackend = types.GpuSurfaceBackend;
|
|
82
|
+
const GpuSurfacePixelFormat = types.GpuSurfacePixelFormat;
|
|
83
|
+
const GpuSurfacePresentMode = types.GpuSurfacePresentMode;
|
|
84
|
+
const GpuSurfaceAlphaMode = types.GpuSurfaceAlphaMode;
|
|
85
|
+
const GpuSurfaceColorSpace = types.GpuSurfaceColorSpace;
|
|
86
|
+
const GpuSurfaceStatus = types.GpuSurfaceStatus;
|
|
87
|
+
const CanvasFrameProfileRisk = types.CanvasFrameProfileRisk;
|
|
88
|
+
const GpuSurfaceOptions = types.GpuSurfaceOptions;
|
|
89
|
+
const ViewOptions = types.ViewOptions;
|
|
90
|
+
const ViewPatch = types.ViewPatch;
|
|
91
|
+
const Cursor = types.Cursor;
|
|
92
|
+
const ViewInfo = types.ViewInfo;
|
|
93
|
+
const AppInfo = types.AppInfo;
|
|
94
|
+
const Surface = types.Surface;
|
|
95
|
+
const BridgeMessage = types.BridgeMessage;
|
|
96
|
+
const max_dialog_path_bytes = types.max_dialog_path_bytes;
|
|
97
|
+
const max_dialog_paths_bytes = types.max_dialog_paths_bytes;
|
|
98
|
+
const max_dialog_title_bytes = types.max_dialog_title_bytes;
|
|
99
|
+
const max_dialog_message_bytes = types.max_dialog_message_bytes;
|
|
100
|
+
const max_dialog_button_bytes = types.max_dialog_button_bytes;
|
|
101
|
+
const max_dialog_filter_name_bytes = types.max_dialog_filter_name_bytes;
|
|
102
|
+
const max_dialog_filter_bytes = types.max_dialog_filter_bytes;
|
|
103
|
+
const FileFilter = types.FileFilter;
|
|
104
|
+
const OpenDialogOptions = types.OpenDialogOptions;
|
|
105
|
+
const OpenDialogResult = types.OpenDialogResult;
|
|
106
|
+
const SaveDialogOptions = types.SaveDialogOptions;
|
|
107
|
+
const MessageDialogStyle = types.MessageDialogStyle;
|
|
108
|
+
const MessageDialogResult = types.MessageDialogResult;
|
|
109
|
+
const MessageDialogOptions = types.MessageDialogOptions;
|
|
110
|
+
const NotificationOptions = types.NotificationOptions;
|
|
111
|
+
const CredentialKey = types.CredentialKey;
|
|
112
|
+
const Credential = types.Credential;
|
|
113
|
+
const TrayItemId = types.TrayItemId;
|
|
114
|
+
const TrayOptions = types.TrayOptions;
|
|
115
|
+
const TrayMenuItem = types.TrayMenuItem;
|
|
116
|
+
const NativeCommandEvent = types.NativeCommandEvent;
|
|
117
|
+
const MenuCommandEvent = types.MenuCommandEvent;
|
|
118
|
+
const TimerEvent = types.TimerEvent;
|
|
119
|
+
const FileDropEvent = types.FileDropEvent;
|
|
120
|
+
const GpuFrame = types.GpuFrame;
|
|
121
|
+
const GpuSurfaceFrameEvent = types.GpuSurfaceFrameEvent;
|
|
122
|
+
const GpuSurfaceResizeEvent = types.GpuSurfaceResizeEvent;
|
|
123
|
+
const GpuSurfaceInputKind = types.GpuSurfaceInputKind;
|
|
124
|
+
const GpuSurfaceInputEvent = types.GpuSurfaceInputEvent;
|
|
125
|
+
const GpuSurfacePixels = types.GpuSurfacePixels;
|
|
126
|
+
const GpuSurfacePacket = types.GpuSurfacePacket;
|
|
127
|
+
const GpuSurfaceImagePixels = types.GpuSurfaceImagePixels;
|
|
128
|
+
const max_gpu_surface_scroll_drivers = types.max_gpu_surface_scroll_drivers;
|
|
129
|
+
const GpuSurfaceScrollDriver = types.GpuSurfaceScrollDriver;
|
|
130
|
+
const max_context_menu_items = types.max_context_menu_items;
|
|
131
|
+
const ContextMenuItem = types.ContextMenuItem;
|
|
132
|
+
const ContextMenuRequest = types.ContextMenuRequest;
|
|
133
|
+
const WidgetAccessibilityRole = types.WidgetAccessibilityRole;
|
|
134
|
+
const WidgetAccessibilityActions = types.WidgetAccessibilityActions;
|
|
135
|
+
const WidgetAccessibilityTextRange = types.WidgetAccessibilityTextRange;
|
|
136
|
+
const WidgetAccessibilityNode = types.WidgetAccessibilityNode;
|
|
137
|
+
const WidgetAccessibilitySnapshot = types.WidgetAccessibilitySnapshot;
|
|
138
|
+
const WidgetAccessibilityActionKind = types.WidgetAccessibilityActionKind;
|
|
139
|
+
const WidgetAccessibilityActionEvent = types.WidgetAccessibilityActionEvent;
|
|
140
|
+
const ClipboardData = types.ClipboardData;
|
|
141
|
+
const ColorScheme = types.ColorScheme;
|
|
142
|
+
const Appearance = types.Appearance;
|
|
143
|
+
const Event = types.Event;
|
|
144
|
+
const splitDropPaths = types.splitDropPaths;
|
|
145
|
+
const EventHandler = types.EventHandler;
|
|
146
|
+
const PlatformServices = types.PlatformServices;
|
|
147
|
+
const Platform = types.Platform;
|
|
148
|
+
const Backend = types.Backend;
|
|
149
|
+
|
|
150
|
+
pub const max_null_timers: usize = 16;
|
|
151
|
+
/// Matches the runtime image registry's slot count
|
|
152
|
+
/// (`canvas_limits.max_registered_canvas_images`).
|
|
153
|
+
pub const max_gpu_surface_images: usize = 16;
|
|
154
|
+
|
|
155
|
+
/// One recorded side-channel image upload (see `gpu_surface_images`).
|
|
156
|
+
pub const NullGpuSurfaceImage = struct {
|
|
157
|
+
id: u64 = 0,
|
|
158
|
+
width: usize = 0,
|
|
159
|
+
height: usize = 0,
|
|
160
|
+
byte_len: usize = 0,
|
|
161
|
+
sample_rgba: [4]u8 = .{ 0, 0, 0, 0 },
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
pub const NullTimer = struct {
|
|
165
|
+
id: u64 = 0,
|
|
166
|
+
interval_ns: u64 = 0,
|
|
167
|
+
repeats: bool = false,
|
|
168
|
+
active: bool = false,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/// Duration table entries for the fake audio player (see
|
|
172
|
+
/// `setAudioDuration`): a loaded path whose tail matches `suffix` reports
|
|
173
|
+
/// `duration_ms`. A table instead of real decoding keeps tests hermetic —
|
|
174
|
+
/// no audio files, no codecs, still honest durations.
|
|
175
|
+
pub const max_null_audio_durations: usize = 8;
|
|
176
|
+
|
|
177
|
+
pub const NullAudioDuration = struct {
|
|
178
|
+
suffix: [128]u8 = undefined,
|
|
179
|
+
suffix_len: usize = 0,
|
|
180
|
+
duration_ms: u64 = 0,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/// Every loaded path without a table entry reports this duration.
|
|
184
|
+
pub const default_null_audio_duration_ms: u64 = 120_000;
|
|
185
|
+
|
|
186
|
+
/// How many distinct URLs the fake track cache remembers. Enough for
|
|
187
|
+
/// resolution-order suites; a real host's cache is the filesystem.
|
|
188
|
+
pub const max_null_audio_cached_urls: usize = 8;
|
|
189
|
+
|
|
190
|
+
/// The fake audio player's whole state: what a deterministic host would
|
|
191
|
+
/// know. Position never advances on its own — tests move it explicitly
|
|
192
|
+
/// with `advanceAudio`, mirroring how `fireTimer` drives timers.
|
|
193
|
+
/// `streaming` is true while the loaded source is a URL being streamed
|
|
194
|
+
/// (not a local file and not a fake-cache hit) — completing a streamed
|
|
195
|
+
/// track flips its URL into the fake cache, so the next `audioLoadUrl`
|
|
196
|
+
/// of the same URL resolves `.cache` deterministically.
|
|
197
|
+
pub const NullAudio = struct {
|
|
198
|
+
loaded: bool = false,
|
|
199
|
+
playing: bool = false,
|
|
200
|
+
streaming: bool = false,
|
|
201
|
+
/// This streamed playback is filling the fake cache: its URL joins
|
|
202
|
+
/// `audio_cached_url_hashes` when it runs to completion (the real
|
|
203
|
+
/// host's atomic install at download end). Stream-only playbacks
|
|
204
|
+
/// (empty cache path) never join.
|
|
205
|
+
cache_fill: bool = false,
|
|
206
|
+
position_ms: u64 = 0,
|
|
207
|
+
duration_ms: u64 = 0,
|
|
208
|
+
volume: f32 = 1.0,
|
|
209
|
+
path_storage: [types.max_audio_path_bytes]u8 = undefined,
|
|
210
|
+
path_len: usize = 0,
|
|
211
|
+
|
|
212
|
+
pub fn path(self: *const NullAudio) []const u8 {
|
|
213
|
+
return self.path_storage[0..self.path_len];
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
pub const NullPlatform = struct {
|
|
218
|
+
surface_value: Surface = .{},
|
|
219
|
+
web_engine: WebEngine = .system,
|
|
220
|
+
app_info: AppInfo = .{},
|
|
221
|
+
gpu_surfaces: bool = false,
|
|
222
|
+
gpu_surface_packets: bool = true,
|
|
223
|
+
/// Model a host that decodes the compact binary packet encoding.
|
|
224
|
+
/// Off by default so existing JSON-asserting tests keep exercising
|
|
225
|
+
/// the JSON wire format; the runtime's per-present negotiation
|
|
226
|
+
/// (binary refused -> JSON attempt in the same frame) is exactly
|
|
227
|
+
/// what a disabled toggle exercises.
|
|
228
|
+
gpu_surface_packet_binary: bool = false,
|
|
229
|
+
/// Model a binary host that ALSO applies incremental `patch`
|
|
230
|
+
/// presents. Disabling it models a binary host without retained
|
|
231
|
+
/// command state (or one that lost it): patch payloads are refused
|
|
232
|
+
/// with `error.UnsupportedService`, which the runtime answers with a
|
|
233
|
+
/// FULL keyed present in the same frame — the resync negotiation the
|
|
234
|
+
/// patch tests pin.
|
|
235
|
+
gpu_surface_packet_binary_patch: bool = true,
|
|
236
|
+
/// Enable the deterministic test image decoder: strict PNGs in the
|
|
237
|
+
/// exact subset `canvas.png.writeRgba8` emits decode through the seam
|
|
238
|
+
/// real platforms serve with CGImageSource/gdk-pixbuf/WIC. Tests
|
|
239
|
+
/// encode raw RGBA fixtures with the canvas PNG writer and exercise
|
|
240
|
+
/// the full decode→register→draw path without bundling a codec.
|
|
241
|
+
image_decode: bool = false,
|
|
242
|
+
image_decode_count: usize = 0,
|
|
243
|
+
requested_frames: u32 = 1,
|
|
244
|
+
loaded_source: ?WebViewSource = null,
|
|
245
|
+
security_policy: security.Policy = .{},
|
|
246
|
+
menus: [max_menus]Menu = undefined,
|
|
247
|
+
menu_items: [max_menu_items]MenuItem = undefined,
|
|
248
|
+
menu_count: usize = 0,
|
|
249
|
+
menu_item_count: usize = 0,
|
|
250
|
+
shortcuts: [max_shortcuts]Shortcut = undefined,
|
|
251
|
+
shortcut_count: usize = 0,
|
|
252
|
+
window_sources: [max_windows]?WebViewSource = [_]?WebViewSource{null} ** max_windows,
|
|
253
|
+
windows: [max_windows]WindowInfo = undefined,
|
|
254
|
+
/// Captured `WindowOptions.resizable` per created window, indexed
|
|
255
|
+
/// like `windows` — `WindowInfo` does not carry it, and tests need
|
|
256
|
+
/// to assert the flag survives to the platform seam (the macOS host
|
|
257
|
+
/// used to drop it at the C ABI).
|
|
258
|
+
window_resizable: [max_windows]bool = [_]bool{true} ** max_windows,
|
|
259
|
+
/// Captured `WindowOptions.titlebar` per created window, indexed
|
|
260
|
+
/// like `windows` — same seam-regression purpose as
|
|
261
|
+
/// `window_resizable` (the startup create used to hardcode it).
|
|
262
|
+
window_titlebar: [max_windows]WindowTitlebarStyle = [_]WindowTitlebarStyle{.standard} ** max_windows,
|
|
263
|
+
/// Minimize calls per window (`minimize_window_fn`), indexed like
|
|
264
|
+
/// `windows`: the observable seam for app-drawn minimize controls —
|
|
265
|
+
/// the null platform has no Dock to genie into, so the count IS the
|
|
266
|
+
/// behavior tests pin.
|
|
267
|
+
window_minimize_count: [max_windows]u32 = [_]u32{0} ** max_windows,
|
|
268
|
+
/// Modeled occlusion per window, indexed like `windows`: true while
|
|
269
|
+
/// the modeled window does not reach the glass (minimized, or a
|
|
270
|
+
/// test covered it via `setWindowOccluded`). Drives the
|
|
271
|
+
/// occluded-emission rule for `.spectrum` reports (`audioSpectrum`
|
|
272
|
+
/// answers null while every open window is occluded), mirroring the
|
|
273
|
+
/// macOS/Windows hosts. Defaults to false — a modeled window is on
|
|
274
|
+
/// glass unless a test says otherwise — so window-less harnesses
|
|
275
|
+
/// and every suite that never occludes keep their reports.
|
|
276
|
+
window_occluded: [max_windows]bool = [_]bool{false} ** max_windows,
|
|
277
|
+
/// Captured `WindowOptions.show` per created window: the
|
|
278
|
+
/// present-before-show policy that must survive to the create seam.
|
|
279
|
+
window_show: [max_windows]types.WindowShowMode = [_]types.WindowShowMode{.immediate} ** max_windows,
|
|
280
|
+
/// Captured `WindowOptions.min_width`/`min_height` per created
|
|
281
|
+
/// window — the content min-size floor that must survive to the
|
|
282
|
+
/// create seam (macOS applies it as `contentMinSize`); same
|
|
283
|
+
/// seam-regression purpose as `window_resizable`.
|
|
284
|
+
window_min_width: [max_windows]f32 = [_]f32{0} ** max_windows,
|
|
285
|
+
window_min_height: [max_windows]f32 = [_]f32{0} ** max_windows,
|
|
286
|
+
/// Live visibility per window, modeling the macOS host: immediate
|
|
287
|
+
/// windows are visible at create; `.on_first_present` windows stay
|
|
288
|
+
/// hidden until their first gpu-surface present (or an explicit
|
|
289
|
+
/// `focusWindow`) shows them.
|
|
290
|
+
window_visible: [max_windows]bool = [_]bool{false} ** max_windows,
|
|
291
|
+
/// The present-before-show ORDERING seam: a per-platform op counter
|
|
292
|
+
/// stamps when each window's first gpu-surface present landed and
|
|
293
|
+
/// when it became visible (0 = never), so tests can assert the
|
|
294
|
+
/// present strictly precedes visibility.
|
|
295
|
+
show_op_seq: usize = 0,
|
|
296
|
+
window_first_present_seq: [max_windows]usize = [_]usize{0} ** max_windows,
|
|
297
|
+
window_shown_seq: [max_windows]usize = [_]usize{0} ** max_windows,
|
|
298
|
+
/// Window ids handed to `startWindowDrag`, in call order: the
|
|
299
|
+
/// window-drag region channel's recording seam. A double-click is
|
|
300
|
+
/// two recorded calls (the host side decides drag vs zoom from the
|
|
301
|
+
/// native event's click count).
|
|
302
|
+
window_drag_starts: [max_windows * 4]WindowId = [_]WindowId{0} ** (max_windows * 4),
|
|
303
|
+
window_drag_start_count: usize = 0,
|
|
304
|
+
/// Chrome overlay geometry `windowChrome` reports for every window
|
|
305
|
+
/// — settable so tests model a hidden-titlebar macOS host (insets
|
|
306
|
+
/// plus the traffic-light cluster frame).
|
|
307
|
+
window_chrome: types.WindowChrome = .{},
|
|
308
|
+
/// The last drag-region mirror pushed through
|
|
309
|
+
/// `setWindowDragRegions` (the Windows `WM_NCHITTEST` seam), so
|
|
310
|
+
/// tests assert what a hit-testing platform would consult. One
|
|
311
|
+
/// mirror suffices: the runtime pushes per canvas view and the
|
|
312
|
+
/// tests drive a single canvas.
|
|
313
|
+
window_drag_regions: [16]types.WindowDragRegion = undefined,
|
|
314
|
+
window_drag_region_count: usize = 0,
|
|
315
|
+
window_drag_region_push_count: usize = 0,
|
|
316
|
+
window_count: usize = 0,
|
|
317
|
+
views: [max_views]NullView = undefined,
|
|
318
|
+
view_count: usize = 0,
|
|
319
|
+
webviews: [max_webviews]NullWebView = undefined,
|
|
320
|
+
webview_count: usize = 0,
|
|
321
|
+
bridge_response: [16 * 1024]u8 = undefined,
|
|
322
|
+
bridge_response_len: usize = 0,
|
|
323
|
+
bridge_response_window_id: WindowId = 0,
|
|
324
|
+
bridge_response_webview_label: []const u8 = "main",
|
|
325
|
+
external_url: [max_external_url_bytes]u8 = undefined,
|
|
326
|
+
external_url_len: usize = 0,
|
|
327
|
+
revealed_path: [max_reveal_path_bytes]u8 = undefined,
|
|
328
|
+
revealed_path_len: usize = 0,
|
|
329
|
+
recent_document_path: [max_recent_document_path_bytes]u8 = undefined,
|
|
330
|
+
recent_document_path_len: usize = 0,
|
|
331
|
+
recent_documents_cleared_count: usize = 0,
|
|
332
|
+
open_dialog_count: usize = 0,
|
|
333
|
+
save_dialog_count: usize = 0,
|
|
334
|
+
message_dialog_count: usize = 0,
|
|
335
|
+
message_dialog_result: MessageDialogResult = .primary,
|
|
336
|
+
notification_title: [max_notification_title_bytes]u8 = undefined,
|
|
337
|
+
notification_title_len: usize = 0,
|
|
338
|
+
notification_subtitle: [max_notification_subtitle_bytes]u8 = undefined,
|
|
339
|
+
notification_subtitle_len: usize = 0,
|
|
340
|
+
notification_body: [max_notification_body_bytes]u8 = undefined,
|
|
341
|
+
notification_body_len: usize = 0,
|
|
342
|
+
notification_count: usize = 0,
|
|
343
|
+
clipboard_mime_type: [max_clipboard_mime_type_bytes]u8 = undefined,
|
|
344
|
+
clipboard_mime_type_len: usize = 0,
|
|
345
|
+
clipboard_data: [max_clipboard_data_bytes]u8 = undefined,
|
|
346
|
+
clipboard_data_len: usize = 0,
|
|
347
|
+
clipboard_write_count: usize = 0,
|
|
348
|
+
credential_service: [max_credential_service_bytes]u8 = undefined,
|
|
349
|
+
credential_service_len: usize = 0,
|
|
350
|
+
credential_account: [max_credential_account_bytes]u8 = undefined,
|
|
351
|
+
credential_account_len: usize = 0,
|
|
352
|
+
credential_secret: [max_credential_secret_bytes]u8 = undefined,
|
|
353
|
+
credential_secret_len: usize = 0,
|
|
354
|
+
credential_set_count: usize = 0,
|
|
355
|
+
credential_delete_count: usize = 0,
|
|
356
|
+
webview_navigate_count: usize = 0,
|
|
357
|
+
tray_icon_path: [max_tray_icon_path_bytes]u8 = undefined,
|
|
358
|
+
tray_icon_path_len: usize = 0,
|
|
359
|
+
tray_title: [max_tray_title_bytes]u8 = undefined,
|
|
360
|
+
tray_title_len: usize = 0,
|
|
361
|
+
tray_tooltip: [max_tray_tooltip_bytes]u8 = undefined,
|
|
362
|
+
tray_tooltip_len: usize = 0,
|
|
363
|
+
tray_items: [max_tray_items]TrayMenuItem = undefined,
|
|
364
|
+
tray_item_count: usize = 0,
|
|
365
|
+
tray_create_count: usize = 0,
|
|
366
|
+
tray_update_count: usize = 0,
|
|
367
|
+
tray_title_update_count: usize = 0,
|
|
368
|
+
tray_remove_count: usize = 0,
|
|
369
|
+
window_event_window_id: WindowId = 0,
|
|
370
|
+
window_event_name: [max_window_event_name_bytes]u8 = undefined,
|
|
371
|
+
window_event_name_len: usize = 0,
|
|
372
|
+
window_event_detail: [max_window_event_detail_bytes]u8 = undefined,
|
|
373
|
+
window_event_detail_len: usize = 0,
|
|
374
|
+
window_event_count: usize = 0,
|
|
375
|
+
gpu_surface_present_window_id: WindowId = 0,
|
|
376
|
+
gpu_surface_present_label_storage: [max_view_label_bytes]u8 = undefined,
|
|
377
|
+
gpu_surface_present_label_len: usize = 0,
|
|
378
|
+
gpu_surface_present_width: usize = 0,
|
|
379
|
+
gpu_surface_present_height: usize = 0,
|
|
380
|
+
gpu_surface_present_scale_factor: f32 = 1,
|
|
381
|
+
gpu_surface_present_dirty_bounds: ?geometry.RectF = null,
|
|
382
|
+
gpu_surface_present_byte_len: usize = 0,
|
|
383
|
+
gpu_surface_present_sample_rgba: [4]u8 = .{ 0, 0, 0, 0 },
|
|
384
|
+
gpu_surface_present_count: usize = 0,
|
|
385
|
+
gpu_surface_packet_present_window_id: WindowId = 0,
|
|
386
|
+
gpu_surface_packet_present_label_storage: [max_view_label_bytes]u8 = undefined,
|
|
387
|
+
gpu_surface_packet_present_label_len: usize = 0,
|
|
388
|
+
gpu_surface_packet_present_frame_index: u64 = 0,
|
|
389
|
+
gpu_surface_packet_present_timestamp_ns: u64 = 0,
|
|
390
|
+
gpu_surface_packet_present_surface_size: geometry.SizeF = .{},
|
|
391
|
+
gpu_surface_packet_present_scale_factor: f32 = 1,
|
|
392
|
+
gpu_surface_packet_present_clear_color_rgba8: [4]u8 = .{ 0, 0, 0, 255 },
|
|
393
|
+
gpu_surface_packet_present_requires_render: bool = false,
|
|
394
|
+
gpu_surface_packet_present_command_count: usize = 0,
|
|
395
|
+
gpu_surface_packet_present_cache_action_count: usize = 0,
|
|
396
|
+
gpu_surface_packet_present_cached_resource_command_count: usize = 0,
|
|
397
|
+
gpu_surface_packet_present_unsupported_command_count: usize = 0,
|
|
398
|
+
gpu_surface_packet_present_representable: bool = true,
|
|
399
|
+
gpu_surface_packet_present_json_len: usize = 0,
|
|
400
|
+
gpu_surface_packet_present_binary_len: usize = 0,
|
|
401
|
+
/// First bytes of the last binary packet payload (magic + version +
|
|
402
|
+
/// header), enough for tests to pin the wire framing without
|
|
403
|
+
/// retaining whole packets.
|
|
404
|
+
gpu_surface_packet_present_binary_prefix: [16]u8 = [_]u8{0} ** 16,
|
|
405
|
+
gpu_surface_packet_present_binary_count: usize = 0,
|
|
406
|
+
/// Full copy of the last binary packet payload, so patch tests can
|
|
407
|
+
/// decode the wire bytes and replay them against a reference retained
|
|
408
|
+
/// store (the Zig-side twin of the AppKit host's command dictionary).
|
|
409
|
+
gpu_surface_packet_present_binary_storage: [types.max_gpu_surface_packet_binary_bytes]u8 = undefined,
|
|
410
|
+
/// Wire load-action code of the last binary present (byte 5 of the
|
|
411
|
+
/// payload: 1 load / 2 clear / 3 patch).
|
|
412
|
+
gpu_surface_packet_present_binary_load_action: u8 = 0,
|
|
413
|
+
/// How many of the recorded binary presents were incremental patches.
|
|
414
|
+
gpu_surface_packet_present_binary_patch_count: usize = 0,
|
|
415
|
+
gpu_surface_packet_present_count: usize = 0,
|
|
416
|
+
gpu_surface_frame_request_window_id: WindowId = 0,
|
|
417
|
+
gpu_surface_frame_request_label_storage: [max_view_label_bytes]u8 = undefined,
|
|
418
|
+
gpu_surface_frame_request_label_len: usize = 0,
|
|
419
|
+
gpu_surface_frame_request_count: usize = 0,
|
|
420
|
+
/// Binary image-upload side-channel recorder: mirrors a packet host's
|
|
421
|
+
/// host-wide texture store (create/replace on upload, drop on remove)
|
|
422
|
+
/// so tests assert the register → re-register → unregister lifecycle
|
|
423
|
+
/// without a real GPU. Disable `gpu_surface_image_uploads` to model a
|
|
424
|
+
/// platform without the seam (`error.UnsupportedService`).
|
|
425
|
+
gpu_surface_image_uploads: bool = true,
|
|
426
|
+
gpu_surface_images: [max_gpu_surface_images]NullGpuSurfaceImage = [_]NullGpuSurfaceImage{.{}} ** max_gpu_surface_images,
|
|
427
|
+
gpu_surface_image_count: usize = 0,
|
|
428
|
+
gpu_surface_image_upload_count: usize = 0,
|
|
429
|
+
gpu_surface_image_remove_count: usize = 0,
|
|
430
|
+
gpu_surface_image_upload_id: u64 = 0,
|
|
431
|
+
gpu_surface_image_upload_width: usize = 0,
|
|
432
|
+
gpu_surface_image_upload_height: usize = 0,
|
|
433
|
+
gpu_surface_image_upload_byte_len: usize = 0,
|
|
434
|
+
gpu_surface_image_upload_sample_rgba: [4]u8 = .{ 0, 0, 0, 0 },
|
|
435
|
+
gpu_surface_image_remove_id: u64 = 0,
|
|
436
|
+
timers: [max_null_timers]NullTimer = [_]NullTimer{.{}} ** max_null_timers,
|
|
437
|
+
timer_count: usize = 0,
|
|
438
|
+
timer_start_count: usize = 0,
|
|
439
|
+
timer_cancel_count: usize = 0,
|
|
440
|
+
/// Whether this modeled host has an audio player. On by default (the
|
|
441
|
+
/// fake below stands in for AVAudioPlayer); tests modelling a
|
|
442
|
+
/// player-less host set it false, which nulls the services AND the
|
|
443
|
+
/// feature report — the same shape as a GTK host whose runtime-loaded
|
|
444
|
+
/// GStreamer is absent.
|
|
445
|
+
audio_playback: bool = true,
|
|
446
|
+
/// Whether this modeled host can stream URL audio sources. On by
|
|
447
|
+
/// default (paired with `audio_playback`, standing in for AVPlayer);
|
|
448
|
+
/// off models a host with a local player but no streaming path —
|
|
449
|
+
/// `audioLoadUrl` is absent and URL playback degrades to one loud
|
|
450
|
+
/// `.failed` Msg, the same explicit degrade a player-less host ships.
|
|
451
|
+
audio_streaming: bool = true,
|
|
452
|
+
/// Whether this modeled host can analyze its own playback into
|
|
453
|
+
/// `.spectrum` band events. On by default (the deterministic fake
|
|
454
|
+
/// generator below stands in for a real analysis tap); off models a
|
|
455
|
+
/// host that plays but cannot reach PCM — `audioSpectrum` answers
|
|
456
|
+
/// null and the feature reports false, so consumers exercise the
|
|
457
|
+
/// honest-absence path (resting glass, never fake dancing).
|
|
458
|
+
audio_spectrum: bool = true,
|
|
459
|
+
/// Whether the modeled filesystem holds the local audio files apps
|
|
460
|
+
/// name in `audioLoad`. On by default (loads succeed hermetically);
|
|
461
|
+
/// off models the gitignored-assets-absent machine: every local load
|
|
462
|
+
/// answers `error.AudioSourceNotFound`, which is exactly what makes
|
|
463
|
+
/// the effects layer fall through to a URL source — the
|
|
464
|
+
/// resolution-order suites pivot on this flag.
|
|
465
|
+
audio_local_files: bool = true,
|
|
466
|
+
/// The deterministic fake audio player: services mutate it, tests
|
|
467
|
+
/// read it and synthesize the events a live host would deliver
|
|
468
|
+
/// (`takeAudioLoaded`, `advanceAudio`).
|
|
469
|
+
audio: NullAudio = .{},
|
|
470
|
+
/// A `.loaded` acknowledgment waiting to be taken — set by a
|
|
471
|
+
/// successful `audioLoad`, consumed by `takeAudioLoaded`.
|
|
472
|
+
audio_loaded_pending: bool = false,
|
|
473
|
+
audio_durations: [max_null_audio_durations]NullAudioDuration = [_]NullAudioDuration{.{}} ** max_null_audio_durations,
|
|
474
|
+
audio_duration_count: usize = 0,
|
|
475
|
+
/// The fake track cache: hashes of URLs whose streamed playback ran
|
|
476
|
+
/// to completion. `audioLoadUrl` answers `.cache` for these — the
|
|
477
|
+
/// deterministic stand-in for a verified on-disk cache entry, so the
|
|
478
|
+
/// "second play is local" story tests hermetically.
|
|
479
|
+
audio_cached_url_hashes: [max_null_audio_cached_urls]u64 = @splat(0),
|
|
480
|
+
audio_cached_url_count: usize = 0,
|
|
481
|
+
audio_load_count: usize = 0,
|
|
482
|
+
audio_load_url_count: usize = 0,
|
|
483
|
+
audio_play_count: usize = 0,
|
|
484
|
+
audio_pause_count: usize = 0,
|
|
485
|
+
audio_stop_count: usize = 0,
|
|
486
|
+
audio_seek_count: usize = 0,
|
|
487
|
+
audio_volume_count: usize = 0,
|
|
488
|
+
/// Pending cross-thread wake requests. Incremented atomically because
|
|
489
|
+
/// `wake_fn` is the one service worker threads call; tests and the
|
|
490
|
+
/// embed host drain it on their own thread via `takeWake` and then
|
|
491
|
+
/// dispatch the `.wake` platform event themselves.
|
|
492
|
+
wake_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
|
|
493
|
+
/// Pending cross-thread frame requests (`request_frame_fn`), counted
|
|
494
|
+
/// atomically like `wake_count`: the automation arrival watcher calls
|
|
495
|
+
/// it from its own thread, and a scripted run loop (or test) drains
|
|
496
|
+
/// it via `takeFrameRequest` into `.frame_requested` dispatches.
|
|
497
|
+
frame_request_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
|
|
498
|
+
view_cursor_window_id: WindowId = 0,
|
|
499
|
+
view_cursor_label_storage: [max_view_label_bytes]u8 = undefined,
|
|
500
|
+
view_cursor_label_len: usize = 0,
|
|
501
|
+
view_cursor: Cursor = .arrow,
|
|
502
|
+
view_cursor_count: usize = 0,
|
|
503
|
+
/// Native scroll-driver recorder. Opt-in (like `gpu_surfaces`): tests
|
|
504
|
+
/// modelling a platform with native scroll drivers set this true;
|
|
505
|
+
/// everything else keeps the engine's wheel physics untouched.
|
|
506
|
+
gpu_surface_scroll_drivers: bool = false,
|
|
507
|
+
scroll_driver_window_id: WindowId = 0,
|
|
508
|
+
scroll_driver_label_storage: [max_view_label_bytes]u8 = undefined,
|
|
509
|
+
scroll_driver_label_len: usize = 0,
|
|
510
|
+
scroll_drivers: [max_gpu_surface_scroll_drivers]GpuSurfaceScrollDriver = undefined,
|
|
511
|
+
scroll_driver_count: usize = 0,
|
|
512
|
+
scroll_driver_set_count: usize = 0,
|
|
513
|
+
/// Lifetime count of driver entries pushed with `set_offset = true`
|
|
514
|
+
/// (the runtime forcing its offset into the native scroller).
|
|
515
|
+
scroll_driver_set_offset_count: usize = 0,
|
|
516
|
+
/// Whether this modeled host presents native context menus. On by
|
|
517
|
+
/// default (the recorder below stands in for the OS menu); tests
|
|
518
|
+
/// modelling a presenter-less host (the anchored-surface fallback
|
|
519
|
+
/// path) set it false, which nulls the service AND the feature
|
|
520
|
+
/// report — the same shape as a real host without a presenter.
|
|
521
|
+
context_menus: bool = true,
|
|
522
|
+
/// Native context-menu recorder: presentations record the request and
|
|
523
|
+
/// return; tests then feed the selection back as a
|
|
524
|
+
/// `.context_menu_action` platform event.
|
|
525
|
+
context_menu_request_count: usize = 0,
|
|
526
|
+
context_menu_window_id: WindowId = 0,
|
|
527
|
+
context_menu_label_storage: [max_view_label_bytes]u8 = undefined,
|
|
528
|
+
context_menu_label_len: usize = 0,
|
|
529
|
+
context_menu_point: geometry.PointF = .{},
|
|
530
|
+
context_menu_token: u64 = 0,
|
|
531
|
+
context_menu_items: [max_context_menu_items]ContextMenuItem = undefined,
|
|
532
|
+
context_menu_item_count: usize = 0,
|
|
533
|
+
context_menu_label_bytes: [max_context_menu_items * 64]u8 = undefined,
|
|
534
|
+
context_menu_label_bytes_len: usize = 0,
|
|
535
|
+
|
|
536
|
+
pub fn init(surface_value: Surface) NullPlatform {
|
|
537
|
+
return .{ .surface_value = surface_value };
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
pub fn initWithEngine(surface_value: Surface, web_engine: WebEngine) NullPlatform {
|
|
541
|
+
return .{ .surface_value = surface_value, .web_engine = web_engine };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
pub fn initWithOptions(surface_value: Surface, web_engine: WebEngine, app_info: AppInfo) NullPlatform {
|
|
545
|
+
return .{ .surface_value = surface_value, .web_engine = web_engine, .app_info = app_info };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
pub fn platform(self: *NullPlatform) Platform {
|
|
549
|
+
return .{
|
|
550
|
+
.context = self,
|
|
551
|
+
.name = "null",
|
|
552
|
+
.surface_value = self.surface_value,
|
|
553
|
+
.run_fn = run,
|
|
554
|
+
.supports_fn = supportsFeature,
|
|
555
|
+
.services = .{
|
|
556
|
+
.context = self,
|
|
557
|
+
.read_clipboard_fn = readClipboard,
|
|
558
|
+
.write_clipboard_fn = writeClipboard,
|
|
559
|
+
.read_clipboard_data_fn = readClipboardData,
|
|
560
|
+
.write_clipboard_data_fn = writeClipboardData,
|
|
561
|
+
.load_webview_fn = loadWebView,
|
|
562
|
+
.load_window_webview_fn = loadWindowWebView,
|
|
563
|
+
.complete_bridge_fn = completeBridge,
|
|
564
|
+
.complete_window_bridge_fn = completeWindowBridge,
|
|
565
|
+
.complete_webview_bridge_fn = completeWebViewBridge,
|
|
566
|
+
.create_window_fn = createWindow,
|
|
567
|
+
.focus_window_fn = focusWindow,
|
|
568
|
+
.close_window_fn = closeWindow,
|
|
569
|
+
.minimize_window_fn = minimizeWindow,
|
|
570
|
+
.start_window_drag_fn = startWindowDrag,
|
|
571
|
+
.window_chrome_fn = windowChrome,
|
|
572
|
+
.set_window_drag_regions_fn = setWindowDragRegions,
|
|
573
|
+
.create_view_fn = createView,
|
|
574
|
+
.update_view_fn = updateView,
|
|
575
|
+
.set_view_frame_fn = setViewFrame,
|
|
576
|
+
.set_view_visible_fn = setViewVisible,
|
|
577
|
+
.set_view_cursor_fn = setViewCursor,
|
|
578
|
+
.focus_view_fn = focusView,
|
|
579
|
+
.close_view_fn = closeView,
|
|
580
|
+
.create_webview_fn = createWebView,
|
|
581
|
+
.set_webview_frame_fn = setWebViewFrame,
|
|
582
|
+
.navigate_webview_fn = navigateWebView,
|
|
583
|
+
.set_webview_zoom_fn = setWebViewZoom,
|
|
584
|
+
.set_webview_layer_fn = setWebViewLayer,
|
|
585
|
+
.close_webview_fn = closeWebView,
|
|
586
|
+
.show_open_dialog_fn = showOpenDialog,
|
|
587
|
+
.show_save_dialog_fn = showSaveDialog,
|
|
588
|
+
.show_message_dialog_fn = showMessageDialog,
|
|
589
|
+
.show_notification_fn = showNotification,
|
|
590
|
+
.set_credential_fn = setCredential,
|
|
591
|
+
.get_credential_fn = getCredential,
|
|
592
|
+
.delete_credential_fn = deleteCredential,
|
|
593
|
+
.create_tray_fn = createTray,
|
|
594
|
+
.update_tray_menu_fn = updateTrayMenu,
|
|
595
|
+
.update_tray_title_fn = updateTrayTitle,
|
|
596
|
+
.remove_tray_fn = removeTray,
|
|
597
|
+
.open_external_url_fn = openExternalUrl,
|
|
598
|
+
.reveal_path_fn = revealPath,
|
|
599
|
+
.add_recent_document_fn = addRecentDocument,
|
|
600
|
+
.clear_recent_documents_fn = clearRecentDocuments,
|
|
601
|
+
.configure_security_policy_fn = configureSecurityPolicy,
|
|
602
|
+
.configure_menus_fn = configureMenus,
|
|
603
|
+
.configure_shortcuts_fn = configureShortcuts,
|
|
604
|
+
.emit_window_event_fn = emitWindowEvent,
|
|
605
|
+
.start_timer_fn = startTimer,
|
|
606
|
+
.cancel_timer_fn = cancelTimer,
|
|
607
|
+
.audio_load_fn = if (self.audio_playback) audioLoad else null,
|
|
608
|
+
.audio_load_url_fn = if (self.audio_playback and self.audio_streaming) audioLoadUrl else null,
|
|
609
|
+
.audio_play_fn = if (self.audio_playback) audioPlay else null,
|
|
610
|
+
.audio_pause_fn = if (self.audio_playback) audioPause else null,
|
|
611
|
+
.audio_stop_fn = if (self.audio_playback) audioStop else null,
|
|
612
|
+
.audio_seek_fn = if (self.audio_playback) audioSeek else null,
|
|
613
|
+
.audio_set_volume_fn = if (self.audio_playback) audioSetVolume else null,
|
|
614
|
+
.wake_fn = wakeService,
|
|
615
|
+
.request_frame_fn = requestFrameService,
|
|
616
|
+
.request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
|
|
617
|
+
.present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
|
|
618
|
+
.present_gpu_surface_packet_fn = presentGpuSurfacePacket,
|
|
619
|
+
.present_gpu_surface_packet_binary_fn = presentGpuSurfacePacketBinary,
|
|
620
|
+
.upload_gpu_surface_image_fn = uploadGpuSurfaceImage,
|
|
621
|
+
.remove_gpu_surface_image_fn = removeGpuSurfaceImage,
|
|
622
|
+
.decode_image_fn = decodeImage,
|
|
623
|
+
.set_gpu_surface_scroll_drivers_fn = setGpuSurfaceScrollDrivers,
|
|
624
|
+
.show_context_menu_fn = if (self.context_menus) showContextMenu else null,
|
|
625
|
+
},
|
|
626
|
+
.app_info = self.app_info,
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
fn supportsFeature(context: *anyopaque, feature: PlatformFeature) bool {
|
|
631
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context));
|
|
632
|
+
return switch (feature) {
|
|
633
|
+
.main_webview,
|
|
634
|
+
.child_webviews,
|
|
635
|
+
.native_views,
|
|
636
|
+
.native_control_commands,
|
|
637
|
+
.menus,
|
|
638
|
+
.shortcuts,
|
|
639
|
+
.dialogs,
|
|
640
|
+
.clipboard_text,
|
|
641
|
+
.clipboard_rich_data,
|
|
642
|
+
.open_url,
|
|
643
|
+
.reveal_path,
|
|
644
|
+
.notifications,
|
|
645
|
+
.recent_documents,
|
|
646
|
+
.credentials,
|
|
647
|
+
.file_drops,
|
|
648
|
+
.app_activation_events,
|
|
649
|
+
=> true,
|
|
650
|
+
.gpu_surfaces => self.gpu_surfaces,
|
|
651
|
+
.gpu_surface_scroll_drivers => self.gpu_surface_scroll_drivers,
|
|
652
|
+
.context_menus => self.context_menus,
|
|
653
|
+
.tray => self.web_engine == .system,
|
|
654
|
+
// The null platform has no real view hierarchy to adopt an
|
|
655
|
+
// app-owned platform view into — reporting support would be a
|
|
656
|
+
// lie the first adopt call exposes.
|
|
657
|
+
.view_surface_adoption => false,
|
|
658
|
+
.audio_playback => self.audio_playback,
|
|
659
|
+
.audio_streaming => self.audio_playback and self.audio_streaming,
|
|
660
|
+
.audio_spectrum => self.audio_playback and self.audio_spectrum,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
pub fn hostInfo(self: NullPlatform) platform_info.HostInfo {
|
|
665
|
+
_ = self;
|
|
666
|
+
const target = platform_info.Target.current();
|
|
667
|
+
return platform_info.detectHost(.{ .target = target });
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
fn run(context: *anyopaque, handler: EventHandler, handler_context: *anyopaque) anyerror!void {
|
|
671
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context));
|
|
672
|
+
try handler(handler_context, .app_start);
|
|
673
|
+
try handler(handler_context, .{ .appearance_changed = .{} });
|
|
674
|
+
try handler(handler_context, .{ .surface_resized = self.surface_value });
|
|
675
|
+
const count = self.app_info.startupWindowCount();
|
|
676
|
+
var index: usize = 0;
|
|
677
|
+
while (index < count) : (index += 1) {
|
|
678
|
+
const window = self.app_info.resolvedStartupWindow(index);
|
|
679
|
+
try handler(handler_context, .{ .window_frame_changed = .{
|
|
680
|
+
.id = window.id,
|
|
681
|
+
.label = window.label,
|
|
682
|
+
.title = window.resolvedTitle(self.app_info.app_name),
|
|
683
|
+
.frame = window.default_frame,
|
|
684
|
+
.scale_factor = self.surface_value.scale_factor,
|
|
685
|
+
.open = true,
|
|
686
|
+
.focused = index == 0,
|
|
687
|
+
} });
|
|
688
|
+
}
|
|
689
|
+
var frame: u32 = 0;
|
|
690
|
+
while (frame < self.requested_frames) : (frame += 1) {
|
|
691
|
+
try handler(handler_context, .frame_requested);
|
|
692
|
+
}
|
|
693
|
+
try handler(handler_context, .app_shutdown);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
fn loadWebView(context: ?*anyopaque, source: WebViewSource) anyerror!void {
|
|
697
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
698
|
+
self.loaded_source = source;
|
|
699
|
+
self.window_sources[0] = source;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
fn readClipboard(context: ?*anyopaque, buffer: []u8) anyerror![]const u8 {
|
|
703
|
+
return readClipboardData(context, "text/plain", buffer);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
fn writeClipboard(context: ?*anyopaque, text: []const u8) anyerror!void {
|
|
707
|
+
try writeClipboardData(context, .{ .mime_type = "text/plain", .bytes = text });
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
fn readClipboardData(context: ?*anyopaque, mime_type: []const u8, buffer: []u8) anyerror![]const u8 {
|
|
711
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
712
|
+
if (!std.mem.eql(u8, mime_type, self.lastClipboardMimeType())) return error.UnsupportedService;
|
|
713
|
+
return try copyInto(buffer, self.lastClipboardData());
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
fn writeClipboardData(context: ?*anyopaque, data: ClipboardData) anyerror!void {
|
|
717
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
718
|
+
self.clipboard_mime_type = undefined;
|
|
719
|
+
self.clipboard_data = undefined;
|
|
720
|
+
self.clipboard_mime_type_len = (try copyInto(&self.clipboard_mime_type, data.mime_type)).len;
|
|
721
|
+
self.clipboard_data_len = (try copyInto(&self.clipboard_data, data.bytes)).len;
|
|
722
|
+
self.clipboard_write_count += 1;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
fn loadWindowWebView(context: ?*anyopaque, window_id: WindowId, source: WebViewSource) anyerror!void {
|
|
726
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
727
|
+
if (window_id == 1) self.loaded_source = source;
|
|
728
|
+
const index = self.findWindowIndex(window_id) orelse if (window_id == 1 and self.window_count == 0) blk: {
|
|
729
|
+
self.windows[0] = .{
|
|
730
|
+
.id = 1,
|
|
731
|
+
.label = "main",
|
|
732
|
+
.title = self.app_info.resolvedWindowTitle(),
|
|
733
|
+
.frame = geometry.RectF.fromSize(self.surface_value.size),
|
|
734
|
+
.scale_factor = self.surface_value.scale_factor,
|
|
735
|
+
.open = true,
|
|
736
|
+
.focused = true,
|
|
737
|
+
};
|
|
738
|
+
self.window_count = 1;
|
|
739
|
+
break :blk 0;
|
|
740
|
+
} else return error.WindowNotFound;
|
|
741
|
+
if (index >= self.window_sources.len) return error.WindowNotFound;
|
|
742
|
+
self.window_sources[index] = source;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
fn completeBridge(context: ?*anyopaque, response: []const u8) anyerror!void {
|
|
746
|
+
try recordBridgeResponse(context, 1, "main", response);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
fn completeWindowBridge(context: ?*anyopaque, window_id: WindowId, response: []const u8) anyerror!void {
|
|
750
|
+
try recordBridgeResponse(context, window_id, "main", response);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
fn completeWebViewBridge(context: ?*anyopaque, window_id: WindowId, webview_label: []const u8, response: []const u8) anyerror!void {
|
|
754
|
+
try recordBridgeResponse(context, window_id, webview_label, response);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
fn recordBridgeResponse(context: ?*anyopaque, window_id: WindowId, webview_label: []const u8, response: []const u8) anyerror!void {
|
|
758
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
759
|
+
const count = @min(response.len, self.bridge_response.len);
|
|
760
|
+
@memcpy(self.bridge_response[0..count], response[0..count]);
|
|
761
|
+
self.bridge_response_len = count;
|
|
762
|
+
self.bridge_response_window_id = window_id;
|
|
763
|
+
self.bridge_response_webview_label = webview_label;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
fn createWindow(context: ?*anyopaque, options: WindowOptions) anyerror!WindowInfo {
|
|
767
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
768
|
+
// A CLOSED window releases its label and id for re-creation —
|
|
769
|
+
// mirroring the real hosts, where a closed NSWindow is gone from
|
|
770
|
+
// the host dictionaries. Model-driven windows reopen under one
|
|
771
|
+
// stable label.
|
|
772
|
+
var scan: usize = 0;
|
|
773
|
+
while (scan < self.window_count) {
|
|
774
|
+
const window = self.windows[scan];
|
|
775
|
+
if (!window.open and (window.id == options.id or std.mem.eql(u8, window.label, options.label))) {
|
|
776
|
+
self.removeWindowAt(scan);
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
scan += 1;
|
|
780
|
+
}
|
|
781
|
+
if (self.window_count >= max_windows) return error.WindowLimitReached;
|
|
782
|
+
for (self.windows[0..self.window_count]) |window| {
|
|
783
|
+
if (window.id == options.id) return error.DuplicateWindowId;
|
|
784
|
+
if (std.mem.eql(u8, window.label, options.label)) return error.DuplicateWindowLabel;
|
|
785
|
+
}
|
|
786
|
+
const info: WindowInfo = .{
|
|
787
|
+
.id = options.id,
|
|
788
|
+
.label = options.label,
|
|
789
|
+
.title = options.resolvedTitle(self.app_info.app_name),
|
|
790
|
+
.frame = options.default_frame,
|
|
791
|
+
.scale_factor = self.surface_value.scale_factor,
|
|
792
|
+
.open = true,
|
|
793
|
+
.focused = false,
|
|
794
|
+
};
|
|
795
|
+
self.windows[self.window_count] = info;
|
|
796
|
+
self.window_resizable[self.window_count] = options.resizable;
|
|
797
|
+
self.window_titlebar[self.window_count] = options.titlebar;
|
|
798
|
+
self.window_show[self.window_count] = options.show;
|
|
799
|
+
self.window_min_width[self.window_count] = options.min_width;
|
|
800
|
+
self.window_min_height[self.window_count] = options.min_height;
|
|
801
|
+
self.window_first_present_seq[self.window_count] = 0;
|
|
802
|
+
// Present-before-show: deferred windows are created hidden and
|
|
803
|
+
// become visible on their first gpu-surface present.
|
|
804
|
+
if (options.show == .immediate) {
|
|
805
|
+
self.window_visible[self.window_count] = true;
|
|
806
|
+
self.show_op_seq += 1;
|
|
807
|
+
self.window_shown_seq[self.window_count] = self.show_op_seq;
|
|
808
|
+
} else {
|
|
809
|
+
self.window_visible[self.window_count] = false;
|
|
810
|
+
self.window_shown_seq[self.window_count] = 0;
|
|
811
|
+
}
|
|
812
|
+
self.window_count += 1;
|
|
813
|
+
return info;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/// Present-before-show bookkeeping shared by every gpu-surface
|
|
817
|
+
/// present path: stamp the window's first present, then make a
|
|
818
|
+
/// deferred window visible — present strictly before visibility.
|
|
819
|
+
fn recordGpuSurfacePresentForWindow(self: *NullPlatform, window_id: WindowId) void {
|
|
820
|
+
const index = self.findWindowIndex(window_id) orelse return;
|
|
821
|
+
if (self.window_first_present_seq[index] == 0) {
|
|
822
|
+
self.show_op_seq += 1;
|
|
823
|
+
self.window_first_present_seq[index] = self.show_op_seq;
|
|
824
|
+
}
|
|
825
|
+
if (!self.window_visible[index] and self.window_show[index] == .on_first_present) {
|
|
826
|
+
self.window_visible[index] = true;
|
|
827
|
+
self.show_op_seq += 1;
|
|
828
|
+
self.window_shown_seq[index] = self.show_op_seq;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
fn startWindowDrag(context: ?*anyopaque, window_id: WindowId) anyerror!void {
|
|
833
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
834
|
+
_ = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
835
|
+
if (self.window_drag_start_count >= self.window_drag_starts.len) return error.WindowLimitReached;
|
|
836
|
+
self.window_drag_starts[self.window_drag_start_count] = window_id;
|
|
837
|
+
self.window_drag_start_count += 1;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
fn windowChrome(context: ?*anyopaque, window_id: WindowId) types.WindowChrome {
|
|
841
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
842
|
+
_ = window_id;
|
|
843
|
+
return self.window_chrome;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
fn setWindowDragRegions(context: ?*anyopaque, window_id: WindowId, label: []const u8, regions: []const types.WindowDragRegion) anyerror!void {
|
|
847
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
848
|
+
// A mirror push, not a window operation: accept any id (the
|
|
849
|
+
// runtime may install layouts before this platform tracks the
|
|
850
|
+
// window), mirroring how `windowChrome` answers for all ids.
|
|
851
|
+
_ = window_id;
|
|
852
|
+
_ = label;
|
|
853
|
+
if (regions.len > self.window_drag_regions.len) return error.WindowLimitReached;
|
|
854
|
+
for (regions, 0..) |region, index| self.window_drag_regions[index] = region;
|
|
855
|
+
self.window_drag_region_count = regions.len;
|
|
856
|
+
self.window_drag_region_push_count += 1;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
fn focusWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
|
|
860
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
861
|
+
const focused_index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
862
|
+
for (self.windows[0..self.window_count], 0..) |*window, index| {
|
|
863
|
+
window.focused = index == focused_index;
|
|
864
|
+
}
|
|
865
|
+
// An explicit focus shows a still-deferred window (the macOS
|
|
866
|
+
// host's makeKeyAndOrderFront override of present-before-show).
|
|
867
|
+
if (!self.window_visible[focused_index]) {
|
|
868
|
+
self.window_visible[focused_index] = true;
|
|
869
|
+
self.show_op_seq += 1;
|
|
870
|
+
self.window_shown_seq[focused_index] = self.show_op_seq;
|
|
871
|
+
}
|
|
872
|
+
// Focusing brings a window back to the glass (clicking the Dock
|
|
873
|
+
// restores a minimized window and orders it in), so the modeled
|
|
874
|
+
// occlusion clears — spectrum reports resume on the next beat.
|
|
875
|
+
self.window_occluded[focused_index] = false;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
fn closeWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
|
|
879
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
880
|
+
const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
881
|
+
self.windows[index].open = false;
|
|
882
|
+
self.windows[index].focused = false;
|
|
883
|
+
self.removeViewsForWindow(window_id);
|
|
884
|
+
self.removeWebViewsForWindow(window_id);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
fn minimizeWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
|
|
888
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
889
|
+
const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
890
|
+
// A minimized window stays OPEN (it comes back from the Dock);
|
|
891
|
+
// only focus leaves. The count is the pinned observable. A
|
|
892
|
+
// minimized window is off the glass, so the modeled occlusion
|
|
893
|
+
// flips too — the real hosts' spectrum gating keys on exactly
|
|
894
|
+
// this fact.
|
|
895
|
+
self.windows[index].focused = false;
|
|
896
|
+
self.window_minimize_count[index] += 1;
|
|
897
|
+
self.window_occluded[index] = true;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
fn createView(context: ?*anyopaque, options: ViewOptions) anyerror!void {
|
|
901
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
902
|
+
if (options.kind == .webview) return createWebView(context, options.webViewOptions());
|
|
903
|
+
if (options.kind == .gpu_surface and !self.gpu_surfaces) return error.UnsupportedViewKind;
|
|
904
|
+
try self.validateViewOptions(options);
|
|
905
|
+
if (self.findViewIndex(options.window_id, options.label) != null) return error.DuplicateViewLabel;
|
|
906
|
+
if (self.view_count >= max_views) return error.ViewLimitReached;
|
|
907
|
+
const index = self.view_count;
|
|
908
|
+
self.view_count += 1;
|
|
909
|
+
self.views[index] = .{
|
|
910
|
+
.window_id = options.window_id,
|
|
911
|
+
.kind = options.kind,
|
|
912
|
+
.frame = options.frame,
|
|
913
|
+
.layer = options.layer,
|
|
914
|
+
.visible = options.visible,
|
|
915
|
+
.enabled = options.enabled,
|
|
916
|
+
.gpu_size = if (options.kind == .gpu_surface) options.frame.size() else geometry.SizeF.init(0, 0),
|
|
917
|
+
.gpu_backend = if (options.kind == .gpu_surface) options.gpu_surface.backend else .none,
|
|
918
|
+
.gpu_pixel_format = if (options.kind == .gpu_surface) options.gpu_surface.pixel_format else .none,
|
|
919
|
+
.gpu_present_mode = if (options.kind == .gpu_surface) options.gpu_surface.present_mode else .none,
|
|
920
|
+
.gpu_alpha_mode = if (options.kind == .gpu_surface) options.gpu_surface.alpha_mode else .none,
|
|
921
|
+
.gpu_color_space = if (options.kind == .gpu_surface) options.gpu_surface.color_space else .none,
|
|
922
|
+
.gpu_vsync = options.kind == .gpu_surface and options.gpu_surface.vsync,
|
|
923
|
+
.gpu_status = if (options.kind == .gpu_surface) .ready else .unavailable,
|
|
924
|
+
.open = true,
|
|
925
|
+
};
|
|
926
|
+
try self.copyViewStrings(index, options.label, options.parent, options.role, options.accessibility_label, options.text, options.command);
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
fn updateView(context: ?*anyopaque, window_id: WindowId, label: []const u8, patch: ViewPatch) anyerror!void {
|
|
930
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
931
|
+
const index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
932
|
+
if (patch.frame) |frame| {
|
|
933
|
+
if (!isValidViewFrame(frame)) return error.InvalidViewOptions;
|
|
934
|
+
self.views[index].frame = frame;
|
|
935
|
+
}
|
|
936
|
+
if (patch.layer) |layer| self.views[index].layer = layer;
|
|
937
|
+
if (patch.visible) |visible| self.views[index].visible = visible;
|
|
938
|
+
if (patch.enabled) |enabled| self.views[index].enabled = enabled;
|
|
939
|
+
if (patch.role) |role| {
|
|
940
|
+
if (role.len > max_view_role_bytes) return error.ViewRoleTooLarge;
|
|
941
|
+
self.views[index].role = try copyInto(&self.views[index].role_storage, role);
|
|
942
|
+
}
|
|
943
|
+
if (patch.accessibility_label) |accessibility_label| {
|
|
944
|
+
if (accessibility_label.len > max_view_accessibility_label_bytes) return error.ViewAccessibilityLabelTooLarge;
|
|
945
|
+
self.views[index].accessibility_label = try copyInto(&self.views[index].accessibility_label_storage, accessibility_label);
|
|
946
|
+
}
|
|
947
|
+
if (patch.text) |text| {
|
|
948
|
+
if (text.len > max_view_text_bytes) return error.ViewTextTooLarge;
|
|
949
|
+
self.views[index].text = try copyInto(&self.views[index].text_storage, text);
|
|
950
|
+
}
|
|
951
|
+
if (patch.command) |command| {
|
|
952
|
+
if (command.len > max_view_command_bytes) return error.InvalidCommand;
|
|
953
|
+
self.views[index].command = try copyInto(&self.views[index].command_storage, command);
|
|
954
|
+
}
|
|
955
|
+
if (patch.url != null) return error.InvalidViewOptions;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
fn setViewFrame(context: ?*anyopaque, window_id: WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
|
|
959
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
960
|
+
const index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
961
|
+
if (!isValidViewFrame(frame)) return error.InvalidViewOptions;
|
|
962
|
+
self.views[index].frame = frame;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
fn setViewVisible(context: ?*anyopaque, window_id: WindowId, label: []const u8, visible: bool) anyerror!void {
|
|
966
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
967
|
+
const index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
968
|
+
self.views[index].visible = visible;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
fn setViewCursor(context: ?*anyopaque, window_id: WindowId, label: []const u8, cursor: Cursor) anyerror!void {
|
|
972
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
973
|
+
const index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
974
|
+
if (self.views[index].kind != .gpu_surface) return error.UnsupportedViewKind;
|
|
975
|
+
self.view_cursor_window_id = window_id;
|
|
976
|
+
self.view_cursor_label_storage = undefined;
|
|
977
|
+
self.view_cursor_label_len = (try copyInto(&self.view_cursor_label_storage, label)).len;
|
|
978
|
+
self.view_cursor = cursor;
|
|
979
|
+
self.view_cursor_count += 1;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
fn focusView(context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void {
|
|
983
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
984
|
+
if (std.mem.eql(u8, label, "main")) {
|
|
985
|
+
if (self.findWindowIndex(window_id)) |window_index| {
|
|
986
|
+
if (!self.windows[window_index].open) return error.WindowNotFound;
|
|
987
|
+
} else if (window_id != 1) {
|
|
988
|
+
return error.WindowNotFound;
|
|
989
|
+
}
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (self.findWebViewIndex(window_id, label) != null) return;
|
|
993
|
+
const index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
994
|
+
if (!self.views[index].enabled or !self.views[index].visible) return error.UnsupportedViewFocus;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
fn closeView(context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void {
|
|
998
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
999
|
+
const index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
1000
|
+
var label_storage: [max_view_label_bytes]u8 = undefined;
|
|
1001
|
+
const view_label = copyInto(&label_storage, self.views[index].label) catch unreachable;
|
|
1002
|
+
self.removeChildViewsForParent(window_id, view_label);
|
|
1003
|
+
if (self.findViewIndex(window_id, view_label)) |current_index| self.removeViewAt(current_index);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
fn createWebView(context: ?*anyopaque, options: WebViewOptions) anyerror!void {
|
|
1007
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1008
|
+
if (self.findWindowIndex(options.window_id)) |window_index| {
|
|
1009
|
+
if (!self.windows[window_index].open) return error.WindowNotFound;
|
|
1010
|
+
} else if (options.window_id != 1) {
|
|
1011
|
+
return error.WindowNotFound;
|
|
1012
|
+
}
|
|
1013
|
+
if (options.label.len == 0) return error.InvalidWebViewOptions;
|
|
1014
|
+
if (options.url.len == 0) return error.MissingWebViewUrl;
|
|
1015
|
+
if (options.label.len > max_webview_label_bytes) return error.WebViewLabelTooLarge;
|
|
1016
|
+
if (options.url.len > max_webview_url_bytes) return error.WebViewUrlTooLarge;
|
|
1017
|
+
if (!isValidWebViewFrame(options.frame)) return error.InvalidWebViewOptions;
|
|
1018
|
+
if (self.findWebViewIndex(options.window_id, options.label) != null) return error.DuplicateWebViewLabel;
|
|
1019
|
+
if (self.webview_count >= max_webviews) return error.WebViewLimitReached;
|
|
1020
|
+
const index = self.webview_count;
|
|
1021
|
+
self.webview_count += 1;
|
|
1022
|
+
var webview = &self.webviews[index];
|
|
1023
|
+
webview.window_id = options.window_id;
|
|
1024
|
+
webview.frame = options.frame;
|
|
1025
|
+
webview.layer = options.layer;
|
|
1026
|
+
webview.transparent = options.transparent;
|
|
1027
|
+
webview.bridge_enabled = options.bridge_enabled;
|
|
1028
|
+
webview.open = true;
|
|
1029
|
+
@memcpy(webview.label_storage[0..options.label.len], options.label);
|
|
1030
|
+
@memcpy(webview.url_storage[0..options.url.len], options.url);
|
|
1031
|
+
webview.label = webview.label_storage[0..options.label.len];
|
|
1032
|
+
webview.url = webview.url_storage[0..options.url.len];
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
fn setWebViewFrame(context: ?*anyopaque, window_id: WindowId, label: []const u8, frame: geometry.RectF) anyerror!void {
|
|
1036
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1037
|
+
if (std.mem.eql(u8, label, "main")) {
|
|
1038
|
+
_ = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
1039
|
+
if (!isValidWebViewFrame(frame)) return error.InvalidWebViewOptions;
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
const index = self.findWebViewIndex(window_id, label) orelse return error.WebViewNotFound;
|
|
1043
|
+
if (!isValidWebViewFrame(frame)) return error.InvalidWebViewOptions;
|
|
1044
|
+
self.webviews[index].frame = frame;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
fn navigateWebView(context: ?*anyopaque, window_id: WindowId, label: []const u8, url: []const u8) anyerror!void {
|
|
1048
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1049
|
+
const index = self.findWebViewIndex(window_id, label) orelse return error.WebViewNotFound;
|
|
1050
|
+
if (url.len == 0) return error.MissingWebViewUrl;
|
|
1051
|
+
if (url.len > max_webview_url_bytes) return error.WebViewUrlTooLarge;
|
|
1052
|
+
var webview = &self.webviews[index];
|
|
1053
|
+
@memcpy(webview.url_storage[0..url.len], url);
|
|
1054
|
+
webview.url = webview.url_storage[0..url.len];
|
|
1055
|
+
self.webview_navigate_count += 1;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
fn setWebViewZoom(context: ?*anyopaque, window_id: WindowId, label: []const u8, zoom: f64) anyerror!void {
|
|
1059
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1060
|
+
if (std.mem.eql(u8, label, "main")) {
|
|
1061
|
+
_ = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
1062
|
+
if (zoom < 0.25 or zoom > 5.0) return error.InvalidWebViewOptions;
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
const index = self.findWebViewIndex(window_id, label) orelse return error.WebViewNotFound;
|
|
1066
|
+
if (zoom < 0.25 or zoom > 5.0) return error.InvalidWebViewOptions;
|
|
1067
|
+
self.webviews[index].zoom = zoom;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
fn setWebViewLayer(context: ?*anyopaque, window_id: WindowId, label: []const u8, layer: i32) anyerror!void {
|
|
1071
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1072
|
+
if (std.mem.eql(u8, label, "main")) {
|
|
1073
|
+
_ = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
const index = self.findWebViewIndex(window_id, label) orelse return error.WebViewNotFound;
|
|
1077
|
+
self.webviews[index].layer = layer;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
fn closeWebView(context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void {
|
|
1081
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1082
|
+
const index = self.findWebViewIndex(window_id, label) orelse return error.WebViewNotFound;
|
|
1083
|
+
self.removeWebViewAt(index);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
fn showOpenDialog(context: ?*anyopaque, options: OpenDialogOptions, buffer: []u8) anyerror!OpenDialogResult {
|
|
1087
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1088
|
+
_ = options;
|
|
1089
|
+
const path = "/tmp/native-sdk-open.txt";
|
|
1090
|
+
const copied = try copyInto(buffer, path);
|
|
1091
|
+
self.open_dialog_count += 1;
|
|
1092
|
+
return .{ .count = 1, .paths = copied };
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
fn showSaveDialog(context: ?*anyopaque, options: SaveDialogOptions, buffer: []u8) anyerror!?[]const u8 {
|
|
1096
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1097
|
+
const path = if (options.default_name.len > 0) options.default_name else "/tmp/native-sdk-save.txt";
|
|
1098
|
+
const copied = try copyInto(buffer, path);
|
|
1099
|
+
self.save_dialog_count += 1;
|
|
1100
|
+
return copied;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
fn showMessageDialog(context: ?*anyopaque, options: MessageDialogOptions) anyerror!MessageDialogResult {
|
|
1104
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1105
|
+
_ = options;
|
|
1106
|
+
self.message_dialog_count += 1;
|
|
1107
|
+
return self.message_dialog_result;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
fn showNotification(context: ?*anyopaque, options: NotificationOptions) anyerror!void {
|
|
1111
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1112
|
+
self.notification_title = undefined;
|
|
1113
|
+
self.notification_subtitle = undefined;
|
|
1114
|
+
self.notification_body = undefined;
|
|
1115
|
+
self.notification_title_len = (try copyInto(&self.notification_title, options.title)).len;
|
|
1116
|
+
self.notification_subtitle_len = (try copyInto(&self.notification_subtitle, options.subtitle)).len;
|
|
1117
|
+
self.notification_body_len = (try copyInto(&self.notification_body, options.body)).len;
|
|
1118
|
+
self.notification_count += 1;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
fn setCredential(context: ?*anyopaque, credential: Credential) anyerror!void {
|
|
1122
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1123
|
+
self.credential_service = undefined;
|
|
1124
|
+
self.credential_account = undefined;
|
|
1125
|
+
self.credential_secret = undefined;
|
|
1126
|
+
self.credential_service_len = (try copyInto(&self.credential_service, credential.service)).len;
|
|
1127
|
+
self.credential_account_len = (try copyInto(&self.credential_account, credential.account)).len;
|
|
1128
|
+
self.credential_secret_len = (try copyInto(&self.credential_secret, credential.secret)).len;
|
|
1129
|
+
self.credential_set_count += 1;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
fn getCredential(context: ?*anyopaque, key: CredentialKey, buffer: []u8) anyerror![]const u8 {
|
|
1133
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1134
|
+
if (self.credential_secret_len == 0) return error.CredentialNotFound;
|
|
1135
|
+
if (!std.mem.eql(u8, key.service, self.lastCredentialService()) or !std.mem.eql(u8, key.account, self.lastCredentialAccount())) return error.CredentialNotFound;
|
|
1136
|
+
return try copyInto(buffer, self.lastCredentialSecret());
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
fn deleteCredential(context: ?*anyopaque, key: CredentialKey) anyerror!void {
|
|
1140
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1141
|
+
if (self.credential_secret_len == 0) return error.CredentialNotFound;
|
|
1142
|
+
if (!std.mem.eql(u8, key.service, self.lastCredentialService()) or !std.mem.eql(u8, key.account, self.lastCredentialAccount())) return error.CredentialNotFound;
|
|
1143
|
+
self.credential_secret_len = 0;
|
|
1144
|
+
self.credential_delete_count += 1;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
fn createTray(context: ?*anyopaque, options: TrayOptions) anyerror!void {
|
|
1148
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1149
|
+
self.tray_icon_path = undefined;
|
|
1150
|
+
self.tray_title = undefined;
|
|
1151
|
+
self.tray_tooltip = undefined;
|
|
1152
|
+
self.tray_icon_path_len = (try copyInto(&self.tray_icon_path, options.icon_path)).len;
|
|
1153
|
+
self.tray_title_len = (try copyInto(&self.tray_title, options.title)).len;
|
|
1154
|
+
self.tray_tooltip_len = (try copyInto(&self.tray_tooltip, options.tooltip)).len;
|
|
1155
|
+
try updateTrayMenu(context, options.items);
|
|
1156
|
+
self.tray_create_count += 1;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
fn updateTrayMenu(context: ?*anyopaque, items: []const TrayMenuItem) anyerror!void {
|
|
1160
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1161
|
+
if (items.len > self.tray_items.len) return error.InvalidTrayOptions;
|
|
1162
|
+
for (items, 0..) |item, index| self.tray_items[index] = item;
|
|
1163
|
+
self.tray_item_count = items.len;
|
|
1164
|
+
self.tray_update_count += 1;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
fn updateTrayTitle(context: ?*anyopaque, title: []const u8) anyerror!void {
|
|
1168
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1169
|
+
self.tray_title = undefined;
|
|
1170
|
+
self.tray_title_len = (try copyInto(&self.tray_title, title)).len;
|
|
1171
|
+
self.tray_title_update_count += 1;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
fn removeTray(context: ?*anyopaque) anyerror!void {
|
|
1175
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1176
|
+
self.tray_item_count = 0;
|
|
1177
|
+
self.tray_remove_count += 1;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
fn openExternalUrl(context: ?*anyopaque, url: []const u8) anyerror!void {
|
|
1181
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1182
|
+
self.external_url = undefined;
|
|
1183
|
+
self.external_url_len = 0;
|
|
1184
|
+
self.external_url_len = (try copyInto(&self.external_url, url)).len;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
fn revealPath(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1188
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1189
|
+
self.revealed_path = undefined;
|
|
1190
|
+
self.revealed_path_len = 0;
|
|
1191
|
+
self.revealed_path_len = (try copyInto(&self.revealed_path, path)).len;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
fn addRecentDocument(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1195
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1196
|
+
self.recent_document_path = undefined;
|
|
1197
|
+
self.recent_document_path_len = 0;
|
|
1198
|
+
self.recent_document_path_len = (try copyInto(&self.recent_document_path, path)).len;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
fn clearRecentDocuments(context: ?*anyopaque) anyerror!void {
|
|
1202
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1203
|
+
self.recent_document_path_len = 0;
|
|
1204
|
+
self.recent_documents_cleared_count += 1;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
fn configureSecurityPolicy(context: ?*anyopaque, policy: security.Policy) anyerror!void {
|
|
1208
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1209
|
+
self.security_policy = policy;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
fn configureMenus(context: ?*anyopaque, menus: []const Menu) anyerror!void {
|
|
1213
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1214
|
+
try validateMenus(menus);
|
|
1215
|
+
self.menu_count = 0;
|
|
1216
|
+
self.menu_item_count = 0;
|
|
1217
|
+
for (menus) |menu| {
|
|
1218
|
+
const start = self.menu_item_count;
|
|
1219
|
+
for (menu.items) |item| {
|
|
1220
|
+
self.menu_items[self.menu_item_count] = item;
|
|
1221
|
+
self.menu_item_count += 1;
|
|
1222
|
+
}
|
|
1223
|
+
const end = self.menu_item_count;
|
|
1224
|
+
self.menus[self.menu_count] = .{
|
|
1225
|
+
.title = menu.title,
|
|
1226
|
+
.items = self.menu_items[start..end],
|
|
1227
|
+
};
|
|
1228
|
+
self.menu_count += 1;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
fn configureShortcuts(context: ?*anyopaque, shortcuts: []const Shortcut) anyerror!void {
|
|
1233
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1234
|
+
if (shortcuts.len > self.shortcuts.len) return error.InvalidShortcut;
|
|
1235
|
+
for (shortcuts, 0..) |shortcut, index| {
|
|
1236
|
+
try validateShortcut(shortcut);
|
|
1237
|
+
self.shortcuts[index] = shortcut;
|
|
1238
|
+
}
|
|
1239
|
+
self.shortcut_count = shortcuts.len;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
fn startTimer(context: ?*anyopaque, id: u64, interval_ns: u64, repeats: bool) anyerror!void {
|
|
1243
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1244
|
+
self.timer_start_count += 1;
|
|
1245
|
+
const entry: NullTimer = .{ .id = id, .interval_ns = interval_ns, .repeats = repeats, .active = true };
|
|
1246
|
+
if (self.findTimerIndex(id)) |index| {
|
|
1247
|
+
self.timers[index] = entry;
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
if (self.timer_count >= max_null_timers) return error.UnsupportedService;
|
|
1251
|
+
self.timers[self.timer_count] = entry;
|
|
1252
|
+
self.timer_count += 1;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
fn cancelTimer(context: ?*anyopaque, id: u64) anyerror!void {
|
|
1256
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1257
|
+
self.timer_cancel_count += 1;
|
|
1258
|
+
if (self.findTimerIndex(id)) |index| self.timers[index].active = false;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
fn audioLoad(context: ?*anyopaque, path: []const u8) anyerror!void {
|
|
1262
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1263
|
+
self.audio_load_count += 1;
|
|
1264
|
+
if (path.len > self.audio.path_storage.len) return error.AudioPathTooLarge;
|
|
1265
|
+
// Model the assets-absent machine: the local file is not there,
|
|
1266
|
+
// exactly the synchronous refusal a real host's open gives.
|
|
1267
|
+
if (!self.audio_local_files) return error.AudioSourceNotFound;
|
|
1268
|
+
@memcpy(self.audio.path_storage[0..path.len], path);
|
|
1269
|
+
self.audio.path_len = path.len;
|
|
1270
|
+
self.audio.loaded = true;
|
|
1271
|
+
self.audio.playing = false;
|
|
1272
|
+
self.audio.streaming = false;
|
|
1273
|
+
self.audio.position_ms = 0;
|
|
1274
|
+
self.audio.duration_ms = self.audioDurationFor(path);
|
|
1275
|
+
self.audio_loaded_pending = true;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
/// URL sources, deterministically: a URL whose streamed playback has
|
|
1279
|
+
/// completed before answers `.cache` (the fake stand-in for a
|
|
1280
|
+
/// verified on-disk entry — no network, plays as a local file);
|
|
1281
|
+
/// anything else "streams" (`.stream`) and joins the fake cache when
|
|
1282
|
+
/// `advanceAudio` runs it to completion. `cache_path` gates caching
|
|
1283
|
+
/// like the real seam: empty means stream-only, never cached.
|
|
1284
|
+
/// Durations come from the same suffix table local loads use — URLs
|
|
1285
|
+
/// end in the same track file names.
|
|
1286
|
+
fn audioLoadUrl(context: ?*anyopaque, url: []const u8, cache_path: []const u8, expected_bytes: u64) anyerror!types.AudioLoadResolution {
|
|
1287
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1288
|
+
_ = expected_bytes;
|
|
1289
|
+
self.audio_load_url_count += 1;
|
|
1290
|
+
if (url.len > self.audio.path_storage.len) return error.AudioPathTooLarge;
|
|
1291
|
+
const caching = cache_path.len > 0;
|
|
1292
|
+
const cached = caching and self.audioUrlCached(url);
|
|
1293
|
+
@memcpy(self.audio.path_storage[0..url.len], url);
|
|
1294
|
+
self.audio.path_len = url.len;
|
|
1295
|
+
self.audio.loaded = true;
|
|
1296
|
+
self.audio.playing = false;
|
|
1297
|
+
self.audio.streaming = !cached;
|
|
1298
|
+
self.audio.cache_fill = caching and !cached;
|
|
1299
|
+
self.audio.position_ms = 0;
|
|
1300
|
+
self.audio.duration_ms = self.audioDurationFor(url);
|
|
1301
|
+
self.audio_loaded_pending = true;
|
|
1302
|
+
return if (cached) .cache else .stream;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
fn audioPlay(context: ?*anyopaque) anyerror!void {
|
|
1306
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1307
|
+
self.audio_play_count += 1;
|
|
1308
|
+
if (!self.audio.loaded) return error.InvalidAudioOptions;
|
|
1309
|
+
self.audio.playing = true;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
fn audioPause(context: ?*anyopaque) anyerror!void {
|
|
1313
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1314
|
+
self.audio_pause_count += 1;
|
|
1315
|
+
self.audio.playing = false;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
fn audioStop(context: ?*anyopaque) anyerror!void {
|
|
1319
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1320
|
+
self.audio_stop_count += 1;
|
|
1321
|
+
self.audio = .{ .volume = self.audio.volume };
|
|
1322
|
+
self.audio_loaded_pending = false;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
fn audioSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
|
|
1326
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1327
|
+
self.audio_seek_count += 1;
|
|
1328
|
+
if (!self.audio.loaded) return error.InvalidAudioOptions;
|
|
1329
|
+
self.audio.position_ms = @min(position_ms, self.audio.duration_ms);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
|
|
1333
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1334
|
+
self.audio_volume_count += 1;
|
|
1335
|
+
self.audio.volume = volume;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
fn audioUrlHash(url: []const u8) u64 {
|
|
1339
|
+
return std.hash.Wyhash.hash(0, url);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
fn audioUrlCached(self: *const NullPlatform, url: []const u8) bool {
|
|
1343
|
+
const hash = audioUrlHash(url);
|
|
1344
|
+
for (self.audio_cached_url_hashes[0..self.audio_cached_url_count]) |cached| {
|
|
1345
|
+
if (cached == hash) return true;
|
|
1346
|
+
}
|
|
1347
|
+
return false;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/// Flip a completed stream's URL into the fake cache — the
|
|
1351
|
+
/// deterministic analog of the host's verify-then-rename install. A
|
|
1352
|
+
/// full table drops the entry (the next play streams again), which
|
|
1353
|
+
/// is also an honest cache behavior.
|
|
1354
|
+
fn audioRecordCached(self: *NullPlatform, url: []const u8) void {
|
|
1355
|
+
if (self.audioUrlCached(url)) return;
|
|
1356
|
+
if (self.audio_cached_url_count >= max_null_audio_cached_urls) return;
|
|
1357
|
+
self.audio_cached_url_hashes[self.audio_cached_url_count] = audioUrlHash(url);
|
|
1358
|
+
self.audio_cached_url_count += 1;
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
fn audioDurationFor(self: *const NullPlatform, path: []const u8) u64 {
|
|
1362
|
+
for (self.audio_durations[0..self.audio_duration_count]) |entry| {
|
|
1363
|
+
const suffix = entry.suffix[0..entry.suffix_len];
|
|
1364
|
+
if (suffix.len <= path.len and std.mem.eql(u8, path[path.len - suffix.len ..], suffix)) {
|
|
1365
|
+
return entry.duration_ms;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
return default_null_audio_duration_ms;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/// Test helper: register a duration for any loaded path ending in
|
|
1372
|
+
/// `suffix`. Paths without a match report
|
|
1373
|
+
/// `default_null_audio_duration_ms`.
|
|
1374
|
+
pub fn setAudioDuration(self: *NullPlatform, suffix: []const u8, duration_ms: u64) !void {
|
|
1375
|
+
if (suffix.len == 0 or suffix.len > 128) return error.InvalidAudioOptions;
|
|
1376
|
+
if (self.audio_duration_count >= max_null_audio_durations) return error.InvalidAudioOptions;
|
|
1377
|
+
var entry = &self.audio_durations[self.audio_duration_count];
|
|
1378
|
+
@memcpy(entry.suffix[0..suffix.len], suffix);
|
|
1379
|
+
entry.suffix_len = suffix.len;
|
|
1380
|
+
entry.duration_ms = duration_ms;
|
|
1381
|
+
self.audio_duration_count += 1;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
/// Consume the pending `.loaded` acknowledgment, returning the
|
|
1385
|
+
/// platform event a live host would deliver after a successful load
|
|
1386
|
+
/// (or null when no load is waiting). Dispatch it through the runtime,
|
|
1387
|
+
/// like `fireTimer`.
|
|
1388
|
+
pub fn takeAudioLoaded(self: *NullPlatform) ?Event {
|
|
1389
|
+
if (!self.audio_loaded_pending) return null;
|
|
1390
|
+
self.audio_loaded_pending = false;
|
|
1391
|
+
return .{ .audio = .{
|
|
1392
|
+
.kind = .loaded,
|
|
1393
|
+
.position_ms = self.audio.position_ms,
|
|
1394
|
+
.duration_ms = self.audio.duration_ms,
|
|
1395
|
+
.playing = self.audio.playing,
|
|
1396
|
+
} };
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
/// Test helper: advance fake playback by `delta_ms` and synthesize
|
|
1400
|
+
/// the event a live host's position timer would deliver — a
|
|
1401
|
+
/// `.position` tick, or `.completed` when the track end is reached
|
|
1402
|
+
/// (which stops playback, matching AVAudioPlayer). Returns null when
|
|
1403
|
+
/// nothing is loaded or playing; position never advances on its own.
|
|
1404
|
+
pub fn advanceAudio(self: *NullPlatform, delta_ms: u64) ?Event {
|
|
1405
|
+
if (!self.audio.loaded or !self.audio.playing) return null;
|
|
1406
|
+
self.audio.position_ms = @min(self.audio.position_ms + delta_ms, self.audio.duration_ms);
|
|
1407
|
+
if (self.audio.position_ms >= self.audio.duration_ms) {
|
|
1408
|
+
self.audio.playing = false;
|
|
1409
|
+
self.audio.position_ms = self.audio.duration_ms;
|
|
1410
|
+
// A cache-filling stream that ran to completion installs its
|
|
1411
|
+
// cache entry — the next `audioLoadUrl` of this URL answers
|
|
1412
|
+
// `.cache`, deterministically modeling "faster next time".
|
|
1413
|
+
if (self.audio.streaming and self.audio.cache_fill) {
|
|
1414
|
+
self.audioRecordCached(self.audio.path());
|
|
1415
|
+
}
|
|
1416
|
+
return .{ .audio = .{
|
|
1417
|
+
.kind = .completed,
|
|
1418
|
+
.position_ms = self.audio.position_ms,
|
|
1419
|
+
.duration_ms = self.audio.duration_ms,
|
|
1420
|
+
.playing = false,
|
|
1421
|
+
} };
|
|
1422
|
+
}
|
|
1423
|
+
return .{ .audio = .{
|
|
1424
|
+
.kind = .position,
|
|
1425
|
+
.position_ms = self.audio.position_ms,
|
|
1426
|
+
.duration_ms = self.audio.duration_ms,
|
|
1427
|
+
.playing = true,
|
|
1428
|
+
} };
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
/// Test helper: synthesize a mid-stream stall — the `.position`
|
|
1432
|
+
/// event a live host's tick delivers while the stream waits for
|
|
1433
|
+
/// network bytes (`buffering = true`, position held). Only a
|
|
1434
|
+
/// streaming playback can stall; local files and cache hits never
|
|
1435
|
+
/// buffer, so anything else answers null.
|
|
1436
|
+
pub fn stallAudio(self: *NullPlatform) ?Event {
|
|
1437
|
+
if (!self.audio.loaded or !self.audio.playing or !self.audio.streaming) return null;
|
|
1438
|
+
return .{ .audio = .{
|
|
1439
|
+
.kind = .position,
|
|
1440
|
+
.position_ms = self.audio.position_ms,
|
|
1441
|
+
.duration_ms = self.audio.duration_ms,
|
|
1442
|
+
.playing = true,
|
|
1443
|
+
.buffering = true,
|
|
1444
|
+
} };
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
/// Test helper: synthesize the `.spectrum` band report a live host's
|
|
1448
|
+
/// analysis tap would deliver at this instant — the deterministic
|
|
1449
|
+
/// fake generator standing in for a real FFT, a pure function of
|
|
1450
|
+
/// (loaded source, playback position), so the same fake playback
|
|
1451
|
+
/// always paints the same bars and the journal round-trips exactly.
|
|
1452
|
+
/// The shape mirrors the reference scale: a mid-weighted comb whose
|
|
1453
|
+
/// motion derives from the position clock, quantized to the u8 band
|
|
1454
|
+
/// bytes real hosts emit. Null while nothing is audibly playing
|
|
1455
|
+
/// (pause and stop starve the stream exactly like real hosts) and on
|
|
1456
|
+
/// a modeled host that cannot analyze (`audio_spectrum = false`).
|
|
1457
|
+
pub fn audioSpectrum(self: *NullPlatform) ?Event {
|
|
1458
|
+
if (!self.audio_playback or !self.audio_spectrum) return null;
|
|
1459
|
+
if (!self.audio.loaded or !self.audio.playing) return null;
|
|
1460
|
+
// The occluded-emission rule, modeled: bands describe a display,
|
|
1461
|
+
// so while every open window is off the glass (minimized or
|
|
1462
|
+
// test-occluded via `setWindowOccluded`) the host emits nothing
|
|
1463
|
+
// — the journal shows honest silence for the stretch, and the
|
|
1464
|
+
// next report after a reveal carries current bands. Keyed on
|
|
1465
|
+
// the modeled occlusion flag ONLY (default false), so
|
|
1466
|
+
// window-less harnesses keep their deterministic reports.
|
|
1467
|
+
if (self.allOpenWindowsOccluded()) return null;
|
|
1468
|
+
var event = Event{ .audio = .{
|
|
1469
|
+
.kind = .spectrum,
|
|
1470
|
+
.position_ms = self.audio.position_ms,
|
|
1471
|
+
.duration_ms = self.audio.duration_ms,
|
|
1472
|
+
.playing = true,
|
|
1473
|
+
} };
|
|
1474
|
+
const seed: f32 = @floatFromInt(audioUrlHash(self.audio.path()) % 97);
|
|
1475
|
+
const phase = @as(f32, @floatFromInt(self.audio.position_ms)) / 1000.0;
|
|
1476
|
+
for (&event.audio.bands, 0..) |*band, index| {
|
|
1477
|
+
const x: f32 = @floatFromInt(index);
|
|
1478
|
+
// Lows tall, highs rolled off — the plausible silhouette a
|
|
1479
|
+
// consumer can sanity-check band ordering against.
|
|
1480
|
+
const envelope = 0.35 + 0.65 * @exp(-x * x / 420.0);
|
|
1481
|
+
const wave = 0.6 * @abs(@sin(phase * (3.4 + seed * 0.026) + x * 0.55 + seed)) +
|
|
1482
|
+
0.4 * @abs(@sin(phase * 7.3 + x * 1.35 + seed * 0.5));
|
|
1483
|
+
band.* = @intFromFloat(std.math.clamp(envelope * wave, 0.0, 1.0) * 255.0);
|
|
1484
|
+
}
|
|
1485
|
+
return event;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
/// Test helper: synthesize an asynchronous decode/device failure,
|
|
1489
|
+
/// the `.failed` event a live host would deliver. Unloads the player
|
|
1490
|
+
/// like a real failure would.
|
|
1491
|
+
pub fn failAudio(self: *NullPlatform) ?Event {
|
|
1492
|
+
if (!self.audio.loaded) return null;
|
|
1493
|
+
self.audio = .{ .volume = self.audio.volume };
|
|
1494
|
+
self.audio_loaded_pending = false;
|
|
1495
|
+
return .{ .audio = .{ .kind = .failed } };
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
fn wakeService(context: ?*anyopaque) anyerror!void {
|
|
1499
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1500
|
+
_ = self.wake_count.fetchAdd(1, .release);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
fn requestFrameService(context: ?*anyopaque) anyerror!void {
|
|
1504
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1505
|
+
_ = self.frame_request_count.fetchAdd(1, .release);
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/// Deterministic decode seam for tests (see `image_decode`): parses
|
|
1509
|
+
/// the strict PNG subset the canvas writer emits. Off by default so
|
|
1510
|
+
/// the null platform models codec-less hosts.
|
|
1511
|
+
fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!types.DecodedImage {
|
|
1512
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1513
|
+
if (!self.image_decode) return error.UnsupportedService;
|
|
1514
|
+
self.image_decode_count += 1;
|
|
1515
|
+
const decoded = canvas.png.decodeRgba8(bytes, buffer) catch |err| return switch (err) {
|
|
1516
|
+
error.PngPixelBufferTooSmall => error.ImageTooLarge,
|
|
1517
|
+
else => error.ImageDecodeFailed,
|
|
1518
|
+
};
|
|
1519
|
+
return .{ .width = decoded.width, .height = decoded.height, .rgba8 = decoded.rgba8 };
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
/// Consume one pending wake request, returning the `.wake` platform
|
|
1523
|
+
/// event a live loop would deliver (or null when none are pending).
|
|
1524
|
+
/// Tests dispatch the returned event through the runtime, mirroring
|
|
1525
|
+
/// how host loops marshal `wake_fn` calls back onto their own thread.
|
|
1526
|
+
pub fn takeWake(self: *NullPlatform) ?Event {
|
|
1527
|
+
var current = self.wake_count.load(.acquire);
|
|
1528
|
+
while (current > 0) {
|
|
1529
|
+
if (self.wake_count.cmpxchgWeak(current, current - 1, .acq_rel, .acquire)) |actual| {
|
|
1530
|
+
current = actual;
|
|
1531
|
+
} else {
|
|
1532
|
+
return .wake;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return null;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
pub fn pendingWakeCount(self: *const NullPlatform) usize {
|
|
1539
|
+
return self.wake_count.load(.acquire);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
/// Consume one pending cross-thread frame request, returning the
|
|
1543
|
+
/// `.frame_requested` event a live loop would deliver (or null when
|
|
1544
|
+
/// none are pending) — `takeWake`'s twin for `request_frame_fn`.
|
|
1545
|
+
pub fn takeFrameRequest(self: *NullPlatform) ?Event {
|
|
1546
|
+
var current = self.frame_request_count.load(.acquire);
|
|
1547
|
+
while (current > 0) {
|
|
1548
|
+
if (self.frame_request_count.cmpxchgWeak(current, current - 1, .acq_rel, .acquire)) |actual| {
|
|
1549
|
+
current = actual;
|
|
1550
|
+
} else {
|
|
1551
|
+
return .frame_requested;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return null;
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
pub fn pendingFrameRequestCount(self: *const NullPlatform) usize {
|
|
1558
|
+
return self.frame_request_count.load(.acquire);
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
/// Test helper: synthesize the platform event a live timer would deliver.
|
|
1562
|
+
/// Returns null when the timer was never started or has been cancelled.
|
|
1563
|
+
/// A non-repeating timer deactivates after firing once, matching host
|
|
1564
|
+
/// backends. Dispatch the returned event through the runtime to drive
|
|
1565
|
+
/// timers deterministically in tests.
|
|
1566
|
+
pub fn fireTimer(self: *NullPlatform, id: u64, timestamp_ns: u64) ?Event {
|
|
1567
|
+
const index = self.findTimerIndex(id) orelse return null;
|
|
1568
|
+
if (!self.timers[index].active) return null;
|
|
1569
|
+
if (!self.timers[index].repeats) self.timers[index].active = false;
|
|
1570
|
+
return .{ .timer = .{ .id = id, .timestamp_ns = timestamp_ns } };
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
pub fn startedTimer(self: *const NullPlatform, id: u64) ?NullTimer {
|
|
1574
|
+
const index = self.findTimerIndex(id) orelse return null;
|
|
1575
|
+
return self.timers[index];
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
pub fn activeTimerCount(self: *const NullPlatform) usize {
|
|
1579
|
+
var count: usize = 0;
|
|
1580
|
+
for (self.timers[0..self.timer_count]) |timer| {
|
|
1581
|
+
if (timer.active) count += 1;
|
|
1582
|
+
}
|
|
1583
|
+
return count;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
pub fn timerStartCount(self: *const NullPlatform) usize {
|
|
1587
|
+
return self.timer_start_count;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
pub fn timerCancelCount(self: *const NullPlatform) usize {
|
|
1591
|
+
return self.timer_cancel_count;
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
fn findTimerIndex(self: *const NullPlatform, id: u64) ?usize {
|
|
1595
|
+
for (self.timers[0..self.timer_count], 0..) |timer, index| {
|
|
1596
|
+
if (timer.id == id) return index;
|
|
1597
|
+
}
|
|
1598
|
+
return null;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
fn emitWindowEvent(context: ?*anyopaque, window_id: WindowId, name: []const u8, detail_json: []const u8) anyerror!void {
|
|
1602
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1603
|
+
self.window_event_name = undefined;
|
|
1604
|
+
self.window_event_detail = undefined;
|
|
1605
|
+
self.window_event_window_id = window_id;
|
|
1606
|
+
self.window_event_name_len = (try copyInto(&self.window_event_name, name)).len;
|
|
1607
|
+
self.window_event_detail_len = (try copyInto(&self.window_event_detail, detail_json)).len;
|
|
1608
|
+
self.window_event_count += 1;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: GpuSurfacePixels) anyerror!void {
|
|
1612
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1613
|
+
if (!self.gpu_surfaces) return error.UnsupportedService;
|
|
1614
|
+
const view_index = self.findViewIndex(pixels.window_id, pixels.label) orelse return error.ViewNotFound;
|
|
1615
|
+
if (self.views[view_index].kind != .gpu_surface) return error.InvalidGpuSurfacePixels;
|
|
1616
|
+
const expected = pixels.expectedByteLen() orelse return error.InvalidGpuSurfacePixels;
|
|
1617
|
+
if (pixels.rgba8.len != expected) return error.InvalidGpuSurfacePixels;
|
|
1618
|
+
|
|
1619
|
+
self.gpu_surface_present_window_id = pixels.window_id;
|
|
1620
|
+
self.gpu_surface_present_label_storage = undefined;
|
|
1621
|
+
self.gpu_surface_present_label_len = (try copyInto(&self.gpu_surface_present_label_storage, pixels.label)).len;
|
|
1622
|
+
self.gpu_surface_present_width = pixels.width;
|
|
1623
|
+
self.gpu_surface_present_height = pixels.height;
|
|
1624
|
+
self.gpu_surface_present_scale_factor = pixels.scale_factor;
|
|
1625
|
+
self.gpu_surface_present_dirty_bounds = pixels.dirty_bounds;
|
|
1626
|
+
self.gpu_surface_present_byte_len = pixels.rgba8.len;
|
|
1627
|
+
self.gpu_surface_present_sample_rgba = if (pixels.rgba8.len >= 4)
|
|
1628
|
+
.{ pixels.rgba8[0], pixels.rgba8[1], pixels.rgba8[2], pixels.rgba8[3] }
|
|
1629
|
+
else
|
|
1630
|
+
.{ 0, 0, 0, 0 };
|
|
1631
|
+
self.gpu_surface_present_count += 1;
|
|
1632
|
+
self.recordGpuSurfacePresentForWindow(pixels.window_id);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
fn requestGpuSurfaceFrame(context: ?*anyopaque, window_id: WindowId, label: []const u8) anyerror!void {
|
|
1636
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1637
|
+
if (!self.gpu_surfaces) return error.UnsupportedService;
|
|
1638
|
+
const view_index = self.findViewIndex(window_id, label) orelse return error.ViewNotFound;
|
|
1639
|
+
if (self.views[view_index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
1640
|
+
|
|
1641
|
+
self.gpu_surface_frame_request_window_id = window_id;
|
|
1642
|
+
self.gpu_surface_frame_request_label_storage = undefined;
|
|
1643
|
+
self.gpu_surface_frame_request_label_len = (try copyInto(&self.gpu_surface_frame_request_label_storage, label)).len;
|
|
1644
|
+
self.gpu_surface_frame_request_count += 1;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
fn presentGpuSurfacePacket(context: ?*anyopaque, packet: GpuSurfacePacket) anyerror!void {
|
|
1648
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1649
|
+
if (!self.gpu_surfaces) return error.UnsupportedService;
|
|
1650
|
+
if (!self.gpu_surface_packets) return error.UnsupportedService;
|
|
1651
|
+
const view_index = self.findViewIndex(packet.window_id, packet.label) orelse return error.ViewNotFound;
|
|
1652
|
+
if (self.views[view_index].kind != .gpu_surface) return error.InvalidGpuSurfacePacket;
|
|
1653
|
+
if (packet.json.len == 0 or packet.json.len > max_gpu_surface_packet_json_bytes) return error.InvalidGpuSurfacePacket;
|
|
1654
|
+
|
|
1655
|
+
self.gpu_surface_packet_present_window_id = packet.window_id;
|
|
1656
|
+
self.gpu_surface_packet_present_label_storage = undefined;
|
|
1657
|
+
self.gpu_surface_packet_present_label_len = (try copyInto(&self.gpu_surface_packet_present_label_storage, packet.label)).len;
|
|
1658
|
+
self.gpu_surface_packet_present_frame_index = packet.frame_index;
|
|
1659
|
+
self.gpu_surface_packet_present_timestamp_ns = packet.timestamp_ns;
|
|
1660
|
+
self.gpu_surface_packet_present_surface_size = packet.surface_size;
|
|
1661
|
+
self.gpu_surface_packet_present_scale_factor = packet.scale_factor;
|
|
1662
|
+
self.gpu_surface_packet_present_clear_color_rgba8 = packet.clear_color_rgba8;
|
|
1663
|
+
self.gpu_surface_packet_present_requires_render = packet.requires_render;
|
|
1664
|
+
self.gpu_surface_packet_present_command_count = packet.command_count;
|
|
1665
|
+
self.gpu_surface_packet_present_cache_action_count = packet.cache_action_count;
|
|
1666
|
+
self.gpu_surface_packet_present_cached_resource_command_count = packet.cached_resource_command_count;
|
|
1667
|
+
self.gpu_surface_packet_present_unsupported_command_count = packet.unsupported_command_count;
|
|
1668
|
+
self.gpu_surface_packet_present_representable = packet.representable;
|
|
1669
|
+
self.gpu_surface_packet_present_json_len = packet.json.len;
|
|
1670
|
+
self.gpu_surface_packet_present_count += 1;
|
|
1671
|
+
self.recordGpuSurfacePresentForWindow(packet.window_id);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/// Binary-encoding twin of `presentGpuSurfacePacket`: same recorder
|
|
1675
|
+
/// fields plus the binary length and a payload prefix, gated by the
|
|
1676
|
+
/// `gpu_surface_packet_binary` toggle so tests choose which wire
|
|
1677
|
+
/// encoding a modeled host accepts.
|
|
1678
|
+
fn presentGpuSurfacePacketBinary(context: ?*anyopaque, packet: GpuSurfacePacket) anyerror!void {
|
|
1679
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1680
|
+
if (!self.gpu_surfaces) return error.UnsupportedService;
|
|
1681
|
+
if (!self.gpu_surface_packets) return error.UnsupportedService;
|
|
1682
|
+
if (!self.gpu_surface_packet_binary) return error.UnsupportedService;
|
|
1683
|
+
const view_index = self.findViewIndex(packet.window_id, packet.label) orelse return error.ViewNotFound;
|
|
1684
|
+
if (self.views[view_index].kind != .gpu_surface) return error.InvalidGpuSurfacePacket;
|
|
1685
|
+
if (packet.binary.len == 0 or packet.binary.len > types.max_gpu_surface_packet_binary_bytes) return error.InvalidGpuSurfacePacket;
|
|
1686
|
+
// Wire byte 5 is the load-action code; 3 = incremental patch. A
|
|
1687
|
+
// host modeled without retained state refuses patches, which the
|
|
1688
|
+
// runtime answers with a full keyed present in the same frame.
|
|
1689
|
+
const load_action: u8 = if (packet.binary.len > 5) packet.binary[5] else 0;
|
|
1690
|
+
if (load_action == 3 and !self.gpu_surface_packet_binary_patch) return error.UnsupportedService;
|
|
1691
|
+
|
|
1692
|
+
self.gpu_surface_packet_present_window_id = packet.window_id;
|
|
1693
|
+
self.gpu_surface_packet_present_label_storage = undefined;
|
|
1694
|
+
self.gpu_surface_packet_present_label_len = (try copyInto(&self.gpu_surface_packet_present_label_storage, packet.label)).len;
|
|
1695
|
+
self.gpu_surface_packet_present_frame_index = packet.frame_index;
|
|
1696
|
+
self.gpu_surface_packet_present_timestamp_ns = packet.timestamp_ns;
|
|
1697
|
+
self.gpu_surface_packet_present_surface_size = packet.surface_size;
|
|
1698
|
+
self.gpu_surface_packet_present_scale_factor = packet.scale_factor;
|
|
1699
|
+
self.gpu_surface_packet_present_clear_color_rgba8 = packet.clear_color_rgba8;
|
|
1700
|
+
self.gpu_surface_packet_present_requires_render = packet.requires_render;
|
|
1701
|
+
self.gpu_surface_packet_present_command_count = packet.command_count;
|
|
1702
|
+
self.gpu_surface_packet_present_cache_action_count = packet.cache_action_count;
|
|
1703
|
+
self.gpu_surface_packet_present_cached_resource_command_count = packet.cached_resource_command_count;
|
|
1704
|
+
self.gpu_surface_packet_present_unsupported_command_count = packet.unsupported_command_count;
|
|
1705
|
+
self.gpu_surface_packet_present_representable = packet.representable;
|
|
1706
|
+
self.gpu_surface_packet_present_json_len = 0;
|
|
1707
|
+
self.gpu_surface_packet_present_binary_len = packet.binary.len;
|
|
1708
|
+
const prefix_len = @min(packet.binary.len, self.gpu_surface_packet_present_binary_prefix.len);
|
|
1709
|
+
@memcpy(self.gpu_surface_packet_present_binary_prefix[0..prefix_len], packet.binary[0..prefix_len]);
|
|
1710
|
+
@memcpy(self.gpu_surface_packet_present_binary_storage[0..packet.binary.len], packet.binary);
|
|
1711
|
+
self.gpu_surface_packet_present_binary_load_action = load_action;
|
|
1712
|
+
if (load_action == 3) self.gpu_surface_packet_present_binary_patch_count += 1;
|
|
1713
|
+
self.gpu_surface_packet_present_binary_count += 1;
|
|
1714
|
+
self.gpu_surface_packet_present_count += 1;
|
|
1715
|
+
self.recordGpuSurfacePresentForWindow(packet.window_id);
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
fn uploadGpuSurfaceImage(context: ?*anyopaque, image: GpuSurfaceImagePixels) anyerror!void {
|
|
1719
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1720
|
+
if (!self.gpu_surfaces) return error.UnsupportedService;
|
|
1721
|
+
if (!self.gpu_surface_image_uploads) return error.UnsupportedService;
|
|
1722
|
+
const expected = image.expectedByteLen() orelse return error.InvalidGpuSurfaceImage;
|
|
1723
|
+
if (image.rgba8.len != expected) return error.InvalidGpuSurfaceImage;
|
|
1724
|
+
|
|
1725
|
+
const index = self.findGpuSurfaceImageIndex(image.id) orelse blk: {
|
|
1726
|
+
if (self.gpu_surface_image_count >= max_gpu_surface_images) return error.InvalidGpuSurfaceImage;
|
|
1727
|
+
const index = self.gpu_surface_image_count;
|
|
1728
|
+
self.gpu_surface_image_count += 1;
|
|
1729
|
+
break :blk index;
|
|
1730
|
+
};
|
|
1731
|
+
const sample: [4]u8 = if (image.rgba8.len >= 4)
|
|
1732
|
+
.{ image.rgba8[0], image.rgba8[1], image.rgba8[2], image.rgba8[3] }
|
|
1733
|
+
else
|
|
1734
|
+
.{ 0, 0, 0, 0 };
|
|
1735
|
+
self.gpu_surface_images[index] = .{
|
|
1736
|
+
.id = image.id,
|
|
1737
|
+
.width = image.width,
|
|
1738
|
+
.height = image.height,
|
|
1739
|
+
.byte_len = image.rgba8.len,
|
|
1740
|
+
.sample_rgba = sample,
|
|
1741
|
+
};
|
|
1742
|
+
self.gpu_surface_image_upload_id = image.id;
|
|
1743
|
+
self.gpu_surface_image_upload_width = image.width;
|
|
1744
|
+
self.gpu_surface_image_upload_height = image.height;
|
|
1745
|
+
self.gpu_surface_image_upload_byte_len = image.rgba8.len;
|
|
1746
|
+
self.gpu_surface_image_upload_sample_rgba = sample;
|
|
1747
|
+
self.gpu_surface_image_upload_count += 1;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
fn removeGpuSurfaceImage(context: ?*anyopaque, id: u64) anyerror!void {
|
|
1751
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1752
|
+
if (!self.gpu_surfaces) return error.UnsupportedService;
|
|
1753
|
+
if (!self.gpu_surface_image_uploads) return error.UnsupportedService;
|
|
1754
|
+
|
|
1755
|
+
self.gpu_surface_image_remove_id = id;
|
|
1756
|
+
self.gpu_surface_image_remove_count += 1;
|
|
1757
|
+
const index = self.findGpuSurfaceImageIndex(id) orelse return;
|
|
1758
|
+
const last = self.gpu_surface_image_count - 1;
|
|
1759
|
+
if (index != last) self.gpu_surface_images[index] = self.gpu_surface_images[last];
|
|
1760
|
+
self.gpu_surface_images[last] = .{};
|
|
1761
|
+
self.gpu_surface_image_count = last;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
/// The recorded side-channel entry for `id`, or null when the id was
|
|
1765
|
+
/// never uploaded (or has been removed) — the store a packet host
|
|
1766
|
+
/// would consult on an upload cache action.
|
|
1767
|
+
pub fn gpuSurfaceImage(self: *const NullPlatform, id: u64) ?NullGpuSurfaceImage {
|
|
1768
|
+
const index = self.findGpuSurfaceImageIndex(id) orelse return null;
|
|
1769
|
+
return self.gpu_surface_images[index];
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
fn findGpuSurfaceImageIndex(self: *const NullPlatform, id: u64) ?usize {
|
|
1773
|
+
for (self.gpu_surface_images[0..self.gpu_surface_image_count], 0..) |image, index| {
|
|
1774
|
+
if (image.id == id) return index;
|
|
1775
|
+
}
|
|
1776
|
+
return null;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
fn findWindowIndex(self: *const NullPlatform, window_id: WindowId) ?usize {
|
|
1780
|
+
for (self.windows[0..self.window_count], 0..) |window, index| {
|
|
1781
|
+
if (window.id == window_id) return index;
|
|
1782
|
+
}
|
|
1783
|
+
return null;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
fn findWebViewIndex(self: *const NullPlatform, window_id: WindowId, label: []const u8) ?usize {
|
|
1787
|
+
for (self.webviews[0..self.webview_count], 0..) |webview, index| {
|
|
1788
|
+
if (webview.open and webview.window_id == window_id and std.mem.eql(u8, webview.label, label)) return index;
|
|
1789
|
+
}
|
|
1790
|
+
return null;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
fn findViewIndex(self: *const NullPlatform, window_id: WindowId, label: []const u8) ?usize {
|
|
1794
|
+
for (self.views[0..self.view_count], 0..) |view, index| {
|
|
1795
|
+
if (view.open and view.window_id == window_id and std.mem.eql(u8, view.label, label)) return index;
|
|
1796
|
+
}
|
|
1797
|
+
return null;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
fn validateViewOptions(self: *const NullPlatform, options: ViewOptions) !void {
|
|
1801
|
+
if (self.findWindowIndex(options.window_id)) |window_index| {
|
|
1802
|
+
if (!self.windows[window_index].open) return error.WindowNotFound;
|
|
1803
|
+
} else if (options.window_id != 1) {
|
|
1804
|
+
return error.WindowNotFound;
|
|
1805
|
+
}
|
|
1806
|
+
if (options.label.len == 0) return error.InvalidViewOptions;
|
|
1807
|
+
if (options.label.len > max_view_label_bytes) return error.ViewLabelTooLarge;
|
|
1808
|
+
if (options.role.len > max_view_role_bytes) return error.ViewRoleTooLarge;
|
|
1809
|
+
if (options.accessibility_label.len > max_view_accessibility_label_bytes) return error.ViewAccessibilityLabelTooLarge;
|
|
1810
|
+
if (options.text.len > max_view_text_bytes) return error.ViewTextTooLarge;
|
|
1811
|
+
if (options.command.len > max_view_command_bytes) return error.InvalidCommand;
|
|
1812
|
+
if (!isValidViewFrame(options.frame)) return error.InvalidViewOptions;
|
|
1813
|
+
if (options.url.len > 0) return error.InvalidViewOptions;
|
|
1814
|
+
if (options.kind == .gpu_surface and !options.gpu_surface.isSupported()) return error.UnsupportedViewKind;
|
|
1815
|
+
if (options.parent) |parent| {
|
|
1816
|
+
if (parent.len == 0 or parent.len > max_view_label_bytes) return error.InvalidViewOptions;
|
|
1817
|
+
if (std.mem.eql(u8, parent, options.label)) return error.InvalidViewOptions;
|
|
1818
|
+
if (!std.mem.eql(u8, parent, "main") and self.findViewIndex(options.window_id, parent) == null and self.findWebViewIndex(options.window_id, parent) == null) return error.ViewNotFound;
|
|
1819
|
+
}
|
|
1820
|
+
if (std.mem.eql(u8, options.label, "main")) return error.DuplicateViewLabel;
|
|
1821
|
+
if (self.findWebViewIndex(options.window_id, options.label) != null) return error.DuplicateViewLabel;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
fn copyViewStrings(self: *NullPlatform, index: usize, label: []const u8, parent: ?[]const u8, role: []const u8, accessibility_label: []const u8, text: []const u8, command: []const u8) !void {
|
|
1825
|
+
self.views[index].label = try copyInto(&self.views[index].label_storage, label);
|
|
1826
|
+
self.views[index].parent = if (parent) |value| try copyInto(&self.views[index].parent_storage, value) else null;
|
|
1827
|
+
self.views[index].role = try copyInto(&self.views[index].role_storage, role);
|
|
1828
|
+
self.views[index].accessibility_label = try copyInto(&self.views[index].accessibility_label_storage, accessibility_label);
|
|
1829
|
+
self.views[index].text = try copyInto(&self.views[index].text_storage, text);
|
|
1830
|
+
self.views[index].command = try copyInto(&self.views[index].command_storage, command);
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
fn removeViewAt(self: *NullPlatform, index: usize) void {
|
|
1834
|
+
if (index >= self.view_count) return;
|
|
1835
|
+
var cursor = index;
|
|
1836
|
+
while (cursor + 1 < self.view_count) : (cursor += 1) {
|
|
1837
|
+
const next = self.views[cursor + 1];
|
|
1838
|
+
self.views[cursor] = .{
|
|
1839
|
+
.window_id = next.window_id,
|
|
1840
|
+
.kind = next.kind,
|
|
1841
|
+
.frame = next.frame,
|
|
1842
|
+
.layer = next.layer,
|
|
1843
|
+
.visible = next.visible,
|
|
1844
|
+
.enabled = next.enabled,
|
|
1845
|
+
.accessibility_label = next.accessibility_label,
|
|
1846
|
+
.command = next.command,
|
|
1847
|
+
.open = next.open,
|
|
1848
|
+
};
|
|
1849
|
+
self.copyViewStrings(cursor, next.label, next.parent, next.role, next.accessibility_label, next.text, next.command) catch unreachable;
|
|
1850
|
+
}
|
|
1851
|
+
self.view_count -= 1;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
/// Test seam: the USER closed a window. Real hosts' window
|
|
1855
|
+
/// delegates tear the native window out of their records before
|
|
1856
|
+
/// emitting the open=false frame event (macOS `windowWillClose`),
|
|
1857
|
+
/// so the fake host mirrors that — remove the window and its views
|
|
1858
|
+
/// here, then dispatch the returned event through the runtime.
|
|
1859
|
+
pub fn userCloseWindow(self: *NullPlatform, window_id: WindowId) ?Event {
|
|
1860
|
+
const index = self.findWindowIndex(window_id) orelse return null;
|
|
1861
|
+
const info = self.windows[index];
|
|
1862
|
+
self.removeViewsForWindow(window_id);
|
|
1863
|
+
self.removeWebViewsForWindow(window_id);
|
|
1864
|
+
self.removeWindowAt(index);
|
|
1865
|
+
return .{ .window_frame_changed = .{
|
|
1866
|
+
.id = info.id,
|
|
1867
|
+
.label = info.label,
|
|
1868
|
+
.title = info.title,
|
|
1869
|
+
.frame = info.frame,
|
|
1870
|
+
.scale_factor = info.scale_factor,
|
|
1871
|
+
.open = false,
|
|
1872
|
+
.focused = false,
|
|
1873
|
+
} };
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
/// Test seam: minimize calls observed for a window (the null host
|
|
1877
|
+
/// has no Dock, so the count is the pinned behavior).
|
|
1878
|
+
pub fn minimizeCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
|
|
1879
|
+
const index = self.findWindowIndex(window_id) orelse return 0;
|
|
1880
|
+
return self.window_minimize_count[index];
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
/// Test seam: model a window leaving or returning to the glass
|
|
1884
|
+
/// without a minimize verb (fully covered by another app, revealed
|
|
1885
|
+
/// again) — the occlusion fact the real hosts' spectrum gating
|
|
1886
|
+
/// reads. Minimize sets the same flag; focus clears it.
|
|
1887
|
+
pub fn setWindowOccluded(self: *NullPlatform, window_id: WindowId, occluded: bool) !void {
|
|
1888
|
+
const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
|
|
1889
|
+
self.window_occluded[index] = occluded;
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
/// Whether every open modeled window is off the glass — the
|
|
1893
|
+
/// occluded-emission rule's gate. False while ANY open window is
|
|
1894
|
+
/// unoccluded, and false with no windows at all (a window-less
|
|
1895
|
+
/// harness models an app whose display nobody took away).
|
|
1896
|
+
fn allOpenWindowsOccluded(self: *const NullPlatform) bool {
|
|
1897
|
+
var any_open = false;
|
|
1898
|
+
for (self.windows[0..self.window_count], 0..) |window, index| {
|
|
1899
|
+
if (!window.open) continue;
|
|
1900
|
+
any_open = true;
|
|
1901
|
+
if (!self.window_occluded[index]) return false;
|
|
1902
|
+
}
|
|
1903
|
+
return any_open;
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
fn removeWindowAt(self: *NullPlatform, index: usize) void {
|
|
1907
|
+
if (index >= self.window_count) return;
|
|
1908
|
+
var cursor = index;
|
|
1909
|
+
while (cursor + 1 < self.window_count) : (cursor += 1) {
|
|
1910
|
+
self.windows[cursor] = self.windows[cursor + 1];
|
|
1911
|
+
self.window_resizable[cursor] = self.window_resizable[cursor + 1];
|
|
1912
|
+
self.window_min_width[cursor] = self.window_min_width[cursor + 1];
|
|
1913
|
+
self.window_min_height[cursor] = self.window_min_height[cursor + 1];
|
|
1914
|
+
self.window_minimize_count[cursor] = self.window_minimize_count[cursor + 1];
|
|
1915
|
+
self.window_occluded[cursor] = self.window_occluded[cursor + 1];
|
|
1916
|
+
}
|
|
1917
|
+
self.window_count -= 1;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
fn removeViewsForWindow(self: *NullPlatform, window_id: WindowId) void {
|
|
1921
|
+
var index: usize = 0;
|
|
1922
|
+
while (index < self.view_count) {
|
|
1923
|
+
if (self.views[index].window_id == window_id) {
|
|
1924
|
+
self.removeViewAt(index);
|
|
1925
|
+
} else {
|
|
1926
|
+
index += 1;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
fn removeChildViewsForParent(self: *NullPlatform, window_id: WindowId, parent_label: []const u8) void {
|
|
1932
|
+
var index: usize = 0;
|
|
1933
|
+
while (index < self.view_count) {
|
|
1934
|
+
const parent = self.views[index].parent orelse {
|
|
1935
|
+
index += 1;
|
|
1936
|
+
continue;
|
|
1937
|
+
};
|
|
1938
|
+
if (self.views[index].window_id != window_id or !std.mem.eql(u8, parent, parent_label)) {
|
|
1939
|
+
index += 1;
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
var child_label_storage: [max_view_label_bytes]u8 = undefined;
|
|
1944
|
+
const child_label = copyInto(&child_label_storage, self.views[index].label) catch unreachable;
|
|
1945
|
+
self.removeChildViewsForParent(window_id, child_label);
|
|
1946
|
+
if (self.findViewIndex(window_id, child_label)) |child_index| self.removeViewAt(child_index);
|
|
1947
|
+
index = 0;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
fn removeWebViewAt(self: *NullPlatform, index: usize) void {
|
|
1952
|
+
if (index >= self.webview_count) return;
|
|
1953
|
+
var cursor = index;
|
|
1954
|
+
while (cursor + 1 < self.webview_count) : (cursor += 1) {
|
|
1955
|
+
const next = self.webviews[cursor + 1];
|
|
1956
|
+
self.webviews[cursor] = .{
|
|
1957
|
+
.window_id = next.window_id,
|
|
1958
|
+
.frame = next.frame,
|
|
1959
|
+
.layer = next.layer,
|
|
1960
|
+
.transparent = next.transparent,
|
|
1961
|
+
.bridge_enabled = next.bridge_enabled,
|
|
1962
|
+
.zoom = next.zoom,
|
|
1963
|
+
.open = next.open,
|
|
1964
|
+
};
|
|
1965
|
+
@memcpy(self.webviews[cursor].label_storage[0..next.label.len], next.label);
|
|
1966
|
+
@memcpy(self.webviews[cursor].url_storage[0..next.url.len], next.url);
|
|
1967
|
+
self.webviews[cursor].label = self.webviews[cursor].label_storage[0..next.label.len];
|
|
1968
|
+
self.webviews[cursor].url = self.webviews[cursor].url_storage[0..next.url.len];
|
|
1969
|
+
}
|
|
1970
|
+
self.webview_count -= 1;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
fn removeWebViewsForWindow(self: *NullPlatform, window_id: WindowId) void {
|
|
1974
|
+
var index: usize = 0;
|
|
1975
|
+
while (index < self.webview_count) {
|
|
1976
|
+
if (self.webviews[index].window_id == window_id) {
|
|
1977
|
+
self.removeWebViewAt(index);
|
|
1978
|
+
} else {
|
|
1979
|
+
index += 1;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
pub fn lastBridgeResponse(self: *const NullPlatform) []const u8 {
|
|
1985
|
+
return self.bridge_response[0..self.bridge_response_len];
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
pub fn lastBridgeResponseWindowId(self: *const NullPlatform) WindowId {
|
|
1989
|
+
return self.bridge_response_window_id;
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
pub fn lastBridgeResponseWebViewLabel(self: *const NullPlatform) []const u8 {
|
|
1993
|
+
return self.bridge_response_webview_label;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
pub fn lastExternalUrl(self: *const NullPlatform) []const u8 {
|
|
1997
|
+
return self.external_url[0..self.external_url_len];
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
pub fn lastRevealedPath(self: *const NullPlatform) []const u8 {
|
|
2001
|
+
return self.revealed_path[0..self.revealed_path_len];
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
pub fn lastRecentDocumentPath(self: *const NullPlatform) []const u8 {
|
|
2005
|
+
return self.recent_document_path[0..self.recent_document_path_len];
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
pub fn recentDocumentsClearedCount(self: *const NullPlatform) usize {
|
|
2009
|
+
return self.recent_documents_cleared_count;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
pub fn lastNotificationTitle(self: *const NullPlatform) []const u8 {
|
|
2013
|
+
return self.notification_title[0..self.notification_title_len];
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
pub fn lastNotificationSubtitle(self: *const NullPlatform) []const u8 {
|
|
2017
|
+
return self.notification_subtitle[0..self.notification_subtitle_len];
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
pub fn lastNotificationBody(self: *const NullPlatform) []const u8 {
|
|
2021
|
+
return self.notification_body[0..self.notification_body_len];
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
pub fn notificationCount(self: *const NullPlatform) usize {
|
|
2025
|
+
return self.notification_count;
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
pub fn lastClipboardMimeType(self: *const NullPlatform) []const u8 {
|
|
2029
|
+
return self.clipboard_mime_type[0..self.clipboard_mime_type_len];
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
pub fn lastClipboardData(self: *const NullPlatform) []const u8 {
|
|
2033
|
+
return self.clipboard_data[0..self.clipboard_data_len];
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
pub fn clipboardWriteCount(self: *const NullPlatform) usize {
|
|
2037
|
+
return self.clipboard_write_count;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
pub fn lastCredentialService(self: *const NullPlatform) []const u8 {
|
|
2041
|
+
return self.credential_service[0..self.credential_service_len];
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
pub fn lastCredentialAccount(self: *const NullPlatform) []const u8 {
|
|
2045
|
+
return self.credential_account[0..self.credential_account_len];
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
pub fn lastCredentialSecret(self: *const NullPlatform) []const u8 {
|
|
2049
|
+
return self.credential_secret[0..self.credential_secret_len];
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
pub fn credentialSetCount(self: *const NullPlatform) usize {
|
|
2053
|
+
return self.credential_set_count;
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
pub fn credentialDeleteCount(self: *const NullPlatform) usize {
|
|
2057
|
+
return self.credential_delete_count;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
pub fn lastTrayIconPath(self: *const NullPlatform) []const u8 {
|
|
2061
|
+
return self.tray_icon_path[0..self.tray_icon_path_len];
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
pub fn lastTrayTitle(self: *const NullPlatform) []const u8 {
|
|
2065
|
+
return self.tray_title[0..self.tray_title_len];
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
pub fn lastTrayTooltip(self: *const NullPlatform) []const u8 {
|
|
2069
|
+
return self.tray_tooltip[0..self.tray_tooltip_len];
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
pub fn trayItems(self: *const NullPlatform) []const TrayMenuItem {
|
|
2073
|
+
return self.tray_items[0..self.tray_item_count];
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
pub fn trayCreateCount(self: *const NullPlatform) usize {
|
|
2077
|
+
return self.tray_create_count;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
pub fn trayUpdateCount(self: *const NullPlatform) usize {
|
|
2081
|
+
return self.tray_update_count;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
pub fn trayTitleUpdateCount(self: *const NullPlatform) usize {
|
|
2085
|
+
return self.tray_title_update_count;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
pub fn trayRemoveCount(self: *const NullPlatform) usize {
|
|
2089
|
+
return self.tray_remove_count;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
pub fn lastWindowEventWindowId(self: *const NullPlatform) WindowId {
|
|
2093
|
+
return self.window_event_window_id;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
pub fn lastWindowEventName(self: *const NullPlatform) []const u8 {
|
|
2097
|
+
return self.window_event_name[0..self.window_event_name_len];
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
pub fn lastWindowEventDetail(self: *const NullPlatform) []const u8 {
|
|
2101
|
+
return self.window_event_detail[0..self.window_event_detail_len];
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
pub fn windowEventCount(self: *const NullPlatform) usize {
|
|
2105
|
+
return self.window_event_count;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
pub fn configuredShortcuts(self: *const NullPlatform) []const Shortcut {
|
|
2109
|
+
return self.shortcuts[0..self.shortcut_count];
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
pub fn configuredMenus(self: *const NullPlatform) []const Menu {
|
|
2113
|
+
return self.menus[0..self.menu_count];
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void {
|
|
2117
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
2118
|
+
if (!self.gpu_surface_scroll_drivers) return error.UnsupportedService;
|
|
2119
|
+
self.scroll_driver_set_count += 1;
|
|
2120
|
+
self.scroll_driver_window_id = window_id;
|
|
2121
|
+
const label_value = try copyInto(&self.scroll_driver_label_storage, label);
|
|
2122
|
+
self.scroll_driver_label_len = label_value.len;
|
|
2123
|
+
const count = @min(drivers.len, self.scroll_drivers.len);
|
|
2124
|
+
@memcpy(self.scroll_drivers[0..count], drivers[0..count]);
|
|
2125
|
+
self.scroll_driver_count = count;
|
|
2126
|
+
for (drivers) |driver| {
|
|
2127
|
+
if (driver.set_offset) self.scroll_driver_set_offset_count += 1;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
fn showContextMenu(context: ?*anyopaque, request: ContextMenuRequest) anyerror!void {
|
|
2132
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
2133
|
+
self.context_menu_request_count += 1;
|
|
2134
|
+
self.context_menu_window_id = request.window_id;
|
|
2135
|
+
const label_value = try copyInto(&self.context_menu_label_storage, request.view_label);
|
|
2136
|
+
self.context_menu_label_len = label_value.len;
|
|
2137
|
+
self.context_menu_point = request.point;
|
|
2138
|
+
self.context_menu_token = request.token;
|
|
2139
|
+
self.context_menu_label_bytes_len = 0;
|
|
2140
|
+
var count: usize = 0;
|
|
2141
|
+
for (request.items) |item| {
|
|
2142
|
+
if (count >= self.context_menu_items.len) break;
|
|
2143
|
+
const start = self.context_menu_label_bytes_len;
|
|
2144
|
+
const end = start + item.label.len;
|
|
2145
|
+
if (end > self.context_menu_label_bytes.len) return error.NoSpaceLeft;
|
|
2146
|
+
@memcpy(self.context_menu_label_bytes[start..end], item.label);
|
|
2147
|
+
self.context_menu_label_bytes_len = end;
|
|
2148
|
+
self.context_menu_items[count] = .{
|
|
2149
|
+
.id = item.id,
|
|
2150
|
+
.label = self.context_menu_label_bytes[start..end],
|
|
2151
|
+
.enabled = item.enabled,
|
|
2152
|
+
.separator = item.separator,
|
|
2153
|
+
};
|
|
2154
|
+
count += 1;
|
|
2155
|
+
}
|
|
2156
|
+
self.context_menu_item_count = count;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
pub fn scrollDrivers(self: *const NullPlatform) []const GpuSurfaceScrollDriver {
|
|
2160
|
+
return self.scroll_drivers[0..self.scroll_driver_count];
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
pub fn scrollDriverLabel(self: *const NullPlatform) []const u8 {
|
|
2164
|
+
return self.scroll_driver_label_storage[0..self.scroll_driver_label_len];
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
pub fn contextMenuItems(self: *const NullPlatform) []const ContextMenuItem {
|
|
2168
|
+
return self.context_menu_items[0..self.context_menu_item_count];
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
pub fn contextMenuLabel(self: *const NullPlatform) []const u8 {
|
|
2172
|
+
return self.context_menu_label_storage[0..self.context_menu_label_len];
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
|
|
2176
|
+
pub const NullWebView = struct {
|
|
2177
|
+
window_id: WindowId = 1,
|
|
2178
|
+
label: []const u8 = "",
|
|
2179
|
+
url: []const u8 = "",
|
|
2180
|
+
frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
|
|
2181
|
+
layer: i32 = 0,
|
|
2182
|
+
transparent: bool = false,
|
|
2183
|
+
bridge_enabled: bool = false,
|
|
2184
|
+
zoom: f64 = 1.0,
|
|
2185
|
+
open: bool = false,
|
|
2186
|
+
label_storage: [max_webview_label_bytes]u8 = undefined,
|
|
2187
|
+
url_storage: [max_webview_url_bytes]u8 = undefined,
|
|
2188
|
+
};
|
|
2189
|
+
|
|
2190
|
+
pub const NullView = struct {
|
|
2191
|
+
window_id: WindowId = 1,
|
|
2192
|
+
label: []const u8 = "",
|
|
2193
|
+
kind: ViewKind = .toolbar,
|
|
2194
|
+
parent: ?[]const u8 = null,
|
|
2195
|
+
frame: geometry.RectF = geometry.RectF.init(0, 0, 0, 0),
|
|
2196
|
+
layer: i32 = 0,
|
|
2197
|
+
visible: bool = true,
|
|
2198
|
+
enabled: bool = true,
|
|
2199
|
+
role: []const u8 = "",
|
|
2200
|
+
accessibility_label: []const u8 = "",
|
|
2201
|
+
text: []const u8 = "",
|
|
2202
|
+
command: []const u8 = "",
|
|
2203
|
+
gpu_size: geometry.SizeF = geometry.SizeF.init(0, 0),
|
|
2204
|
+
gpu_backend: GpuSurfaceBackend = .none,
|
|
2205
|
+
gpu_pixel_format: GpuSurfacePixelFormat = .none,
|
|
2206
|
+
gpu_present_mode: GpuSurfacePresentMode = .none,
|
|
2207
|
+
gpu_alpha_mode: GpuSurfaceAlphaMode = .none,
|
|
2208
|
+
gpu_color_space: GpuSurfaceColorSpace = .none,
|
|
2209
|
+
gpu_vsync: bool = false,
|
|
2210
|
+
gpu_status: GpuSurfaceStatus = .unavailable,
|
|
2211
|
+
open: bool = false,
|
|
2212
|
+
label_storage: [max_view_label_bytes]u8 = undefined,
|
|
2213
|
+
parent_storage: [max_view_label_bytes]u8 = undefined,
|
|
2214
|
+
role_storage: [max_view_role_bytes]u8 = undefined,
|
|
2215
|
+
accessibility_label_storage: [max_view_accessibility_label_bytes]u8 = undefined,
|
|
2216
|
+
text_storage: [max_view_text_bytes]u8 = undefined,
|
|
2217
|
+
command_storage: [max_view_command_bytes]u8 = undefined,
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
fn copyInto(buffer: []u8, value: []const u8) ![]const u8 {
|
|
2221
|
+
if (value.len > buffer.len) return error.NoSpaceLeft;
|
|
2222
|
+
@memcpy(buffer[0..value.len], value);
|
|
2223
|
+
return buffer[0..value.len];
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
fn isValidWebViewFrame(frame: geometry.RectF) bool {
|
|
2227
|
+
return frame.x >= 0 and frame.y >= 0 and frame.width > 0 and frame.height > 0;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
fn isValidViewFrame(frame: geometry.RectF) bool {
|
|
2231
|
+
return frame.x >= 0 and frame.y >= 0 and frame.width >= 0 and frame.height >= 0;
|
|
2232
|
+
}
|