@native-sdk/cli 0.5.2 → 0.5.4
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 +41 -1
- package/build.zig +264 -3
- package/native-sdk.d.ts +17 -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 +138 -3
- package/packages/core/sdk/core.ts +225 -3
- package/packages/core/sdk/events.ts +39 -2
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/emitter.ts +2625 -262
- package/packages/core/src/infer.ts +53 -7
- package/skill-data/automation/SKILL.md +7 -4
- package/skill-data/core/references/app-model-runtime.md +3 -0
- package/skill-data/native-ui/SKILL.md +4 -2
- package/skill-data/ts-core/SKILL.md +9 -1
- package/src/app_runner/root.zig +106 -1
- package/src/app_runner/ts_core_main.zig +4 -0
- package/src/automation/protocol.zig +20 -1
- package/src/embed/host.zig +27 -0
- package/src/embed/tests.zig +187 -0
- package/src/embed/ui_host.zig +4 -0
- package/src/platform/linux/gtk_host.c +112 -3
- package/src/platform/linux/root.zig +71 -0
- package/src/platform/macos/appkit_host.h +59 -2
- package/src/platform/macos/appkit_host.m +663 -34
- package/src/platform/macos/cef_host.mm +262 -10
- package/src/platform/macos/root.zig +126 -4
- package/src/platform/null_platform.zig +298 -5
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +36 -0
- package/src/platform/types.zig +247 -8
- package/src/platform/windows/root.zig +134 -0
- package/src/platform/windows/webview2_host.cpp +152 -40
- package/src/primitives/app_manifest/comptime_scene.zig +5 -0
- package/src/primitives/app_manifest/root.zig +1 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/canvas/chart.zig +7 -7
- package/src/primitives/canvas/chart_tests.zig +66 -0
- package/src/primitives/canvas/commands.zig +48 -0
- package/src/primitives/canvas/events.zig +161 -0
- package/src/primitives/canvas/font_ttf.zig +155 -8
- package/src/primitives/canvas/font_ttf_tests.zig +686 -0
- package/src/primitives/canvas/reference.zig +67 -8
- package/src/primitives/canvas/render_fingerprints.zig +8 -0
- package/src/primitives/canvas/root.zig +25 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/ui.zig +46 -9
- package/src/primitives/canvas/ui_markup.zig +82 -34
- package/src/primitives/canvas/ui_markup_binary.zig +4 -1
- package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
- package/src/primitives/canvas/ui_markup_contract.zig +10 -1
- package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
- package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
- package/src/primitives/canvas/ui_markup_tests.zig +55 -9
- package/src/primitives/canvas/ui_markup_view.zig +81 -14
- package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
- package/src/primitives/canvas/ui_schema.zig +29 -0
- package/src/primitives/canvas/ui_schema_tests.zig +11 -11
- package/src/primitives/canvas/ui_tests.zig +31 -0
- package/src/primitives/canvas/vector.zig +258 -141
- package/src/primitives/canvas/widget_access.zig +1 -1
- package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
- package/src/primitives/canvas/widget_layout.zig +9 -4
- package/src/primitives/canvas/widget_render.zig +78 -40
- package/src/primitives/canvas/widget_render_controls.zig +15 -4
- package/src/primitives/canvas/widget_semantics.zig +6 -1
- package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
- package/src/primitives/canvas/widget_text_input.zig +118 -10
- package/src/primitives/canvas/widgets.zig +16 -0
- package/src/root.zig +12 -0
- package/src/runtime/api.zig +15 -0
- package/src/runtime/automation_commands.zig +33 -0
- package/src/runtime/automation_widget_dispatch.zig +64 -0
- package/src/runtime/bridge_payload.zig +7 -0
- package/src/runtime/bridge_responses.zig +5 -0
- package/src/runtime/builtin_bridge.zig +9 -4
- package/src/runtime/canvas_font_tests.zig +711 -5
- package/src/runtime/canvas_fonts.zig +120 -25
- package/src/runtime/canvas_frame_helpers.zig +15 -0
- package/src/runtime/canvas_image_tests.zig +221 -0
- package/src/runtime/canvas_images.zig +78 -19
- package/src/runtime/canvas_limits.zig +44 -8
- package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
- package/src/runtime/canvas_widget_events.zig +24 -4
- package/src/runtime/canvas_widget_runtime.zig +24 -7
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +277 -0
- package/src/runtime/core.zig +148 -9
- package/src/runtime/effects.zig +1664 -43
- package/src/runtime/effects_fetch_tests.zig +89 -1
- package/src/runtime/effects_file_tests.zig +41 -1
- package/src/runtime/effects_image_tests.zig +1304 -0
- package/src/runtime/effects_tests.zig +153 -0
- package/src/runtime/flow.zig +44 -0
- package/src/runtime/gpu_surface_events.zig +7 -0
- package/src/runtime/media_surface.zig +726 -0
- package/src/runtime/media_surface_tests.zig +1476 -0
- package/src/runtime/root.zig +20 -0
- package/src/runtime/session_blobs.zig +689 -0
- package/src/runtime/session_journal.zig +111 -20
- package/src/runtime/session_record.zig +27 -2
- package/src/runtime/session_replay.zig +168 -16
- package/src/runtime/session_tests.zig +2118 -4
- package/src/runtime/shell_layout.zig +7 -0
- package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
- package/src/runtime/testdata/fonts/OFL.txt +93 -0
- package/src/runtime/tests.zig +3 -0
- package/src/runtime/ts_core_host.zig +439 -4
- package/src/runtime/ts_core_host_tests.zig +41 -0
- package/src/runtime/ts_ui_app.zig +63 -0
- package/src/runtime/ui_app.zig +169 -6
- package/src/runtime/ui_app_tests.zig +334 -0
- package/src/runtime/ui_app_window_tests.zig +468 -0
- package/src/runtime/window_command_bridge_tests.zig +117 -0
- package/src/runtime/window_storage.zig +32 -0
- package/src/runtime/window_views.zig +61 -1
- package/src/tooling/manifest.zig +75 -0
- package/src/tooling/raw_manifest.zig +2 -0
- package/src/tooling/templates.zig +219 -1
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// into a slot some use forces to be an integer — that is a conflict reported
|
|
24
24
|
// as a teaching error (NS1016), never a downstream Zig type error.
|
|
25
25
|
|
|
26
|
-
import { ts, TypedAst } from "./typed_ast.ts";
|
|
26
|
+
import { ts, TypedAst, exportListBindings } from "./typed_ast.ts";
|
|
27
27
|
import { constFunctionValue } from "./ownership.ts";
|
|
28
28
|
import { thrownShapeOf } from "./checker.ts";
|
|
29
29
|
import type { TypeTable } from "./types.ts";
|
|
@@ -491,15 +491,61 @@ export class IntInference {
|
|
|
491
491
|
markType("Msg");
|
|
492
492
|
// Only the ENTRY module's exports face the host ABI (the wiring and
|
|
493
493
|
// markup bind through the entry). An exported function in an imported
|
|
494
|
-
// module is an ordinary cross-module call, so proof still applies
|
|
494
|
+
// module is an ordinary cross-module call, so proof still applies —
|
|
495
|
+
// unless the entry's export list re-exports it, which puts it on the
|
|
496
|
+
// entry surface like any other export.
|
|
497
|
+
//
|
|
498
|
+
// Both export spellings mark: the inline modifier and an un-renamed
|
|
499
|
+
// export list entry (`export { pinchMsg }`) export the DECLARATION
|
|
500
|
+
// itself (the emitter's isExportedDecl seam emits them identically),
|
|
501
|
+
// so boundary classing must see them identically too. Renamed entries
|
|
502
|
+
// stay out on purpose: renamed wiring names never reach inference
|
|
503
|
+
// (the checker fences them, NS1014/NS1047), and a renamed ordinary
|
|
504
|
+
// function keeps its historical classing.
|
|
505
|
+
const entryExportedFns = new Set<ts.FunctionDeclaration>();
|
|
495
506
|
for (const stmt of this.files[0].statements) {
|
|
496
507
|
if (ts.isFunctionDeclaration(stmt) && stmt.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
|
|
508
|
+
entryExportedFns.add(stmt);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
for (const b of exportListBindings(this.tast, this.files[0])) {
|
|
512
|
+
if (!b.renamed && b.target && ts.isFunctionDeclaration(b.target)) entryExportedFns.add(b.target);
|
|
513
|
+
}
|
|
514
|
+
for (const stmt of entryExportedFns) {
|
|
515
|
+
for (const p of stmt.parameters) {
|
|
516
|
+
const slot = this.slots.get(p);
|
|
517
|
+
if (slot) {
|
|
518
|
+
slot.external = true;
|
|
519
|
+
slot.hostBoundary = true;
|
|
520
|
+
slot.proven = false;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
// The pinch channel's parameter record is intrinsically
|
|
524
|
+
// fractional: magnification deltas are ~0.01..0.3 per event and
|
|
525
|
+
// the pointer anchor is sub-point, so its number fields are HOST
|
|
526
|
+
// values, never provable integers. Marking them boundary-fed
|
|
527
|
+
// keeps a core's `pinch.scale === 0` comparison from
|
|
528
|
+
// int-claiming the slot (which would round every zoom product
|
|
529
|
+
// to whole numbers); the integer side of such a comparison
|
|
530
|
+
// widens to f64 instead. The loop marks EVERY field of the
|
|
531
|
+
// record, so any field the channel grows (windowId, the source
|
|
532
|
+
// identity, included) is boundary-classed without a new rule.
|
|
533
|
+
// frameMsg/keyMsg records keep their historical by-usage
|
|
534
|
+
// classing.
|
|
535
|
+
if (stmt.name?.text === "pinchMsg") {
|
|
497
536
|
for (const p of stmt.parameters) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
537
|
+
if (!p.type) continue;
|
|
538
|
+
const t = this.table.resolveTypeNode(p.type);
|
|
539
|
+
if (t.k !== "struct") continue;
|
|
540
|
+
const struct = this.table.structs.get(t.name);
|
|
541
|
+
if (!struct) continue;
|
|
542
|
+
for (const f of struct.fields) {
|
|
543
|
+
const slot = this.slots.get(f.decl);
|
|
544
|
+
if (slot) {
|
|
545
|
+
slot.external = true;
|
|
546
|
+
slot.hostBoundary = true;
|
|
547
|
+
slot.proven = false;
|
|
548
|
+
}
|
|
503
549
|
}
|
|
504
550
|
}
|
|
505
551
|
}
|
|
@@ -71,6 +71,8 @@ native automate widget-drag canvas 4 0.25 0.82
|
|
|
71
71
|
native automate widget-wheel canvas 5 18
|
|
72
72
|
native automate widget-key canvas tab
|
|
73
73
|
native automate widget-key canvas cmd+c
|
|
74
|
+
native automate widget-pinch canvas 1.5
|
|
75
|
+
native automate widget-pinch canvas 0.5 120 80
|
|
74
76
|
native automate profile on
|
|
75
77
|
native automate profile off
|
|
76
78
|
native automate bridge '{"id":"smoke","command":"native.ping","payload":{"source":"automation"}}'
|
|
@@ -113,10 +115,11 @@ Semantics:
|
|
|
113
115
|
8. Use `native automate widget-drag <view-label> <widget-id> <start-x-ratio> <end-x-ratio> [start-y-ratio end-y-ratio]` for continuous pointer controls.
|
|
114
116
|
9. Use `native automate widget-wheel <view-label> <widget-id> <delta-y>` for retained widget scroll input. Wheel targets must be interactive/scrollable widgets — a plain layout column or text node is not a wheel target; aim at the scroll/list widget id from the snapshot. Failures land in the snapshot as named reasons: `error event=automation.widget_wheel name=WheelTargetUnknown|WheelTargetNotInteractive|WheelTargetHasEmptyBounds detail="<command args>"`.
|
|
115
117
|
10. Use `native automate widget-key <view-label> <key> [text]` for focused retained widget keyboard input. The key accepts modifier chords — `cmd+a`, `cmd+c`, `cmd+v`, `cmd+x`, `ctrl+shift+arrowleft` (`cmd` sets the primary shortcut modifier on every platform) — so select-all/copy/cut/paste and shift-extended selection are drivable; after a copy, widget lines in the snapshot show the live selection as `selection=a..b`, and the copied text lands on the real system clipboard (`pbpaste` on macOS).
|
|
116
|
-
11. Use `native automate
|
|
117
|
-
12. Use `native automate
|
|
118
|
-
13. Use `native automate
|
|
119
|
-
14. Use `native automate
|
|
118
|
+
11. Use `native automate widget-pinch <view-label> <scale> [x y]` for trackpad pinch gestures against a gpu-surface view: the runtime dispatches the real `pinch_begin`/`pinch_change`/`pinch_end` platform events, with one change carrying `scale - 1`. `<scale>` is the FINAL multiplicative zoom for the gesture — the cumulative gesture scale (the product of `1 + delta`) lands exactly on it — `1.5` zooms in 50%, `0.5` zooms out to half. The optional anchor point is view-local points, defaulting to the view center. Apps hear it through the pinch channel (`Options.on_pinch` / the TS core's `pinchMsg`).
|
|
119
|
+
12. Use `native automate screenshot <view-label> [scale]` to capture the named `gpu_surface` view's canvas as `screenshot-<view-label>.png` (the CLI prints the artifact path and waits for the file).
|
|
120
|
+
13. Use `native automate tray-action <item-id>` to select a status-item dropdown row through the same platform event a real menu-bar click emits (command dispatch with source `.tray`). The live tray is visible in `snapshot.txt` as a `tray title="..." items=N` line followed by ` tray-item #id label="..." command="..." enabled=...` rows — the macOS menu bar is outside every window capture, so the snapshot is the only automation evidence the model-driven tray exists, and the `#id` there is what `tray-action` takes. Unknown ids degrade into the dispatch-error ring as `automation.tray_action`.
|
|
121
|
+
14. Use `native automate reload` to request a WebView reload.
|
|
122
|
+
15. Use `native automate profile on` to enable per-stage frame timing: while on, `snapshot.txt` carries a `frame_profile` line with rolling p50/p90/max microseconds per pipeline stage (`rebuild`, `layout`, `reconcile`, `emit`, `a11y`, `plan`, `patch`, `encode`, `present`, `host_decode`, `host_draw`), each with a lifetime sample count (`<stage>_n=`). Drive some interactions, then `native automate snapshot | grep -o 'frame_profile.*'` to read where frame time goes; `profile off` stops recording and drops the line. Turning it on starts a fresh sample window.
|
|
120
123
|
|
|
121
124
|
## Screenshots
|
|
122
125
|
|
|
@@ -111,6 +111,7 @@ Use `EmbeddedApp` when another host owns the main loop:
|
|
|
111
111
|
|
|
112
112
|
```zig
|
|
113
113
|
var embedded = native_sdk.embed.EmbeddedApp.init(my_app.app(), my_platform);
|
|
114
|
+
defer embedded.deinit();
|
|
114
115
|
try embedded.start();
|
|
115
116
|
try embedded.frame();
|
|
116
117
|
try embedded.resize(new_surface);
|
|
@@ -119,6 +120,8 @@ try embedded.stop();
|
|
|
119
120
|
|
|
120
121
|
This is useful for mobile hosts, game engines, custom render loops, and headless tests. The repository includes iOS and Android examples that link `libnative-sdk.a` through Swift/Kotlin host apps.
|
|
121
122
|
|
|
123
|
+
`stop()` tells the app it is shutting down; `deinit()` releases what the embedded runtime owns on the heap (registered canvas font bytes). It is idempotent, so `defer embedded.deinit()` right after `init` is the idiom — an embedder that creates and destroys apps in one process leaks the font registry per cycle without it. The C ABI's `native_sdk_app_destroy` runs the same deinit through its host wrapper.
|
|
124
|
+
|
|
122
125
|
## Headless tests
|
|
123
126
|
|
|
124
127
|
Use `NullPlatform` or `TestHarness` when GUI behavior is not required:
|
|
@@ -180,6 +180,8 @@ Automation drives the native path honestly: snapshots list every widget's declar
|
|
|
180
180
|
| `separator`, `spacer` | separator, flexible space | `separator` is axis-aware: a horizontal rule in a `column`, a thin vertical divider in a `row`; give `spacer` a `grow` |
|
|
181
181
|
| `skeleton`, `spinner` | loading leaves | size `skeleton` with `width`/`height` |
|
|
182
182
|
| `icon` | vector icon leaf | `name` picks the icon: a bare literal is a curated built-in stroke icon (compile-checked; 49 names: search, plus, x, x-circle, check, check-circle, chevron-up/down/left/right, arrow-up/down/right, menu, panel-left, panel-right, settings, terminal, wrench, trash, edit, copy, external-link, play, pause, skip-back/forward, shuffle, repeat, music, volume, info, alert, download, save, folder, folder-open, file-text, sun, moon, eye, clock, git-pull-request, git-merge, git-branch, circle-dot, archive, refresh-cw, send); `app:<name>` reaches an icon the app registered at boot with `canvas.icons.registerAppIcons` (declare the table as `pub const app_icons` on the app root so `native check` verifies the name against the model contract), and one `{binding}` defers the choice to model data - an unknown resolved name draws the missing-icon fallback (a slashed circle) with a Debug warning naming the value, never a silent gap; tint with `foreground`, size with `width`/`height` |
|
|
183
|
+
| `media-surface` | media surface leaf | composites a texture produced OUTSIDE the widget tree (video decoder, camera, an external renderer like mpv) into the layout like any widget — clipped, z-ordered, rounded. `surface="{binding}"` (required) binds the model-owned u64 surface id a Zig-tier producer targets (`runtime.acquireMediaSurfaceProducer` pushes RGBA8 frames, latest-wins, paced by the presented-frame clock; 0 = unbound, draws nothing; usable ids are nonzero values below the reserved bit 63). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content). Texture contents are presentation chrome: goldens, reference screenshots, and session replay show the deterministic id-derived placeholder, never producer frames |
|
|
184
|
+
| `image` | runtime image leaf | draws a RUNTIME-REGISTERED image by its model-owned u64 ImageId — the id `Cmd.imageLoad` (TS) or `fx.loadImage`/`fx.registerImageBytes` (Zig) registered pixels under. `image="{binding}"` (required) binds a model field/fn; ids are model data, never markup literals, and 0 draws nothing (store the id only when the load reports loaded — see the Images section). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content) |
|
|
183
185
|
| `markdown` | rendered markdown subtree | leaf; `source` is one `{binding}` — see "Markdown in markup" |
|
|
184
186
|
| `stepper` > `step` | composite stage track | `active="{index}"` (required) derives each step's completed/active/pending state; steps are text leaves (no attributes) joined by connectors; stepper also takes `key`, `global-key`, `label` |
|
|
185
187
|
| `timeline` > `timeline-item` | composite ledger list | items only inside a timeline (for/if fine); items are leaves — `title` (required), `description`, `meta`, `indicator`, `variant`, `connector="false"` on the last item, `selected`; `on-press` makes the whole item pressable with a trailing chevron |
|
|
@@ -187,7 +189,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
|
|
|
187
189
|
| `context-menu` | consumed by its parent | right-click menu on its DIRECT parent (a hit target or an element with `on-press`/`on-hold`); metadata, never a flow child. Children: `menu-item`s (`on-press` required, `disabled` optional, no `icon`) and bare `separator`s, with `if`/`else`/`for` around them. Attribute-less; presents natively where the host has a menu presenter, as an anchored surface elsewhere — see "Context menus" |
|
|
188
190
|
| `input-group` > `textarea` + `input-group-actions` | composite grouped input | the composer shape: ONE bordered field wrapping exactly one `textarea` (first — document order is focus order) plus an optional `input-group-actions` row of controls inside the same border. The group wears the focus ring for its focused descendant and the textarea's own chrome dissolves automatically, so the whole group reads as one field; the textarea keeps its full behavior (`text`, `placeholder`, `on-input`, `on-submit`, `autofocus`). Group takes `label`, `width`, `height`, `min-width`, `grow`, `key`, `global-key`; the actions row takes `gap` and holds ordinary elements (`if`/`else`/`for` work — swap send for stop while streaming) — put a `<spacer grow="1"/>` between leading and trailing controls (`Ui.inputGroup`/`Ui.inputGroupActions` are the Zig-view equivalents) |
|
|
189
191
|
|
|
190
|
-
Not markup-expressible (deliberately — write these as Zig view functions with `canvas.Ui`): `
|
|
192
|
+
Not markup-expressible (deliberately — write these as Zig view functions with `canvas.Ui`): `icon_button` (`<button icon="...">` with empty content is the declarative icon button), `data_grid` (per-column cell templates), `popover`/`menu_surface` (anchored to runtime geometry), `segmented_control` (use `tabs`/`toggle-group`: `<button>` children of `<tabs>` lower to segmented triggers automatically, so the active tab lifts per the house treatment). Charts ARE expressible: `<chart>` with `<series values="{binding}">` children binding model f32 iterables — see the Charts section (`.band` series and dynamic series composition stay with `ui.chart`). Built-in vector icons ARE expressible: `<icon name="search"/>` (closed, compile-checked name set; `Ui.icon` is the Zig-view equivalent). App-authored icons: `canvas.svg_icon.parseComptime(@embedFile("icons/logo.svg"))` parses any SVG in the common 24x24 stroke-icon dialect at comptime; register the parsed table once at boot with `canvas.icons.registerAppIcons(&table)` and draw by name via `ui.appIcon(.{...}, "logo")` or `ElementOptions.icon` — registered names render exactly like built-ins on every draw path. Markup `<icon>`/`<button icon>` stay built-in-only (the compiled engine validates names at comptime, where runtime registrations cannot exist — engine parity). Runtime images ARE expressible: `<image image="{cover}" width="120" height="80" label="Cover art"/>` and `<avatar image="{user_image}">CT</avatar>` bind a `u64` ImageId model field/fn (the id is just model data; 0 draws nothing / keeps the initials fallback) — see the Images section; the `image` binding is required on the leaf (an unbound `<image>` is dead markup) and stays avatar+image scoped.
|
|
191
193
|
|
|
192
194
|
## Attributes
|
|
193
195
|
|
|
@@ -1063,7 +1065,7 @@ Tests that touch files or clocks get their `Io` from `std.testing.io`. The full
|
|
|
1063
1065
|
|
|
1064
1066
|
## Validate without building
|
|
1065
1067
|
|
|
1066
|
-
`native markup check src/view.native` — instant grammar/structure validation with `file:line:column` errors, including the font-coverage tofu guard: literal text with a codepoint outside the bundled face (⌘, ✓, ⑂, dingbats, CJK) is a teaching error naming the character, because it renders as a tofu box on the reference/screenshot and mobile paths — use a vector icon (`icon=` / `<icon name>`) or plain words. Dynamic strings get the same lesson as a Debug-build `zero_canvas_ui` diagnostic when the view builds. The accessibility lint rides the same pass: unnamed interactive controls and role misuse are errors, unnamed images and redundant labels are warnings (`--strict` promotes).
|
|
1068
|
+
`native markup check src/view.native` — instant grammar/structure validation with `file:line:column` errors, including the font-coverage tofu guard: literal text with a codepoint outside the bundled face (⌘, ✓, ⑂, dingbats, CJK) is a teaching error naming the character, because it renders as a tofu box on the reference/screenshot and mobile paths — register a font that covers it (`UiApp.Options.fonts`) and bind the text from the model (the guard skips `{bindings}`), or use a vector icon (`icon=` / `<icon name>`) or plain words. Dynamic strings get the same lesson as a Debug-build `zero_canvas_ui` diagnostic when the view builds. The accessibility lint rides the same pass: unnamed interactive controls and role misuse are errors, unnamed images and redundant labels are warnings (`--strict` promotes).
|
|
1067
1069
|
|
|
1068
1070
|
The model side checks at check time too: the model-contract step (refreshed by `native test`, or run directly as `zig build model-contract` in an app that owns its build) reflects Model/Msg into `zig-out/model-contract.zon`, and `native check` (or `markup check` run in the app directory) then verifies every binding path, iterable, `key` field, message tag, payload type, and expression type against the app's real surface — did-you-mean over your actual field names, and type errors naming the field's Zig type. It also WARNS on model state and Msg tags no view uses; opt update-only names out with `pub const view_unbound = .{ "next_id" };` on Model or Msg (`--strict` turns the warnings into failures) — state consumed only by a Zig-BUILT view needs `view_unbound` too, because the markup checker cannot see Zig view reads. A stale artifact degrades to grammar-only checking with a loud note ("model contract: not yet built - bindings checked structurally only; run `native test` to enable typed checks"); binding paths and message tags are always re-enforced when the app builds (and on hot reload).
|
|
1069
1071
|
|
|
@@ -121,7 +121,7 @@ export function update(model: Model, msg: Msg): Model | [Model, Cmd<Msg>] {
|
|
|
121
121
|
}
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
The command set (Cmd wire format
|
|
124
|
+
The command set (Cmd wire format v3):
|
|
125
125
|
|
|
126
126
|
- `Cmd.none` — no effects; returning a bare `Model` is sugar for `[model, Cmd.none]`.
|
|
127
127
|
- `Cmd.persist()` — ask the host to persist the committed model.
|
|
@@ -154,6 +154,14 @@ Two effect families deliver MANY results from one command — a keyed stream the
|
|
|
154
154
|
- `Cmd.audioPlay(key, { path?, url?, cachePath?, expectedBytes? }, { event })` — open the audio event stream. One player is the whole surface, so a new `audioPlay` always REPLACES the current playback (the one key-reuse exception besides `Cmd.request`). The source cascade is the engine's: the local `path` is tried first, a missing file falls through to `url` (streamed progressively, cached at `cachePath` when given, integrity-gated by `expectedBytes` — omitted/0 means unknown size). At least one of `path`/`url` is required (NS1029); each is bytes, at most 1 KiB (NS1030). Prefer OMITTING `cachePath` for URL sources: when the app wiring configures a caches directory (`TsUiApp`'s `audio_cache_dir`), the host derives the conventional content-addressed cache path from the URL itself — your update never builds filesystem paths, and replay re-derives the same path by construction. Pass `cachePath` only to override that convention.
|
|
155
155
|
- The `event` arm is the one SDK-fixed record shape, six fields matched by NAME: `state` (the `AudioState` string-literal union — import it from `@native-sdk/core/events`, or declare an alias with exactly the members `"loaded" | "position" | "completed" | "failed" | "rejected" | "spectrum"` in any order; the runtime matches members by name), `positionMs: number`, `durationMs: number` (milliseconds; the duration is the player's estimate), `playing: boolean`, `buffering: boolean` (true while a streamed url is stalled waiting for bytes), and `bands: Uint8Array` (the 32 spectrum band magnitudes, 0–255 each, all zeros outside `"spectrum"` events). Every playback event dispatches this arm — `"failed"` (unplayable source, decode/device failure) and `"rejected"` (an empty or over-long source) included, so failure is never silence — until `Cmd.audioStop` closes the stream. `"completed"` fires once at the natural end and does NOT close the stream: starting the next track from it is the idiom.
|
|
156
156
|
- `Cmd.audioPause(key)` / `Cmd.audioResume(key)` / `Cmd.audioStop(key)` / `Cmd.audioSeek(key, ms)` / `Cmd.audioSetVolume(key, volume)` — fire-and-forget control verbs: no result of their own; their consequences arrive on the event stream (`audioResume` on a dead player reports one `"failed"` event, never silence). A verb whose key names no open stream is a no-op. `audioStop` is the audio stream's close — no events for the key after it (`Cmd.cancel` does not apply to audio). Volume is clamped 0..1 and remembered across tracks; a literal outside 0..1 (or a negative seek literal) stops the build (NS1030).
|
|
157
|
+
- `Cmd.imageLoad(id, { path?, url?, cachePath?, expectedBytes? }, { event })` — load an image at runtime under the model-owned NUMERIC ImageId your markup binds (`<image image="{cover}"/>`, `<avatar image="{avatar}"/>`); `id` may be any number expression (ids are model data), a positive integer below 2^53 (a certain-to-be-refused literal like 0 stops the build, NS1030). The source cascade is `audioPlay`'s exactly: local `path` first, a missing file falls through to `url` (fetched whole, installed at the cache path and integrity-gated by `expectedBytes`); at least one of `path`/`url` (NS1029), and prefer OMITTING `cachePath` — the wiring's caches directory (`TsUiApp`'s `image_cache_dir`) derives the content-addressed path from the URL. Exactly ONE `event` arm dispatches per load — a five-field record matched by NAME: `id` (the requested ImageId echoed verbatim, so concurrent loads sharing one arm stay distinguishable; an id the wire cannot carry exactly echoes 0), `state` (the `ImageState` union — exactly the fifteen members `"loaded" | "rejected" | "not_found" | "io_failed" | "connect_failed" | "tls_failed" | "protocol_failed" | "timed_out" | "http_status" | "cancelled" | "too_large" | "unsupported" | "decode_failed" | "registry_full" | "alloc_failed"`, any order; `"alloc_failed"` is resource exhaustion at registration — the host refused the memory, the bytes may be fine, retry when memory frees), `width`/`height` (the decoded dimensions on `"loaded"`, 0 otherwise), and `status` (the HTTP status for url loads that performed an exchange; 0 when none occurred — local paths, cache hits — so a cached `"loaded"` is distinguishable from a network one). On `"loaded"` the pixels are already registered under the id — store the id in the model then (the store-on-success discipline keeps a fallback rendering until the load lands). One load per id at a time: a duplicate live id dispatches `"rejected"` (the spawn discipline — a load in flight is never replaced implicitly), and image loads are not the string-keyed `Cmd.cancel`'s to end — `Cmd.imageCancel(id)` is their cancel, LOUD like spawn's: the one terminal still arrives as the event arm's `"cancelled"`, and the id frees for a fresh load once it lands (an id with no live load no-ops; the same NS1030 literal gate as `imageLoad`). Decode limits are the registered-image limits (16 slots, 1 MiB decoded pixels — avatar/cover scale, not photo scale); the encoded source bound is 1.25 MiB, and over-bound sources fail whole with `"too_large"`, never cut. `Cmd.imageUnregister(id)` releases a loaded image's registry slot — the gallery eviction move when the 17th distinct image would answer `"registry_full"`: views bound to the id fall back, and the slot accepts the next load. Unregister is synchronous registry surgery, NOT an effect — no result Msg, an unregistered id no-ops (the same NS1030 literal gate) — and it frees only the CURRENT registration: a load in flight under the id still registers at its terminal, so cancel the load first (`Cmd.imageCancel`) to keep the slot free.
|
|
158
|
+
|
|
159
|
+
### The window verbs
|
|
160
|
+
|
|
161
|
+
The menu-bar lifecycle pair — fire-and-forget, no routing and no result Msg (the window's own frame event carries the resulting state):
|
|
162
|
+
|
|
163
|
+
- `Cmd.showWindow(label)` — un-hide + activate the window with the declared label (a string literal — window labels are declarations, in `app.zon` or a `windows_fn` descriptor): the counterpart to a `close_policy = "hide"` close and the tray "Open" consequence; also restores a minimized window. An unknown label is a no-op.
|
|
164
|
+
- `Cmd.quitApp()` — the graceful terminate, and the tray "Quit" consequence: the host quits through the SAME shutdown path a last-window close takes, so the stop hook runs exactly once and a recording session seals its journal.
|
|
157
165
|
|
|
158
166
|
Commands are constructed inline in the return path and nowhere else (NS1017): never in the Model or a Msg, never in a local, never in a helper. This is what keeps effects inside the dispatch cycle and replay honest.
|
|
159
167
|
|
package/src/app_runner/root.zig
CHANGED
|
@@ -64,6 +64,7 @@ pub const RunOptions = struct {
|
|
|
64
64
|
.version = manifestStringField("version"),
|
|
65
65
|
.description = manifestStringField("description"),
|
|
66
66
|
.has_web_content = manifestHasWebContent(),
|
|
67
|
+
.declares_tray = manifestDeclaresTrayCapability(),
|
|
67
68
|
.window_title = self.window_title,
|
|
68
69
|
.bundle_id = self.bundle_id,
|
|
69
70
|
.icon_path = self.icon_path,
|
|
@@ -96,6 +97,9 @@ pub const RunOptions = struct {
|
|
|
96
97
|
// enforced floor is host state from the first frame on.
|
|
97
98
|
info.main_window.min_width = manifestShellStartupMinSize("min_width");
|
|
98
99
|
info.main_window.min_height = manifestShellStartupMinSize("min_height");
|
|
100
|
+
// Close handling is host window state like the titlebar:
|
|
101
|
+
// the manifest's declaration rides the host create.
|
|
102
|
+
info.main_window.close_policy = manifestShellStartupClosePolicy();
|
|
99
103
|
}
|
|
100
104
|
return info;
|
|
101
105
|
}
|
|
@@ -156,6 +160,7 @@ fn manifestWindow(comptime window: anytype, comptime index: usize) native_sdk.Wi
|
|
|
156
160
|
.titlebar = windowTitlebarStyle(window),
|
|
157
161
|
.min_width = windowMinSize(window, "min_width"),
|
|
158
162
|
.min_height = windowMinSize(window, "min_height"),
|
|
163
|
+
.close_policy = windowClosePolicy(window),
|
|
159
164
|
};
|
|
160
165
|
}
|
|
161
166
|
|
|
@@ -202,6 +207,17 @@ fn manifestShellStartupResizable() bool {
|
|
|
202
207
|
return windowBool(shell.windows[0], "resizable", true);
|
|
203
208
|
}
|
|
204
209
|
|
|
210
|
+
/// The startup window's close policy for scene-first apps: app.zon's
|
|
211
|
+
/// `.shell.windows[0].close_policy`. Like the titlebar, close handling
|
|
212
|
+
/// is host window state fixed at create time.
|
|
213
|
+
fn manifestShellStartupClosePolicy() native_sdk.WindowClosePolicy {
|
|
214
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .quit;
|
|
215
|
+
const shell = app_manifest.shell;
|
|
216
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return .quit;
|
|
217
|
+
if (comptime shell.windows.len == 0) return .quit;
|
|
218
|
+
return windowClosePolicy(shell.windows[0]);
|
|
219
|
+
}
|
|
220
|
+
|
|
205
221
|
/// The startup window's content min-size floor for scene-first apps:
|
|
206
222
|
/// app.zon's `.shell.windows[0].min_width`/`.min_height` (0 = none).
|
|
207
223
|
fn manifestShellStartupMinSize(comptime field: []const u8) f32 {
|
|
@@ -358,6 +374,42 @@ fn windowRestorePolicy(comptime window: anytype) native_sdk.WindowRestorePolicy
|
|
|
358
374
|
@compileError("unknown app.zon window restore_policy");
|
|
359
375
|
}
|
|
360
376
|
|
|
377
|
+
/// What the window's close affordance does, from app.zon. `.hide` is
|
|
378
|
+
/// validated against the TARGET platform at comptime: a host with no
|
|
379
|
+
/// affordance to bring a hidden window back (GTK has no status item;
|
|
380
|
+
/// windows without a declared tray, since hiding removes the taskbar
|
|
381
|
+
/// entry and windows has no dock) refuses the declaration here, at
|
|
382
|
+
/// build time, instead of stranding a hidden window at runtime.
|
|
383
|
+
fn windowClosePolicy(comptime window: anytype) native_sdk.WindowClosePolicy {
|
|
384
|
+
if (comptime !@hasField(@TypeOf(window), "close_policy")) return .quit;
|
|
385
|
+
const value = window.close_policy;
|
|
386
|
+
if (comptime std.mem.eql(u8, value, "quit")) return .quit;
|
|
387
|
+
if (comptime std.mem.eql(u8, value, "hide")) {
|
|
388
|
+
if (comptime std.mem.eql(u8, build_options.platform, "linux")) {
|
|
389
|
+
@compileError("app.zon window close_policy \"hide\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \"quit\" (the default), or scope the .hide declaration to macos/windows builds");
|
|
390
|
+
}
|
|
391
|
+
if (comptime std.mem.eql(u8, build_options.platform, "windows")) {
|
|
392
|
+
if (comptime !manifestDeclaresTrayCapability()) {
|
|
393
|
+
@compileError("app.zon window close_policy \"hide\" on windows requires the \"tray\" capability: hiding removes the taskbar entry and windows has no dock-reopen path, so only a status item (tray) could bring the hidden window back - add \"tray\" to .capabilities and install a status item, or declare \"quit\" (the default); macos needs no capability because the dock reopen path always exists");
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return .hide;
|
|
397
|
+
}
|
|
398
|
+
@compileError("unknown app.zon window close_policy - supported values: \"quit\" (close really closes; the default) and \"hide\" (the menu-bar-app shape: close hides the window and the app keeps running)");
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/// Whether app.zon declares the "tray" capability — the status item
|
|
402
|
+
/// `.hide` leans on where the OS has no built-in re-show affordance.
|
|
403
|
+
/// Evaluated at comptime over the manifest import, like the web scan.
|
|
404
|
+
fn manifestDeclaresTrayCapability() bool {
|
|
405
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
|
|
406
|
+
inline for (app_manifest.capabilities) |capability| {
|
|
407
|
+
const name: []const u8 = capability;
|
|
408
|
+
if (comptime std.mem.eql(u8, name, "tray")) return true;
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
|
|
361
413
|
fn shortcutModifiers(comptime shortcut: anytype) native_sdk.ShortcutModifiers {
|
|
362
414
|
const values = if (@hasField(@TypeOf(shortcut), "modifiers")) shortcut.modifiers else .{};
|
|
363
415
|
var modifiers: native_sdk.ShortcutModifiers = .{};
|
|
@@ -428,6 +480,11 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
|
|
|
428
480
|
// stack overflows on a stack instance, so construct it on the heap.
|
|
429
481
|
const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
|
|
430
482
|
defer std.heap.page_allocator.destroy(runtime);
|
|
483
|
+
// Fonts registered at startup and media-surface texture buffers
|
|
484
|
+
// adopted during the run are heap-owned by the runtime; return them
|
|
485
|
+
// (and disarm the producer wake bindings) before the runtime
|
|
486
|
+
// storage itself goes.
|
|
487
|
+
defer runtime.deinit();
|
|
431
488
|
native_sdk.Runtime.initAt(runtime, .{
|
|
432
489
|
.platform = null_platform.platform(),
|
|
433
490
|
.trace_sink = runtime_trace_sink,
|
|
@@ -483,6 +540,11 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
483
540
|
// stack overflows on a stack instance, so construct it on the heap.
|
|
484
541
|
const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
|
|
485
542
|
defer std.heap.page_allocator.destroy(runtime);
|
|
543
|
+
// Fonts registered at startup and media-surface texture buffers
|
|
544
|
+
// adopted during the run are heap-owned by the runtime; return them
|
|
545
|
+
// (and disarm the producer wake bindings) before the runtime
|
|
546
|
+
// storage itself goes.
|
|
547
|
+
defer runtime.deinit();
|
|
486
548
|
native_sdk.Runtime.initAt(runtime, .{
|
|
487
549
|
.platform = mac_platform.platform(),
|
|
488
550
|
.trace_sink = runtime_trace_sink,
|
|
@@ -535,6 +597,11 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
535
597
|
// stack overflows on a stack instance, so construct it on the heap.
|
|
536
598
|
const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
|
|
537
599
|
defer std.heap.page_allocator.destroy(runtime);
|
|
600
|
+
// Fonts registered at startup and media-surface texture buffers
|
|
601
|
+
// adopted during the run are heap-owned by the runtime; return them
|
|
602
|
+
// (and disarm the producer wake bindings) before the runtime
|
|
603
|
+
// storage itself goes.
|
|
604
|
+
defer runtime.deinit();
|
|
538
605
|
native_sdk.Runtime.initAt(runtime, .{
|
|
539
606
|
.platform = linux_platform.platform(),
|
|
540
607
|
.trace_sink = runtime_trace_sink,
|
|
@@ -586,6 +653,11 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
|
|
|
586
653
|
// stack overflows on a stack instance, so construct it on the heap.
|
|
587
654
|
const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
|
|
588
655
|
defer std.heap.page_allocator.destroy(runtime);
|
|
656
|
+
// Fonts registered at startup and media-surface texture buffers
|
|
657
|
+
// adopted during the run are heap-owned by the runtime; return them
|
|
658
|
+
// (and disarm the producer wake bindings) before the runtime
|
|
659
|
+
// storage itself goes.
|
|
660
|
+
defer runtime.deinit();
|
|
589
661
|
native_sdk.Runtime.initAt(runtime, .{
|
|
590
662
|
.platform = windows_platform.platform(),
|
|
591
663
|
.trace_sink = runtime_trace_sink,
|
|
@@ -629,6 +701,22 @@ const SessionRecordContext = struct {
|
|
|
629
701
|
}
|
|
630
702
|
};
|
|
631
703
|
|
|
704
|
+
/// The blob directory beside a session journal: `blobs/` in the
|
|
705
|
+
/// journal's directory — large effect payloads (an image load's source
|
|
706
|
+
/// bytes) live there content-addressed, referenced from journal
|
|
707
|
+
/// records by hash + length (see session_blobs.zig).
|
|
708
|
+
fn sessionBlobStore(io: std.Io, journal_path: []const u8) ?*native_sdk.runtime.SessionBlobDirStore {
|
|
709
|
+
var dir_buffer: [1024]u8 = undefined;
|
|
710
|
+
const parent = std.fs.path.dirname(journal_path) orelse ".";
|
|
711
|
+
const blob_dir = std.fmt.bufPrint(&dir_buffer, "{s}/blobs", .{parent}) catch return null;
|
|
712
|
+
const store = std.heap.page_allocator.create(native_sdk.runtime.SessionBlobDirStore) catch return null;
|
|
713
|
+
store.* = native_sdk.runtime.SessionBlobDirStore.init(io, blob_dir) catch {
|
|
714
|
+
std.heap.page_allocator.destroy(store);
|
|
715
|
+
return null;
|
|
716
|
+
};
|
|
717
|
+
return store;
|
|
718
|
+
}
|
|
719
|
+
|
|
632
720
|
/// `NATIVE_SDK_SESSION_RECORD=<path>`: create the journal file and a
|
|
633
721
|
/// recorder that streams the session into it from the very first
|
|
634
722
|
/// dispatched event (init determinism needs init-time effect results).
|
|
@@ -643,6 +731,7 @@ fn setupSessionRecorder(init: std.process.Init, app_info: native_sdk.AppInfo) ?*
|
|
|
643
731
|
context.* = .{ .io = init.io, .file = file };
|
|
644
732
|
const recorder = std.heap.page_allocator.create(native_sdk.runtime.SessionRecorder) catch return null;
|
|
645
733
|
recorder.* = native_sdk.runtime.SessionRecorder.init(context.sink());
|
|
734
|
+
if (sessionBlobStore(init.io, path)) |store| recorder.blob_sink = store.sink();
|
|
646
735
|
recorder.begin(native_sdk.runtime.sessionHeaderNow(
|
|
647
736
|
native_sdk.runtime.sessionPlatformName(),
|
|
648
737
|
app_info.app_name,
|
|
@@ -697,8 +786,20 @@ fn runSessionReplay(app: native_sdk.App, options: RunOptions, init: std.process.
|
|
|
697
786
|
native_sdk.platform.macos.installHeadlessTextServices(&replay_platform.services);
|
|
698
787
|
null_platform.gpu_surface_scroll_drivers = true;
|
|
699
788
|
}
|
|
789
|
+
// Replayed image loads decode too: successful `.image` records feed
|
|
790
|
+
// their journaled blob-store bytes back through decode+register, so
|
|
791
|
+
// the codec must be the recording host's own or every replayed load
|
|
792
|
+
// (and every replayed screenshot with an image in it) drops its
|
|
793
|
+
// pixels. Journaled bytes stay the only input — the codec is a pure
|
|
794
|
+
// bytes-to-pixels call and the network stays absent.
|
|
795
|
+
native_sdk.platform.installHeadlessImageCodec(build_options.platform, &null_platform, &replay_platform.services);
|
|
700
796
|
const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
|
|
701
797
|
defer std.heap.page_allocator.destroy(runtime);
|
|
798
|
+
// Fonts registered at startup and media-surface texture buffers
|
|
799
|
+
// adopted during the run are heap-owned by the runtime; return them
|
|
800
|
+
// (and disarm the producer wake bindings) before the runtime
|
|
801
|
+
// storage itself goes.
|
|
802
|
+
defer runtime.deinit();
|
|
702
803
|
// Bridge policy and security must match what the recording ran
|
|
703
804
|
// under (they gate replayed bridge_message dispatch); automation,
|
|
704
805
|
// window-state restore, and tracing stay off — replay consumes only
|
|
@@ -717,7 +818,11 @@ fn runSessionReplay(app: native_sdk.App, options: RunOptions, init: std.process.
|
|
|
717
818
|
!std.mem.eql(u8, value, "0")
|
|
718
819
|
else
|
|
719
820
|
true;
|
|
720
|
-
const
|
|
821
|
+
const blob_store = sessionBlobStore(init.io, journal_path);
|
|
822
|
+
const report = native_sdk.runtime.replaySession(runtime, app, journal_bytes, .{
|
|
823
|
+
.verify = verify,
|
|
824
|
+
.blobs = if (blob_store) |store| store.source() else null,
|
|
825
|
+
}) catch |err| {
|
|
721
826
|
switch (err) {
|
|
722
827
|
error.JournalBadMagic,
|
|
723
828
|
error.JournalUnsupportedVersion,
|
|
@@ -136,6 +136,10 @@ pub fn main(init: std.process.Init) !void {
|
|
|
136
136
|
// heap-allocates and constructs in place, so neither rides the stack.
|
|
137
137
|
const app_state = try Adapter.create(std.heap.page_allocator, .{
|
|
138
138
|
.audio_cache_dir = audio_cache_dir,
|
|
139
|
+
// Image loads share the same launch-resolved caches directory:
|
|
140
|
+
// the bridge keys the two caches into their own segments
|
|
141
|
+
// (audio/ and images/), so one directory serves both.
|
|
142
|
+
.image_cache_dir = audio_cache_dir,
|
|
139
143
|
.boot_images = boot_images_buffer[0..boot_image_count],
|
|
140
144
|
.env_values = env_values_buffer[0..env_value_count],
|
|
141
145
|
}, options);
|
|
@@ -34,7 +34,10 @@ pub const max_command_bytes: usize = 16 * 1024 + 64;
|
|
|
34
34
|
/// never touches (same loud timeout) — and both directions are refused
|
|
35
35
|
/// up front by this handshake whenever a live snapshot exists.
|
|
36
36
|
/// Snapshots without a `protocol=` field predate the handshake entirely.
|
|
37
|
-
|
|
37
|
+
/// 7 = the `widget-pinch` verb (drive a trackpad pinch gesture as the
|
|
38
|
+
/// real begin/change/end platform input events, journaled like every
|
|
39
|
+
/// synthesized input).
|
|
40
|
+
pub const version: u32 = 7;
|
|
38
41
|
|
|
39
42
|
/// How many commands may sit in the dropbox queue at once. Automation
|
|
40
43
|
/// drivers are scripts, not firehoses: the app drains one command per
|
|
@@ -93,6 +96,14 @@ pub const Action = enum {
|
|
|
93
96
|
widget_drag,
|
|
94
97
|
widget_wheel,
|
|
95
98
|
widget_key,
|
|
99
|
+
/// `widget-pinch <view-label> <scale> [<x> <y>]`: drive a trackpad
|
|
100
|
+
/// pinch gesture against a gpu-surface view — the real
|
|
101
|
+
/// `pinch_begin`/`pinch_change`/`pinch_end` platform events, with
|
|
102
|
+
/// one change carrying `scale - 1` so the cumulative gesture scale
|
|
103
|
+
/// (the product of `1 + delta`) lands exactly on `<scale>`, the
|
|
104
|
+
/// gesture's FINAL multiplicative zoom. The anchor point defaults
|
|
105
|
+
/// to the view center.
|
|
106
|
+
widget_pinch,
|
|
96
107
|
menu_command,
|
|
97
108
|
shortcut,
|
|
98
109
|
tray_action,
|
|
@@ -133,6 +144,7 @@ pub const Command = struct {
|
|
|
133
144
|
if (std.mem.eql(u8, action_text, "widget-drag") and value.len > 0) return .{ .action = .widget_drag, .value = value };
|
|
134
145
|
if (std.mem.eql(u8, action_text, "widget-wheel") and value.len > 0) return .{ .action = .widget_wheel, .value = value };
|
|
135
146
|
if (std.mem.eql(u8, action_text, "widget-key") and value.len > 0) return .{ .action = .widget_key, .value = value };
|
|
147
|
+
if (std.mem.eql(u8, action_text, "widget-pinch") and value.len > 0) return .{ .action = .widget_pinch, .value = value };
|
|
136
148
|
if (std.mem.eql(u8, action_text, "menu-command") and value.len > 0) return .{ .action = .menu_command, .value = value };
|
|
137
149
|
if (std.mem.eql(u8, action_text, "shortcut") and value.len > 0) return .{ .action = .shortcut, .value = value };
|
|
138
150
|
if (std.mem.eql(u8, action_text, "tray-action") and value.len > 0) return .{ .action = .tray_action, .value = value };
|
|
@@ -226,6 +238,13 @@ test "commands parse reload and wait" {
|
|
|
226
238
|
const widget_key = try Command.parse("widget-key canvas tab");
|
|
227
239
|
try std.testing.expectEqual(Action.widget_key, widget_key.action);
|
|
228
240
|
try std.testing.expectEqualStrings("canvas tab", widget_key.value);
|
|
241
|
+
const widget_pinch = try Command.parse("widget-pinch canvas 1.5");
|
|
242
|
+
try std.testing.expectEqual(Action.widget_pinch, widget_pinch.action);
|
|
243
|
+
try std.testing.expectEqualStrings("canvas 1.5", widget_pinch.value);
|
|
244
|
+
const widget_pinch_at = try Command.parse("widget-pinch canvas 0.5 120 80");
|
|
245
|
+
try std.testing.expectEqual(Action.widget_pinch, widget_pinch_at.action);
|
|
246
|
+
try std.testing.expectEqualStrings("canvas 0.5 120 80", widget_pinch_at.value);
|
|
247
|
+
try std.testing.expectError(error.InvalidCommand, Command.parse("widget-pinch"));
|
|
229
248
|
const menu_command = try Command.parse("menu-command app.refresh");
|
|
230
249
|
try std.testing.expectEqual(Action.menu_command, menu_command.action);
|
|
231
250
|
const shortcut = try Command.parse("shortcut app.refresh");
|
package/src/embed/host.zig
CHANGED
|
@@ -436,6 +436,15 @@ pub fn deliverPresentedPixels(self: anytype, scale: f32, buffer: []u8, out: *typ
|
|
|
436
436
|
return true;
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
+
/// A runtime embedded in a host that owns the main loop (the mobile
|
|
440
|
+
/// shims, game engines, custom render loops, headless tests). Lifecycle:
|
|
441
|
+
/// `init`/`initInPlace`, `defer embedded.deinit()`, `start`, host-pumped
|
|
442
|
+
/// events and `frame`s, `stop` (dispatches app_shutdown), and finally
|
|
443
|
+
/// that deferred `deinit` — `stop` only tells the app it is shutting
|
|
444
|
+
/// down; `deinit` is what returns the embedded runtime's heap-owned
|
|
445
|
+
/// registrations (registered canvas font bytes), so a direct embedder
|
|
446
|
+
/// that creates and destroys apps in one process leaks a full font
|
|
447
|
+
/// registry per cycle without it.
|
|
439
448
|
pub const EmbeddedApp = struct {
|
|
440
449
|
app: runtime.App,
|
|
441
450
|
runtime: runtime.Runtime,
|
|
@@ -451,6 +460,17 @@ pub const EmbeddedApp = struct {
|
|
|
451
460
|
runtime.Runtime.initAt(&self.runtime, .{ .platform = platform_value });
|
|
452
461
|
}
|
|
453
462
|
|
|
463
|
+
/// End of the embedded lifecycle, symmetric with `init`/`initInPlace`:
|
|
464
|
+
/// releases everything the embedded app owns on the heap — the
|
|
465
|
+
/// runtime's registered canvas font bytes (`Runtime.deinit`); `init`
|
|
466
|
+
/// itself allocates nothing else. Idempotent: a second call is a
|
|
467
|
+
/// no-op, so `defer embedded.deinit()` composes with early exits.
|
|
468
|
+
/// Everything borrowing the runtime (parsed faces, measure
|
|
469
|
+
/// providers, views) is invalid past this point.
|
|
470
|
+
pub fn deinit(self: *EmbeddedApp) void {
|
|
471
|
+
self.runtime.deinit();
|
|
472
|
+
}
|
|
473
|
+
|
|
454
474
|
pub fn start(self: *EmbeddedApp) anyerror!void {
|
|
455
475
|
try self.runtime.dispatchPlatformEvent(self.app, .app_start);
|
|
456
476
|
}
|
|
@@ -757,6 +777,13 @@ pub const MobileHostApp = struct {
|
|
|
757
777
|
|
|
758
778
|
pub fn destroy(self: *MobileHostApp) void {
|
|
759
779
|
disableAutomation(self);
|
|
780
|
+
// One lifecycle owner: the embedded app's own deinit returns
|
|
781
|
+
// the runtime's heap-owned storage (registered canvas font
|
|
782
|
+
// bytes, lazily allocated media-surface texture buffers) AND
|
|
783
|
+
// disarms the producer wake bindings, so a media producer the
|
|
784
|
+
// embedding app keeps past destroy can never wake the freed
|
|
785
|
+
// host storage (the embedded null platform included).
|
|
786
|
+
self.embedded.deinit();
|
|
760
787
|
std.heap.page_allocator.destroy(self);
|
|
761
788
|
}
|
|
762
789
|
|