@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
@@ -42,6 +42,7 @@ const AppKitEventKind = enum(c_int) {
42
42
  audio = 20,
43
43
  video = 21,
44
44
  view_focused = 22,
45
+ tray_command = 23,
45
46
  };
46
47
 
47
48
  const AppKitEvent = extern struct {
@@ -179,7 +180,11 @@ extern fn native_sdk_appkit_set_window_content_min_size(host: *AppKitHost, windo
179
180
  extern fn native_sdk_appkit_focus_window(host: *AppKitHost, window_id: u64) c_int;
180
181
  extern fn native_sdk_appkit_close_window(host: *AppKitHost, window_id: u64) c_int;
181
182
  extern fn native_sdk_appkit_minimize_window(host: *AppKitHost, window_id: u64) c_int;
183
+ extern fn native_sdk_appkit_hide_window(host: *AppKitHost, window_id: u64) c_int;
182
184
  extern fn native_sdk_appkit_show_window(host: *AppKitHost, window_id: u64) c_int;
185
+ extern fn native_sdk_appkit_set_dock_presence(host: *AppKitHost, visible: c_int) c_int;
186
+ extern fn native_sdk_appkit_launch_at_login_status(host: *AppKitHost) c_int;
187
+ extern fn native_sdk_appkit_set_launch_at_login(host: *AppKitHost, enabled: c_int) c_int;
183
188
  extern fn native_sdk_appkit_set_window_close_policy(host: *AppKitHost, window_id: u64, close_policy: c_int) c_int;
184
189
  extern fn native_sdk_appkit_start_window_drag(host: *AppKitHost, window_id: u64) c_int;
185
190
  extern fn native_sdk_appkit_window_chrome_insets(host: *AppKitHost, window_id: u64, top: *f64, left: *f64, bottom: *f64, right: *f64, buttons_x: *f64, buttons_y: *f64, buttons_width: *f64, buttons_height: *f64) c_int;
@@ -205,6 +210,10 @@ extern fn native_sdk_appkit_audio_pause(host: *AppKitHost) c_int;
205
210
  extern fn native_sdk_appkit_audio_stop(host: *AppKitHost) c_int;
206
211
  extern fn native_sdk_appkit_audio_seek(host: *AppKitHost, position_ms: u64) c_int;
207
212
  extern fn native_sdk_appkit_audio_set_volume(host: *AppKitHost, volume: f64) c_int;
213
+ const AppKitAudioCapturePush = *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;
214
+ extern fn native_sdk_appkit_audio_capture_start(host: *AppKitHost, source: c_int, sample_rate: u32, channels: u8, push_fn: AppKitAudioCapturePush, push_context: ?*anyopaque) c_int;
215
+ extern fn native_sdk_appkit_audio_capture_stop(host: *AppKitHost, source: c_int) c_int;
216
+ extern fn native_sdk_appkit_audio_capture_supported(host: *AppKitHost, source: c_int) c_int;
208
217
  extern fn native_sdk_appkit_video_load(host: *AppKitHost, path: [*]const u8, path_len: usize, token: u64, push_fn: AppKitVideoSinkPush, push_context: ?*anyopaque) c_int;
209
218
  extern fn native_sdk_appkit_video_load_url(host: *AppKitHost, url: [*]const u8, url_len: usize, token: u64, push_fn: AppKitVideoSinkPush, push_context: ?*anyopaque) c_int;
210
219
  extern fn native_sdk_appkit_video_play(host: *AppKitHost) c_int;
@@ -245,6 +254,7 @@ extern fn native_sdk_appkit_clear_recent_documents(host: *AppKitHost) c_int;
245
254
  extern fn native_sdk_appkit_set_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, secret: [*]const u8, secret_len: usize) c_int;
246
255
  extern fn native_sdk_appkit_get_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize, buffer: [*]u8, buffer_len: usize) usize;
247
256
  extern fn native_sdk_appkit_delete_credential(host: *AppKitHost, service: [*]const u8, service_len: usize, account: [*]const u8, account_len: usize) c_int;
257
+ extern fn native_sdk_appkit_format_local_time(host: *AppKitHost, timestamp_ms: i64, style: c_int, buffer: [*]u8, buffer_len: usize) usize;
248
258
 
249
259
  const AppKitScrollOccluder = extern struct {
250
260
  x: f64,
@@ -394,9 +404,10 @@ const AppKitTrayCallback = *const fn (context: ?*anyopaque, item_id: u32) callco
394
404
  extern fn native_sdk_appkit_show_open_dialog(host: *AppKitHost, opts: *const AppKitOpenDialogOpts, buffer: [*]u8, buffer_len: usize) AppKitOpenDialogResult;
395
405
  extern fn native_sdk_appkit_show_save_dialog(host: *AppKitHost, opts: *const AppKitSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
396
406
  extern fn native_sdk_appkit_show_message_dialog(host: *AppKitHost, opts: *const AppKitMessageDialogOpts) c_int;
397
- extern fn native_sdk_appkit_create_tray(host: *AppKitHost, icon_path: [*]const u8, icon_path_len: usize, title: [*]const u8, title_len: usize, tooltip: [*]const u8, tooltip_len: usize) void;
398
- extern fn native_sdk_appkit_update_tray_menu(host: *AppKitHost, item_ids: [*]const u32, labels: [*]const [*]const u8, label_lens: [*]const usize, separators: [*]const c_int, enabled_flags: [*]const c_int, count: usize) void;
407
+ extern fn native_sdk_appkit_create_tray(host: *AppKitHost, icon_path: [*]const u8, icon_path_len: usize, title: [*]const u8, title_len: usize, tooltip: [*]const u8, tooltip_len: usize, width: f64, tone: c_int, icon_opacity: f64, monospaced: c_int, 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) void;
408
+ extern fn native_sdk_appkit_update_tray_menu(host: *AppKitHost, 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) void;
399
409
  extern fn native_sdk_appkit_update_tray_title(host: *AppKitHost, title: [*]const u8, title_len: usize) void;
410
+ extern fn native_sdk_appkit_update_tray_presentation(host: *AppKitHost, title: [*]const u8, title_len: usize, width: f64, tone: c_int, icon_opacity: f64, monospaced: c_int) void;
400
411
  extern fn native_sdk_appkit_remove_tray(host: *AppKitHost) void;
401
412
  extern fn native_sdk_appkit_set_tray_callback(host: *AppKitHost, callback: AppKitTrayCallback, context: ?*anyopaque) void;
402
413
 
@@ -568,9 +579,8 @@ pub const MacPlatform = struct {
568
579
  app_info: platform_mod.AppInfo,
569
580
  surface_value: platform_mod.Surface,
570
581
  state: RunState = .{},
571
- /// Latched when the runtime's effects teardown abandons an
572
- /// in-flight channel `wake_fn` call (see
573
- /// `PlatformServices.note_channel_wake_abandoned_fn`): the stale
582
+ /// Latched when effects teardown abandons an in-flight platform call
583
+ /// (a channel wake or blocking credential operation): the stale
574
584
  /// call still holds this platform as its context and may execute
575
585
  /// into it at any later time, so `deinit` must skip destruction
576
586
  /// and leak the host, process-lived — and the wrapper struct the
@@ -587,6 +597,7 @@ pub const MacPlatform = struct {
587
597
  /// every push happens on the main thread (the host's frame pump is
588
598
  /// a run-loop timer), so a plain field is race-free.
589
599
  video_sink: platform_mod.VideoFrameSink = .{},
600
+ audio_capture_sinks: [2]platform_mod.AudioCaptureSink = [_]platform_mod.AudioCaptureSink{.{}} ** 2,
590
601
 
591
602
  pub fn init(title: []const u8, size: geometry.SizeF) Error!MacPlatform {
592
603
  return initWithEngine(title, size, .system);
@@ -669,13 +680,13 @@ pub const MacPlatform = struct {
669
680
  }
670
681
 
671
682
  pub fn deinit(self: *MacPlatform) void {
672
- // An abandoned channel wake call may still enter this host at
683
+ // An abandoned platform call may still enter this host at
673
684
  // any later time (see `channel_wake_abandoned`): destroying it
674
685
  // would turn that stale call into a use-after-free, so the
675
686
  // host is deliberately leaked, process-lived — the
676
687
  // abandoned-worker idiom, applied to the platform itself.
677
688
  if (self.channel_wake_abandoned.load(.seq_cst)) {
678
- std.debug.print("macos 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", .{});
689
+ std.debug.print("macos 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", .{});
679
690
  return;
680
691
  }
681
692
  native_sdk_appkit_destroy(self.host);
@@ -703,7 +714,11 @@ pub const MacPlatform = struct {
703
714
  .focus_window_fn = focusWindow,
704
715
  .close_window_fn = closeWindow,
705
716
  .minimize_window_fn = minimizeWindow,
717
+ .hide_window_fn = hideWindow,
706
718
  .show_window_fn = showWindow,
719
+ .set_dock_presence_fn = setDockPresence,
720
+ .launch_at_login_status_fn = launchAtLoginStatus,
721
+ .set_launch_at_login_fn = setLaunchAtLogin,
707
722
  .quit_app_fn = quitApp,
708
723
  .start_window_drag_fn = startWindowDrag,
709
724
  .window_chrome_fn = windowChrome,
@@ -729,6 +744,8 @@ pub const MacPlatform = struct {
729
744
  .set_credential_fn = setCredential,
730
745
  .get_credential_fn = getCredential,
731
746
  .delete_credential_fn = deleteCredential,
747
+ .note_blocking_call_abandoned_fn = noteChannelWakeAbandoned,
748
+ .format_local_time_fn = formatLocalTime,
732
749
  .open_external_url_fn = openExternalUrl,
733
750
  .reveal_path_fn = revealPath,
734
751
  .add_recent_document_fn = addRecentDocument,
@@ -736,6 +753,7 @@ pub const MacPlatform = struct {
736
753
  .create_tray_fn = createTray,
737
754
  .update_tray_menu_fn = updateTrayMenu,
738
755
  .update_tray_title_fn = updateTrayTitle,
756
+ .update_tray_presentation_fn = updateTrayPresentation,
739
757
  .remove_tray_fn = removeTray,
740
758
  .configure_security_policy_fn = configureSecurityPolicy,
741
759
  .configure_menus_fn = configureMenus,
@@ -750,6 +768,8 @@ pub const MacPlatform = struct {
750
768
  .audio_stop_fn = audioStop,
751
769
  .audio_seek_fn = audioSeek,
752
770
  .audio_set_volume_fn = audioSetVolume,
771
+ .audio_capture_start_fn = if (self.web_engine == .system) audioCaptureStart else null,
772
+ .audio_capture_stop_fn = if (self.web_engine == .system) audioCaptureStop else null,
753
773
  .video_load_fn = videoLoad,
754
774
  .video_load_url_fn = videoLoadUrl,
755
775
  .video_play_fn = videoPlay,
@@ -822,6 +842,8 @@ pub const MacPlatform = struct {
822
842
  .audio_streaming,
823
843
  .audio_spectrum,
824
844
  => self.web_engine == .system,
845
+ .microphone_capture => self.web_engine == .system and audioCaptureSupported(self.host, .microphone),
846
+ .system_audio_capture => self.web_engine == .system and audioCaptureSupported(self.host, .system),
825
847
  // AVFoundation video ships in the AppKit host only (one
826
848
  // AVPlayer whose AVPlayerItemVideoOutput frames feed the
827
849
  // media-surface sink); the CEF host stubs the C ABI and
@@ -831,6 +853,17 @@ pub const MacPlatform = struct {
831
853
  };
832
854
  }
833
855
 
856
+ /// The host performs the availability probe because system capture is
857
+ /// version-gated at runtime (the deployment target predates
858
+ /// ScreenCaptureKit audio). Hermetic Zig tests do not link an AppKit
859
+ /// host, so keep the probe behind the same test/target seam as Linux's
860
+ /// runtime-loaded service probes.
861
+ fn audioCaptureSupported(host: *AppKitHost, source: platform_mod.AudioCaptureSource) bool {
862
+ if (comptime @import("builtin").is_test) return false;
863
+ if (@import("builtin").target.os.tag != .macos) return false;
864
+ return native_sdk_appkit_audio_capture_supported(host, @intFromEnum(source)) != 0;
865
+ }
866
+
834
867
  fn run(context: *anyopaque, handler: platform_mod.EventHandler, handler_context: *anyopaque) anyerror!void {
835
868
  const self: *MacPlatform = @ptrCast(@alignCast(context));
836
869
  self.state = .{
@@ -934,6 +967,10 @@ fn appkitCallback(context: ?*anyopaque, event: *const AppKitEvent) callconv(.c)
934
967
  .name = event.command_name[0..event.command_name_len],
935
968
  .window_id = event.window_id,
936
969
  } }),
970
+ .tray_command => state.emit(.{ .tray_command = .{
971
+ .name = event.command_name[0..event.command_name_len],
972
+ .window_id = event.window_id,
973
+ } }),
937
974
  .timer => state.emit(.{ .timer = .{
938
975
  .id = event.timer_id,
939
976
  .timestamp_ns = event.timestamp_ns,
@@ -1221,6 +1258,7 @@ fn showModeInt(mode: platform_mod.WindowShowMode) c_int {
1221
1258
  return switch (mode) {
1222
1259
  .immediate => 0,
1223
1260
  .on_first_present => 1,
1261
+ .hidden => 2,
1224
1262
  };
1225
1263
  }
1226
1264
 
@@ -1230,6 +1268,7 @@ fn windowFlags(options: platform_mod.WindowOptions) u32 {
1230
1268
  if (options.always_on_top) flags |= 1 << 1;
1231
1269
  if (options.click_through) flags |= 1 << 2;
1232
1270
  if (!options.activate_on_show) flags |= 1 << 3;
1271
+ if (!options.allows_fullscreen) flags |= 1 << 4;
1233
1272
  return flags;
1234
1273
  }
1235
1274
 
@@ -1280,6 +1319,7 @@ fn createWindow(context: ?*anyopaque, options: platform_mod.WindowOptions) anyer
1280
1319
  .scale_factor = 1,
1281
1320
  .open = true,
1282
1321
  .focused = options.activate_on_show and options.show == .immediate,
1322
+ .hidden = options.show == .hidden,
1283
1323
  };
1284
1324
  }
1285
1325
 
@@ -1298,11 +1338,42 @@ fn minimizeWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerr
1298
1338
  if (native_sdk_appkit_minimize_window(self.host, window_id) == 0) return error.WindowNotFound;
1299
1339
  }
1300
1340
 
1341
+ fn hideWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1342
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1343
+ if (native_sdk_appkit_hide_window(self.host, window_id) == 0) return error.WindowNotFound;
1344
+ }
1345
+
1301
1346
  fn showWindow(context: ?*anyopaque, window_id: platform_mod.WindowId) anyerror!void {
1302
1347
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1303
1348
  if (native_sdk_appkit_show_window(self.host, window_id) == 0) return error.WindowNotFound;
1304
1349
  }
1305
1350
 
1351
+ fn setDockPresence(context: ?*anyopaque, visible: bool) anyerror!void {
1352
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1353
+ if (native_sdk_appkit_set_dock_presence(self.host, if (visible) 1 else 0) == 0) return error.UnsupportedService;
1354
+ }
1355
+
1356
+ fn launchAtLoginStatus(context: ?*anyopaque) anyerror!platform_mod.LaunchAtLoginStatus {
1357
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1358
+ return launchAtLoginStatusFromInt(native_sdk_appkit_launch_at_login_status(self.host));
1359
+ }
1360
+
1361
+ fn setLaunchAtLogin(context: ?*anyopaque, enabled: bool) anyerror!platform_mod.LaunchAtLoginStatus {
1362
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1363
+ return launchAtLoginStatusFromInt(native_sdk_appkit_set_launch_at_login(self.host, if (enabled) 1 else 0));
1364
+ }
1365
+
1366
+ fn launchAtLoginStatusFromInt(value: c_int) anyerror!platform_mod.LaunchAtLoginStatus {
1367
+ return switch (value) {
1368
+ 0 => .disabled,
1369
+ 1 => .enabled,
1370
+ 2 => .requires_approval,
1371
+ 3 => .not_found,
1372
+ -1 => error.UnsupportedService,
1373
+ else => error.LaunchAtLoginFailed,
1374
+ };
1375
+ }
1376
+
1306
1377
  /// The graceful quit: the same emitShutdown + stop the last-window
1307
1378
  /// close runs, ALWAYS deferred past the dispatch that requested it —
1308
1379
  /// this verb arrives mid dispatch (the command whose update returned
@@ -1531,6 +1602,54 @@ fn audioSetVolume(context: ?*anyopaque, volume: f32) anyerror!void {
1531
1602
  _ = native_sdk_appkit_audio_set_volume(self.host, volume);
1532
1603
  }
1533
1604
 
1605
+ 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 {
1606
+ const sink: *platform_mod.AudioCaptureSink = @ptrCast(@alignCast(context orelse return 1));
1607
+ const source: platform_mod.AudioCaptureSource = switch (source_value) {
1608
+ 1 => .system,
1609
+ else => .microphone,
1610
+ };
1611
+ const event_kind: platform_mod.AudioCaptureEventKind = switch (kind) {
1612
+ 0 => .started,
1613
+ 1 => .data,
1614
+ else => .failed,
1615
+ };
1616
+ const bytes = if (pcm) |ptr| ptr[0..pcm_len] else "";
1617
+ return switch (sink.push(.{
1618
+ .kind = event_kind,
1619
+ .source = source,
1620
+ .format = .{ .sample_rate = sample_rate, .channels = channels },
1621
+ .timestamp_ns = timestamp_ns,
1622
+ .frames = frames,
1623
+ .pcm_s16le = bytes,
1624
+ })) {
1625
+ .accepted => 0,
1626
+ .closed => 1,
1627
+ .dropped_full => 2,
1628
+ .dropped_oversized => 3,
1629
+ };
1630
+ }
1631
+
1632
+ fn audioCaptureStart(context: ?*anyopaque, source: platform_mod.AudioCaptureSource, format: platform_mod.AudioCaptureFormat, sink: platform_mod.AudioCaptureSink) anyerror!void {
1633
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1634
+ if (self.web_engine != .system) return error.UnsupportedService;
1635
+ const stored = &self.audio_capture_sinks[@intFromEnum(source)];
1636
+ // The native stop is a synchronous callback fence. Quiesce the old
1637
+ // producer before replacing the memory its callback context points at;
1638
+ // otherwise a final old-source callback can be delivered to the new sink.
1639
+ _ = native_sdk_appkit_audio_capture_stop(self.host, @intFromEnum(source));
1640
+ stored.* = sink;
1641
+ if (native_sdk_appkit_audio_capture_start(self.host, @intFromEnum(source), format.sample_rate, format.channels, nativeSdkAudioCapturePush, stored) == 0) {
1642
+ stored.* = .{};
1643
+ return error.AudioCaptureStartFailed;
1644
+ }
1645
+ }
1646
+
1647
+ fn audioCaptureStop(context: ?*anyopaque, source: platform_mod.AudioCaptureSource) anyerror!void {
1648
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1649
+ _ = native_sdk_appkit_audio_capture_stop(self.host, @intFromEnum(source));
1650
+ self.audio_capture_sinks[@intFromEnum(source)] = .{};
1651
+ }
1652
+
1534
1653
  /// The C-callable bridge for `VideoFrameSink.push`: the sink's `push_fn`
1535
1654
  /// is a Zig-calling-convention error-union fn the host cannot invoke, so
1536
1655
  /// the host is handed this trampoline (context = the `MacPlatform`) and
@@ -1995,7 +2114,7 @@ fn showNotification(context: ?*anyopaque, options: platform_mod.NotificationOpti
1995
2114
 
1996
2115
  fn setCredential(context: ?*anyopaque, credential: platform_mod.Credential) anyerror!void {
1997
2116
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
1998
- if (native_sdk_appkit_set_credential(
2117
+ const result = native_sdk_appkit_set_credential(
1999
2118
  self.host,
2000
2119
  credential.service.ptr,
2001
2120
  credential.service.len,
@@ -2003,7 +2122,10 @@ fn setCredential(context: ?*anyopaque, credential: platform_mod.Credential) anye
2003
2122
  credential.account.len,
2004
2123
  credential.secret.ptr,
2005
2124
  credential.secret.len,
2006
- ) == 0) return error.UnsupportedService;
2125
+ );
2126
+ if (result == -2) return error.CredentialStoreLocked;
2127
+ if (result == -3) return error.AccessDenied;
2128
+ if (result <= 0) return error.CredentialStoreFailed;
2007
2129
  }
2008
2130
 
2009
2131
  fn getCredential(context: ?*anyopaque, key: platform_mod.CredentialKey, buffer: []u8) anyerror![]const u8 {
@@ -2017,20 +2139,34 @@ fn getCredential(context: ?*anyopaque, key: platform_mod.CredentialKey, buffer:
2017
2139
  buffer.ptr,
2018
2140
  buffer.len,
2019
2141
  );
2020
- if (len == 0) return error.CredentialNotFound;
2142
+ if (len == std.math.maxInt(usize)) return error.CredentialNotFound;
2143
+ if (len == std.math.maxInt(usize) - 2) return error.CredentialStoreLocked;
2144
+ if (len == std.math.maxInt(usize) - 3) return error.AccessDenied;
2145
+ if (len == std.math.maxInt(usize) - 1) return error.CredentialStoreFailed;
2021
2146
  if (len > buffer.len) return error.NoSpaceLeft;
2022
2147
  return buffer[0..len];
2023
2148
  }
2024
2149
 
2025
2150
  fn deleteCredential(context: ?*anyopaque, key: platform_mod.CredentialKey) anyerror!void {
2026
2151
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2027
- if (native_sdk_appkit_delete_credential(
2152
+ const result = native_sdk_appkit_delete_credential(
2028
2153
  self.host,
2029
2154
  key.service.ptr,
2030
2155
  key.service.len,
2031
2156
  key.account.ptr,
2032
2157
  key.account.len,
2033
- ) == 0) return error.CredentialNotFound;
2158
+ );
2159
+ if (result == -2) return error.CredentialStoreLocked;
2160
+ if (result == -3) return error.AccessDenied;
2161
+ if (result < 0) return error.CredentialStoreFailed;
2162
+ if (result == 0) return error.CredentialNotFound;
2163
+ }
2164
+
2165
+ fn formatLocalTime(context: ?*anyopaque, timestamp_ms: i64, style: platform_mod.LocalTimeStyle, buffer: []u8) anyerror![]const u8 {
2166
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2167
+ const len = native_sdk_appkit_format_local_time(self.host, timestamp_ms, @intFromEnum(style), buffer.ptr, buffer.len);
2168
+ if (len == 0 or len > buffer.len) return error.LocalTimeFormatFailed;
2169
+ return buffer[0..len];
2034
2170
  }
2035
2171
 
2036
2172
  fn openExternalUrl(context: ?*anyopaque, url: []const u8) anyerror!void {
@@ -2388,7 +2524,27 @@ const max_tray_items: usize = 32;
2388
2524
 
2389
2525
  fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
2390
2526
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2391
- native_sdk_appkit_create_tray(self.host, options.icon_path.ptr, options.icon_path.len, options.title.ptr, options.title.len, options.tooltip.ptr, options.tooltip.len);
2527
+ var presentation = options.presentation;
2528
+ if (presentation.title.len == 0) presentation.title = options.title;
2529
+ native_sdk_appkit_create_tray(
2530
+ self.host,
2531
+ options.icon_path.ptr,
2532
+ options.icon_path.len,
2533
+ presentation.title.ptr,
2534
+ presentation.title.len,
2535
+ options.tooltip.ptr,
2536
+ options.tooltip.len,
2537
+ presentation.width,
2538
+ @intFromEnum(presentation.tone),
2539
+ presentation.icon_opacity,
2540
+ if (presentation.monospaced) 1 else 0,
2541
+ options.activation_command.ptr,
2542
+ options.activation_command.len,
2543
+ options.alternate_activation_command.ptr,
2544
+ options.alternate_activation_command.len,
2545
+ options.open_command.ptr,
2546
+ options.open_command.len,
2547
+ );
2392
2548
  if (options.items.len > 0) {
2393
2549
  try updateTrayMenu(context, options.items);
2394
2550
  }
@@ -2402,14 +2558,30 @@ fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem
2402
2558
  var label_lens: [max_tray_items]usize = undefined;
2403
2559
  var separators: [max_tray_items]c_int = undefined;
2404
2560
  var enabled_flags: [max_tray_items]c_int = undefined;
2561
+ var details: [max_tray_items][*]const u8 = undefined;
2562
+ var detail_lens: [max_tray_items]usize = undefined;
2563
+ var roles: [max_tray_items]c_int = undefined;
2564
+ var keys: [max_tray_items][*]const u8 = undefined;
2565
+ var key_lens: [max_tray_items]usize = undefined;
2566
+ var modifiers: [max_tray_items]u32 = undefined;
2405
2567
  for (items[0..count], 0..) |item, i| {
2406
2568
  ids[i] = item.id;
2407
2569
  labels[i] = item.label.ptr;
2408
2570
  label_lens[i] = item.label.len;
2409
2571
  separators[i] = if (item.separator) 1 else 0;
2410
2572
  enabled_flags[i] = if (item.enabled) 1 else 0;
2573
+ details[i] = item.detail.ptr;
2574
+ detail_lens[i] = item.detail.len;
2575
+ roles[i] = @intFromEnum(item.role);
2576
+ keys[i] = item.key.ptr;
2577
+ key_lens[i] = item.key.len;
2578
+ modifiers[i] = @as(u32, @intFromBool(item.modifiers.primary)) |
2579
+ (@as(u32, @intFromBool(item.modifiers.command)) << 1) |
2580
+ (@as(u32, @intFromBool(item.modifiers.control)) << 2) |
2581
+ (@as(u32, @intFromBool(item.modifiers.option)) << 3) |
2582
+ (@as(u32, @intFromBool(item.modifiers.shift)) << 4);
2411
2583
  }
2412
- native_sdk_appkit_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, count);
2584
+ native_sdk_appkit_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, &details, &detail_lens, &roles, &keys, &key_lens, &modifiers, count);
2413
2585
  }
2414
2586
 
2415
2587
  fn updateTrayTitle(context: ?*anyopaque, title: []const u8) anyerror!void {
@@ -2417,6 +2589,11 @@ fn updateTrayTitle(context: ?*anyopaque, title: []const u8) anyerror!void {
2417
2589
  native_sdk_appkit_update_tray_title(self.host, title.ptr, title.len);
2418
2590
  }
2419
2591
 
2592
+ fn updateTrayPresentation(context: ?*anyopaque, presentation: platform_mod.TrayPresentation) anyerror!void {
2593
+ const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2594
+ native_sdk_appkit_update_tray_presentation(self.host, presentation.title.ptr, presentation.title.len, presentation.width, @intFromEnum(presentation.tone), presentation.icon_opacity, if (presentation.monospaced) 1 else 0);
2595
+ }
2596
+
2420
2597
  fn removeTray(context: ?*anyopaque) anyerror!void {
2421
2598
  const self: *MacPlatform = @ptrCast(@alignCast(context.?));
2422
2599
  native_sdk_appkit_remove_tray(self.host);
@@ -2449,6 +2626,51 @@ test "mac platform module exports type" {
2449
2626
  _ = MacPlatform;
2450
2627
  }
2451
2628
 
2629
+ test "mac status agent rows recognize decorated states and stay actionable" {
2630
+ const host_source = @embedFile("appkit_host.m");
2631
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "[state hasPrefix:@\"configured \"]") != null);
2632
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "[state hasPrefix:@\"warning \"]") != null);
2633
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "label.textColor = configured ? successColor : warning ? warningColor : NSColor.secondaryLabelColor;") != null);
2634
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "button.tag = itemIds[index];") != null);
2635
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "button.enabled = enabled[index].boolValue;") != null);
2636
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "button.keyEquivalent = NativeSdkMenuKeyEquivalent(key);") != null);
2637
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "button.keyEquivalentModifierMask = NativeSdkMenuModifierFlags(modifiers[index].unsignedIntValue);") != null);
2638
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "item.keyEquivalent = @\"\";") != null);
2639
+ }
2640
+
2641
+ test "mac title-only tray updates preserve the applied presentation" {
2642
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2643
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "object.statusPresentationWidth = width;") != null);
2644
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "object.statusPresentationTone = tone;") != null);
2645
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "object.statusPresentationIconOpacity = iconOpacity;") != null);
2646
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "object.statusPresentationMonospaced = monospaced;") != null);
2647
+ const update_at = std.mem.indexOf(u8, host_source, "void native_sdk_appkit_update_tray_title(") orelse return error.TestExpectedEqual;
2648
+ const update_tail = host_source[update_at..];
2649
+ try std.testing.expect(std.mem.indexOf(u8, update_tail, "object.statusPresentationWidth,") != null);
2650
+ try std.testing.expect(std.mem.indexOf(u8, update_tail, "object.statusPresentationTone,") != null);
2651
+ try std.testing.expect(std.mem.indexOf(u8, update_tail, "object.statusPresentationIconOpacity,") != null);
2652
+ try std.testing.expect(std.mem.indexOf(u8, update_tail, "object.statusPresentationMonospaced") != null);
2653
+ }
2654
+ }
2655
+
2656
+ test "mac status lifecycle hooks emit tray commands" {
2657
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2658
+ const emit_at = std.mem.indexOf(u8, host_source, "- (void)emitStatusCommand:(NSString *)command {") orelse return error.TestExpectedEqual;
2659
+ const emit_tail = host_source[emit_at..];
2660
+ const emit_end = std.mem.indexOf(u8, emit_tail, "- (void)statusItemActivated:") orelse return error.TestExpectedEqual;
2661
+ const emit_source = emit_tail[0..emit_end];
2662
+ try std.testing.expect(std.mem.indexOf(u8, emit_source, "NATIVE_SDK_APPKIT_EVENT_TRAY_COMMAND") != null);
2663
+ try std.testing.expect(std.mem.indexOf(u8, emit_source, "NATIVE_SDK_APPKIT_EVENT_MENU_COMMAND") == null);
2664
+ }
2665
+ }
2666
+
2667
+ test "mac status menu updates preserve the menu being opened" {
2668
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2669
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSMenu *menu = object.statusMenu;") != null);
2670
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "[menu removeAllItems];") != null);
2671
+ }
2672
+ }
2673
+
2452
2674
  test "mac webview presses report the focused child label" {
2453
2675
  // WKWebView owns the page's pointer stream, so the AppKit host
2454
2676
  // observes the down before dispatch and emits the explicit inverse
@@ -2460,15 +2682,15 @@ test "mac webview presses report the focused child label" {
2460
2682
  }
2461
2683
 
2462
2684
  test "mac active implicit show activates before making the window key" {
2463
- const host_source = @embedFile("appkit_host.m");
2464
- try std.testing.expect(std.mem.indexOf(u8, host_source,
2465
- \\ if ([self.passiveShowWindows containsObject:@(windowId)]) {
2466
- \\ [window orderFront:nil];
2467
- \\ } else {
2468
- \\ [NSApp activate];
2469
- \\ [window makeKeyAndOrderFront:nil];
2470
- \\ }
2471
- ) != null);
2685
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2686
+ const show_at = std.mem.indexOf(u8, host_source, "- (void)orderWindowForImplicitShow:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
2687
+ const show_tail = host_source[show_at..];
2688
+ const show_end = std.mem.indexOf(u8, show_tail, "- (void)focusWindowWithId:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
2689
+ const show_body = show_tail[0..show_end];
2690
+ const activate_at = std.mem.indexOf(u8, show_body, "[NSApp activateIgnoringOtherApps:YES];") orelse return error.TestExpectedEqual;
2691
+ const make_key_at = std.mem.indexOf(u8, show_body, "[window makeKeyAndOrderFront:nil];") orelse return error.TestExpectedEqual;
2692
+ try std.testing.expect(activate_at < make_key_at);
2693
+ }
2472
2694
  }
2473
2695
 
2474
2696
  test "mac unrestored secondary windows cascade within the active screen" {
@@ -2485,17 +2707,26 @@ test "mac unrestored secondary windows cascade within the active screen" {
2485
2707
  }
2486
2708
 
2487
2709
  test "mac explicit focus activates before making the window key" {
2488
- const host_source = @embedFile("appkit_host.m");
2489
- try std.testing.expect(std.mem.indexOf(u8, host_source,
2490
- \\- (void)focusWindowWithId:(uint64_t)windowId {
2491
- \\ NSWindow *window = self.windows[@(windowId)];
2492
- \\ if (!window) return;
2493
- \\ // An explicit focus overrides a pending present-before-show defer:
2494
- \\ // the runtime asked for the window NOW.
2495
- \\ [self.deferredShowWindows removeObjectForKey:@(windowId)];
2496
- \\ [NSApp activate];
2497
- \\ [window makeKeyAndOrderFront:nil];
2498
- ) != null);
2710
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2711
+ const focus_at = std.mem.indexOf(u8, host_source, "- (void)focusWindowWithId:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
2712
+ const focus_tail = host_source[focus_at..];
2713
+ const focus_end = std.mem.indexOf(u8, focus_tail, "- (void)closeWindowWithId:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
2714
+ const focus_body = focus_tail[0..focus_end];
2715
+ const activate_at = std.mem.indexOf(u8, focus_body, "[NSApp activateIgnoringOtherApps:YES];") orelse return error.TestExpectedEqual;
2716
+ const make_key_at = std.mem.indexOf(u8, focus_body, "[window makeKeyAndOrderFront:nil];") orelse return error.TestExpectedEqual;
2717
+ try std.testing.expect(activate_at < make_key_at);
2718
+ }
2719
+ }
2720
+
2721
+ test "mac dock presence changes policy without activating the app" {
2722
+ for ([_][]const u8{ @embedFile("appkit_host.m"), @embedFile("cef_host.mm") }) |host_source| {
2723
+ const dock_at = std.mem.indexOf(u8, host_source, "int native_sdk_appkit_set_dock_presence(") orelse return error.TestExpectedEqual;
2724
+ const dock_tail = host_source[dock_at..];
2725
+ const dock_end = std.mem.indexOf(u8, dock_tail, "int native_sdk_appkit_launch_at_login_status(") orelse return error.TestExpectedEqual;
2726
+ const dock_body = dock_tail[0..dock_end];
2727
+ try std.testing.expect(std.mem.indexOf(u8, dock_body, "[NSApp setActivationPolicy:policy]") != null);
2728
+ try std.testing.expect(std.mem.indexOf(u8, dock_body, "[NSApp activate") == null);
2729
+ }
2499
2730
  }
2500
2731
 
2501
2732
  test "mac transparent raw frames are premultiplied exactly once before Metal upload" {
@@ -2817,3 +3048,50 @@ test "mac appearance event carries accessibility preferences" {
2817
3048
  try std.testing.expect(event.reduce_motion != 0);
2818
3049
  try std.testing.expect(event.high_contrast != 0);
2819
3050
  }
3051
+
3052
+ test "mac launch-at-login result keeps unsupported separate from operation failure" {
3053
+ try std.testing.expectEqual(platform_mod.LaunchAtLoginStatus.disabled, try launchAtLoginStatusFromInt(0));
3054
+ try std.testing.expectEqual(platform_mod.LaunchAtLoginStatus.enabled, try launchAtLoginStatusFromInt(1));
3055
+ try std.testing.expectEqual(platform_mod.LaunchAtLoginStatus.requires_approval, try launchAtLoginStatusFromInt(2));
3056
+ try std.testing.expectEqual(platform_mod.LaunchAtLoginStatus.not_found, try launchAtLoginStatusFromInt(3));
3057
+ try std.testing.expectError(error.UnsupportedService, launchAtLoginStatusFromInt(-1));
3058
+ try std.testing.expectError(error.LaunchAtLoginFailed, launchAtLoginStatusFromInt(-2));
3059
+ try std.testing.expectError(error.LaunchAtLoginFailed, launchAtLoginStatusFromInt(99));
3060
+ }
3061
+
3062
+ test "both mac hosts carry the menu-bar lifecycle and fullscreen hooks" {
3063
+ const hosts = [_][]const u8{
3064
+ @embedFile("appkit_host.m"),
3065
+ @embedFile("cef_host.mm"),
3066
+ };
3067
+ for (hosts) |host_source| {
3068
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_appkit_hide_window") != null);
3069
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_appkit_set_dock_presence") != null);
3070
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_appkit_launch_at_login_status") != null);
3071
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_appkit_set_launch_at_login") != null);
3072
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "registerAndReturnError:") != null);
3073
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "unregisterAndReturnError:") != null);
3074
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "before == 1 || before == 2") != null);
3075
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "return succeeded ? NativeSdkLaunchAtLoginStatus() : -2;") != null);
3076
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "dlopen(") != null);
3077
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "ServiceManagement.framework/ServiceManagement") != null);
3078
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "NSWindowCollectionBehaviorFullScreenNone") != null);
3079
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "standardWindowButton:NSWindowZoomButton") != null);
3080
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "1u << 4") != null);
3081
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "policyHiddenWindows") != null);
3082
+ }
3083
+
3084
+ // AppKit canvas windows also carry a pending first-present/fallback
3085
+ // reveal. An explicit hide must retire that pending reveal before it
3086
+ // records the policy-hidden state.
3087
+ const appkit_source = hosts[0];
3088
+ try std.testing.expect(std.mem.indexOf(u8, appkit_source, "[NSApp activate]") == null);
3089
+ try std.testing.expect(std.mem.indexOf(u8, appkit_source, "[NSApp activateIgnoringOtherApps:YES]") != null);
3090
+ const hide_at = std.mem.indexOf(u8, appkit_source, "- (void)hideWindowWithId:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
3091
+ const hide_tail = appkit_source[hide_at..];
3092
+ const show_at = std.mem.indexOf(u8, hide_tail, "- (void)showWindowWithId:(uint64_t)windowId {") orelse return error.TestExpectedEqual;
3093
+ const hide_body = hide_tail[0..show_at];
3094
+ const cancel_at = std.mem.indexOf(u8, hide_body, "[self.deferredShowWindows removeObjectForKey:@(windowId)];") orelse return error.TestExpectedEqual;
3095
+ const policy_at = std.mem.indexOf(u8, hide_body, "[self.policyHiddenWindows addObject:@(windowId)];") orelse return error.TestExpectedEqual;
3096
+ try std.testing.expect(cancel_at < policy_at);
3097
+ }