@native-sdk/cli 0.8.3 → 0.9.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 (188) hide show
  1. package/build/app.zig +905 -61
  2. package/build.zig +674 -373
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +6 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +455 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  12. package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
  13. package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
  14. package/packages/core/scripts/stage_external_core.mjs +9 -1
  15. package/packages/core/scripts/stage_external_services.mjs +172 -0
  16. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  17. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  18. package/packages/core/sdk/core.d.ts +214 -2
  19. package/packages/core/sdk/core.ts +715 -42
  20. package/packages/core/sdk/events.d.ts +50 -0
  21. package/packages/core/sdk/events.ts +75 -0
  22. package/packages/core/src/checker.ts +528 -15
  23. package/packages/core/src/cli.ts +143 -3
  24. package/packages/core/src/contract.ts +26 -5
  25. package/packages/core/src/devhost.ts +1849 -18
  26. package/packages/core/src/devhost_journal.mjs +181 -0
  27. package/packages/core/src/devhost_resolver.mjs +17 -1
  28. package/packages/core/src/devhost_service_worker.mjs +90 -0
  29. package/packages/core/src/diagnostics.ts +84 -18
  30. package/packages/core/src/frontend.ts +204 -34
  31. package/packages/core/src/modules.ts +129 -80
  32. package/packages/core/src/service_contract.ts +597 -0
  33. package/packages/core/src/sqlite_cli.ts +93 -0
  34. package/packages/core/src/sqlite_codegen.ts +806 -0
  35. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  36. package/packages/core/src/typed_ast.ts +36 -8
  37. package/skill-data/core/SKILL.md +4 -2
  38. package/skill-data/core/references/project-anatomy.md +3 -2
  39. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  40. package/skill-data/native-ui/SKILL.md +55 -8
  41. package/skill-data/ts-core/SKILL.md +92 -40
  42. package/skill-data/ts-services/SKILL.md +126 -0
  43. package/skill-data/ts-services/references/service-surface.md +603 -0
  44. package/skill-data/zig/SKILL.md +1 -1
  45. package/skills/native-sdk/SKILL.md +1 -1
  46. package/src/app_runner/no_migrations.zig +3 -0
  47. package/src/app_runner/no_services.zig +20 -0
  48. package/src/app_runner/root.zig +104 -4
  49. package/src/app_runner/ts_core_main.zig +268 -4
  50. package/src/automation/snapshot.zig +23 -5
  51. package/src/embed/app_exports.zig +11 -1
  52. package/src/embed/c_api.zig +48 -2
  53. package/src/embed/conversions.zig +4 -5
  54. package/src/embed/host.zig +115 -1
  55. package/src/embed/root.zig +7 -0
  56. package/src/embed/tests.zig +213 -0
  57. package/src/embed/types.zig +51 -0
  58. package/src/embed/ui_host.zig +121 -5
  59. package/src/platform/android/NativeSdkActivity.java +131 -0
  60. package/src/platform/android/android_host.c +182 -1
  61. package/src/platform/android/native_sdk_app.h +17 -0
  62. package/src/platform/ios/native_sdk_app.h +17 -0
  63. package/src/platform/ios/uikit_host.m +115 -0
  64. package/src/platform/linux/cef_host.cpp +1 -1
  65. package/src/platform/linux/gtk_host.c +89 -17
  66. package/src/platform/linux/gtk_host.h +3 -0
  67. package/src/platform/linux/root.zig +41 -18
  68. package/src/platform/macos/appkit_host.h +26 -3
  69. package/src/platform/macos/appkit_host.m +1051 -129
  70. package/src/platform/macos/capture_info_plist.c +25 -0
  71. package/src/platform/macos/cef_host.mm +270 -36
  72. package/src/platform/macos/root.zig +312 -34
  73. package/src/platform/null_platform.zig +281 -19
  74. package/src/platform/null_platform_tests.zig +74 -0
  75. package/src/platform/root.zig +16 -0
  76. package/src/platform/types.zig +279 -15
  77. package/src/platform/windows/root.zig +243 -21
  78. package/src/platform/windows/webview2_host.cpp +464 -46
  79. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  80. package/src/primitives/app_manifest/root.zig +4 -0
  81. package/src/primitives/app_manifest/tests.zig +3 -0
  82. package/src/primitives/app_manifest/types.zig +34 -0
  83. package/src/primitives/app_manifest/validation.zig +19 -1
  84. package/src/primitives/canvas/code_tests.zig +9 -9
  85. package/src/primitives/canvas/events.zig +12 -11
  86. package/src/primitives/canvas/frame.zig +44 -9
  87. package/src/primitives/canvas/icons/mic.svg +1 -0
  88. package/src/primitives/canvas/icons.zig +2 -0
  89. package/src/primitives/canvas/root.zig +8 -0
  90. package/src/primitives/canvas/text_span_tests.zig +39 -0
  91. package/src/primitives/canvas/ui.zig +23 -4
  92. package/src/primitives/canvas/ui_markup.zig +15 -0
  93. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  94. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  95. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  96. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  97. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  98. package/src/primitives/canvas/ui_schema.zig +19 -10
  99. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  100. package/src/primitives/canvas/ui_tests.zig +18 -4
  101. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  102. package/src/primitives/canvas/widget_render.zig +296 -114
  103. package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
  104. package/src/primitives/canvas/widget_text_input.zig +10 -10
  105. package/src/primitives/canvas/widget_tree.zig +1 -1
  106. package/src/primitives/canvas/widgets.zig +29 -5
  107. package/src/root.zig +56 -0
  108. package/src/runtime/api.zig +11 -0
  109. package/src/runtime/automation_snapshot.zig +4 -0
  110. package/src/runtime/automation_widget_dispatch.zig +1 -0
  111. package/src/runtime/bridge_payload.zig +2 -0
  112. package/src/runtime/bridge_permission_tests.zig +23 -2
  113. package/src/runtime/bridge_responses.zig +3 -1
  114. package/src/runtime/canvas_frame.zig +31 -13
  115. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  116. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  117. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  118. package/src/runtime/canvas_widget_events.zig +69 -24
  119. package/src/runtime/canvas_widget_runtime.zig +101 -6
  120. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  121. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  122. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  123. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  124. package/src/runtime/canvas_widget_state.zig +6 -1
  125. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  126. package/src/runtime/clock.zig +13 -1
  127. package/src/runtime/core.zig +133 -1
  128. package/src/runtime/credentials_store.zig +115 -0
  129. package/src/runtime/effects.zig +2568 -75
  130. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  131. package/src/runtime/effects_credentials_tests.zig +332 -0
  132. package/src/runtime/effects_host_tests.zig +208 -1
  133. package/src/runtime/effects_relational_tests.zig +314 -0
  134. package/src/runtime/effects_store_tests.zig +211 -0
  135. package/src/runtime/flow.zig +14 -1
  136. package/src/runtime/gpu_surface_events.zig +6 -1
  137. package/src/runtime/native_command_event_tests.zig +42 -0
  138. package/src/runtime/persist_store.zig +666 -0
  139. package/src/runtime/record_store.zig +788 -0
  140. package/src/runtime/relational_store.zig +854 -0
  141. package/src/runtime/root.zig +52 -0
  142. package/src/runtime/runtime_event_tests.zig +70 -0
  143. package/src/runtime/service_host.zig +711 -0
  144. package/src/runtime/service_pool.zig +1314 -0
  145. package/src/runtime/session_blobs.zig +1 -1
  146. package/src/runtime/session_journal.zig +102 -0
  147. package/src/runtime/session_record.zig +177 -0
  148. package/src/runtime/session_replay.zig +109 -4
  149. package/src/runtime/shell_layout.zig +1 -0
  150. package/src/runtime/shell_layout_tests.zig +120 -0
  151. package/src/runtime/sqlite_engine.zig +474 -0
  152. package/src/runtime/state.zig +6 -0
  153. package/src/runtime/system_services.zig +49 -10
  154. package/src/runtime/tests.zig +5 -0
  155. package/src/runtime/ts_core_host.zig +1189 -118
  156. package/src/runtime/ts_core_host_tests.zig +638 -11
  157. package/src/runtime/ts_ui_app.zig +537 -1
  158. package/src/runtime/ui_app.zig +160 -19
  159. package/src/runtime/ui_app_tests.zig +203 -5
  160. package/src/runtime/validation.zig +22 -0
  161. package/src/runtime/view.zig +11 -0
  162. package/src/runtime/view_widget_scroll.zig +56 -5
  163. package/src/runtime/view_widget_text.zig +24 -5
  164. package/src/runtime/view_widget_tree.zig +1 -1
  165. package/src/runtime/window_storage.zig +1 -0
  166. package/src/runtime/window_view_runtime.zig +2 -3
  167. package/src/runtime/window_views.zig +19 -0
  168. package/src/tooling/android.zig +21 -16
  169. package/src/tooling/db.zig +160 -0
  170. package/src/tooling/ios.zig +7 -1
  171. package/src/tooling/manifest.zig +1248 -2
  172. package/src/tooling/package.zig +953 -6
  173. package/src/tooling/raw_manifest.zig +65 -0
  174. package/src/tooling/root.zig +1 -0
  175. package/src/tooling/templates.zig +216 -4
  176. package/src/tooling/ts_core.zig +283 -17
  177. package/src/tooling/verbs.zig +7 -0
  178. package/third_party/sqlite/README.md +13 -0
  179. package/third_party/sqlite/sqlite3.c +269649 -0
  180. package/third_party/sqlite/sqlite3.h +14349 -0
  181. package/tools/corewire/core_abi.zig +14 -2
  182. package/tools/corewire/emit.zig +98 -29
  183. package/tools/corewire/emit_facade.zig +414 -23
  184. package/tools/corewire/emit_profile.zig +6 -2
  185. package/tools/corewire/emit_service.zig +924 -0
  186. package/tools/corewire/main.zig +122 -0
  187. package/tools/corewire/service_contract.zig +250 -0
  188. package/tools/corewire/sidecar.zig +26 -15
@@ -40,6 +40,7 @@ const WindowsEventKind = enum(c_int) {
40
40
  audio = 18,
41
41
  context_menu_action = 19,
42
42
  view_focused = 20,
43
+ tray_command = 21,
43
44
  };
44
45
 
45
46
  const WindowsEvent = extern struct {
@@ -159,6 +160,7 @@ extern fn native_sdk_windows_cancel_timer(host: *WindowsHost, timer_id: u64) voi
159
160
  extern fn native_sdk_windows_focus_window(host: *WindowsHost, window_id: u64) c_int;
160
161
  extern fn native_sdk_windows_close_window(host: *WindowsHost, window_id: u64) c_int;
161
162
  extern fn native_sdk_windows_minimize_window(host: *WindowsHost, window_id: u64) c_int;
163
+ extern fn native_sdk_windows_hide_window(host: *WindowsHost, window_id: u64) c_int;
162
164
  extern fn native_sdk_windows_show_window(host: *WindowsHost, window_id: u64) c_int;
163
165
  extern fn native_sdk_windows_set_window_close_policy(host: *WindowsHost, window_id: u64, close_policy: c_int) c_int;
164
166
  extern fn native_sdk_windows_create_view(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, kind: c_int, gpu_backend_request: c_int, parent: [*]const u8, parent_len: usize, x: f64, y: f64, width: f64, height: f64, layer: c_int, visible: c_int, enabled: c_int, role: [*]const u8, role_len: usize, accessibility_label: [*]const u8, accessibility_label_len: usize, text: [*]const u8, text_len: usize, command: [*]const u8, command_len: usize) c_int;
@@ -187,14 +189,15 @@ extern fn native_sdk_windows_show_open_dialog(host: *WindowsHost, opts: *const W
187
189
  extern fn native_sdk_windows_show_save_dialog(host: *WindowsHost, opts: *const WindowsSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
188
190
  extern fn native_sdk_windows_show_message_dialog(host: *WindowsHost, opts: *const WindowsMessageDialogOpts) c_int;
189
191
  extern fn native_sdk_windows_show_notification(host: *WindowsHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize) c_int;
190
- extern fn native_sdk_windows_create_tray(host: *WindowsHost, icon_path: [*]const u8, icon_path_len: usize, tooltip: [*]const u8, tooltip_len: usize) c_int;
191
- extern fn native_sdk_windows_update_tray_menu(host: *WindowsHost, item_ids: [*]const u32, labels: [*]const [*]const u8, label_lens: [*]const usize, separators: [*]const c_int, enabled_flags: [*]const c_int, count: usize) c_int;
192
+ extern fn native_sdk_windows_create_tray(host: *WindowsHost, icon_path: [*]const u8, icon_path_len: usize, tooltip: [*]const u8, tooltip_len: usize, activation_command: [*]const u8, activation_command_len: usize, alternate_activation_command: [*]const u8, alternate_activation_command_len: usize, open_command: [*]const u8, open_command_len: usize) c_int;
193
+ extern fn native_sdk_windows_update_tray_menu(host: *WindowsHost, item_ids: [*]const u32, labels: [*]const [*]const u8, label_lens: [*]const usize, separators: [*]const c_int, enabled_flags: [*]const c_int, details: [*]const [*]const u8, detail_lens: [*]const usize, roles: [*]const c_int, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) c_int;
192
194
  extern fn native_sdk_windows_remove_tray(host: *WindowsHost) void;
193
195
  extern fn native_sdk_windows_add_recent_document(host: *WindowsHost, path: [*]const u8, path_len: usize) c_int;
194
196
  extern fn native_sdk_windows_clear_recent_documents(host: *WindowsHost) c_int;
195
197
  extern fn native_sdk_windows_set_credential(host: *WindowsHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, secret: [*]const u8, secret_len: usize) c_int;
196
198
  extern fn native_sdk_windows_get_credential(host: *WindowsHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, buffer: [*]u8, buffer_len: usize) usize;
197
199
  extern fn native_sdk_windows_delete_credential(host: *WindowsHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize) c_int;
200
+ extern fn native_sdk_windows_format_local_time(host: *WindowsHost, timestamp_ms: i64, style: c_int, buffer: [*]u8, buffer_len: usize) usize;
198
201
  extern fn native_sdk_windows_clipboard_read(host: *WindowsHost, buffer: [*]u8, buffer_len: usize) usize;
199
202
  extern fn native_sdk_windows_clipboard_write(host: *WindowsHost, text: [*]const u8, text_len: usize) void;
200
203
  extern fn native_sdk_windows_clipboard_read_data(host: *WindowsHost, mime_type: [*]const u8, mime_type_len: usize, buffer: [*]u8, buffer_len: usize) usize;
@@ -206,6 +209,9 @@ extern fn native_sdk_windows_audio_pause(host: *WindowsHost) c_int;
206
209
  extern fn native_sdk_windows_audio_stop(host: *WindowsHost) c_int;
207
210
  extern fn native_sdk_windows_audio_seek(host: *WindowsHost, position_ms: u64) c_int;
208
211
  extern fn native_sdk_windows_audio_set_volume(host: *WindowsHost, volume: f64) c_int;
212
+ const WindowsAudioCapturePush = *const fn (context: ?*anyopaque, kind: c_int, source: c_int, sample_rate: u32, channels: u8, timestamp_ns: u64, frames: u32, pcm: ?[*]const u8, pcm_len: usize) callconv(.c) c_int;
213
+ extern fn native_sdk_windows_audio_capture_start(host: *WindowsHost, source: c_int, sample_rate: u32, channels: u8, push_fn: WindowsAudioCapturePush, push_context: ?*anyopaque) c_int;
214
+ extern fn native_sdk_windows_audio_capture_stop(host: *WindowsHost, source: c_int) c_int;
209
215
  extern fn native_sdk_windows_audio_spectrum_supported(host: *WindowsHost) c_int;
210
216
  extern fn native_sdk_windows_show_context_menu(host: *WindowsHost, window_id: u64, label: [*]const u8, label_len: usize, x: f64, y: f64, token: u64, items: [*]const WindowsContextMenuItem, count: usize) c_int;
211
217
 
@@ -303,9 +309,8 @@ pub const WindowsPlatform = struct {
303
309
  /// later runtime-created alpha window can fail with the precise
304
310
  /// transparency error before crossing the C ABI.
305
311
  menus_active: bool = false,
306
- /// Latched when the runtime's effects teardown abandons an
307
- /// in-flight channel `wake_fn` call (see
308
- /// `PlatformServices.note_channel_wake_abandoned_fn`): the stale
312
+ /// Latched when effects teardown abandons an in-flight platform call
313
+ /// (a channel wake or blocking credential operation): the stale
309
314
  /// call still holds this platform as its context and may execute
310
315
  /// into it at any later time, so `deinit` must skip destruction
311
316
  /// and leak the host, process-lived — and the wrapper struct the
@@ -315,6 +320,7 @@ pub const WindowsPlatform = struct {
315
320
  /// `createWithOptions` and retire it through `destroy`, the
316
321
  /// latch-gated free.
317
322
  channel_wake_abandoned: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
323
+ audio_capture_sinks: [2]platform_mod.AudioCaptureSink = [_]platform_mod.AudioCaptureSink{.{}} ** 2,
318
324
 
319
325
  pub fn init(title: []const u8, size: geometry.SizeF) Error!WindowsPlatform {
320
326
  return initWithEngine(title, size, .system);
@@ -395,13 +401,13 @@ pub const WindowsPlatform = struct {
395
401
  }
396
402
 
397
403
  pub fn deinit(self: *WindowsPlatform) void {
398
- // An abandoned channel wake call may still enter this host at
404
+ // An abandoned platform call may still enter this host at
399
405
  // any later time (see `channel_wake_abandoned`): destroying it
400
406
  // would turn that stale call into a use-after-free, so the
401
407
  // host is deliberately leaked, process-lived — the
402
408
  // abandoned-worker idiom, applied to the platform itself.
403
409
  if (self.channel_wake_abandoned.load(.seq_cst)) {
404
- std.debug.print("windows platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it (and the wrapper it enters through), process-lived, so the stale call stays safe\n", .{});
410
+ std.debug.print("windows platform teardown: an abandoned platform call may still enter this host; skipping destruction and leaking it (and the wrapper it enters through), process-lived, so the stale call stays safe\n", .{});
405
411
  return;
406
412
  }
407
413
  native_sdk_windows_destroy(self.host);
@@ -429,6 +435,7 @@ pub const WindowsPlatform = struct {
429
435
  .focus_window_fn = focusWindow,
430
436
  .close_window_fn = closeWindow,
431
437
  .minimize_window_fn = minimizeWindow,
438
+ .hide_window_fn = hideWindow,
432
439
  .show_window_fn = showWindow,
433
440
  .quit_app_fn = quitApp,
434
441
  .start_window_drag_fn = startWindowDrag,
@@ -469,6 +476,8 @@ pub const WindowsPlatform = struct {
469
476
  .set_credential_fn = setCredential,
470
477
  .get_credential_fn = getCredential,
471
478
  .delete_credential_fn = deleteCredential,
479
+ .note_blocking_call_abandoned_fn = noteChannelWakeAbandoned,
480
+ .format_local_time_fn = formatLocalTime,
472
481
  .audio_load_fn = audioLoad,
473
482
  .audio_load_url_fn = audioLoadUrl,
474
483
  .audio_play_fn = audioPlay,
@@ -476,6 +485,8 @@ pub const WindowsPlatform = struct {
476
485
  .audio_stop_fn = audioStop,
477
486
  .audio_seek_fn = audioSeek,
478
487
  .audio_set_volume_fn = audioSetVolume,
488
+ .audio_capture_start_fn = if (self.web_engine == .system) audioCaptureStart else null,
489
+ .audio_capture_stop_fn = if (self.web_engine == .system) audioCaptureStop else null,
479
490
  // The video load verbs are teaching refusals (see
480
491
  // `videoLoad`); the transport verbs stay null — the
481
492
  // channel never activates without a successful load.
@@ -513,13 +524,17 @@ pub const WindowsPlatform = struct {
513
524
  .reveal_path,
514
525
  .notifications,
515
526
  .recent_documents,
516
- .credentials,
517
527
  .file_drops,
518
528
  .app_activation_events,
519
529
  .gpu_surfaces,
520
530
  .audio_playback,
521
531
  .audio_streaming,
532
+ .microphone_capture,
533
+ .system_audio_capture,
522
534
  => self.web_engine == .system,
535
+ // Credential Manager backs both core effects and the builtin
536
+ // bridge and does not depend on WebView2 being selected.
537
+ .credentials => true,
523
538
  // close_policy .hide: WM_CLOSE hides (ShowWindow SW_HIDE),
524
539
  // the window stays in the host map, and the tray is the
525
540
  // ONLY re-show affordance — SW_HIDE removes the taskbar
@@ -661,6 +676,10 @@ fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c
661
676
  .window_id = event.window_id,
662
677
  } }),
663
678
  .tray_action => state.emit(.{ .tray_action = event.tray_item_id }),
679
+ .tray_command => state.emit(.{ .tray_command = .{
680
+ .name = event.command_name[0..event.command_name_len],
681
+ .window_id = event.window_id,
682
+ } }),
664
683
  .gpu_surface_frame => state.emit(.{ .gpu_surface_frame = gpuSurfaceFrameEventFromWindowsEvent(event) }),
665
684
  .gpu_surface_resize => state.emit(.{ .gpu_surface_resized = .{
666
685
  .window_id = event.window_id,
@@ -923,6 +942,7 @@ fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
923
942
  return switch (mode) {
924
943
  .immediate => 0,
925
944
  .on_first_present => 1,
945
+ .hidden => 2,
926
946
  };
927
947
  }
928
948
 
@@ -932,6 +952,7 @@ fn windowFlags(options: platform_mod.WindowOptions) u32 {
932
952
  if (options.always_on_top) flags |= 1 << 1;
933
953
  if (options.click_through) flags |= 1 << 2;
934
954
  if (!options.activate_on_show) flags |= 1 << 3;
955
+ if (!options.allows_fullscreen) flags |= 1 << 4;
935
956
  return flags;
936
957
  }
937
958
 
@@ -970,6 +991,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
970
991
  .scale_factor = 1,
971
992
  .open = true,
972
993
  .focused = options.activate_on_show and options.show == .immediate,
994
+ .hidden = options.show == .hidden,
973
995
  };
974
996
  }
975
997
 
@@ -988,6 +1010,11 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
988
1010
  if (native_sdk_windows_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
989
1011
  }
990
1012
 
1013
+ fn hideWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1014
+ const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1015
+ if (native_sdk_windows_hide_window(self.host, window_id) == 0) return error.WindowNotFound;
1016
+ }
1017
+
991
1018
  fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
992
1019
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
993
1020
  if (native_sdk_windows_show_window(self.host, window_id) == 0) return error.WindowNotFound;
@@ -1469,7 +1496,19 @@ const max_tray_items: usize = 32;
1469
1496
  fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
1470
1497
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1471
1498
  if (self.web_engine != .system) return error.UnsupportedService;
1472
- if (native_sdk_windows_create_tray(self.host, options.icon_path.ptr, options.icon_path.len, options.tooltip.ptr, options.tooltip.len) == 0) return error.UnsupportedService;
1499
+ if (native_sdk_windows_create_tray(
1500
+ self.host,
1501
+ options.icon_path.ptr,
1502
+ options.icon_path.len,
1503
+ options.tooltip.ptr,
1504
+ options.tooltip.len,
1505
+ options.activation_command.ptr,
1506
+ options.activation_command.len,
1507
+ options.alternate_activation_command.ptr,
1508
+ options.alternate_activation_command.len,
1509
+ options.open_command.ptr,
1510
+ options.open_command.len,
1511
+ ) == 0) return error.UnsupportedService;
1473
1512
  if (options.items.len > 0) {
1474
1513
  try updateTrayMenu(context, options.items);
1475
1514
  }
@@ -1484,19 +1523,37 @@ fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem
1484
1523
  var label_lens: [max_tray_items]usize = undefined;
1485
1524
  var separators: [max_tray_items]c_int = undefined;
1486
1525
  var enabled_flags: [max_tray_items]c_int = undefined;
1526
+ var details: [max_tray_items][*]const u8 = undefined;
1527
+ var detail_lens: [max_tray_items]usize = undefined;
1528
+ var roles: [max_tray_items]c_int = undefined;
1529
+ var keys: [max_tray_items][*]const u8 = undefined;
1530
+ var key_lens: [max_tray_items]usize = undefined;
1531
+ var modifiers: [max_tray_items]u32 = undefined;
1487
1532
  // Tray labels are app-supplied too, so they get the same mnemonic
1488
- // escape as context-menu items (the host copies before returning).
1489
- var label_pool: [max_tray_items * 64]u8 = undefined;
1533
+ // escape as context-menu items. Detail is appended to the visible
1534
+ // Windows fallback label, so escape it too (the host copies both before
1535
+ // returning). Doubling covers the all-ampersands worst case.
1536
+ var label_pool: [max_tray_items * (platform_mod.max_tray_item_label_bytes + platform_mod.max_tray_item_detail_bytes) * 2]u8 = undefined;
1490
1537
  var pool_used: usize = 0;
1491
1538
  for (items[0..count], 0..) |item, index| {
1492
1539
  const label = escapeMenuLabelAmpersands(item.label, &label_pool, &pool_used);
1540
+ const detail = escapeMenuLabelAmpersands(item.detail, &label_pool, &pool_used);
1493
1541
  ids[index] = item.id;
1494
1542
  labels[index] = label.ptr;
1495
1543
  label_lens[index] = label.len;
1496
1544
  separators[index] = if (item.separator) 1 else 0;
1497
- enabled_flags[index] = if (item.enabled) 1 else 0;
1545
+ // Windows has no custom status-menu row seam. Preserve semantic
1546
+ // readouts as visible detail text, while only command/agent rows can
1547
+ // become actions.
1548
+ enabled_flags[index] = if (item.enabled and (item.role == .command or item.role == .agent)) 1 else 0;
1549
+ details[index] = detail.ptr;
1550
+ detail_lens[index] = detail.len;
1551
+ roles[index] = @intFromEnum(item.role);
1552
+ keys[index] = item.key.ptr;
1553
+ key_lens[index] = item.key.len;
1554
+ modifiers[index] = shortcutModifierFlags(item.modifiers);
1498
1555
  }
1499
- if (native_sdk_windows_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, count) == 0) return error.UnsupportedService;
1556
+ if (native_sdk_windows_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, &details, &detail_lens, &roles, &keys, &key_lens, &modifiers, count) == 0) return error.UnsupportedService;
1500
1557
  }
1501
1558
 
1502
1559
  fn removeTray(context: ?*anyopaque) anyerror!void {
@@ -1531,8 +1588,7 @@ fn clearRecentDocuments(context: ?*anyopaque) anyerror!void {
1531
1588
 
1532
1589
  fn setCredential(context: ?*anyopaque, credential: platform_mod.Credential) anyerror!void {
1533
1590
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1534
- if (self.web_engine != .system) return error.UnsupportedService;
1535
- if (native_sdk_windows_set_credential(
1591
+ const result = native_sdk_windows_set_credential(
1536
1592
  self.host,
1537
1593
  credential.service.ptr,
1538
1594
  credential.service.len,
@@ -1540,12 +1596,14 @@ fn setCredential(context: ?*anyopaque, credential: platform_mod.Credential) anye
1540
1596
  credential.account.len,
1541
1597
  credential.secret.ptr,
1542
1598
  credential.secret.len,
1543
- ) == 0) return error.UnsupportedService;
1599
+ );
1600
+ if (result == -3) return error.AccessDenied;
1601
+ if (result == -4) return error.CredentialFieldTooLarge;
1602
+ if (result <= 0) return error.CredentialStoreFailed;
1544
1603
  }
1545
1604
 
1546
1605
  fn getCredential(context: ?*anyopaque, key: platform_mod.CredentialKey, buffer: []u8) anyerror![]const u8 {
1547
1606
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1548
- if (self.web_engine != .system) return error.UnsupportedService;
1549
1607
  const len = native_sdk_windows_get_credential(
1550
1608
  self.host,
1551
1609
  key.service.ptr,
@@ -1555,21 +1613,32 @@ fn getCredential(context: ?*anyopaque, key: platform_mod.CredentialKey, buffer:
1555
1613
  buffer.ptr,
1556
1614
  buffer.len,
1557
1615
  );
1558
- if (len == 0) return error.CredentialNotFound;
1616
+ if (len == std.math.maxInt(usize)) return error.CredentialNotFound;
1617
+ if (len == std.math.maxInt(usize) - 3) return error.AccessDenied;
1618
+ if (len == std.math.maxInt(usize) - 1) return error.CredentialStoreFailed;
1559
1619
  if (len > buffer.len) return error.NoSpaceLeft;
1560
1620
  return buffer[0..len];
1561
1621
  }
1562
1622
 
1563
1623
  fn deleteCredential(context: ?*anyopaque, key: platform_mod.CredentialKey) anyerror!void {
1564
1624
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1565
- if (self.web_engine != .system) return error.UnsupportedService;
1566
- if (native_sdk_windows_delete_credential(
1625
+ const result = native_sdk_windows_delete_credential(
1567
1626
  self.host,
1568
1627
  key.service.ptr,
1569
1628
  key.service.len,
1570
1629
  key.account.ptr,
1571
1630
  key.account.len,
1572
- ) == 0) return error.CredentialNotFound;
1631
+ );
1632
+ if (result == -3) return error.AccessDenied;
1633
+ if (result < 0) return error.CredentialStoreFailed;
1634
+ if (result == 0) return error.CredentialNotFound;
1635
+ }
1636
+
1637
+ fn formatLocalTime(context: ?*anyopaque, timestamp_ms: i64, style: platform_mod.LocalTimeStyle, buffer: []u8) anyerror![]const u8 {
1638
+ const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1639
+ const len = native_sdk_windows_format_local_time(self.host, timestamp_ms, @intFromEnum(style), buffer.ptr, buffer.len);
1640
+ if (len == 0 or len > buffer.len) return error.LocalTimeFormatFailed;
1641
+ return buffer[0..len];
1573
1642
  }
1574
1643
 
1575
1644
  /// Map the audio host's synchronous load result: 0 loaded, 1 the file is
@@ -1626,6 +1695,54 @@ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1626
1695
  _ = native_sdk_windows_audio_set_volume(self.host, volume);
1627
1696
  }
1628
1697
 
1698
+ fn nativeSdkAudioCapturePush(context: ?*anyopaque, kind: c_int, source_value: c_int, sample_rate: u32, channels: u8, timestamp_ns: u64, frames: u32, pcm: ?[*]const u8, pcm_len: usize) callconv(.c) c_int {
1699
+ const sink: *platform_mod.AudioCaptureSink = @ptrCast(@alignCast(context orelse return 1));
1700
+ const source: platform_mod.AudioCaptureSource = switch (source_value) {
1701
+ 1 => .system,
1702
+ else => .microphone,
1703
+ };
1704
+ const event_kind: platform_mod.AudioCaptureEventKind = switch (kind) {
1705
+ 0 => .started,
1706
+ 1 => .data,
1707
+ else => .failed,
1708
+ };
1709
+ const bytes = if (pcm) |ptr| ptr[0..pcm_len] else "";
1710
+ return switch (sink.push(.{
1711
+ .kind = event_kind,
1712
+ .source = source,
1713
+ .format = .{ .sample_rate = sample_rate, .channels = channels },
1714
+ .timestamp_ns = timestamp_ns,
1715
+ .frames = frames,
1716
+ .pcm_s16le = bytes,
1717
+ })) {
1718
+ .accepted => 0,
1719
+ .closed => 1,
1720
+ .dropped_full => 2,
1721
+ .dropped_oversized => 3,
1722
+ };
1723
+ }
1724
+
1725
+ fn audioCaptureStart(context: ?*anyopaque, source: platform_mod.AudioCaptureSource, format: platform_mod.AudioCaptureFormat, sink: platform_mod.AudioCaptureSink) anyerror!void {
1726
+ const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1727
+ if (self.web_engine != .system) return error.UnsupportedService;
1728
+ const stored = &self.audio_capture_sinks[@intFromEnum(source)];
1729
+ // The native stop is a synchronous callback fence. Quiesce the old
1730
+ // producer before replacing the memory its callback context points at;
1731
+ // otherwise a final old-source callback can be delivered to the new sink.
1732
+ _ = native_sdk_windows_audio_capture_stop(self.host, @intFromEnum(source));
1733
+ stored.* = sink;
1734
+ if (native_sdk_windows_audio_capture_start(self.host, @intFromEnum(source), format.sample_rate, format.channels, nativeSdkAudioCapturePush, stored) == 0) {
1735
+ stored.* = .{};
1736
+ return error.AudioCaptureStartFailed;
1737
+ }
1738
+ }
1739
+
1740
+ fn audioCaptureStop(context: ?*anyopaque, source: platform_mod.AudioCaptureSource) anyerror!void {
1741
+ const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1742
+ _ = native_sdk_windows_audio_capture_stop(self.host, @intFromEnum(source));
1743
+ self.audio_capture_sinks[@intFromEnum(source)] = .{};
1744
+ }
1745
+
1629
1746
  /// The video tier's teaching refusal: the load verbs exist so a video
1630
1747
  /// source fails with a NAMED explanation instead of a bare
1631
1748
  /// unsupported-service, while the transport verbs stay null — the
@@ -1996,6 +2113,47 @@ test "windows hide-on-close support requires the declared tray (the only re-show
1996
2113
  try std.testing.expect(!WindowsPlatform.supportsFeature(&chromium, .window_hide_on_close));
1997
2114
  }
1998
2115
 
2116
+ test "windows local time conversion applies the timestamp's dynamic daylight rules" {
2117
+ // The Win32 host cannot execute in this portable suite, so pin the API
2118
+ // sequence Microsoft requires: first expose the UTC SYSTEMTIME, then let
2119
+ // the active dynamic time zone select the offset for that instant. Using
2120
+ // FileTimeToLocalFileTime here would instead apply the current DST bias.
2121
+ const host_source = @embedFile("webview2_host.cpp");
2122
+ const format_at = std.mem.indexOf(u8, host_source, "size_t native_sdk_windows_format_local_time(") orelse return error.TestExpectedEqual;
2123
+ const format_tail = host_source[format_at..];
2124
+ const format_end = std.mem.indexOf(u8, format_tail, "size_t native_sdk_windows_clipboard_read(") orelse return error.TestExpectedEqual;
2125
+ const format_source = format_tail[0..format_end];
2126
+ const utc_at = std.mem.indexOf(u8, format_source, "FileTimeToSystemTime(&utc, &utc_system_time)") orelse return error.TestExpectedEqual;
2127
+ const local_at = std.mem.indexOf(u8, format_source, "SystemTimeToTzSpecificLocalTimeEx(nullptr, &utc_system_time, &system_time)") orelse return error.TestExpectedEqual;
2128
+ try std.testing.expect(utc_at < local_at);
2129
+ try std.testing.expect(std.mem.indexOf(u8, format_source, "FileTimeToLocalFileTime") == null);
2130
+ }
2131
+
2132
+ test "windows tray carries lifecycle commands rich rows and key equivalents into the host" {
2133
+ // These are native Win32 behaviors, so the portable suite pins the
2134
+ // compiled host seam. Windows packaging builds cross-compile the same
2135
+ // source and catch signature/type drift.
2136
+ const host_source = @embedFile("webview2_host.cpp");
2137
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "host->tray_activation_command = slice(activation_command, activation_command_len);") != null);
2138
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "emitStatusCommand(host, hwnd, host->tray_alternate_activation_command);") != null);
2139
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "emitStatusCommand(host, hwnd, host->tray_activation_command);") != null);
2140
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "emitStatusCommand(host, hwnd, host->tray_open_command);") != null);
2141
+ const emit_at = std.mem.indexOf(u8, host_source, "static bool emitStatusCommand(") orelse return error.TestExpectedEqual;
2142
+ const emit_tail = host_source[emit_at..];
2143
+ const emit_end = std.mem.indexOf(u8, emit_tail, "static void showTrayMenu(") orelse return error.TestExpectedEqual;
2144
+ const emit_source = emit_tail[0..emit_end];
2145
+ try std.testing.expect(std.mem.indexOf(u8, emit_source, "event.kind = kTrayCommand;") != null);
2146
+ try std.testing.expect(std.mem.indexOf(u8, emit_source, "event.kind = kMenuCommand;") == null);
2147
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "item.detail = slice(details[index], detail_lens[index]);") != null);
2148
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "item.key = lowerAscii(slice(keys[index], key_lens[index]));") != null);
2149
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "item.modifiers = modifiers[index];") != null);
2150
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "display_label += shortcutSuffix(item.key, item.modifiers);") != null);
2151
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "const std::vector<TrayItem> displayed_items = host->tray_items;") != null);
2152
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "emitTrayActionForCommandId(host, displayed_items, command_id);") != null);
2153
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "return emitTrayActionForCommandId(host, host->tray_items, item.command_id);") != null);
2154
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "tray_event == NIN_SELECT || tray_event == NIN_KEYSELECT || tray_event == WM_LBUTTONUP") != null);
2155
+ }
2156
+
1999
2157
  test "windows refuses a tray-less .hide main window at platform init instead of stranding it hidden" {
2000
2158
  // The pre-created MAIN window never passes through the runtime's
2001
2159
  // create gate, so the platform's init gate must hold the same line
@@ -2326,6 +2484,70 @@ test "windows first-present windows have a fallback reveal deadline" {
2326
2484
  host_source,
2327
2485
  "window.deferred_show_started_ms = window.show_on_first_present ? GetTickCount64() : 0;",
2328
2486
  ) != null);
2487
+ try std.testing.expect(std.mem.indexOf(
2488
+ u8,
2489
+ host_source,
2490
+ "if (!window.hwnd || window.shown || window.policy_hidden) return;",
2491
+ ) != null);
2492
+ }
2493
+
2494
+ test "windows busy message loop drains due gpu frames outside input callbacks" {
2495
+ // The waitable timer is the precise idle wake source, but queued input
2496
+ // may win the message-loop race. Pin the complementary post-dispatch
2497
+ // drain: it must run only after DispatchMessage returns (outside the
2498
+ // runtime callback that requested the frame) while the host is still
2499
+ // running. The helper must retire the one-shot before emitting so
2500
+ // synchronous presentation can re-arm it, and abort if that callback
2501
+ // stops the host so no later due surface receives a post-shutdown event.
2502
+ const host_source = @embedFile("webview2_host.cpp");
2503
+ const run_at = std.mem.indexOf(u8, host_source, "void native_sdk_windows_run(") orelse return error.TestExpectedEqual;
2504
+ const run_tail = host_source[run_at..];
2505
+ const dispatch_at = std.mem.indexOf(u8, run_tail, "DispatchMessageW(&message);") orelse return error.TestExpectedEqual;
2506
+ const post_dispatch = run_tail[dispatch_at..];
2507
+ try std.testing.expect(std.mem.indexOf(u8, post_dispatch, "if (host->running) gpuSurfaceDrainDueFrameEmissions(host);") != null);
2508
+
2509
+ const helper_at = std.mem.indexOf(u8, host_source, "static void gpuSurfaceDrainDueFrameEmissions(Host *host)") orelse return error.TestExpectedEqual;
2510
+ const helper_tail = host_source[helper_at..];
2511
+ const helper_end = std.mem.indexOf(u8, helper_tail, "static void paintGpuSurface(") orelse return error.TestExpectedEqual;
2512
+ const helper = helper_tail[0..helper_end];
2513
+ try std.testing.expect(std.mem.indexOf(u8, helper, "if (!host || !host->running) return;") != null);
2514
+ const loop_at = std.mem.indexOf(u8, helper, "for (const std::string &key : due_keys)") orelse return error.TestExpectedEqual;
2515
+ const loop = helper[loop_at..];
2516
+ const before_emit_guard_at = std.mem.indexOf(u8, loop, "if (!host->running) return;") orelse return error.TestExpectedEqual;
2517
+ const kill_at = std.mem.indexOf(u8, helper, "KillTimer(hwnd, kGpuEmitTimerId);") orelse return error.TestExpectedEqual;
2518
+ const clear_at = std.mem.indexOf(u8, helper, "view.gpu_emission_scheduled = false;") orelse return error.TestExpectedEqual;
2519
+ const emit_at = std.mem.indexOf(u8, helper, "gpuSurfaceEmitFrame(host, view, hwnd);") orelse return error.TestExpectedEqual;
2520
+ const after_emit = helper[emit_at + "gpuSurfaceEmitFrame(host, view, hwnd);".len ..];
2521
+ try std.testing.expect(std.mem.indexOf(u8, after_emit, "if (!host->running) return;") != null);
2522
+ try std.testing.expect(loop_at + before_emit_guard_at < emit_at);
2523
+ try std.testing.expect(kill_at < clear_at);
2524
+ try std.testing.expect(clear_at < emit_at);
2525
+ }
2526
+
2527
+ test "windows gpu frame deadlines use a high resolution waitable timer" {
2528
+ // A nominal 16.67 ms SetTimer is commonly rounded to the legacy timer
2529
+ // grid. Pin the host's precise path: one process-owned high-resolution
2530
+ // waitable timer follows the earliest scheduled surface, participates in
2531
+ // the message loop, refreshes after an emission, and closes at teardown.
2532
+ const host_source = @embedFile("webview2_host.cpp");
2533
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "CREATE_WAITABLE_TIMER_HIGH_RESOLUTION") != null);
2534
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "SetWaitableTimer(host->gpu_frame_wake_timer") != null);
2535
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "MsgWaitForMultipleObjectsEx(") != null);
2536
+
2537
+ const schedule_at = std.mem.indexOf(u8, host_source, "static void gpuSurfaceScheduleFrameEmission(Host *host, NativeView &view)") orelse return error.TestExpectedEqual;
2538
+ const schedule_tail = host_source[schedule_at..];
2539
+ const schedule_end = std.mem.indexOf(u8, schedule_tail, "static void gpuSurfaceDrainDueFrameEmissions(") orelse return error.TestExpectedEqual;
2540
+ const schedule = schedule_tail[0..schedule_end];
2541
+ const scheduled_at = std.mem.indexOf(u8, schedule, "view.gpu_emission_scheduled = true;") orelse return error.TestExpectedEqual;
2542
+ const wake_at = std.mem.indexOf(u8, schedule, "gpuSurfaceRefreshFrameWakeTimer(host);") orelse return error.TestExpectedEqual;
2543
+ try std.testing.expect(scheduled_at < wake_at);
2544
+
2545
+ const timer_at = std.mem.indexOf(u8, host_source, "if (wparam == kGpuEmitTimerId)") orelse return error.TestExpectedEqual;
2546
+ const timer_tail = host_source[timer_at..];
2547
+ const emit_at = std.mem.indexOf(u8, timer_tail, "gpuSurfaceEmitFrame(host, *view, hwnd);") orelse return error.TestExpectedEqual;
2548
+ const refresh_at = std.mem.indexOf(u8, timer_tail, "gpuSurfaceRefreshFrameWakeTimer(host);") orelse return error.TestExpectedEqual;
2549
+ try std.testing.expect(emit_at < refresh_at);
2550
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "gpuSurfaceDestroyFrameWakeTimer(host);") != null);
2329
2551
  }
2330
2552
 
2331
2553
  test "windows window focus includes focused native child views" {