@native-sdk/cli 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +50 -1
- package/build.zig +534 -3
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +280 -8
- package/packages/core/sdk/core.ts +481 -2
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1283 -66
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +16 -0
- package/src/runtime/api.zig +70 -1
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +1 -0
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +240 -24
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +473 -13
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +109 -15
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2333 -63
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +268 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -209,6 +209,59 @@ pub const max_null_audio_cached_urls: usize = 8;
|
|
|
209
209
|
/// (not a local file and not a fake-cache hit) — completing a streamed
|
|
210
210
|
/// track flips its URL into the fake cache, so the next `audioLoadUrl`
|
|
211
211
|
/// of the same URL resolves `.cache` deterministically.
|
|
212
|
+
/// Metadata table entries for the fake video player (see
|
|
213
|
+
/// `setVideoMeta`): a loaded source whose tail matches `suffix` reports
|
|
214
|
+
/// `duration_ms` and `width`x`height`. A table instead of real decoding
|
|
215
|
+
/// keeps tests hermetic — no video files, no codecs, still honest
|
|
216
|
+
/// dimensions and durations.
|
|
217
|
+
pub const max_null_video_metas: usize = 8;
|
|
218
|
+
|
|
219
|
+
pub const NullVideoMeta = struct {
|
|
220
|
+
suffix: [128]u8 = undefined,
|
|
221
|
+
suffix_len: usize = 0,
|
|
222
|
+
duration_ms: u64 = 0,
|
|
223
|
+
width: u64 = 0,
|
|
224
|
+
height: u64 = 0,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/// Every loaded video source without a table entry reports these.
|
|
228
|
+
pub const default_null_video_duration_ms: u64 = 60_000;
|
|
229
|
+
pub const default_null_video_width: u64 = 640;
|
|
230
|
+
pub const default_null_video_height: u64 = 360;
|
|
231
|
+
|
|
232
|
+
/// The fake video player's whole state: what a deterministic host would
|
|
233
|
+
/// know. Position never advances on its own — tests move it explicitly
|
|
234
|
+
/// with `advanceVideo`, mirroring `advanceAudio`. Frames never decode on
|
|
235
|
+
/// their own either: tests push synthetic RGBA8 through the captured
|
|
236
|
+
/// sink with `pushVideoFrame`, standing in for a real decode callback.
|
|
237
|
+
/// A looping player wraps at the end instead of completing.
|
|
238
|
+
pub const NullVideo = struct {
|
|
239
|
+
loaded: bool = false,
|
|
240
|
+
/// The engine-minted load token this playback echoes in every
|
|
241
|
+
/// event it emits (the real hosts' contract — see
|
|
242
|
+
/// `platform.VideoEvent.token`).
|
|
243
|
+
token: u64 = 0,
|
|
244
|
+
playing: bool = false,
|
|
245
|
+
streaming: bool = false,
|
|
246
|
+
looping: bool = false,
|
|
247
|
+
muted: bool = false,
|
|
248
|
+
position_ms: u64 = 0,
|
|
249
|
+
duration_ms: u64 = 0,
|
|
250
|
+
width: u64 = 0,
|
|
251
|
+
height: u64 = 0,
|
|
252
|
+
volume: f32 = 1.0,
|
|
253
|
+
/// The frame sink the last load handed over — where a real host's
|
|
254
|
+
/// decode callback would push pixels. Kept across pause (a paused
|
|
255
|
+
/// player keeps its claim); cleared by stop.
|
|
256
|
+
sink: types.VideoFrameSink = .{},
|
|
257
|
+
path_storage: [types.max_video_path_bytes]u8 = undefined,
|
|
258
|
+
path_len: usize = 0,
|
|
259
|
+
|
|
260
|
+
pub fn path(self: *const NullVideo) []const u8 {
|
|
261
|
+
return self.path_storage[0..self.path_len];
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
212
265
|
pub const NullAudio = struct {
|
|
213
266
|
loaded: bool = false,
|
|
214
267
|
playing: bool = false,
|
|
@@ -568,11 +621,54 @@ pub const NullPlatform = struct {
|
|
|
568
621
|
audio_stop_count: usize = 0,
|
|
569
622
|
audio_seek_count: usize = 0,
|
|
570
623
|
audio_volume_count: usize = 0,
|
|
624
|
+
/// Whether this modeled host has a video decoder. On by default (the
|
|
625
|
+
/// fake below stands in for AVFoundation); tests modelling a staged
|
|
626
|
+
/// host (Windows/Linux today) set it false BEFORE `platform()` so
|
|
627
|
+
/// every video service fn is absent, exactly like the real hosts.
|
|
628
|
+
video_playback: bool = true,
|
|
629
|
+
/// Whether the modeled filesystem holds the local video files apps
|
|
630
|
+
/// name in `videoLoad`. On by default; false models the
|
|
631
|
+
/// assets-absent machine: every local load answers
|
|
632
|
+
/// `error.VideoSourceNotFound`, which is what sends the source
|
|
633
|
+
/// cascade to the URL.
|
|
634
|
+
video_local_files: bool = true,
|
|
635
|
+
/// The deterministic fake video player: services mutate it, tests
|
|
636
|
+
/// read it and synthesize the events a live host would deliver
|
|
637
|
+
/// (`takeVideoLoaded`, `advanceVideo`), and push synthetic frames
|
|
638
|
+
/// through its captured sink (`pushVideoFrame`).
|
|
639
|
+
video: NullVideo = .{},
|
|
640
|
+
/// A `.loaded` acknowledgment waiting to be taken — set by a
|
|
641
|
+
/// successful video load, consumed by `takeVideoLoaded`.
|
|
642
|
+
video_loaded_pending: bool = false,
|
|
643
|
+
video_metas: [max_null_video_metas]NullVideoMeta = [_]NullVideoMeta{.{}} ** max_null_video_metas,
|
|
644
|
+
video_meta_count: usize = 0,
|
|
645
|
+
video_load_count: usize = 0,
|
|
646
|
+
video_load_url_count: usize = 0,
|
|
647
|
+
video_play_count: usize = 0,
|
|
648
|
+
video_pause_count: usize = 0,
|
|
649
|
+
video_stop_count: usize = 0,
|
|
650
|
+
video_seek_count: usize = 0,
|
|
651
|
+
video_volume_count: usize = 0,
|
|
652
|
+
video_muted_count: usize = 0,
|
|
653
|
+
video_loop_count: usize = 0,
|
|
571
654
|
/// Pending cross-thread wake requests. Incremented atomically because
|
|
572
655
|
/// `wake_fn` is the one service worker threads call; tests and the
|
|
573
656
|
/// embed host drain it on their own thread via `takeWake` and then
|
|
574
657
|
/// dispatch the `.wake` platform event themselves.
|
|
575
658
|
wake_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
|
|
659
|
+
/// Latched when the runtime's effects teardown abandons an in-flight
|
|
660
|
+
/// channel `wake_fn` call (see
|
|
661
|
+
/// `PlatformServices.note_channel_wake_abandoned_fn`): the stale call
|
|
662
|
+
/// still holds this platform as its context, so `deinit` must skip
|
|
663
|
+
/// destruction and leak the host, process-lived — the reference model
|
|
664
|
+
/// of the real hosts' destroy gate, and the seam channel teardown
|
|
665
|
+
/// tests observe.
|
|
666
|
+
channel_wake_abandoned: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
|
|
667
|
+
/// Whether `deinit` actually ran its destruction (the null platform
|
|
668
|
+
/// holds no OS resources, so "destruction" is this flag): stays false
|
|
669
|
+
/// when `channel_wake_abandoned` forced the deliberate leak. The
|
|
670
|
+
/// observation seam the abandon tests assert against.
|
|
671
|
+
destroyed: bool = false,
|
|
576
672
|
/// Pending cross-thread frame requests (`request_frame_fn`), counted
|
|
577
673
|
/// atomically like `wake_count`: the automation arrival watcher calls
|
|
578
674
|
/// it from its own thread, and a scripted run loop (or test) drains
|
|
@@ -592,9 +688,12 @@ pub const NullPlatform = struct {
|
|
|
592
688
|
scroll_driver_label_len: usize = 0,
|
|
593
689
|
scroll_drivers: [max_gpu_surface_scroll_drivers]GpuSurfaceScrollDriver = undefined,
|
|
594
690
|
scroll_driver_count: usize = 0,
|
|
691
|
+
scroll_occluders: [types.max_gpu_surface_scroll_occluders]types.GpuSurfaceScrollOccluder = undefined,
|
|
692
|
+
scroll_occluder_count: usize = 0,
|
|
595
693
|
scroll_driver_set_count: usize = 0,
|
|
596
|
-
/// Lifetime count of driver entries pushed with
|
|
597
|
-
/// (the runtime forcing
|
|
694
|
+
/// Lifetime count of driver entries pushed with a set-offset flag
|
|
695
|
+
/// on EITHER axis (the runtime forcing an offset into the native
|
|
696
|
+
/// scroller).
|
|
598
697
|
scroll_driver_set_offset_count: usize = 0,
|
|
599
698
|
/// Whether this modeled host presents native context menus. On by
|
|
600
699
|
/// default (the recorder below stands in for the OS menu); tests
|
|
@@ -633,6 +732,53 @@ pub const NullPlatform = struct {
|
|
|
633
732
|
return .{ .surface_value = surface_value, .web_engine = web_engine, .app_info = app_info };
|
|
634
733
|
}
|
|
635
734
|
|
|
735
|
+
/// Heap-allocate the wrapper (process allocator) and initialize it
|
|
736
|
+
/// in place — the reference model of the real hosts'
|
|
737
|
+
/// `createWithOptions`. Runners must use this over a stack
|
|
738
|
+
/// `initWithOptions` value: `platform().services.context` is this
|
|
739
|
+
/// wrapper's ADDRESS, worker threads dereference it inside the
|
|
740
|
+
/// channel wake path (the null wake counts into `wake_count`, a
|
|
741
|
+
/// wrapper field), and a wake call teardown abandons may do so at
|
|
742
|
+
/// any later time — after a runner's stack frame would have
|
|
743
|
+
/// unwound. Pair with `destroy`, the latch-gated free. Tests that
|
|
744
|
+
/// own the wrapper's lifetime themselves keep using the stack
|
|
745
|
+
/// initializers.
|
|
746
|
+
pub fn createWithOptions(surface_value: Surface, web_engine: WebEngine, app_info: AppInfo) std.mem.Allocator.Error!*NullPlatform {
|
|
747
|
+
const self = try std.heap.page_allocator.create(NullPlatform);
|
|
748
|
+
self.* = initWithOptions(surface_value, web_engine, app_info);
|
|
749
|
+
return self;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/// `deinit` plus the wrapper's own storage, gated by the same
|
|
753
|
+
/// latch: an abandoned channel wake call dereferences this wrapper
|
|
754
|
+
/// (its context) the moment it resumes, so on abandon the storage
|
|
755
|
+
/// is leaked, process-lived — deinit-gating extended to
|
|
756
|
+
/// lifetime-gating, the reference model of the real hosts'
|
|
757
|
+
/// `destroy`. No cross-thread race on the gate: the latch is set
|
|
758
|
+
/// synchronously on the loop thread during effects teardown, which
|
|
759
|
+
/// runs before the runner's deferred destroy.
|
|
760
|
+
pub fn destroy(self: *NullPlatform) void {
|
|
761
|
+
self.deinit();
|
|
762
|
+
if (self.channel_wake_abandoned.load(.seq_cst)) return;
|
|
763
|
+
std.heap.page_allocator.destroy(self);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/// The reference model of the real hosts' destroy gate (`MacPlatform`
|
|
767
|
+
/// / `LinuxPlatform` / `WindowsPlatform` `deinit`): destruction is
|
|
768
|
+
/// SKIPPED — the platform deliberately leaked, process-lived, with
|
|
769
|
+
/// one loud line — while an abandoned channel wake call may still
|
|
770
|
+
/// enter this host (see `channel_wake_abandoned`); otherwise the
|
|
771
|
+
/// `destroyed` flag records that destruction ran. The null platform
|
|
772
|
+
/// holds no OS resources, so the flag is the whole destruction —
|
|
773
|
+
/// which is exactly what makes the gate observable in tests.
|
|
774
|
+
pub fn deinit(self: *NullPlatform) void {
|
|
775
|
+
if (self.channel_wake_abandoned.load(.seq_cst)) {
|
|
776
|
+
std.debug.print("null platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it, process-lived, so the stale call stays safe\n", .{});
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
self.destroyed = true;
|
|
780
|
+
}
|
|
781
|
+
|
|
636
782
|
pub fn platform(self: *NullPlatform) Platform {
|
|
637
783
|
return .{
|
|
638
784
|
.context = self,
|
|
@@ -701,7 +847,17 @@ pub const NullPlatform = struct {
|
|
|
701
847
|
.audio_stop_fn = if (self.audio_playback) audioStop else null,
|
|
702
848
|
.audio_seek_fn = if (self.audio_playback) audioSeek else null,
|
|
703
849
|
.audio_set_volume_fn = if (self.audio_playback) audioSetVolume else null,
|
|
850
|
+
.video_load_fn = if (self.video_playback) videoLoad else null,
|
|
851
|
+
.video_load_url_fn = if (self.video_playback) videoLoadUrl else null,
|
|
852
|
+
.video_play_fn = if (self.video_playback) videoPlay else null,
|
|
853
|
+
.video_pause_fn = if (self.video_playback) videoPause else null,
|
|
854
|
+
.video_stop_fn = if (self.video_playback) videoStop else null,
|
|
855
|
+
.video_seek_fn = if (self.video_playback) videoSeek else null,
|
|
856
|
+
.video_set_volume_fn = if (self.video_playback) videoSetVolume else null,
|
|
857
|
+
.video_set_muted_fn = if (self.video_playback) videoSetMuted else null,
|
|
858
|
+
.video_set_loop_fn = if (self.video_playback) videoSetLoop else null,
|
|
704
859
|
.wake_fn = wakeService,
|
|
860
|
+
.note_channel_wake_abandoned_fn = noteChannelWakeAbandoned,
|
|
705
861
|
.request_frame_fn = requestFrameService,
|
|
706
862
|
.request_gpu_surface_frame_fn = requestGpuSurfaceFrame,
|
|
707
863
|
.present_gpu_surface_pixels_fn = presentGpuSurfacePixels,
|
|
@@ -755,6 +911,7 @@ pub const NullPlatform = struct {
|
|
|
755
911
|
.audio_playback => self.audio_playback,
|
|
756
912
|
.audio_streaming => self.audio_playback and self.audio_streaming,
|
|
757
913
|
.audio_spectrum => self.audio_playback and self.audio_spectrum,
|
|
914
|
+
.video_playback => self.video_playback,
|
|
758
915
|
};
|
|
759
916
|
}
|
|
760
917
|
|
|
@@ -1651,11 +1808,245 @@ pub const NullPlatform = struct {
|
|
|
1651
1808
|
return .{ .audio = .{ .kind = .failed } };
|
|
1652
1809
|
}
|
|
1653
1810
|
|
|
1811
|
+
fn videoLoad(context: ?*anyopaque, path: []const u8, token: u64, sink: types.VideoFrameSink) anyerror!void {
|
|
1812
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1813
|
+
self.video_load_count += 1;
|
|
1814
|
+
// Retire the previous player FIRST — the macOS host's ordering
|
|
1815
|
+
// (videoStop before the file probe): a load that then refuses
|
|
1816
|
+
// must not leave the replaced playback emitting frames and
|
|
1817
|
+
// events under its old token.
|
|
1818
|
+
const volume = self.video.volume;
|
|
1819
|
+
self.video = .{ .volume = volume };
|
|
1820
|
+
self.video_loaded_pending = false;
|
|
1821
|
+
if (path.len > self.video.path_storage.len) return error.VideoPathTooLarge;
|
|
1822
|
+
// Model the assets-absent machine: the local file is not there,
|
|
1823
|
+
// exactly the synchronous refusal a real host's open gives.
|
|
1824
|
+
if (!self.video_local_files) return error.VideoSourceNotFound;
|
|
1825
|
+
self.video = .{ .volume = volume, .sink = sink, .token = token };
|
|
1826
|
+
@memcpy(self.video.path_storage[0..path.len], path);
|
|
1827
|
+
self.video.path_len = path.len;
|
|
1828
|
+
self.video.loaded = true;
|
|
1829
|
+
self.applyVideoMeta(path);
|
|
1830
|
+
self.video_loaded_pending = true;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
fn videoLoadUrl(context: ?*anyopaque, url: []const u8, token: u64, sink: types.VideoFrameSink) anyerror!void {
|
|
1834
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1835
|
+
self.video_load_url_count += 1;
|
|
1836
|
+
// Retire-first, `videoLoad`'s ordering.
|
|
1837
|
+
const volume = self.video.volume;
|
|
1838
|
+
self.video = .{ .volume = volume };
|
|
1839
|
+
self.video_loaded_pending = false;
|
|
1840
|
+
if (url.len > self.video.path_storage.len) return error.VideoPathTooLarge;
|
|
1841
|
+
self.video = .{ .volume = volume, .sink = sink, .token = token };
|
|
1842
|
+
@memcpy(self.video.path_storage[0..url.len], url);
|
|
1843
|
+
self.video.path_len = url.len;
|
|
1844
|
+
self.video.loaded = true;
|
|
1845
|
+
self.video.streaming = true;
|
|
1846
|
+
self.applyVideoMeta(url);
|
|
1847
|
+
self.video_loaded_pending = true;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
fn videoPlay(context: ?*anyopaque) anyerror!void {
|
|
1851
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1852
|
+
self.video_play_count += 1;
|
|
1853
|
+
if (!self.video.loaded) return error.InvalidVideoOptions;
|
|
1854
|
+
self.video.playing = true;
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
fn videoPause(context: ?*anyopaque) anyerror!void {
|
|
1858
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1859
|
+
self.video_pause_count += 1;
|
|
1860
|
+
self.video.playing = false;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
fn videoStop(context: ?*anyopaque) anyerror!void {
|
|
1864
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1865
|
+
self.video_stop_count += 1;
|
|
1866
|
+
self.video = .{ .volume = self.video.volume };
|
|
1867
|
+
self.video_loaded_pending = false;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
fn videoSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
|
|
1871
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1872
|
+
self.video_seek_count += 1;
|
|
1873
|
+
if (!self.video.loaded) return error.InvalidVideoOptions;
|
|
1874
|
+
self.video.position_ms = @min(position_ms, self.video.duration_ms);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
fn videoSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
|
|
1878
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1879
|
+
self.video_volume_count += 1;
|
|
1880
|
+
self.video.volume = volume;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
fn videoSetMuted(context: ?*anyopaque, muted: bool) anyerror!void {
|
|
1884
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1885
|
+
self.video_muted_count += 1;
|
|
1886
|
+
self.video.muted = muted;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
fn videoSetLoop(context: ?*anyopaque, loop: bool) anyerror!void {
|
|
1890
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1891
|
+
self.video_loop_count += 1;
|
|
1892
|
+
self.video.looping = loop;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
fn applyVideoMeta(self: *NullPlatform, source: []const u8) void {
|
|
1896
|
+
for (self.video_metas[0..self.video_meta_count]) |entry| {
|
|
1897
|
+
const suffix = entry.suffix[0..entry.suffix_len];
|
|
1898
|
+
if (suffix.len <= source.len and std.mem.eql(u8, source[source.len - suffix.len ..], suffix)) {
|
|
1899
|
+
self.video.duration_ms = entry.duration_ms;
|
|
1900
|
+
self.video.width = entry.width;
|
|
1901
|
+
self.video.height = entry.height;
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
self.video.duration_ms = default_null_video_duration_ms;
|
|
1906
|
+
self.video.width = default_null_video_width;
|
|
1907
|
+
self.video.height = default_null_video_height;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
/// Test helper: register duration and dimensions for any loaded
|
|
1911
|
+
/// video source ending in `suffix`. Sources without a match report
|
|
1912
|
+
/// the `default_null_video_*` values.
|
|
1913
|
+
pub fn setVideoMeta(self: *NullPlatform, suffix: []const u8, duration_ms: u64, width: u64, height: u64) !void {
|
|
1914
|
+
if (suffix.len == 0 or suffix.len > 128) return error.InvalidVideoOptions;
|
|
1915
|
+
if (self.video_meta_count >= max_null_video_metas) return error.InvalidVideoOptions;
|
|
1916
|
+
var entry = &self.video_metas[self.video_meta_count];
|
|
1917
|
+
@memcpy(entry.suffix[0..suffix.len], suffix);
|
|
1918
|
+
entry.suffix_len = suffix.len;
|
|
1919
|
+
entry.duration_ms = duration_ms;
|
|
1920
|
+
entry.width = width;
|
|
1921
|
+
entry.height = height;
|
|
1922
|
+
self.video_meta_count += 1;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
/// Consume the pending video `.loaded` acknowledgment — the platform
|
|
1926
|
+
/// event a live host delivers after a successful load, carrying the
|
|
1927
|
+
/// stream's dimensions and the player's duration readout. Dispatch
|
|
1928
|
+
/// it through the runtime, like `takeAudioLoaded`.
|
|
1929
|
+
pub fn takeVideoLoaded(self: *NullPlatform) ?Event {
|
|
1930
|
+
if (!self.video_loaded_pending) return null;
|
|
1931
|
+
self.video_loaded_pending = false;
|
|
1932
|
+
return .{ .video = .{
|
|
1933
|
+
.kind = .loaded,
|
|
1934
|
+
.token = self.video.token,
|
|
1935
|
+
.position_ms = self.video.position_ms,
|
|
1936
|
+
.duration_ms = self.video.duration_ms,
|
|
1937
|
+
.playing = self.video.playing,
|
|
1938
|
+
.width = self.video.width,
|
|
1939
|
+
.height = self.video.height,
|
|
1940
|
+
} };
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/// Test helper: advance fake playback by `delta_ms` and synthesize
|
|
1944
|
+
/// the event a live host's position timer would deliver — a
|
|
1945
|
+
/// `.position` tick, or `.completed` when a non-looping video
|
|
1946
|
+
/// reaches its end. A non-looping completion unloads the player
|
|
1947
|
+
/// (retire-before-emit, the live hosts' teardown): a later
|
|
1948
|
+
/// `videoPlay`/`videoSeek` refuses exactly as it would against a
|
|
1949
|
+
/// torn-down AVPlayer, and no second completion can ever emit. A
|
|
1950
|
+
/// LOOPING player wraps past the end and keeps ticking: no
|
|
1951
|
+
/// completion, because the playback never ends. Returns null when
|
|
1952
|
+
/// nothing is loaded or playing; position never advances on its own.
|
|
1953
|
+
pub fn advanceVideo(self: *NullPlatform, delta_ms: u64) ?Event {
|
|
1954
|
+
if (!self.video.loaded or !self.video.playing) return null;
|
|
1955
|
+
// Widened, not saturated: a hostile or fuzzing advance past
|
|
1956
|
+
// u64 completes (or wraps EXACTLY, for a looping player)
|
|
1957
|
+
// instead of trapping — saturating before the loop modulo
|
|
1958
|
+
// would land the wrapped position on the wrong residue.
|
|
1959
|
+
const advanced = @as(u128, self.video.position_ms) + delta_ms;
|
|
1960
|
+
if (advanced >= self.video.duration_ms and self.video.duration_ms > 0) {
|
|
1961
|
+
if (self.video.looping) {
|
|
1962
|
+
self.video.position_ms = @intCast(advanced % self.video.duration_ms);
|
|
1963
|
+
return .{ .video = .{
|
|
1964
|
+
.kind = .position,
|
|
1965
|
+
.token = self.video.token,
|
|
1966
|
+
.position_ms = self.video.position_ms,
|
|
1967
|
+
.duration_ms = self.video.duration_ms,
|
|
1968
|
+
.playing = true,
|
|
1969
|
+
} };
|
|
1970
|
+
}
|
|
1971
|
+
const token = self.video.token;
|
|
1972
|
+
const duration_ms = self.video.duration_ms;
|
|
1973
|
+
self.video = .{ .volume = self.video.volume };
|
|
1974
|
+
self.video_loaded_pending = false;
|
|
1975
|
+
return .{ .video = .{
|
|
1976
|
+
.kind = .completed,
|
|
1977
|
+
.token = token,
|
|
1978
|
+
.position_ms = duration_ms,
|
|
1979
|
+
.duration_ms = duration_ms,
|
|
1980
|
+
.playing = false,
|
|
1981
|
+
} };
|
|
1982
|
+
}
|
|
1983
|
+
// Below the duration, so it fits u64 again by construction —
|
|
1984
|
+
// except under a zero duration (no end to reach), where the
|
|
1985
|
+
// readout saturates like a real clock display would.
|
|
1986
|
+
self.video.position_ms = if (advanced > std.math.maxInt(u64))
|
|
1987
|
+
std.math.maxInt(u64)
|
|
1988
|
+
else
|
|
1989
|
+
@intCast(advanced);
|
|
1990
|
+
return .{ .video = .{
|
|
1991
|
+
.kind = .position,
|
|
1992
|
+
.token = self.video.token,
|
|
1993
|
+
.position_ms = self.video.position_ms,
|
|
1994
|
+
.duration_ms = self.video.duration_ms,
|
|
1995
|
+
.playing = true,
|
|
1996
|
+
} };
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/// Test helper: synthesize a mid-stream stall — the `.position`
|
|
2000
|
+
/// event a live host's tick delivers while the stream waits for
|
|
2001
|
+
/// network bytes. Only a streaming playback can stall; local files
|
|
2002
|
+
/// never buffer, so anything else answers null.
|
|
2003
|
+
pub fn stallVideo(self: *NullPlatform) ?Event {
|
|
2004
|
+
if (!self.video.loaded or !self.video.playing or !self.video.streaming) return null;
|
|
2005
|
+
return .{ .video = .{
|
|
2006
|
+
.kind = .position,
|
|
2007
|
+
.token = self.video.token,
|
|
2008
|
+
.position_ms = self.video.position_ms,
|
|
2009
|
+
.duration_ms = self.video.duration_ms,
|
|
2010
|
+
.playing = true,
|
|
2011
|
+
.buffering = true,
|
|
2012
|
+
} };
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
/// Test helper: synthesize an asynchronous decode/device failure,
|
|
2016
|
+
/// the `.failed` event a live host would deliver. Unloads the
|
|
2017
|
+
/// player like a real failure would.
|
|
2018
|
+
pub fn failVideo(self: *NullPlatform) ?Event {
|
|
2019
|
+
if (!self.video.loaded) return null;
|
|
2020
|
+
const token = self.video.token;
|
|
2021
|
+
self.video = .{ .volume = self.video.volume };
|
|
2022
|
+
self.video_loaded_pending = false;
|
|
2023
|
+
return .{ .video = .{ .kind = .failed, .token = token } };
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
/// Test helper: push one synthetic RGBA8 frame through the sink the
|
|
2027
|
+
/// last load captured — the deterministic stand-in for a real
|
|
2028
|
+
/// host's decode callback delivering a converted CVPixelBuffer.
|
|
2029
|
+
/// Errors surface exactly as a real producer push would
|
|
2030
|
+
/// (`error.MediaSurfaceReleased` after the claim ended,
|
|
2031
|
+
/// `error.InvalidVideoOptions` when nothing is loaded).
|
|
2032
|
+
pub fn pushVideoFrame(self: *NullPlatform, width: usize, height: usize, rgba8: []const u8) anyerror!void {
|
|
2033
|
+
if (!self.video.loaded) return error.InvalidVideoOptions;
|
|
2034
|
+
return self.video.sink.push(width, height, rgba8);
|
|
2035
|
+
}
|
|
2036
|
+
|
|
1654
2037
|
fn wakeService(context: ?*anyopaque) anyerror!void {
|
|
1655
2038
|
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1656
2039
|
_ = self.wake_count.fetchAdd(1, .release);
|
|
1657
2040
|
}
|
|
1658
2041
|
|
|
2042
|
+
/// Teardown abandoned an in-flight channel wake call: latch the
|
|
2043
|
+
/// flag `deinit` consults so this host is leaked rather than
|
|
2044
|
+
/// destroyed (see `channel_wake_abandoned`).
|
|
2045
|
+
fn noteChannelWakeAbandoned(context: ?*anyopaque) void {
|
|
2046
|
+
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
2047
|
+
self.channel_wake_abandoned.store(true, .seq_cst);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
1659
2050
|
fn requestFrameService(context: ?*anyopaque) anyerror!void {
|
|
1660
2051
|
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
1661
2052
|
_ = self.frame_request_count.fetchAdd(1, .release);
|
|
@@ -2406,7 +2797,7 @@ pub const NullPlatform = struct {
|
|
|
2406
2797
|
return self.menus[0..self.menu_count];
|
|
2407
2798
|
}
|
|
2408
2799
|
|
|
2409
|
-
fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver) anyerror!void {
|
|
2800
|
+
fn setGpuSurfaceScrollDrivers(context: ?*anyopaque, window_id: WindowId, label: []const u8, drivers: []const GpuSurfaceScrollDriver, occluders: []const types.GpuSurfaceScrollOccluder) anyerror!void {
|
|
2410
2801
|
const self: *NullPlatform = @ptrCast(@alignCast(context.?));
|
|
2411
2802
|
if (!self.gpu_surface_scroll_drivers) return error.UnsupportedService;
|
|
2412
2803
|
self.scroll_driver_set_count += 1;
|
|
@@ -2416,8 +2807,11 @@ pub const NullPlatform = struct {
|
|
|
2416
2807
|
const count = @min(drivers.len, self.scroll_drivers.len);
|
|
2417
2808
|
@memcpy(self.scroll_drivers[0..count], drivers[0..count]);
|
|
2418
2809
|
self.scroll_driver_count = count;
|
|
2810
|
+
const occluder_count = @min(occluders.len, self.scroll_occluders.len);
|
|
2811
|
+
@memcpy(self.scroll_occluders[0..occluder_count], occluders[0..occluder_count]);
|
|
2812
|
+
self.scroll_occluder_count = occluder_count;
|
|
2419
2813
|
for (drivers) |driver| {
|
|
2420
|
-
if (driver.
|
|
2814
|
+
if (driver.set_offset_x or driver.set_offset_y) self.scroll_driver_set_offset_count += 1;
|
|
2421
2815
|
}
|
|
2422
2816
|
}
|
|
2423
2817
|
|
|
@@ -162,6 +162,41 @@ test "null platform emits deterministic lifecycle events" {
|
|
|
162
162
|
try std.testing.expectEqualStrings("app_shutdown", recorder.names[5]);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
test "the videoLoadUrl seam refuses non-http(s) schemes for every caller" {
|
|
166
|
+
// The streaming contract holds at the seam, not just behind the
|
|
167
|
+
// engine's own gated loads: hosts hand the URL to their media
|
|
168
|
+
// stack whole, and AVPlayer opens file: URLs happily.
|
|
169
|
+
var null_platform = NullPlatform.init(.{});
|
|
170
|
+
null_platform.video_playback = true;
|
|
171
|
+
const services = null_platform.platform().services;
|
|
172
|
+
const sink: types.VideoFrameSink = .{};
|
|
173
|
+
try std.testing.expectError(error.InvalidVideoOptions, services.videoLoadUrl("file:///tmp/clip.mp4", 1, sink));
|
|
174
|
+
try std.testing.expectError(error.InvalidVideoOptions, services.videoLoadUrl("ftp://media.example.test/clip.mp4", 1, sink));
|
|
175
|
+
try std.testing.expectError(error.InvalidVideoOptions, services.videoLoadUrl("not a url", 1, sink));
|
|
176
|
+
try std.testing.expectEqual(@as(usize, 0), null_platform.video_load_url_count);
|
|
177
|
+
try services.videoLoadUrl("https://media.example.test/clip.mp4", 2, sink);
|
|
178
|
+
try std.testing.expectEqual(@as(usize, 1), null_platform.video_load_url_count);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
test "a refused video load retires the player it was replacing" {
|
|
182
|
+
// The macOS host stops the previous player before the file probe,
|
|
183
|
+
// so a load that then refuses leaves NO playback behind — the null
|
|
184
|
+
// platform must model the same ordering, or a replaced player
|
|
185
|
+
// keeps emitting frames and events under its old token.
|
|
186
|
+
var null_platform = NullPlatform.init(.{});
|
|
187
|
+
null_platform.video_playback = true;
|
|
188
|
+
const services = null_platform.platform().services;
|
|
189
|
+
const sink: types.VideoFrameSink = .{};
|
|
190
|
+
try services.videoLoad("a.mp4", 1, sink);
|
|
191
|
+
try services.videoPlay();
|
|
192
|
+
try std.testing.expect(null_platform.video.playing);
|
|
193
|
+
null_platform.video_local_files = false;
|
|
194
|
+
try std.testing.expectError(error.VideoSourceNotFound, services.videoLoad("b.mp4", 2, sink));
|
|
195
|
+
try std.testing.expect(!null_platform.video.loaded);
|
|
196
|
+
try std.testing.expect(null_platform.takeVideoLoaded() == null);
|
|
197
|
+
try std.testing.expect(null_platform.advanceVideo(500) == null);
|
|
198
|
+
}
|
|
199
|
+
|
|
165
200
|
test "null platform records loaded webview source" {
|
|
166
201
|
var null_platform = NullPlatform.initWithOptions(.{}, .chromium, .{ .app_name = "Demo", .window_title = "Demo Window" });
|
|
167
202
|
try null_platform.platform().services.loadWebView(WebViewSource.html("<h1>Hello</h1>"));
|
package/src/platform/root.zig
CHANGED
|
@@ -104,6 +104,7 @@ pub const ViewInfo = types.ViewInfo;
|
|
|
104
104
|
pub const AppInfo = types.AppInfo;
|
|
105
105
|
pub const Surface = types.Surface;
|
|
106
106
|
pub const BridgeMessage = types.BridgeMessage;
|
|
107
|
+
pub const ViewFocusEvent = types.ViewFocusEvent;
|
|
107
108
|
pub const max_dialog_path_bytes = types.max_dialog_path_bytes;
|
|
108
109
|
pub const max_dialog_paths_bytes = types.max_dialog_paths_bytes;
|
|
109
110
|
pub const max_dialog_title_bytes = types.max_dialog_title_bytes;
|
|
@@ -135,16 +136,24 @@ pub const AudioLoadResolution = types.AudioLoadResolution;
|
|
|
135
136
|
pub const max_audio_path_bytes = types.max_audio_path_bytes;
|
|
136
137
|
pub const audio_spectrum_band_count = types.audio_spectrum_band_count;
|
|
137
138
|
pub const audio_spectrum_floor_db = types.audio_spectrum_floor_db;
|
|
139
|
+
pub const VideoEvent = types.VideoEvent;
|
|
140
|
+
pub const VideoEventKind = types.VideoEventKind;
|
|
141
|
+
pub const VideoFrameSink = types.VideoFrameSink;
|
|
142
|
+
pub const max_video_path_bytes = types.max_video_path_bytes;
|
|
138
143
|
pub const FileDropEvent = types.FileDropEvent;
|
|
139
144
|
pub const GpuFrame = types.GpuFrame;
|
|
140
145
|
pub const GpuSurfaceFrameEvent = types.GpuSurfaceFrameEvent;
|
|
141
146
|
pub const GpuSurfaceResizeEvent = types.GpuSurfaceResizeEvent;
|
|
142
147
|
pub const GpuSurfaceInputKind = types.GpuSurfaceInputKind;
|
|
143
148
|
pub const GpuSurfaceInputEvent = types.GpuSurfaceInputEvent;
|
|
149
|
+
pub const touch_pointer_id_bit = types.touch_pointer_id_bit;
|
|
144
150
|
pub const PinchPhase = types.PinchPhase;
|
|
145
151
|
pub const PinchEvent = types.PinchEvent;
|
|
152
|
+
pub const WheelEvent = types.WheelEvent;
|
|
146
153
|
pub const max_gpu_surface_scroll_drivers = types.max_gpu_surface_scroll_drivers;
|
|
154
|
+
pub const max_gpu_surface_scroll_occluders = types.max_gpu_surface_scroll_occluders;
|
|
147
155
|
pub const GpuSurfaceScrollDriver = types.GpuSurfaceScrollDriver;
|
|
156
|
+
pub const GpuSurfaceScrollOccluder = types.GpuSurfaceScrollOccluder;
|
|
148
157
|
pub const GpuSurfaceScrollDriverEvent = types.GpuSurfaceScrollDriverEvent;
|
|
149
158
|
pub const max_context_menu_items = types.max_context_menu_items;
|
|
150
159
|
pub const ContextMenuItem = types.ContextMenuItem;
|