@native-sdk/cli 0.0.0 → 0.4.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.
Files changed (367) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/bin/native.js +156 -0
  5. package/build/app.zig +716 -0
  6. package/build.zig +2593 -0
  7. package/build.zig.zon +24 -0
  8. package/native-sdk.d.ts +615 -0
  9. package/package.json +44 -8
  10. package/skill-data/automation/SKILL.md +248 -0
  11. package/skill-data/core/SKILL.md +249 -0
  12. package/skill-data/core/references/app-model-runtime.md +141 -0
  13. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  14. package/skill-data/core/references/frontend-assets.md +124 -0
  15. package/skill-data/core/references/project-anatomy.md +108 -0
  16. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  17. package/skill-data/native-ui/SKILL.md +1080 -0
  18. package/skills/native-sdk/SKILL.md +33 -0
  19. package/src/app_runner/root.zig +740 -0
  20. package/src/assets/root.zig +20 -0
  21. package/src/automation/protocol.zig +285 -0
  22. package/src/automation/root.zig +13 -0
  23. package/src/automation/server.zig +506 -0
  24. package/src/automation/snapshot.zig +1202 -0
  25. package/src/automation/watcher.zig +165 -0
  26. package/src/bridge/root.zig +507 -0
  27. package/src/debug/root.zig +246 -0
  28. package/src/embed/app_exports.zig +11 -0
  29. package/src/embed/c_api.zig +793 -0
  30. package/src/embed/c_exports.zig +10 -0
  31. package/src/embed/chrome.zig +168 -0
  32. package/src/embed/conversions.zig +359 -0
  33. package/src/embed/host.zig +960 -0
  34. package/src/embed/root.zig +81 -0
  35. package/src/embed/tests.zig +2552 -0
  36. package/src/embed/types.zig +382 -0
  37. package/src/embed/ui_host.zig +289 -0
  38. package/src/extensions/root.zig +197 -0
  39. package/src/frontend/root.zig +48 -0
  40. package/src/js/root.zig +65 -0
  41. package/src/platform/android/NativeSdkActivity.java +1370 -0
  42. package/src/platform/android/android_host.c +696 -0
  43. package/src/platform/android/files.zig +9 -0
  44. package/src/platform/android/native_sdk_app.h +237 -0
  45. package/src/platform/ios/files.zig +8 -0
  46. package/src/platform/ios/native_sdk_app.h +289 -0
  47. package/src/platform/ios/uikit_host.m +2739 -0
  48. package/src/platform/linux/cef_host.cpp +599 -0
  49. package/src/platform/linux/gtk_host.c +5362 -0
  50. package/src/platform/linux/gtk_host.h +265 -0
  51. package/src/platform/linux/root.zig +1519 -0
  52. package/src/platform/macos/appkit_host.h +604 -0
  53. package/src/platform/macos/appkit_host.m +10392 -0
  54. package/src/platform/macos/automation_host.h +14 -0
  55. package/src/platform/macos/automation_host.m +12 -0
  56. package/src/platform/macos/cef_host.mm +3028 -0
  57. package/src/platform/macos/root.zig +2260 -0
  58. package/src/platform/null_platform.zig +2232 -0
  59. package/src/platform/null_platform_tests.zig +670 -0
  60. package/src/platform/policy_values.zig +14 -0
  61. package/src/platform/root.zig +181 -0
  62. package/src/platform/types.zig +2681 -0
  63. package/src/platform/windows/cef_host.cpp +3 -0
  64. package/src/platform/windows/root.zig +1521 -0
  65. package/src/platform/windows/webview2_host.cpp +6230 -0
  66. package/src/primitives/app_dirs/root.zig +440 -0
  67. package/src/primitives/app_manifest/root.zig +109 -0
  68. package/src/primitives/app_manifest/tests.zig +758 -0
  69. package/src/primitives/app_manifest/types.zig +587 -0
  70. package/src/primitives/app_manifest/validation.zig +828 -0
  71. package/src/primitives/assets/root.zig +520 -0
  72. package/src/primitives/canvas/a11y_audit.zig +390 -0
  73. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  74. package/src/primitives/canvas/app_icon.zig +1590 -0
  75. package/src/primitives/canvas/chart.zig +392 -0
  76. package/src/primitives/canvas/chart_tests.zig +751 -0
  77. package/src/primitives/canvas/commands.zig +446 -0
  78. package/src/primitives/canvas/drawing.zig +309 -0
  79. package/src/primitives/canvas/equality.zig +316 -0
  80. package/src/primitives/canvas/events.zig +696 -0
  81. package/src/primitives/canvas/font_coverage.zig +118 -0
  82. package/src/primitives/canvas/font_ttf.zig +510 -0
  83. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  84. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  85. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  86. package/src/primitives/canvas/frame.zig +679 -0
  87. package/src/primitives/canvas/frame_metrics.zig +462 -0
  88. package/src/primitives/canvas/gpu.zig +639 -0
  89. package/src/primitives/canvas/hash.zig +112 -0
  90. package/src/primitives/canvas/icons/alert.svg +1 -0
  91. package/src/primitives/canvas/icons/archive.svg +1 -0
  92. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  93. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  94. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  95. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  96. package/src/primitives/canvas/icons/check.svg +1 -0
  97. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  98. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  99. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  100. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  101. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  102. package/src/primitives/canvas/icons/clock.svg +1 -0
  103. package/src/primitives/canvas/icons/copy.svg +1 -0
  104. package/src/primitives/canvas/icons/download.svg +1 -0
  105. package/src/primitives/canvas/icons/edit.svg +1 -0
  106. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  107. package/src/primitives/canvas/icons/external-link.svg +1 -0
  108. package/src/primitives/canvas/icons/eye.svg +1 -0
  109. package/src/primitives/canvas/icons/file-text.svg +1 -0
  110. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  111. package/src/primitives/canvas/icons/folder.svg +1 -0
  112. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  113. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  114. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  115. package/src/primitives/canvas/icons/info.svg +1 -0
  116. package/src/primitives/canvas/icons/menu.svg +1 -0
  117. package/src/primitives/canvas/icons/missing.svg +1 -0
  118. package/src/primitives/canvas/icons/moon.svg +1 -0
  119. package/src/primitives/canvas/icons/music.svg +1 -0
  120. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  121. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  122. package/src/primitives/canvas/icons/pause.svg +1 -0
  123. package/src/primitives/canvas/icons/play.svg +1 -0
  124. package/src/primitives/canvas/icons/plus.svg +1 -0
  125. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  126. package/src/primitives/canvas/icons/repeat.svg +1 -0
  127. package/src/primitives/canvas/icons/save.svg +1 -0
  128. package/src/primitives/canvas/icons/search.svg +1 -0
  129. package/src/primitives/canvas/icons/send.svg +1 -0
  130. package/src/primitives/canvas/icons/settings.svg +1 -0
  131. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  132. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  133. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  134. package/src/primitives/canvas/icons/sun.svg +1 -0
  135. package/src/primitives/canvas/icons/terminal.svg +1 -0
  136. package/src/primitives/canvas/icons/trash.svg +1 -0
  137. package/src/primitives/canvas/icons/volume.svg +1 -0
  138. package/src/primitives/canvas/icons/wrench.svg +1 -0
  139. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  140. package/src/primitives/canvas/icons/x.svg +1 -0
  141. package/src/primitives/canvas/icons.zig +249 -0
  142. package/src/primitives/canvas/layout_audit.zig +744 -0
  143. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  144. package/src/primitives/canvas/markdown.zig +1031 -0
  145. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  146. package/src/primitives/canvas/markdown_tests.zig +538 -0
  147. package/src/primitives/canvas/plan_key_index.zig +120 -0
  148. package/src/primitives/canvas/png.zig +355 -0
  149. package/src/primitives/canvas/reference.zig +1457 -0
  150. package/src/primitives/canvas/reference_blur.zig +104 -0
  151. package/src/primitives/canvas/reference_memo.zig +322 -0
  152. package/src/primitives/canvas/reference_paths.zig +184 -0
  153. package/src/primitives/canvas/reference_tests.zig +1650 -0
  154. package/src/primitives/canvas/render.zig +747 -0
  155. package/src/primitives/canvas/render_effects.zig +255 -0
  156. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  157. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  158. package/src/primitives/canvas/render_images.zig +247 -0
  159. package/src/primitives/canvas/render_layers.zig +260 -0
  160. package/src/primitives/canvas/render_paths.zig +347 -0
  161. package/src/primitives/canvas/render_resources.zig +51 -0
  162. package/src/primitives/canvas/render_tests.zig +3186 -0
  163. package/src/primitives/canvas/root.zig +744 -0
  164. package/src/primitives/canvas/serialization.zig +1528 -0
  165. package/src/primitives/canvas/svg_icon.zig +636 -0
  166. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  167. package/src/primitives/canvas/test_support.zig +422 -0
  168. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  169. package/src/primitives/canvas/tests.zig +30 -0
  170. package/src/primitives/canvas/text.zig +82 -0
  171. package/src/primitives/canvas/text_atlas.zig +408 -0
  172. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  173. package/src/primitives/canvas/text_interaction.zig +615 -0
  174. package/src/primitives/canvas/text_layout.zig +1069 -0
  175. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  176. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  177. package/src/primitives/canvas/text_layout_types.zig +128 -0
  178. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  179. package/src/primitives/canvas/text_metrics.zig +309 -0
  180. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  181. package/src/primitives/canvas/text_span_tests.zig +608 -0
  182. package/src/primitives/canvas/text_spans.zig +1010 -0
  183. package/src/primitives/canvas/text_tests.zig +1949 -0
  184. package/src/primitives/canvas/themes/geist.zig +470 -0
  185. package/src/primitives/canvas/tokens.zig +1522 -0
  186. package/src/primitives/canvas/ui.zig +2686 -0
  187. package/src/primitives/canvas/ui_markup.zig +3791 -0
  188. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  189. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  190. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  191. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  192. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  193. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  194. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  195. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  196. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  197. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  198. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  199. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  200. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  201. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  202. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  203. package/src/primitives/canvas/ui_provenance.zig +96 -0
  204. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  205. package/src/primitives/canvas/ui_schema.zig +825 -0
  206. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  207. package/src/primitives/canvas/ui_tests.zig +1432 -0
  208. package/src/primitives/canvas/vector.zig +919 -0
  209. package/src/primitives/canvas/vector_tests.zig +547 -0
  210. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  211. package/src/primitives/canvas/virtual_extents.zig +540 -0
  212. package/src/primitives/canvas/widget_access.zig +208 -0
  213. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  214. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  215. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  216. package/src/primitives/canvas/widget_layout.zig +2055 -0
  217. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  218. package/src/primitives/canvas/widget_metrics.zig +228 -0
  219. package/src/primitives/canvas/widget_render.zig +2534 -0
  220. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  221. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  222. package/src/primitives/canvas/widget_render_style.zig +626 -0
  223. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  224. package/src/primitives/canvas/widget_routing.zig +475 -0
  225. package/src/primitives/canvas/widget_runtime.zig +307 -0
  226. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  227. package/src/primitives/canvas/widget_semantics.zig +480 -0
  228. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  229. package/src/primitives/canvas/widget_tests.zig +8 -0
  230. package/src/primitives/canvas/widget_text_input.zig +351 -0
  231. package/src/primitives/canvas/widget_text_select.zig +147 -0
  232. package/src/primitives/canvas/widget_tree.zig +232 -0
  233. package/src/primitives/canvas/widgets.zig +1319 -0
  234. package/src/primitives/diagnostics/root.zig +445 -0
  235. package/src/primitives/geometry/root.zig +889 -0
  236. package/src/primitives/json/root.zig +272 -0
  237. package/src/primitives/platform_info/root.zig +450 -0
  238. package/src/primitives/trace/root.zig +569 -0
  239. package/src/root.zig +165 -0
  240. package/src/runtime/api.zig +431 -0
  241. package/src/runtime/async_bridge.zig +49 -0
  242. package/src/runtime/automation_commands.zig +686 -0
  243. package/src/runtime/automation_liveness_tests.zig +140 -0
  244. package/src/runtime/automation_snapshot.zig +246 -0
  245. package/src/runtime/automation_widget_dispatch.zig +617 -0
  246. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  247. package/src/runtime/bridge_payload.zig +194 -0
  248. package/src/runtime/bridge_permission_tests.zig +551 -0
  249. package/src/runtime/bridge_responses.zig +414 -0
  250. package/src/runtime/builtin_bridge.zig +554 -0
  251. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  252. package/src/runtime/canvas_font_tests.zig +410 -0
  253. package/src/runtime/canvas_fonts.zig +229 -0
  254. package/src/runtime/canvas_frame.zig +1734 -0
  255. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  256. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  257. package/src/runtime/canvas_frame_helpers.zig +414 -0
  258. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  259. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  260. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  261. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  262. package/src/runtime/canvas_frame_tests.zig +9 -0
  263. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  264. package/src/runtime/canvas_image_tests.zig +362 -0
  265. package/src/runtime/canvas_images.zig +224 -0
  266. package/src/runtime/canvas_limits.zig +317 -0
  267. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  268. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  269. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  270. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  271. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  272. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  273. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  274. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  275. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  276. package/src/runtime/canvas_widget_display.zig +677 -0
  277. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  278. package/src/runtime/canvas_widget_events.zig +1098 -0
  279. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  280. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  281. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  282. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  283. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  284. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  285. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  286. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  287. package/src/runtime/canvas_widget_state.zig +798 -0
  288. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  289. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  290. package/src/runtime/clock.zig +231 -0
  291. package/src/runtime/core.zig +927 -0
  292. package/src/runtime/effects.zig +4197 -0
  293. package/src/runtime/effects_audio_tests.zig +690 -0
  294. package/src/runtime/effects_clipboard_tests.zig +317 -0
  295. package/src/runtime/effects_fetch_tests.zig +1031 -0
  296. package/src/runtime/effects_file_tests.zig +407 -0
  297. package/src/runtime/effects_tests.zig +1251 -0
  298. package/src/runtime/flow.zig +1175 -0
  299. package/src/runtime/frame_profile.zig +221 -0
  300. package/src/runtime/gpu_surface_events.zig +639 -0
  301. package/src/runtime/launch_timing.zig +59 -0
  302. package/src/runtime/markdown_app_tests.zig +224 -0
  303. package/src/runtime/native_command_event_tests.zig +431 -0
  304. package/src/runtime/platform_bridge_tests.zig +8 -0
  305. package/src/runtime/platform_config_tests.zig +392 -0
  306. package/src/runtime/root.zig +150 -0
  307. package/src/runtime/runtime_event_tests.zig +1079 -0
  308. package/src/runtime/session_journal.zig +1522 -0
  309. package/src/runtime/session_record.zig +332 -0
  310. package/src/runtime/session_replay.zig +274 -0
  311. package/src/runtime/session_state.zig +30 -0
  312. package/src/runtime/session_tests.zig +399 -0
  313. package/src/runtime/shell_layout.zig +472 -0
  314. package/src/runtime/shell_layout_tests.zig +1246 -0
  315. package/src/runtime/shell_view_tests.zig +604 -0
  316. package/src/runtime/state.zig +110 -0
  317. package/src/runtime/system_services.zig +392 -0
  318. package/src/runtime/test_support.zig +79 -0
  319. package/src/runtime/tests.zig +30 -0
  320. package/src/runtime/ui_app.zig +3290 -0
  321. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  322. package/src/runtime/ui_app_provenance.zig +370 -0
  323. package/src/runtime/ui_app_tests.zig +3254 -0
  324. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  325. package/src/runtime/ui_app_window_tests.zig +442 -0
  326. package/src/runtime/validation.zig +206 -0
  327. package/src/runtime/view.zig +908 -0
  328. package/src/runtime/view_canvas.zig +850 -0
  329. package/src/runtime/view_widget_control.zig +433 -0
  330. package/src/runtime/view_widget_scroll.zig +360 -0
  331. package/src/runtime/view_widget_text.zig +275 -0
  332. package/src/runtime/view_widget_tree.zig +843 -0
  333. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  334. package/src/runtime/widget_bridge.zig +231 -0
  335. package/src/runtime/window_command_bridge_tests.zig +403 -0
  336. package/src/runtime/window_storage.zig +255 -0
  337. package/src/runtime/window_view_runtime.zig +727 -0
  338. package/src/runtime/window_views.zig +334 -0
  339. package/src/security/root.zig +118 -0
  340. package/src/tooling/android.zig +1172 -0
  341. package/src/tooling/assets.zig +128 -0
  342. package/src/tooling/buildgraph.zig +379 -0
  343. package/src/tooling/cef.zig +671 -0
  344. package/src/tooling/codesign.zig +172 -0
  345. package/src/tooling/components/identity_tests.zig +185 -0
  346. package/src/tooling/components/stepper.zig +113 -0
  347. package/src/tooling/components/timeline.native +27 -0
  348. package/src/tooling/components/timeline_item.zig +131 -0
  349. package/src/tooling/default_icon.icns +0 -0
  350. package/src/tooling/default_icon.png +0 -0
  351. package/src/tooling/dev.zig +172 -0
  352. package/src/tooling/doctor.zig +349 -0
  353. package/src/tooling/eject_components.zig +170 -0
  354. package/src/tooling/embedlib.zig +290 -0
  355. package/src/tooling/ios.zig +528 -0
  356. package/src/tooling/manifest.zig +1939 -0
  357. package/src/tooling/package.zig +2388 -0
  358. package/src/tooling/process_tree.zig +114 -0
  359. package/src/tooling/raw_manifest.zig +193 -0
  360. package/src/tooling/root.zig +22 -0
  361. package/src/tooling/templates.zig +3191 -0
  362. package/src/tooling/toolchain.zig +371 -0
  363. package/src/tooling/verbs.zig +204 -0
  364. package/src/tooling/web_engine.zig +135 -0
  365. package/src/tooling/xcodeproj.zig +462 -0
  366. package/src/window_state/root.zig +507 -0
  367. package/index.js +0 -2
@@ -0,0 +1,960 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("canvas");
4
+ const app_manifest = @import("app_manifest");
5
+ const runtime = @import("../runtime/root.zig");
6
+ const platform = @import("../platform/root.zig");
7
+ const automation = @import("../automation/root.zig");
8
+ const types = @import("types.zig");
9
+ const conversions = @import("conversions.zig");
10
+
11
+ const max_mobile_command_name_bytes = types.max_mobile_command_name_bytes;
12
+ const max_mobile_input_text_bytes = types.max_mobile_input_text_bytes;
13
+ const max_mobile_asset_root_bytes = types.max_mobile_asset_root_bytes;
14
+ const max_mobile_asset_entry_bytes = types.max_mobile_asset_entry_bytes;
15
+ const mobile_gpu_surface_label = types.mobile_gpu_surface_label;
16
+ const mobileTouchKindFromPhase = conversions.mobileTouchKindFromPhase;
17
+ const mobileKeyKindFromPhase = conversions.mobileKeyKindFromPhase;
18
+ const mobileImeKindFromInt = conversions.mobileImeKindFromInt;
19
+ const mobileModifiersFromMask = conversions.mobileModifiersFromMask;
20
+ const copyInputText = conversions.copyInputText;
21
+ const nowNanoseconds = conversions.nowNanoseconds;
22
+
23
+ /// Host-owned storage for the shim's registered text-measure callback.
24
+ /// The canvas `TextMeasureProvider` carries a pointer to this struct as
25
+ /// its context, so the field must live on the (heap-allocated) host for
26
+ /// the runtime's lifetime.
27
+ pub const MobileTextMeasure = struct {
28
+ measure: ?types.MobileTextMeasureFn = null,
29
+ context: ?*anyopaque = null,
30
+ };
31
+
32
+ /// Bridges the C-ABI measure callback into the canvas provider seam. A
33
+ /// negative return (including a cleared callback) falls back to the
34
+ /// deterministic estimator inside `TextMeasureProvider.measureWidth`.
35
+ fn mobileMeasureText(context: ?*anyopaque, font_id: canvas.FontId, size: f32, text: []const u8) f32 {
36
+ const store: *const MobileTextMeasure = @ptrCast(@alignCast(context.?));
37
+ const measure = store.measure orelse return -1;
38
+ return @floatCast(measure(store.context, font_id, size, text.ptr, text.len));
39
+ }
40
+
41
+ /// Install (or clear, with a null callback) the platform text measurement
42
+ /// on the embedded runtime — the mobile counterpart of the desktop
43
+ /// platforms' `measure_text_fn` service, threaded into layout the same
44
+ /// way (`Runtime.tokensWithTextMeasure` stamps it into design tokens on
45
+ /// every rebuild). Register it before `native_sdk_app_start` so the
46
+ /// installing layout already uses real metrics; later changes apply on
47
+ /// the next rebuild.
48
+ ///
49
+ /// Retained display-list commands carry the provider *pointer*, so once
50
+ /// the runtime's provider is installed it must stay in place for the
51
+ /// runtime's lifetime (the same invariant desktop platforms keep by
52
+ /// capturing it at init). Clearing therefore only nulls the callback
53
+ /// inside the host's bridge storage; the bridge then reports "no
54
+ /// measurement" and every consumer falls back to the deterministic
55
+ /// estimator.
56
+ pub fn setTextMeasure(self: anytype, measure: ?types.MobileTextMeasureFn, context: ?*anyopaque) void {
57
+ self.text_measure = .{ .measure = measure, .context = context };
58
+ if (measure != null and self.embedded.runtime.text_measure_provider == null) {
59
+ self.embedded.runtime.text_measure_provider = .{
60
+ .context = &self.text_measure,
61
+ .measure_fn = mobileMeasureText,
62
+ };
63
+ }
64
+ }
65
+
66
+ /// Host-owned storage for the shim's registered audio service (callback
67
+ /// table + shim context). Lives on the (heap-allocated) host beside the
68
+ /// text-measure store so the platform-services bridge can reach it for
69
+ /// the runtime's lifetime.
70
+ pub const MobileAudio = struct {
71
+ service: types.MobileAudioService = .{},
72
+ context: ?*anyopaque = null,
73
+ };
74
+
75
+ /// Platform-services bridge from the runtime's audio service seam to the
76
+ /// shim's registered C callbacks. The runtime's `PlatformServices` carries
77
+ /// ONE shared context — the host's embedded `NullPlatform` — so the bridge
78
+ /// recovers the host from that field and reads the `audio` store; result
79
+ /// codes map exactly like the macOS host's (`src/platform/macos/root.zig`
80
+ /// audioLoad/audioLoadUrl and friends), so the effect layer sees identical
81
+ /// error semantics on every platform.
82
+ fn MobileAudioBridge(comptime Host: type) type {
83
+ return struct {
84
+ fn hostFromContext(context: ?*anyopaque) *Host {
85
+ const null_platform: *platform.NullPlatform = @ptrCast(@alignCast(context.?));
86
+ return @alignCast(@fieldParentPtr("null_platform", null_platform));
87
+ }
88
+
89
+ fn audioLoad(context: ?*anyopaque, path: []const u8) anyerror!void {
90
+ const audio = &hostFromContext(context).audio;
91
+ const load_fn = audio.service.load orelse return error.UnsupportedService;
92
+ return switch (load_fn(audio.context, path.ptr, path.len)) {
93
+ 0 => {},
94
+ 1 => error.AudioSourceNotFound,
95
+ else => error.AudioDecodeFailed,
96
+ };
97
+ }
98
+
99
+ fn audioLoadUrl(context: ?*anyopaque, url: []const u8, cache_path: []const u8, expected_bytes: u64) anyerror!platform.AudioLoadResolution {
100
+ const audio = &hostFromContext(context).audio;
101
+ const load_fn = audio.service.load_url orelse return error.UnsupportedService;
102
+ return switch (load_fn(audio.context, url.ptr, url.len, if (cache_path.len > 0) cache_path.ptr else null, cache_path.len, expected_bytes)) {
103
+ 0 => .stream,
104
+ 1 => .cache,
105
+ else => error.InvalidAudioOptions,
106
+ };
107
+ }
108
+
109
+ fn audioPlay(context: ?*anyopaque) anyerror!void {
110
+ const audio = &hostFromContext(context).audio;
111
+ const play_fn = audio.service.play orelse return error.UnsupportedService;
112
+ if (play_fn(audio.context) == 0) return error.InvalidAudioOptions;
113
+ }
114
+
115
+ fn audioPause(context: ?*anyopaque) anyerror!void {
116
+ const audio = &hostFromContext(context).audio;
117
+ const pause_fn = audio.service.pause orelse return error.UnsupportedService;
118
+ _ = pause_fn(audio.context);
119
+ }
120
+
121
+ fn audioStop(context: ?*anyopaque) anyerror!void {
122
+ const audio = &hostFromContext(context).audio;
123
+ const stop_fn = audio.service.stop orelse return error.UnsupportedService;
124
+ _ = stop_fn(audio.context);
125
+ }
126
+
127
+ fn audioSeek(context: ?*anyopaque, position_ms: u64) anyerror!void {
128
+ const audio = &hostFromContext(context).audio;
129
+ const seek_fn = audio.service.seek orelse return error.UnsupportedService;
130
+ if (seek_fn(audio.context, position_ms) == 0) return error.InvalidAudioOptions;
131
+ }
132
+
133
+ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
134
+ const audio = &hostFromContext(context).audio;
135
+ const volume_fn = audio.service.set_volume orelse return error.UnsupportedService;
136
+ _ = volume_fn(audio.context, volume);
137
+ }
138
+ };
139
+ }
140
+
141
+ /// Install (or clear, with an all-null table) the shim's platform audio
142
+ /// service on the embedded runtime — the mobile counterpart of the desktop
143
+ /// hosts' `audio_*_fn` platform services. Registration flips the host's
144
+ /// `audio_playback`/`audio_streaming` capability answers to match what was
145
+ /// actually registered, so `runtime.supports` stays honest in both
146
+ /// directions. Register before `native_sdk_app_start` (like the text
147
+ /// measure) so the first effect dispatch already sees the service; a
148
+ /// partial playback table is refused whole with `error.InvalidCommand`.
149
+ pub fn setAudioService(self: anytype, service: types.MobileAudioService, context: ?*anyopaque) anyerror!void {
150
+ const Host = std.meta.Child(@TypeOf(self));
151
+ const Bridge = MobileAudioBridge(Host);
152
+ const playback = service.playbackComplete();
153
+ if (!playback and !service.empty()) return error.InvalidCommand;
154
+ const streaming = playback and service.load_url != null;
155
+ self.audio = .{ .service = service, .context = if (playback) context else null };
156
+ const services = &self.embedded.runtime.options.platform.services;
157
+ services.audio_load_fn = if (playback) Bridge.audioLoad else null;
158
+ services.audio_load_url_fn = if (streaming) Bridge.audioLoadUrl else null;
159
+ services.audio_play_fn = if (playback) Bridge.audioPlay else null;
160
+ services.audio_pause_fn = if (playback) Bridge.audioPause else null;
161
+ services.audio_stop_fn = if (playback) Bridge.audioStop else null;
162
+ services.audio_seek_fn = if (playback) Bridge.audioSeek else null;
163
+ services.audio_set_volume_fn = if (playback) Bridge.audioSetVolume else null;
164
+ self.null_platform.audio_playback = playback;
165
+ self.null_platform.audio_streaming = streaming;
166
+ }
167
+
168
+ /// Host-owned storage for the shim's registered image-decode service
169
+ /// (callback table + shim context). Lives on the (heap-allocated) host
170
+ /// beside the audio store so the platform-services bridge can reach it
171
+ /// for the runtime's lifetime.
172
+ pub const MobileImage = struct {
173
+ service: types.MobileImageService = .{},
174
+ context: ?*anyopaque = null,
175
+ };
176
+
177
+ /// Platform-services bridge from the runtime's image-decode seam
178
+ /// (`PlatformServices.decode_image_fn`, the `fx.registerImageBytes` path)
179
+ /// to the shim's registered C callback. Context recovery mirrors the
180
+ /// audio bridge: the services table carries the host's embedded
181
+ /// `NullPlatform`, and the host is recovered from that field. Result
182
+ /// codes map exactly like the macOS host's `decodeImage`
183
+ /// (`src/platform/macos/root.zig`): 1 decoded, -1 too large for the
184
+ /// buffer, anything else undecodable — with the shim-reported dimensions
185
+ /// re-validated against the buffer before any slice is formed, so a
186
+ /// buggy shim answer surfaces as `error.ImageDecodeFailed`, never as an
187
+ /// out-of-bounds pixel slice.
188
+ fn MobileImageBridge(comptime Host: type) type {
189
+ return struct {
190
+ fn hostFromContext(context: ?*anyopaque) *Host {
191
+ const null_platform: *platform.NullPlatform = @ptrCast(@alignCast(context.?));
192
+ return @alignCast(@fieldParentPtr("null_platform", null_platform));
193
+ }
194
+
195
+ fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!platform.DecodedImage {
196
+ const image = &hostFromContext(context).image;
197
+ const decode_fn = image.service.decode orelse return error.UnsupportedService;
198
+ var width: usize = 0;
199
+ var height: usize = 0;
200
+ return switch (decode_fn(image.context, bytes.ptr, bytes.len, buffer.ptr, buffer.len, &width, &height)) {
201
+ 1 => {
202
+ if (width == 0 or height == 0) return error.ImageDecodeFailed;
203
+ const row_len = std.math.mul(usize, width, 4) catch return error.ImageDecodeFailed;
204
+ const byte_len = std.math.mul(usize, row_len, height) catch return error.ImageDecodeFailed;
205
+ if (byte_len > buffer.len) return error.ImageDecodeFailed;
206
+ return .{ .width = width, .height = height, .rgba8 = buffer[0..byte_len] };
207
+ },
208
+ -1 => error.ImageTooLarge,
209
+ else => error.ImageDecodeFailed,
210
+ };
211
+ }
212
+ };
213
+ }
214
+
215
+ /// Install (or clear, with an all-null table) the shim's platform image
216
+ /// decoder on the embedded runtime — the mobile counterpart of the
217
+ /// desktop hosts' `decode_image_fn` platform service. Registration flips
218
+ /// the runtime's service entry so `fx.registerImageBytes` decodes for
219
+ /// real; clearing (and never registering) keeps the honest decline:
220
+ /// `error.UnsupportedService`, image/avatar widgets on their fallback.
221
+ /// Register before `native_sdk_app_start` (like the audio service) so a
222
+ /// boot-effect registration already sees the codec.
223
+ pub fn setImageService(self: anytype, service: types.MobileImageService, context: ?*anyopaque) void {
224
+ const Host = std.meta.Child(@TypeOf(self));
225
+ const Bridge = MobileImageBridge(Host);
226
+ const complete = service.complete();
227
+ self.image = .{ .service = service, .context = if (complete) context else null };
228
+ const services = &self.embedded.runtime.options.platform.services;
229
+ services.decode_image_fn = if (complete) Bridge.decodeImage else null;
230
+ }
231
+
232
+ // -------------------------------------------------- presented-pixel capture
233
+ //
234
+ // The damage seam behind `native_sdk_app_render_pixels_damage`. The
235
+ // runtime's frame dispatch presents the mobile surface through the CPU
236
+ // pixel path once per changed frame — an INCREMENTAL, dirty-scissored
237
+ // raster into the ui-app's retained pixel buffer (the same machinery the
238
+ // desktop software platforms use). The capture below rides that present:
239
+ // it remembers a borrowed view of the presented buffer plus the damage
240
+ // accumulated since the shim last consumed it, so the ABI call can hand
241
+ // the shim exactly the changed pixels without a second raster. Every
242
+ // changed frame therefore costs ONE dirty-region raster and one
243
+ // damage-region copy — never the full-surface re-render the plain
244
+ // `native_sdk_app_render_pixels` screenshot pays.
245
+
246
+ /// The platform pixel presenter the capture bridge chains
247
+ /// (`PlatformServices.present_gpu_surface_pixels_fn`'s shape).
248
+ pub const MobilePresentPixelsFn = *const fn (context: ?*anyopaque, pixels: platform.GpuSurfacePixels) anyerror!void;
249
+
250
+ /// One rectangle in device-pixel units.
251
+ pub const MobilePixelRect = struct {
252
+ x: usize = 0,
253
+ y: usize = 0,
254
+ width: usize = 0,
255
+ height: usize = 0,
256
+
257
+ fn unionWith(self: MobilePixelRect, other: MobilePixelRect) MobilePixelRect {
258
+ if (self.width == 0 or self.height == 0) return other;
259
+ if (other.width == 0 or other.height == 0) return self;
260
+ const min_x = @min(self.x, other.x);
261
+ const min_y = @min(self.y, other.y);
262
+ const max_x = @max(self.x + self.width, other.x + other.width);
263
+ const max_y = @max(self.y + self.height, other.y + other.height);
264
+ return .{ .x = min_x, .y = min_y, .width = max_x - min_x, .height = max_y - min_y };
265
+ }
266
+ };
267
+
268
+ /// Host-owned mirror of the last presented mobile-surface pixels: a
269
+ /// BORROWED view of the runtime's presented buffer (the ui-app owns it;
270
+ /// the slice is refreshed on every capture, and every buffer
271
+ /// reallocation is a surface-size change whose present re-captures
272
+ /// before any ABI read — the embed entry points all run on the shim's
273
+ /// single loop thread), the accumulated damage since the shim's last
274
+ /// `native_sdk_app_render_pixels_damage` delivery, and the delivery
275
+ /// bookkeeping for the shim's single retained buffer.
276
+ pub const MobilePresentedCanvas = struct {
277
+ pixels: []const u8 = &.{},
278
+ width: usize = 0,
279
+ height: usize = 0,
280
+ scale: f32 = 0,
281
+ /// Captured presents; 0 = nothing presented yet.
282
+ epoch: u64 = 0,
283
+ /// Damage accumulated since the last delivery (device pixels); null
284
+ /// with `epoch > 0` means no visual change since then.
285
+ damage: ?MobilePixelRect = null,
286
+ /// Delivery bookkeeping: which capture epoch (and at what
287
+ /// dimensions) the shim's retained buffer last received. A zero
288
+ /// epoch or dimension drift forces the next delivery to copy the
289
+ /// full surface.
290
+ delivered_epoch: u64 = 0,
291
+ delivered_width: usize = 0,
292
+ delivered_height: usize = 0,
293
+ };
294
+
295
+ /// The dirty rect's device-pixel coverage, mirroring the reference
296
+ /// renderer's rounding exactly (`referencePixelRect`: floor(min) ..
297
+ /// ceil(max), clipped) so the reported damage covers every pixel the
298
+ /// dirty-scissored raster touched.
299
+ fn mobilePixelRectFromBounds(bounds: geometry.RectF, scale: f32, width: usize, height: usize) ?MobilePixelRect {
300
+ const normalized = bounds.normalized();
301
+ if (normalized.isEmpty() or width == 0 or height == 0) return null;
302
+ const effective_scale = if (!std.math.isFinite(scale) or scale <= 0) 1 else scale;
303
+ const min_x = @floor(normalized.minX() * effective_scale);
304
+ const min_y = @floor(normalized.minY() * effective_scale);
305
+ const max_x = @ceil(normalized.maxX() * effective_scale);
306
+ const max_y = @ceil(normalized.maxY() * effective_scale);
307
+ const width_f: f32 = @floatFromInt(width);
308
+ const height_f: f32 = @floatFromInt(height);
309
+ const x0: usize = @intFromFloat(std.math.clamp(min_x, 0, width_f));
310
+ const y0: usize = @intFromFloat(std.math.clamp(min_y, 0, height_f));
311
+ const x1: usize = @intFromFloat(std.math.clamp(max_x, 0, width_f));
312
+ const y1: usize = @intFromFloat(std.math.clamp(max_y, 0, height_f));
313
+ if (x1 <= x0 or y1 <= y0) return null;
314
+ return .{ .x = x0, .y = y0, .width = x1 - x0, .height = y1 - y0 };
315
+ }
316
+
317
+ fn mobileFullPixelRect(width: usize, height: usize) MobilePixelRect {
318
+ return .{ .x = 0, .y = 0, .width = width, .height = height };
319
+ }
320
+
321
+ /// Record one pixel present into the host's capture state. Dimension or
322
+ /// scale changes reset the delivery bookkeeping (the shim's buffer no
323
+ /// longer matches) and mark the full surface damaged; steady-state
324
+ /// presents union their dirty rect in. A present with no dirty rect is
325
+ /// conservatively a full-surface damage (full repaints report the full
326
+ /// surface as their dirty bounds anyway).
327
+ pub fn recordPresentedPixels(state: *MobilePresentedCanvas, pixels: platform.GpuSurfacePixels) void {
328
+ const byte_len = pixels.expectedByteLen() orelse return;
329
+ if (pixels.rgba8.len != byte_len) return;
330
+ const changed_shape = state.epoch == 0 or
331
+ state.width != pixels.width or
332
+ state.height != pixels.height or
333
+ state.scale != pixels.scale_factor;
334
+ state.pixels = pixels.rgba8;
335
+ state.width = pixels.width;
336
+ state.height = pixels.height;
337
+ state.scale = pixels.scale_factor;
338
+ state.epoch += 1;
339
+ if (changed_shape) {
340
+ state.damage = mobileFullPixelRect(pixels.width, pixels.height);
341
+ state.delivered_epoch = 0;
342
+ return;
343
+ }
344
+ const incoming = if (pixels.dirty_bounds) |bounds|
345
+ mobilePixelRectFromBounds(bounds, pixels.scale_factor, pixels.width, pixels.height) orelse return
346
+ else
347
+ mobileFullPixelRect(pixels.width, pixels.height);
348
+ state.damage = if (state.damage) |current| current.unionWith(incoming) else incoming;
349
+ }
350
+
351
+ /// Platform-services bridge that chains the platform's own pixel
352
+ /// presenter (the null platform's recording present — nonblank sample,
353
+ /// present counters) and then captures the presented frame for the
354
+ /// damage ABI. Context recovery mirrors the audio bridge: the services
355
+ /// table carries the host's embedded `NullPlatform`, and the host is
356
+ /// recovered from that field.
357
+ fn MobilePresentCaptureBridge(comptime Host: type) type {
358
+ return struct {
359
+ fn hostFromContext(context: ?*anyopaque) *Host {
360
+ const null_platform: *platform.NullPlatform = @ptrCast(@alignCast(context.?));
361
+ return @alignCast(@fieldParentPtr("null_platform", null_platform));
362
+ }
363
+
364
+ fn presentGpuSurfacePixels(context: ?*anyopaque, pixels: platform.GpuSurfacePixels) anyerror!void {
365
+ const self = hostFromContext(context);
366
+ if (self.present_pixels_chain) |chain| try chain(context, pixels);
367
+ recordPresentedPixels(&self.presented, pixels);
368
+ }
369
+ };
370
+ }
371
+
372
+ /// Wire the presented-pixel capture into the embedded runtime: chain the
373
+ /// platform's pixel presenter behind the capture bridge, drop the packet
374
+ /// presenters (no mobile shim consumes packets, and their presence
375
+ /// forces the pixel path to a FULL repaint every changed frame), opt
376
+ /// the runtime into the pixel-present retained baseline so per-frame
377
+ /// dirty bounds refine to the commands that actually changed, and attach
378
+ /// the host's render memo so heavyweight per-pixel commands replay and
379
+ /// scaled image draws blend from scale-once panels. Call once from the
380
+ /// host's `create`, after the embedded runtime is initialized.
381
+ pub fn installPresentCapture(self: anytype) void {
382
+ const Host = std.meta.Child(@TypeOf(self));
383
+ const Bridge = MobilePresentCaptureBridge(Host);
384
+ const services = &self.embedded.runtime.options.platform.services;
385
+ self.present_pixels_chain = services.present_gpu_surface_pixels_fn;
386
+ services.present_gpu_surface_pixels_fn = Bridge.presentGpuSurfacePixels;
387
+ services.present_gpu_surface_packet_fn = null;
388
+ services.present_gpu_surface_packet_binary_fn = null;
389
+ self.embedded.runtime.options.pixel_present_retained_baseline = true;
390
+ self.render_memo = canvas.ReferenceRenderMemo.init(std.heap.page_allocator);
391
+ self.embedded.runtime.options.pixel_present_render_memo = &self.render_memo;
392
+ }
393
+
394
+ /// Deliver the captured present into the shim's RETAINED buffer: copies
395
+ /// only the damage accumulated since the previous delivery (the full
396
+ /// surface when the buffer is out of sync — first call, size or scale
397
+ /// change) and reports the copied region. Returns false when no capture
398
+ /// matches the request (nothing presented yet, scale drift, byte-length
399
+ /// mismatch) — the caller falls back to a full render.
400
+ pub fn deliverPresentedPixels(self: anytype, scale: f32, buffer: []u8, out: *types.MobileCanvasPixelsDamage) bool {
401
+ const state: *MobilePresentedCanvas = &self.presented;
402
+ if (state.epoch == 0) return false;
403
+ if (state.scale != scale) return false;
404
+ const byte_len = state.width * state.height * 4;
405
+ if (state.pixels.len != byte_len or buffer.len < byte_len) return false;
406
+
407
+ const in_sync = state.delivered_epoch != 0 and
408
+ state.delivered_width == state.width and
409
+ state.delivered_height == state.height;
410
+ const copy_rect: ?MobilePixelRect = if (in_sync) state.damage else mobileFullPixelRect(state.width, state.height);
411
+ var damage = MobilePixelRect{};
412
+ if (copy_rect) |rect| {
413
+ damage = rect;
414
+ const row_stride = state.width * 4;
415
+ const first_byte = rect.x * 4;
416
+ const span = rect.width * 4;
417
+ var row: usize = 0;
418
+ while (row < rect.height) : (row += 1) {
419
+ const offset = (rect.y + row) * row_stride + first_byte;
420
+ @memcpy(buffer[offset .. offset + span], state.pixels[offset .. offset + span]);
421
+ }
422
+ }
423
+ out.* = .{
424
+ .width = state.width,
425
+ .height = state.height,
426
+ .byte_len = byte_len,
427
+ .damage_x = damage.x,
428
+ .damage_y = damage.y,
429
+ .damage_width = damage.width,
430
+ .damage_height = damage.height,
431
+ };
432
+ state.delivered_epoch = state.epoch;
433
+ state.delivered_width = state.width;
434
+ state.delivered_height = state.height;
435
+ state.damage = null;
436
+ return true;
437
+ }
438
+
439
+ pub const EmbeddedApp = struct {
440
+ app: runtime.App,
441
+ runtime: runtime.Runtime,
442
+
443
+ pub fn init(app: runtime.App, platform_value: platform.Platform) EmbeddedApp {
444
+ var embedded: EmbeddedApp = undefined;
445
+ embedded.initInPlace(app, platform_value);
446
+ return embedded;
447
+ }
448
+
449
+ pub fn initInPlace(self: *EmbeddedApp, app: runtime.App, platform_value: platform.Platform) void {
450
+ self.app = app;
451
+ runtime.Runtime.initAt(&self.runtime, .{ .platform = platform_value });
452
+ }
453
+
454
+ pub fn start(self: *EmbeddedApp) anyerror!void {
455
+ try self.runtime.dispatchPlatformEvent(self.app, .app_start);
456
+ }
457
+
458
+ pub fn activate(self: *EmbeddedApp) anyerror!void {
459
+ try self.runtime.dispatchPlatformEvent(self.app, .app_activated);
460
+ }
461
+
462
+ pub fn deactivate(self: *EmbeddedApp) anyerror!void {
463
+ try self.runtime.dispatchPlatformEvent(self.app, .app_deactivated);
464
+ }
465
+
466
+ pub fn resize(self: *EmbeddedApp, surface: platform.Surface) anyerror!void {
467
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .surface_resized = surface });
468
+ if (surface.native_handle != null) {
469
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_resized = .{
470
+ .window_id = 1,
471
+ .label = mobile_gpu_surface_label,
472
+ .frame = geometry.RectF.fromSize(surface.size),
473
+ .scale_factor = surface.scale_factor,
474
+ } });
475
+ }
476
+ }
477
+
478
+ pub fn touch(self: *EmbeddedApp, id: u64, phase: c_int, x: f32, y: f32, pressure: f32) anyerror!void {
479
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
480
+ .window_id = 1,
481
+ .label = mobile_gpu_surface_label,
482
+ .kind = try mobileTouchKindFromPhase(phase),
483
+ .timestamp_ns = nowNanoseconds(),
484
+ .pointer_id = id,
485
+ .x = x,
486
+ .y = y,
487
+ .button = 0,
488
+ .pressure = pressure,
489
+ } });
490
+ }
491
+
492
+ pub fn scroll(self: *EmbeddedApp, id: u64, x: f32, y: f32, delta_x: f32, delta_y: f32) anyerror!void {
493
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
494
+ .window_id = 1,
495
+ .label = mobile_gpu_surface_label,
496
+ .kind = .scroll,
497
+ .timestamp_ns = nowNanoseconds(),
498
+ .pointer_id = id,
499
+ .x = x,
500
+ .y = y,
501
+ .delta_x = delta_x,
502
+ .delta_y = delta_y,
503
+ } });
504
+ }
505
+
506
+ pub fn key(self: *EmbeddedApp, phase: c_int, key_value: []const u8, text_value: []const u8, modifiers_mask: u32) anyerror!void {
507
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
508
+ .window_id = 1,
509
+ .label = mobile_gpu_surface_label,
510
+ .kind = try mobileKeyKindFromPhase(phase),
511
+ .timestamp_ns = nowNanoseconds(),
512
+ .key = key_value,
513
+ .text = text_value,
514
+ .modifiers = mobileModifiersFromMask(modifiers_mask),
515
+ } });
516
+ }
517
+
518
+ pub fn text(self: *EmbeddedApp, text_value: []const u8) anyerror!void {
519
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
520
+ .window_id = 1,
521
+ .label = mobile_gpu_surface_label,
522
+ .kind = .text_input,
523
+ .timestamp_ns = nowNanoseconds(),
524
+ .text = text_value,
525
+ } });
526
+ }
527
+
528
+ pub fn ime(self: *EmbeddedApp, kind: c_int, text_value: []const u8, cursor: isize) anyerror!void {
529
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .gpu_surface_input = .{
530
+ .window_id = 1,
531
+ .label = mobile_gpu_surface_label,
532
+ .kind = try mobileImeKindFromInt(kind),
533
+ .timestamp_ns = nowNanoseconds(),
534
+ .text = text_value,
535
+ .composition_cursor = if (cursor >= 0) @intCast(cursor) else null,
536
+ } });
537
+ }
538
+
539
+ pub fn frame(self: *EmbeddedApp) anyerror!void {
540
+ try self.runtime.dispatchPlatformEvent(self.app, .frame_requested);
541
+ }
542
+
543
+ pub fn command(self: *EmbeddedApp, name: []const u8) anyerror!void {
544
+ try self.runtime.dispatchCommand(self.app, .{
545
+ .name = name,
546
+ .source = .native_view,
547
+ .window_id = 1,
548
+ .view_label = "mobile-header",
549
+ });
550
+ }
551
+
552
+ pub fn widgetSemantics(self: *const EmbeddedApp) anyerror![]const canvas.WidgetSemanticsNode {
553
+ return self.runtime.canvasWidgetSemantics(1, mobile_gpu_surface_label);
554
+ }
555
+
556
+ pub fn gpuFrameState(self: *const EmbeddedApp) anyerror!platform.GpuFrame {
557
+ return self.runtime.gpuSurfaceFrame(1, mobile_gpu_surface_label);
558
+ }
559
+
560
+ /// The mobile surface's retained-canvas revisions: `current` is what
561
+ /// `gpu_frame_state` reports, `presented` is the revision the last
562
+ /// planned present reflects (it advances at plan time even when a
563
+ /// change turned out to move no pixels, so a host gating on it
564
+ /// converges instead of polling forever). Zeros when the view does
565
+ /// not exist yet.
566
+ pub const CanvasRevisions = struct {
567
+ current: u64 = 0,
568
+ presented: u64 = 0,
569
+ };
570
+
571
+ pub fn canvasRevisions(self: *const EmbeddedApp) CanvasRevisions {
572
+ for (self.runtime.views[0..self.runtime.view_count]) |*view| {
573
+ if (!view.open or view.window_id != 1 or view.kind != .gpu_surface) continue;
574
+ if (!std.mem.eql(u8, view.label, mobile_gpu_surface_label)) continue;
575
+ return .{ .current = view.canvas_revision, .presented = view.presented_canvas_revision };
576
+ }
577
+ return .{};
578
+ }
579
+
580
+ pub fn widgetTextGeometry(self: *const EmbeddedApp, id: canvas.ObjectId) anyerror!canvas.WidgetTextGeometry {
581
+ return self.runtime.canvasWidgetTextGeometry(1, mobile_gpu_surface_label, id);
582
+ }
583
+
584
+ pub fn widgetAction(self: *EmbeddedApp, action: runtime.CanvasWidgetAccessibilityAction) anyerror!void {
585
+ _ = try self.runtime.dispatchCanvasWidgetAccessibilityAction(self.app, 1, mobile_gpu_surface_label, action);
586
+ }
587
+
588
+ /// Focus / IME-intent state for the mobile surface: reads the live
589
+ /// pointer/keyboard focus (`canvas_widget_focused_id`, the same state
590
+ /// desktop hosts key their IME activation on) rather than the
591
+ /// source-declared semantics `focused` flag, and reports whether the
592
+ /// focused widget accepts text edits right now.
593
+ pub fn textInputState(self: *const EmbeddedApp) types.MobileTextInputState {
594
+ var state = types.MobileTextInputState{};
595
+ for (self.runtime.views[0..self.runtime.view_count]) |*view| {
596
+ if (!view.open or view.window_id != 1 or view.kind != .gpu_surface) continue;
597
+ if (!std.mem.eql(u8, view.label, mobile_gpu_surface_label)) continue;
598
+ if (!view.focused or view.canvas_widget_focused_id == 0) return state;
599
+ state.widget_id = view.canvas_widget_focused_id;
600
+ for (view.widgetSemantics()) |node| {
601
+ if (node.id != state.widget_id) continue;
602
+ state.x = node.bounds.x;
603
+ state.y = node.bounds.y;
604
+ state.width = node.bounds.width;
605
+ state.height = node.bounds.height;
606
+ break;
607
+ }
608
+ if (view.canEditCanvasWidgetText(state.widget_id)) state.active = 1;
609
+ return state;
610
+ }
611
+ return state;
612
+ }
613
+
614
+ /// One report from the shim's audio player, dispatched exactly like a
615
+ /// desktop platform's `.audio` event: the runtime routes it into the
616
+ /// active playback channel's `on_event` Msg (and the journal). Kind
617
+ /// ordinals match `platform.AudioEventKind` (0 loaded, 1 position,
618
+ /// 2 completed, 3 failed). Shims must call this between runtime entry
619
+ /// points (their loop thread, never from inside a service callback) —
620
+ /// the same next-turn discipline the macOS host keeps for its LOADED
621
+ /// acknowledgment.
622
+ pub fn audioEvent(self: *EmbeddedApp, kind: c_int, position_ms: u64, duration_ms: u64, playing: bool, buffering: bool) anyerror!void {
623
+ try self.runtime.dispatchPlatformEvent(self.app, .{ .audio = .{
624
+ .kind = try conversions.mobileAudioEventKindFromInt(kind),
625
+ .position_ms = position_ms,
626
+ .duration_ms = duration_ms,
627
+ .playing = playing,
628
+ .buffering = buffering,
629
+ } });
630
+ }
631
+
632
+ pub fn stop(self: *EmbeddedApp) anyerror!void {
633
+ try self.runtime.dispatchPlatformEvent(self.app, .app_shutdown);
634
+ }
635
+ };
636
+
637
+ pub const MobileHostApp = struct {
638
+ null_platform: platform.NullPlatform,
639
+ embedded: EmbeddedApp,
640
+ last_error: ?anyerror = null,
641
+ activation_count: usize = 0,
642
+ deactivation_count: usize = 0,
643
+ command_count: usize = 0,
644
+ mobile_surface_resize_count: usize = 0,
645
+ mobile_surface_width: f32 = 0,
646
+ mobile_surface_height: f32 = 0,
647
+ mobile_surface_scale: f32 = 1,
648
+ input_count: usize = 0,
649
+ touch_count: usize = 0,
650
+ last_touch_id: u64 = 0,
651
+ last_touch_kind: platform.GpuSurfaceInputKind = .pointer_up,
652
+ last_touch_timestamp_ns: u64 = 0,
653
+ last_touch_x: f32 = 0,
654
+ last_touch_y: f32 = 0,
655
+ last_touch_delta_x: f32 = 0,
656
+ last_touch_delta_y: f32 = 0,
657
+ last_touch_pressure: f32 = 0,
658
+ last_input_kind: platform.GpuSurfaceInputKind = .pointer_up,
659
+ last_input_timestamp_ns: u64 = 0,
660
+ last_input_key: [max_mobile_input_text_bytes]u8 = undefined,
661
+ last_input_key_len: usize = 0,
662
+ last_input_text: [max_mobile_input_text_bytes]u8 = undefined,
663
+ last_input_text_len: usize = 0,
664
+ last_input_composition_cursor: ?usize = null,
665
+ last_input_modifiers: platform.ShortcutModifiers = .{},
666
+ asset_root: [max_mobile_asset_root_bytes]u8 = undefined,
667
+ asset_root_len: usize = 0,
668
+ asset_entry: [max_mobile_asset_entry_bytes]u8 = undefined,
669
+ asset_entry_len: usize = 0,
670
+ automation_dir: [max_mobile_asset_root_bytes]u8 = undefined,
671
+ automation_dir_len: usize = 0,
672
+ automation_io: ?*std.Io.Threaded = null,
673
+ text_measure: MobileTextMeasure = .{},
674
+ audio: MobileAudio = .{},
675
+ // Image decode stays declined until the shim registers a real codec
676
+ // (`native_sdk_app_set_image_service`): the null platform's strict
677
+ // test decoder is opt-in (`image_decode`, default off), so with no
678
+ // registration `fx.registerImageBytes` reports UnsupportedService and
679
+ // image/avatar widgets keep their fallback — never a bundled codec.
680
+ image: MobileImage = .{},
681
+ /// Standing host chrome reports (see `setFormFactor` /
682
+ /// `setChromeTabsProjected`): composed into every viewport-driven
683
+ /// chrome publish.
684
+ form_factor: platform.FormFactor = .unknown,
685
+ chrome_tabs_projected: bool = false,
686
+ /// Presented-pixel capture state for the damage ABI. The fixed
687
+ /// WebView shell presents no gpu-surface pixels, so this stays at
688
+ /// its empty zero-epoch state and `native_sdk_app_render_pixels_damage`
689
+ /// answers through the full-render fallback — the same honest error
690
+ /// path as `native_sdk_app_render_pixels`.
691
+ presented: MobilePresentedCanvas = .{},
692
+ present_pixels_chain: ?MobilePresentPixelsFn = null,
693
+ last_command_name: [max_mobile_command_name_bytes + 1]u8 = [_]u8{0} ** (max_mobile_command_name_bytes + 1),
694
+
695
+ pub fn create() !*MobileHostApp {
696
+ const allocator = std.heap.page_allocator;
697
+ const self = try allocator.create(MobileHostApp);
698
+ errdefer allocator.destroy(self);
699
+ self.null_platform = platform.NullPlatform.init(.{});
700
+ // Audio is declined until the shim registers a real service
701
+ // (`native_sdk_app_set_audio_service`): the null platform's
702
+ // deterministic fake player belongs to hermetic tests, not to a
703
+ // real app — a load that "succeeds" but never sounds or ticks
704
+ // would be a lie. Cleared before `platform()` is snapshotted
705
+ // below so the runtime's service table starts without audio.
706
+ self.null_platform.audio_playback = false;
707
+ self.null_platform.audio_streaming = false;
708
+ self.last_error = null;
709
+ self.activation_count = 0;
710
+ self.deactivation_count = 0;
711
+ self.command_count = 0;
712
+ self.mobile_surface_resize_count = 0;
713
+ self.mobile_surface_width = 0;
714
+ self.mobile_surface_height = 0;
715
+ self.mobile_surface_scale = 1;
716
+ self.input_count = 0;
717
+ self.touch_count = 0;
718
+ self.last_touch_id = 0;
719
+ self.last_touch_kind = .pointer_up;
720
+ self.last_touch_timestamp_ns = 0;
721
+ self.last_touch_x = 0;
722
+ self.last_touch_y = 0;
723
+ self.last_touch_delta_x = 0;
724
+ self.last_touch_delta_y = 0;
725
+ self.last_touch_pressure = 0;
726
+ self.last_input_kind = .pointer_up;
727
+ self.last_input_timestamp_ns = 0;
728
+ self.last_input_key = undefined;
729
+ self.last_input_key_len = 0;
730
+ self.last_input_text = undefined;
731
+ self.last_input_text_len = 0;
732
+ self.last_input_composition_cursor = null;
733
+ self.last_input_modifiers = .{};
734
+ self.asset_root = undefined;
735
+ self.asset_root_len = 0;
736
+ self.asset_entry = undefined;
737
+ self.asset_entry_len = 0;
738
+ self.automation_dir = undefined;
739
+ self.automation_dir_len = 0;
740
+ self.automation_io = null;
741
+ self.text_measure = .{};
742
+ self.audio = .{};
743
+ self.image = .{};
744
+ self.form_factor = .unknown;
745
+ self.chrome_tabs_projected = false;
746
+ self.presented = .{};
747
+ self.present_pixels_chain = null;
748
+ self.last_command_name = [_]u8{0} ** (max_mobile_command_name_bytes + 1);
749
+ self.embedded.initInPlace(.{
750
+ .context = self,
751
+ .name = "native-sdk-mobile",
752
+ .source_fn = mobileSource,
753
+ .event_fn = handleEvent,
754
+ }, self.null_platform.platform());
755
+ return self;
756
+ }
757
+
758
+ pub fn destroy(self: *MobileHostApp) void {
759
+ disableAutomation(self);
760
+ std.heap.page_allocator.destroy(self);
761
+ }
762
+
763
+ pub fn start(self: *MobileHostApp) anyerror!void {
764
+ try self.embedded.start();
765
+ }
766
+
767
+ pub fn frame(self: *MobileHostApp) anyerror!void {
768
+ try self.embedded.frame();
769
+ }
770
+
771
+ /// The fixed WebView shell declares no scene, so it declares no
772
+ /// platform chrome: the tab set is empty, there is no primary
773
+ /// action, and no selection exists — the honest zero a canvas-less
774
+ /// host answers the chrome ABI with.
775
+ pub fn chromeTabs(self: *const MobileHostApp) []const app_manifest.ShellTab {
776
+ _ = self;
777
+ return &.{};
778
+ }
779
+
780
+ pub fn chromePrimaryAction(self: *const MobileHostApp) ?app_manifest.ShellPrimaryAction {
781
+ _ = self;
782
+ return null;
783
+ }
784
+
785
+ pub fn chromeSelectedTab(self: *const MobileHostApp) []const u8 {
786
+ _ = self;
787
+ return "";
788
+ }
789
+
790
+ /// No scene means no navigation projection either: depth answers -1
791
+ /// (hosts present no transitions) and no back command exists.
792
+ pub fn chromeNavigationDepth(self: *const MobileHostApp) isize {
793
+ _ = self;
794
+ return -1;
795
+ }
796
+
797
+ pub fn chromeNavigationBackCommand(self: *const MobileHostApp) []const u8 {
798
+ _ = self;
799
+ return "";
800
+ }
801
+
802
+ fn source(self: *MobileHostApp) platform.WebViewSource {
803
+ if (self.asset_root_len > 0) {
804
+ return platform.WebViewSource.assets(.{
805
+ .root_path = self.asset_root[0..self.asset_root_len],
806
+ .entry = if (self.asset_entry_len > 0) self.asset_entry[0..self.asset_entry_len] else "index.html",
807
+ .origin = "zero://app",
808
+ .spa_fallback = true,
809
+ });
810
+ }
811
+ return platform.WebViewSource.html(mobile_html);
812
+ }
813
+
814
+ fn handleEvent(context: *anyopaque, runtime_value: *runtime.Runtime, event: runtime.Event) anyerror!void {
815
+ _ = runtime_value;
816
+ const self: *MobileHostApp = @ptrCast(@alignCast(context));
817
+ switch (event) {
818
+ .lifecycle => |lifecycle| switch (lifecycle) {
819
+ .activate => self.activation_count += 1,
820
+ .deactivate => self.deactivation_count += 1,
821
+ else => {},
822
+ },
823
+ .command => |command_event| {
824
+ self.command_count += 1;
825
+ const count = @min(command_event.name.len, max_mobile_command_name_bytes);
826
+ @memcpy(self.last_command_name[0..count], command_event.name[0..count]);
827
+ self.last_command_name[count] = 0;
828
+ },
829
+ .gpu_surface_resized => |resize| {
830
+ if (!std.mem.eql(u8, resize.label, mobile_gpu_surface_label)) return;
831
+ self.mobile_surface_resize_count += 1;
832
+ self.mobile_surface_width = resize.frame.width;
833
+ self.mobile_surface_height = resize.frame.height;
834
+ self.mobile_surface_scale = resize.scale_factor;
835
+ },
836
+ .gpu_surface_input => |input| {
837
+ if (!std.mem.eql(u8, input.label, mobile_gpu_surface_label)) return;
838
+ self.input_count += 1;
839
+ self.last_input_kind = input.kind;
840
+ self.last_input_timestamp_ns = input.timestamp_ns;
841
+ self.last_input_key_len = copyInputText(&self.last_input_key, input.key);
842
+ self.last_input_text_len = copyInputText(&self.last_input_text, input.text);
843
+ self.last_input_composition_cursor = input.composition_cursor;
844
+ self.last_input_modifiers = input.modifiers;
845
+ switch (input.kind) {
846
+ .pointer_down, .pointer_up, .pointer_cancel, .pointer_move, .pointer_drag, .scroll => {
847
+ self.touch_count += 1;
848
+ self.last_touch_id = input.pointer_id;
849
+ self.last_touch_kind = input.kind;
850
+ self.last_touch_timestamp_ns = input.timestamp_ns;
851
+ self.last_touch_x = input.x;
852
+ self.last_touch_y = input.y;
853
+ self.last_touch_delta_x = input.delta_x;
854
+ self.last_touch_delta_y = input.delta_y;
855
+ self.last_touch_pressure = input.pressure;
856
+ },
857
+ else => {},
858
+ }
859
+ },
860
+ else => {},
861
+ }
862
+ }
863
+ };
864
+
865
+ fn mobileSource(context: *anyopaque) anyerror!platform.WebViewSource {
866
+ const self: *MobileHostApp = @ptrCast(@alignCast(context));
867
+ return self.source();
868
+ }
869
+
870
+ pub const mobile_html =
871
+ \\<!doctype html>
872
+ \\<html>
873
+ \\<body style="font-family: system-ui; padding: 2rem;">
874
+ \\ <h1>native-sdk mobile</h1>
875
+ \\ <p>This content is loaded through the native-sdk embedded C ABI.</p>
876
+ \\</body>
877
+ \\</html>
878
+ ;
879
+
880
+ pub fn mobileApp(raw: ?*anyopaque) ?*MobileHostApp {
881
+ const pointer = raw orelse return null;
882
+ return @ptrCast(@alignCast(pointer));
883
+ }
884
+
885
+ /// Publish the viewport's safe-area insets as the mobile surface's window
886
+ /// chrome — the same `windowChrome` platform channel macOS answers with
887
+ /// its titlebar band and traffic-light cluster — so a `UiApp` subscribed
888
+ /// to `on_chrome` pads for the notch, status bar, and home indicator with
889
+ /// the identical code path it pads for desktop chrome. The keyboard is
890
+ /// input avoidance, not OS chrome, so it stays out of the report (the
891
+ /// runtime keeps insetting layout by the keyboard's residual overlap).
892
+ /// The host's standing chrome reports — form factor, projected declared
893
+ /// tabs — ride every publish so a viewport push never erases them.
894
+ pub fn publishViewportChrome(self: anytype, safe_area_insets: geometry.InsetsF) void {
895
+ self.null_platform.window_chrome = .{
896
+ .insets = safe_area_insets,
897
+ .form_factor = self.form_factor,
898
+ .tabs_projected = self.chrome_tabs_projected,
899
+ };
900
+ }
901
+
902
+ /// Record the host-reported form factor (`native_sdk_app_set_form_factor`)
903
+ /// on the window-chrome channel. The report is standing state: it
904
+ /// composes into every later `publishViewportChrome` and updates the
905
+ /// live chrome immediately, so the app's next chrome re-query (the
906
+ /// resize the host's layout pass triggers, or the pre-install query)
907
+ /// delivers it as an ordinary `on_chrome` Msg.
908
+ pub fn setFormFactor(self: anytype, form_factor: platform.FormFactor) void {
909
+ self.form_factor = form_factor;
910
+ self.null_platform.window_chrome.form_factor = form_factor;
911
+ }
912
+
913
+ /// Record whether the host is projecting the app's declared chrome tabs
914
+ /// as real native controls (`native_sdk_app_set_chrome_tabs_projected`).
915
+ /// Standing state on the chrome channel, exactly like the form factor:
916
+ /// an app whose canvas composes its own tab switcher yields it while
917
+ /// this is set.
918
+ pub fn setChromeTabsProjected(self: anytype, projected: bool) void {
919
+ self.chrome_tabs_projected = projected;
920
+ self.null_platform.window_chrome.tabs_projected = projected;
921
+ }
922
+
923
+ pub fn recordError(self: anytype, err: anyerror) void {
924
+ self.last_error = err;
925
+ }
926
+
927
+ /// Point the embedded runtime's automation server at `dir` (the desktop
928
+ /// equivalent is `-Dautomation=true` + `.zig-cache/native-sdk-automation`;
929
+ /// mobile shims pass an absolute path inside the app's data container).
930
+ /// The host-pumped frame loop then consumes the `command-<n>.txt` queue
931
+ /// and publishes `snapshot.txt` / `accessibility.txt` / `windows.txt`
932
+ /// exactly like the desktop runners.
933
+ pub fn enableAutomation(self: anytype, dir: []const u8) anyerror!void {
934
+ if (dir.len == 0) return error.InvalidCommand;
935
+ if (dir.len > self.automation_dir.len) return error.WindowSourceTooLarge;
936
+ const allocator = std.heap.page_allocator;
937
+ if (self.automation_io == null) {
938
+ const threaded = try allocator.create(std.Io.Threaded);
939
+ errdefer allocator.destroy(threaded);
940
+ threaded.* = std.Io.Threaded.init(allocator, .{});
941
+ self.automation_io = threaded;
942
+ }
943
+ @memcpy(self.automation_dir[0..dir.len], dir);
944
+ self.automation_dir_len = dir.len;
945
+ self.embedded.runtime.options.automation = automation.Server.init(
946
+ self.automation_io.?.io(),
947
+ self.automation_dir[0..self.automation_dir_len],
948
+ self.embedded.app.name,
949
+ );
950
+ }
951
+
952
+ pub fn disableAutomation(self: anytype) void {
953
+ self.embedded.runtime.options.automation = null;
954
+ self.automation_dir_len = 0;
955
+ if (self.automation_io) |threaded| {
956
+ threaded.deinit();
957
+ std.heap.page_allocator.destroy(threaded);
958
+ self.automation_io = null;
959
+ }
960
+ }