@native-sdk/cli 0.9.0 → 0.9.2

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 (181) hide show
  1. package/build/app.zig +357 -33
  2. package/build.zig +234 -11
  3. package/native-sdk.d.ts +8 -0
  4. package/package.json +10 -10
  5. package/packages/core/compile-surface/core.ts +70 -1
  6. package/packages/core/package-lock.json +11 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  9. package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
  10. package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
  11. package/packages/core/scripts/stage_external_services.mjs +1 -1
  12. package/packages/core/sdk/core.d.ts +75 -0
  13. package/packages/core/sdk/core.ts +170 -13
  14. package/packages/core/sdk/events.d.ts +53 -0
  15. package/packages/core/sdk/events.ts +78 -7
  16. package/packages/core/src/checker.ts +470 -2
  17. package/packages/core/src/cli.ts +13 -0
  18. package/packages/core/src/contract.ts +3 -1
  19. package/packages/core/src/devhost.ts +30 -1
  20. package/packages/core/src/devhost_journal.mjs +10 -8
  21. package/packages/core/src/diagnostics.ts +99 -8
  22. package/packages/core/src/frontend.ts +6 -0
  23. package/packages/core/src/infer.ts +24 -0
  24. package/skill-data/automation/SKILL.md +1 -1
  25. package/skill-data/native-ui/SKILL.md +18 -12
  26. package/skill-data/ts-core/SKILL.md +54 -21
  27. package/skill-data/ts-services/SKILL.md +4 -4
  28. package/skill-data/ts-services/references/service-surface.md +2 -1
  29. package/skill-data/zig/SKILL.md +1 -1
  30. package/src/app_runner/root.zig +122 -6
  31. package/src/app_runner/ts_core_main.zig +9 -4
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/app_runner/window_placement.zig +63 -0
  34. package/src/automation/protocol.zig +5 -1
  35. package/src/automation/snapshot.zig +8 -6
  36. package/src/embed/app_exports.zig +3 -1
  37. package/src/embed/conversions.zig +1 -0
  38. package/src/embed/host.zig +10 -3
  39. package/src/embed/root.zig +2 -0
  40. package/src/embed/tests.zig +41 -1
  41. package/src/embed/types.zig +2 -0
  42. package/src/embed/ui_host.zig +94 -4
  43. package/src/platform/android/NativeSdkActivity.java +49 -4
  44. package/src/platform/android/android_host.c +3 -3
  45. package/src/platform/android/native_sdk_app.h +1 -1
  46. package/src/platform/ios/apple_image_fit.h +38 -0
  47. package/src/platform/ios/files.zig +1 -0
  48. package/src/platform/ios/native_sdk_app.h +1 -1
  49. package/src/platform/ios/uikit_host.m +28 -5
  50. package/src/platform/linux/cef_host.cpp +17 -3
  51. package/src/platform/linux/gtk_host.c +243 -15
  52. package/src/platform/linux/gtk_host.h +5 -4
  53. package/src/platform/linux/root.zig +91 -11
  54. package/src/platform/macos/appkit_host.h +18 -11
  55. package/src/platform/macos/appkit_host.m +402 -128
  56. package/src/platform/macos/cef_host.mm +342 -122
  57. package/src/platform/macos/image_fit_test.m +44 -0
  58. package/src/platform/macos/root.zig +231 -39
  59. package/src/platform/null_platform.zig +251 -54
  60. package/src/platform/null_platform_tests.zig +97 -4
  61. package/src/platform/root.zig +12 -0
  62. package/src/platform/types.zig +174 -35
  63. package/src/platform/windows/root.zig +42 -13
  64. package/src/platform/windows/webview2_host.cpp +72 -11
  65. package/src/primitives/app_manifest/root.zig +3 -0
  66. package/src/primitives/app_manifest/tests.zig +24 -0
  67. package/src/primitives/app_manifest/types.zig +13 -0
  68. package/src/primitives/app_manifest/validation.zig +24 -0
  69. package/src/primitives/canvas/a11y_audit.zig +9 -7
  70. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  71. package/src/primitives/canvas/events.zig +50 -0
  72. package/src/primitives/canvas/layout_audit.zig +6 -6
  73. package/src/primitives/canvas/markdown.zig +4 -0
  74. package/src/primitives/canvas/markdown_tests.zig +1 -0
  75. package/src/primitives/canvas/png.zig +138 -0
  76. package/src/primitives/canvas/root.zig +13 -2
  77. package/src/primitives/canvas/text_span_tests.zig +5 -3
  78. package/src/primitives/canvas/text_spans.zig +2 -0
  79. package/src/primitives/canvas/text_tests.zig +20 -0
  80. package/src/primitives/canvas/ui.zig +55 -2
  81. package/src/primitives/canvas/ui_markup.zig +40 -13
  82. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  83. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  84. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  85. package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
  86. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  87. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  88. package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
  89. package/src/primitives/canvas/ui_schema.zig +17 -13
  90. package/src/primitives/canvas/ui_tests.zig +47 -0
  91. package/src/primitives/canvas/widget_access.zig +3 -3
  92. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  93. package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
  94. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  95. package/src/primitives/canvas/widget_layout.zig +333 -126
  96. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  97. package/src/primitives/canvas/widget_metrics.zig +7 -8
  98. package/src/primitives/canvas/widget_render.zig +76 -44
  99. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  100. package/src/primitives/canvas/widget_render_style.zig +58 -18
  101. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  102. package/src/primitives/canvas/widget_routing.zig +40 -34
  103. package/src/primitives/canvas/widget_runtime.zig +11 -2
  104. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  105. package/src/primitives/canvas/widget_semantics.zig +8 -3
  106. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  107. package/src/primitives/canvas/widget_tree.zig +99 -5
  108. package/src/primitives/canvas/widgets.zig +20 -7
  109. package/src/root.zig +10 -0
  110. package/src/runtime/api.zig +14 -0
  111. package/src/runtime/automation_commands.zig +35 -2
  112. package/src/runtime/automation_snapshot.zig +32 -24
  113. package/src/runtime/automation_widget_dispatch.zig +48 -6
  114. package/src/runtime/bridge_permission_tests.zig +35 -1
  115. package/src/runtime/bridge_responses.zig +1 -1
  116. package/src/runtime/builtin_bridge.zig +16 -3
  117. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  118. package/src/runtime/canvas_image_tests.zig +146 -2
  119. package/src/runtime/canvas_images.zig +35 -16
  120. package/src/runtime/canvas_limits.zig +13 -3
  121. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  122. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  123. package/src/runtime/canvas_widget_control_tests.zig +31 -1
  124. package/src/runtime/canvas_widget_events.zig +151 -26
  125. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  126. package/src/runtime/canvas_widget_runtime.zig +322 -102
  127. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  128. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  129. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  130. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  131. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  132. package/src/runtime/canvas_widget_state.zig +33 -7
  133. package/src/runtime/core.zig +28 -6
  134. package/src/runtime/effects.zig +1337 -49
  135. package/src/runtime/effects_file_tests.zig +587 -0
  136. package/src/runtime/effects_image_tests.zig +91 -0
  137. package/src/runtime/effects_notification_tests.zig +11 -0
  138. package/src/runtime/file_access.zig +400 -0
  139. package/src/runtime/file_effect_crash_helper.zig +28 -0
  140. package/src/runtime/file_effect_crash_tests.zig +37 -0
  141. package/src/runtime/flow.zig +21 -9
  142. package/src/runtime/gpu_surface_events.zig +25 -2
  143. package/src/runtime/native_command_event_tests.zig +44 -2
  144. package/src/runtime/pty.zig +5 -2
  145. package/src/runtime/root.zig +7 -0
  146. package/src/runtime/session_blobs.zig +4 -1
  147. package/src/runtime/session_journal.zig +56 -5
  148. package/src/runtime/session_record.zig +38 -0
  149. package/src/runtime/session_replay.zig +110 -15
  150. package/src/runtime/session_tests.zig +192 -4
  151. package/src/runtime/shell_layout_tests.zig +12 -0
  152. package/src/runtime/state.zig +10 -0
  153. package/src/runtime/system_services.zig +129 -36
  154. package/src/runtime/ts_core_host.zig +281 -11
  155. package/src/runtime/ts_core_host_tests.zig +142 -1
  156. package/src/runtime/ts_ui_app.zig +461 -8
  157. package/src/runtime/ui_app.zig +330 -112
  158. package/src/runtime/ui_app_tests.zig +251 -25
  159. package/src/runtime/ui_app_window_tests.zig +74 -8
  160. package/src/runtime/validation.zig +20 -0
  161. package/src/runtime/view.zig +3 -0
  162. package/src/runtime/view_widget_control.zig +18 -0
  163. package/src/runtime/view_widget_scroll.zig +112 -18
  164. package/src/runtime/view_widget_tree.zig +110 -13
  165. package/src/runtime/widget_bridge.zig +2 -0
  166. package/src/runtime/window_command_bridge_tests.zig +86 -0
  167. package/src/runtime/window_storage.zig +16 -1
  168. package/src/runtime/window_views.zig +1 -0
  169. package/src/tooling/ios.zig +3 -0
  170. package/src/tooling/manifest.zig +90 -2
  171. package/src/tooling/package.zig +67 -2
  172. package/src/tooling/raw_manifest.zig +10 -0
  173. package/src/tooling/templates.zig +156 -18
  174. package/src/tooling/ts_core.zig +83 -0
  175. package/src/tooling/web_engine.zig +1 -1
  176. package/tools/corewire/emit.zig +3 -3
  177. package/tools/corewire/emit_facade.zig +65 -5
  178. package/tools/corewire/emit_profile.zig +2 -2
  179. package/tools/corewire/emit_service.zig +2 -2
  180. package/tools/corewire/service_contract.zig +4 -4
  181. package/tools/corewire/sidecar.zig +4 -4
@@ -29,12 +29,16 @@ const max_recent_document_path_bytes = types.max_recent_document_path_bytes;
29
29
  const max_notification_title_bytes = types.max_notification_title_bytes;
30
30
  const max_notification_subtitle_bytes = types.max_notification_subtitle_bytes;
31
31
  const max_notification_body_bytes = types.max_notification_body_bytes;
32
+ const max_notification_id_bytes = types.max_notification_id_bytes;
33
+ const max_notification_action_label_bytes = types.max_notification_action_label_bytes;
34
+ const max_notification_action_command_bytes = types.max_notification_action_command_bytes;
32
35
  const max_clipboard_mime_type_bytes = types.max_clipboard_mime_type_bytes;
33
36
  const max_clipboard_data_bytes = types.max_clipboard_data_bytes;
34
37
  const max_credential_service_bytes = types.max_credential_service_bytes;
35
38
  const max_credential_account_bytes = types.max_credential_account_bytes;
36
39
  const max_credential_secret_bytes = types.max_credential_secret_bytes;
37
40
  const max_local_time_text_bytes = types.max_local_time_text_bytes;
41
+ const max_status_items = types.max_status_items;
38
42
  const max_tray_items = types.max_tray_items;
39
43
  const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
40
44
  const max_tray_title_bytes = types.max_tray_title_bytes;
@@ -72,6 +76,7 @@ const validateMenus = types.validateMenus;
72
76
  const validateMenuItem = types.validateMenuItem;
73
77
  const isValidShortcutKey = types.isValidShortcutKey;
74
78
  const WindowRestorePolicy = types.WindowRestorePolicy;
79
+ const WindowInitialPlacement = types.WindowInitialPlacement;
75
80
  const WindowOptions = types.WindowOptions;
76
81
  const WindowState = types.WindowState;
77
82
  const WindowInfo = types.WindowInfo;
@@ -112,6 +117,8 @@ const NotificationOptions = types.NotificationOptions;
112
117
  const CredentialKey = types.CredentialKey;
113
118
  const Credential = types.Credential;
114
119
  const LocalTimeStyle = types.LocalTimeStyle;
120
+ const StatusItemId = types.StatusItemId;
121
+ const TrayShell = types.TrayShell;
115
122
  const TrayItemId = types.TrayItemId;
116
123
  const TrayOptions = types.TrayOptions;
117
124
  const TrayPresentation = types.TrayPresentation;
@@ -119,6 +126,7 @@ const TrayMenuItem = types.TrayMenuItem;
119
126
  const NativeCommandEvent = types.NativeCommandEvent;
120
127
  const MenuCommandEvent = types.MenuCommandEvent;
121
128
  const TrayCommandEvent = types.TrayCommandEvent;
129
+ const Event = types.Event;
122
130
  const TimerEvent = types.TimerEvent;
123
131
  const FileDropEvent = types.FileDropEvent;
124
132
  const GpuFrame = types.GpuFrame;
@@ -145,7 +153,6 @@ const WidgetAccessibilityActionEvent = types.WidgetAccessibilityActionEvent;
145
153
  const ClipboardData = types.ClipboardData;
146
154
  const ColorScheme = types.ColorScheme;
147
155
  const Appearance = types.Appearance;
148
- const Event = types.Event;
149
156
  const splitDropPaths = types.splitDropPaths;
150
157
  const EventHandler = types.EventHandler;
151
158
  const PlatformServices = types.PlatformServices;
@@ -294,6 +301,37 @@ pub const NullAudioCapture = struct {
294
301
  stop_count: usize = 0,
295
302
  };
296
303
 
304
+ const NullStatusItem = struct {
305
+ id: StatusItemId = 0,
306
+ active: bool = false,
307
+ visible: bool = true,
308
+ icon_path: [max_tray_icon_path_bytes]u8 = undefined,
309
+ icon_path_len: usize = 0,
310
+ title: [max_tray_title_bytes]u8 = undefined,
311
+ title_len: usize = 0,
312
+ tooltip: [max_tray_tooltip_bytes]u8 = undefined,
313
+ tooltip_len: usize = 0,
314
+ activation_command: [max_tray_item_command_bytes]u8 = undefined,
315
+ activation_command_len: usize = 0,
316
+ alternate_activation_command: [max_tray_item_command_bytes]u8 = undefined,
317
+ alternate_activation_command_len: usize = 0,
318
+ open_command: [max_tray_item_command_bytes]u8 = undefined,
319
+ open_command_len: usize = 0,
320
+ presentation: TrayPresentation = .{},
321
+ items: [max_tray_items]TrayMenuItem = undefined,
322
+ item_count: usize = 0,
323
+ };
324
+
325
+ const max_null_notifications: usize = 16;
326
+
327
+ const NullNotification = struct {
328
+ active: bool = false,
329
+ id: [max_notification_id_bytes]u8 = undefined,
330
+ id_len: usize = 0,
331
+ action_command: [max_notification_action_command_bytes]u8 = undefined,
332
+ action_command_len: usize = 0,
333
+ };
334
+
297
335
  pub const NullPlatform = struct {
298
336
  surface_value: Surface = .{},
299
337
  web_engine: WebEngine = .system,
@@ -340,6 +378,10 @@ pub const NullPlatform = struct {
340
378
  /// like `windows` — same seam-regression purpose as
341
379
  /// `window_resizable` (the startup create used to hardcode it).
342
380
  window_titlebar: [max_windows]WindowTitlebarStyle = [_]WindowTitlebarStyle{.standard} ** max_windows,
381
+ /// Captured independently from `restore_state`: persistence opt-in does
382
+ /// not mean a frame was actually found and restored.
383
+ window_placement: [max_windows]WindowInitialPlacement = [_]WindowInitialPlacement{.default} ** max_windows,
384
+ window_restore_policy: [max_windows]WindowRestorePolicy = [_]WindowRestorePolicy{.clamp_to_visible_screen} ** max_windows,
343
385
  window_transparent: [max_windows]bool = [_]bool{false} ** max_windows,
344
386
  window_always_on_top: [max_windows]bool = [_]bool{false} ** max_windows,
345
387
  window_click_through: [max_windows]bool = [_]bool{false} ** max_windows,
@@ -464,7 +506,15 @@ pub const NullPlatform = struct {
464
506
  notification_subtitle_len: usize = 0,
465
507
  notification_body: [max_notification_body_bytes]u8 = undefined,
466
508
  notification_body_len: usize = 0,
509
+ notification_id: [max_notification_id_bytes]u8 = undefined,
510
+ notification_id_len: usize = 0,
511
+ notification_action_label: [max_notification_action_label_bytes]u8 = undefined,
512
+ notification_action_label_len: usize = 0,
513
+ notification_action_command: [max_notification_action_command_bytes]u8 = undefined,
514
+ notification_action_command_len: usize = 0,
515
+ notifications: [max_null_notifications]NullNotification = [_]NullNotification{.{}} ** max_null_notifications,
467
516
  notification_count: usize = 0,
517
+ notification_replacement_count: usize = 0,
468
518
  clipboard_mime_type: [max_clipboard_mime_type_bytes]u8 = undefined,
469
519
  clipboard_mime_type_len: usize = 0,
470
520
  clipboard_data: [max_clipboard_data_bytes]u8 = undefined,
@@ -487,22 +537,10 @@ pub const NullPlatform = struct {
487
537
  /// fixed offset so suites can pin exact output without ambient state.
488
538
  local_time_offset_minutes: i16 = 0,
489
539
  webview_navigate_count: usize = 0,
490
- tray_icon_path: [max_tray_icon_path_bytes]u8 = undefined,
491
- tray_icon_path_len: usize = 0,
492
- tray_title: [max_tray_title_bytes]u8 = undefined,
493
- tray_title_len: usize = 0,
494
- tray_tooltip: [max_tray_tooltip_bytes]u8 = undefined,
495
- tray_tooltip_len: usize = 0,
496
- tray_activation_command: [max_tray_item_command_bytes]u8 = undefined,
497
- tray_activation_command_len: usize = 0,
498
- tray_alternate_activation_command: [max_tray_item_command_bytes]u8 = undefined,
499
- tray_alternate_activation_command_len: usize = 0,
500
- tray_open_command: [max_tray_item_command_bytes]u8 = undefined,
501
- tray_open_command_len: usize = 0,
502
- tray_presentation: TrayPresentation = .{},
503
- tray_items: [max_tray_items]TrayMenuItem = undefined,
504
- tray_item_count: usize = 0,
540
+ status_items: [max_status_items]NullStatusItem = [_]NullStatusItem{.{}} ** max_status_items,
541
+ status_item_count: usize = 0,
505
542
  tray_create_count: usize = 0,
543
+ tray_shell_update_count: usize = 0,
506
544
  tray_update_count: usize = 0,
507
545
  tray_title_update_count: usize = 0,
508
546
  tray_remove_count: usize = 0,
@@ -769,7 +807,12 @@ pub const NullPlatform = struct {
769
807
  }
770
808
 
771
809
  pub fn initWithOptions(surface_value: Surface, web_engine: WebEngine, app_info: AppInfo) NullPlatform {
772
- return .{ .surface_value = surface_value, .web_engine = web_engine, .app_info = app_info };
810
+ return .{
811
+ .surface_value = surface_value,
812
+ .web_engine = web_engine,
813
+ .app_info = app_info,
814
+ .dock_visible = app_info.dock_visible,
815
+ };
773
816
  }
774
817
 
775
818
  /// Heap-allocate the wrapper (process allocator) and initialize it
@@ -885,6 +928,7 @@ pub const NullPlatform = struct {
885
928
  .note_blocking_call_abandoned_fn = noteChannelWakeAbandoned,
886
929
  .format_local_time_fn = formatLocalTime,
887
930
  .create_tray_fn = createTray,
931
+ .update_tray_shell_fn = updateTrayShell,
888
932
  .update_tray_menu_fn = updateTrayMenu,
889
933
  .update_tray_title_fn = updateTrayTitle,
890
934
  .update_tray_presentation_fn = updateTrayPresentation,
@@ -1118,6 +1162,8 @@ pub const NullPlatform = struct {
1118
1162
  self.windows[self.window_count] = info;
1119
1163
  self.window_resizable[self.window_count] = options.resizable;
1120
1164
  self.window_titlebar[self.window_count] = options.titlebar;
1165
+ self.window_placement[self.window_count] = options.initial_placement;
1166
+ self.window_restore_policy[self.window_count] = options.restore_policy;
1121
1167
  self.window_transparent[self.window_count] = options.transparent;
1122
1168
  self.window_always_on_top[self.window_count] = options.always_on_top;
1123
1169
  self.window_click_through[self.window_count] = options.click_through;
@@ -1541,9 +1587,36 @@ pub const NullPlatform = struct {
1541
1587
  self.notification_title = undefined;
1542
1588
  self.notification_subtitle = undefined;
1543
1589
  self.notification_body = undefined;
1590
+ self.notification_id = undefined;
1591
+ self.notification_action_label = undefined;
1592
+ self.notification_action_command = undefined;
1544
1593
  self.notification_title_len = (try copyInto(&self.notification_title, options.title)).len;
1545
1594
  self.notification_subtitle_len = (try copyInto(&self.notification_subtitle, options.subtitle)).len;
1546
1595
  self.notification_body_len = (try copyInto(&self.notification_body, options.body)).len;
1596
+ self.notification_id_len = (try copyInto(&self.notification_id, options.id)).len;
1597
+ self.notification_action_label_len = (try copyInto(&self.notification_action_label, options.action_label)).len;
1598
+ self.notification_action_command_len = (try copyInto(&self.notification_action_command, options.action_command)).len;
1599
+
1600
+ if (options.id.len > 0) {
1601
+ var selected: ?usize = null;
1602
+ var free: ?usize = null;
1603
+ for (&self.notifications, 0..) |*entry, index| {
1604
+ if (!entry.active) {
1605
+ if (free == null) free = index;
1606
+ continue;
1607
+ }
1608
+ if (std.mem.eql(u8, entry.id[0..entry.id_len], options.id)) {
1609
+ selected = index;
1610
+ self.notification_replacement_count += 1;
1611
+ break;
1612
+ }
1613
+ }
1614
+ const index = selected orelse free orelse (self.notification_count % max_null_notifications);
1615
+ var entry = &self.notifications[index];
1616
+ entry.* = .{ .active = true };
1617
+ entry.id_len = (try copyInto(&entry.id, options.id)).len;
1618
+ entry.action_command_len = (try copyInto(&entry.action_command, options.action_command)).len;
1619
+ }
1547
1620
  self.notification_count += 1;
1548
1621
  }
1549
1622
 
@@ -1657,51 +1730,92 @@ pub const NullPlatform = struct {
1657
1730
  return .{ .year = @intCast(civil_year), .month = month, .day = day };
1658
1731
  }
1659
1732
 
1660
- fn createTray(context: ?*anyopaque, options: TrayOptions) anyerror!void {
1733
+ fn findStatusItem(self: *NullPlatform, status_item_id: StatusItemId) ?*NullStatusItem {
1734
+ for (&self.status_items) |*item| {
1735
+ if (item.active and item.id == status_item_id) return item;
1736
+ }
1737
+ return null;
1738
+ }
1739
+
1740
+ fn findStatusItemConst(self: *const NullPlatform, status_item_id: StatusItemId) ?*const NullStatusItem {
1741
+ for (&self.status_items) |*item| {
1742
+ if (item.active and item.id == status_item_id) return item;
1743
+ }
1744
+ return null;
1745
+ }
1746
+
1747
+ fn statusItemSlot(self: *NullPlatform, status_item_id: StatusItemId) anyerror!*NullStatusItem {
1748
+ if (self.findStatusItem(status_item_id)) |item| return item;
1749
+ for (&self.status_items) |*item| {
1750
+ if (!item.active) {
1751
+ item.* = .{ .id = status_item_id, .active = true };
1752
+ self.status_item_count += 1;
1753
+ return item;
1754
+ }
1755
+ }
1756
+ return error.UnsupportedService;
1757
+ }
1758
+
1759
+ fn copyTrayShell(item: *NullStatusItem, shell: TrayShell) anyerror!void {
1760
+ item.icon_path_len = (try copyInto(&item.icon_path, shell.icon_path)).len;
1761
+ item.tooltip_len = (try copyInto(&item.tooltip, shell.tooltip)).len;
1762
+ item.activation_command_len = (try copyInto(&item.activation_command, shell.activation_command)).len;
1763
+ item.alternate_activation_command_len = (try copyInto(&item.alternate_activation_command, shell.alternate_activation_command)).len;
1764
+ item.open_command_len = (try copyInto(&item.open_command, shell.open_command)).len;
1765
+ item.visible = shell.visible;
1766
+ }
1767
+
1768
+ fn createTray(context: ?*anyopaque, status_item_id: StatusItemId, options: TrayOptions) anyerror!void {
1661
1769
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1662
- self.tray_icon_path = undefined;
1663
- self.tray_title = undefined;
1664
- self.tray_tooltip = undefined;
1665
- self.tray_icon_path_len = (try copyInto(&self.tray_icon_path, options.icon_path)).len;
1770
+ const item = try self.statusItemSlot(status_item_id);
1771
+ try copyTrayShell(item, types.trayShell(options));
1666
1772
  var presentation = options.presentation;
1667
1773
  if (presentation.title.len == 0) presentation.title = options.title;
1668
- self.tray_title_len = (try copyInto(&self.tray_title, presentation.title)).len;
1669
- self.tray_tooltip_len = (try copyInto(&self.tray_tooltip, options.tooltip)).len;
1670
- self.tray_activation_command_len = (try copyInto(&self.tray_activation_command, options.activation_command)).len;
1671
- self.tray_alternate_activation_command_len = (try copyInto(&self.tray_alternate_activation_command, options.alternate_activation_command)).len;
1672
- self.tray_open_command_len = (try copyInto(&self.tray_open_command, options.open_command)).len;
1673
- self.tray_presentation = presentation;
1674
- self.tray_presentation.title = self.tray_title[0..self.tray_title_len];
1675
- try updateTrayMenu(context, options.items);
1774
+ item.title_len = (try copyInto(&item.title, presentation.title)).len;
1775
+ item.presentation = presentation;
1776
+ item.presentation.title = item.title[0..item.title_len];
1777
+ try updateTrayMenu(context, status_item_id, options.items);
1676
1778
  self.tray_create_count += 1;
1677
1779
  }
1678
1780
 
1679
- fn updateTrayMenu(context: ?*anyopaque, items: []const TrayMenuItem) anyerror!void {
1781
+ fn updateTrayShell(context: ?*anyopaque, status_item_id: StatusItemId, shell: TrayShell) anyerror!void {
1782
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1783
+ const item = self.findStatusItem(status_item_id) orelse return error.InvalidTrayOptions;
1784
+ try copyTrayShell(item, shell);
1785
+ self.tray_shell_update_count += 1;
1786
+ }
1787
+
1788
+ fn updateTrayMenu(context: ?*anyopaque, status_item_id: StatusItemId, items: []const TrayMenuItem) anyerror!void {
1680
1789
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1681
- if (items.len > self.tray_items.len) return error.InvalidTrayOptions;
1682
- for (items, 0..) |item, index| self.tray_items[index] = item;
1683
- self.tray_item_count = items.len;
1790
+ const status_item = self.findStatusItem(status_item_id) orelse return error.InvalidTrayOptions;
1791
+ if (items.len > status_item.items.len) return error.InvalidTrayOptions;
1792
+ for (items, 0..) |item, index| status_item.items[index] = item;
1793
+ status_item.item_count = items.len;
1684
1794
  self.tray_update_count += 1;
1685
1795
  }
1686
1796
 
1687
- fn updateTrayTitle(context: ?*anyopaque, title: []const u8) anyerror!void {
1797
+ fn updateTrayTitle(context: ?*anyopaque, status_item_id: StatusItemId, title: []const u8) anyerror!void {
1688
1798
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1689
- self.tray_title = undefined;
1690
- self.tray_title_len = (try copyInto(&self.tray_title, title)).len;
1691
- self.tray_presentation.title = self.tray_title[0..self.tray_title_len];
1799
+ const item = self.findStatusItem(status_item_id) orelse return error.InvalidTrayOptions;
1800
+ item.title_len = (try copyInto(&item.title, title)).len;
1801
+ item.presentation.title = item.title[0..item.title_len];
1692
1802
  self.tray_title_update_count += 1;
1693
1803
  }
1694
1804
 
1695
- fn updateTrayPresentation(context: ?*anyopaque, presentation: TrayPresentation) anyerror!void {
1805
+ fn updateTrayPresentation(context: ?*anyopaque, status_item_id: StatusItemId, presentation: TrayPresentation) anyerror!void {
1696
1806
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1697
- try updateTrayTitle(context, presentation.title);
1698
- self.tray_presentation = presentation;
1699
- self.tray_presentation.title = self.tray_title[0..self.tray_title_len];
1807
+ try updateTrayTitle(context, status_item_id, presentation.title);
1808
+ const item = self.findStatusItem(status_item_id) orelse return error.InvalidTrayOptions;
1809
+ item.presentation = presentation;
1810
+ item.presentation.title = item.title[0..item.title_len];
1700
1811
  }
1701
1812
 
1702
- fn removeTray(context: ?*anyopaque) anyerror!void {
1813
+ fn removeTray(context: ?*anyopaque, status_item_id: StatusItemId) anyerror!void {
1703
1814
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1704
- self.tray_item_count = 0;
1815
+ const item = self.findStatusItem(status_item_id) orelse return;
1816
+ item.active = false;
1817
+ item.item_count = 0;
1818
+ self.status_item_count -= 1;
1705
1819
  self.tray_remove_count += 1;
1706
1820
  }
1707
1821
 
@@ -2313,11 +2427,11 @@ pub const NullPlatform = struct {
2313
2427
  /// Deterministic decode seam for tests (see `image_decode`): parses
2314
2428
  /// the strict PNG subset the canvas writer emits. Off by default so
2315
2429
  /// the null platform models codec-less hosts.
2316
- fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8) anyerror!types.DecodedImage {
2430
+ fn decodeImage(context: ?*anyopaque, bytes: []const u8, buffer: []u8, max_pixels: usize) anyerror!types.DecodedImage {
2317
2431
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
2318
2432
  if (!self.image_decode) return error.UnsupportedService;
2319
2433
  self.image_decode_count += 1;
2320
- const decoded = canvas.png.decodeRgba8(bytes, buffer) catch |err| return switch (err) {
2434
+ const decoded = canvas.png.decodeRgba8Fitted(bytes, buffer, max_pixels, types.max_decoded_image_dimension) catch |err| return switch (err) {
2321
2435
  error.PngPixelBufferTooSmall => error.ImageTooLarge,
2322
2436
  else => error.ImageDecodeFailed,
2323
2437
  };
@@ -2855,6 +2969,8 @@ pub const NullPlatform = struct {
2855
2969
  self.windows[cursor] = self.windows[cursor + 1];
2856
2970
  self.window_resizable[cursor] = self.window_resizable[cursor + 1];
2857
2971
  self.window_titlebar[cursor] = self.window_titlebar[cursor + 1];
2972
+ self.window_placement[cursor] = self.window_placement[cursor + 1];
2973
+ self.window_restore_policy[cursor] = self.window_restore_policy[cursor + 1];
2858
2974
  self.window_transparent[cursor] = self.window_transparent[cursor + 1];
2859
2975
  self.window_always_on_top[cursor] = self.window_always_on_top[cursor + 1];
2860
2976
  self.window_click_through[cursor] = self.window_click_through[cursor + 1];
@@ -2979,10 +3095,45 @@ pub const NullPlatform = struct {
2979
3095
  return self.notification_body[0..self.notification_body_len];
2980
3096
  }
2981
3097
 
3098
+ pub fn lastNotificationId(self: *const NullPlatform) []const u8 {
3099
+ return self.notification_id[0..self.notification_id_len];
3100
+ }
3101
+
3102
+ pub fn lastNotificationActionLabel(self: *const NullPlatform) []const u8 {
3103
+ return self.notification_action_label[0..self.notification_action_label_len];
3104
+ }
3105
+
3106
+ pub fn lastNotificationActionCommand(self: *const NullPlatform) []const u8 {
3107
+ return self.notification_action_command[0..self.notification_action_command_len];
3108
+ }
3109
+
3110
+ /// Deterministically model a user activating the action on a named,
3111
+ /// currently active notification. The returned event borrows this
3112
+ /// platform's fixed storage until the next notification update.
3113
+ pub fn activateNotification(self: *const NullPlatform, id: []const u8) ?Event {
3114
+ for (&self.notifications) |*entry| {
3115
+ if (!entry.active or !std.mem.eql(u8, entry.id[0..entry.id_len], id)) continue;
3116
+ if (entry.action_command_len == 0) return null;
3117
+ return .{ .notification_command = .{ .name = entry.action_command[0..entry.action_command_len] } };
3118
+ }
3119
+ return null;
3120
+ }
3121
+
3122
+ /// Anonymous notifications have no replacement key; tests can still
3123
+ /// activate the most recently delivered action through this seam.
3124
+ pub fn activateLastNotification(self: *const NullPlatform) ?Event {
3125
+ if (self.notification_action_command_len == 0) return null;
3126
+ return .{ .notification_command = .{ .name = self.lastNotificationActionCommand() } };
3127
+ }
3128
+
2982
3129
  pub fn notificationCount(self: *const NullPlatform) usize {
2983
3130
  return self.notification_count;
2984
3131
  }
2985
3132
 
3133
+ pub fn notificationReplacementCount(self: *const NullPlatform) usize {
3134
+ return self.notification_replacement_count;
3135
+ }
3136
+
2986
3137
  pub fn lastClipboardMimeType(self: *const NullPlatform) []const u8 {
2987
3138
  return self.clipboard_mime_type[0..self.clipboard_mime_type_len];
2988
3139
  }
@@ -3016,35 +3167,77 @@ pub const NullPlatform = struct {
3016
3167
  }
3017
3168
 
3018
3169
  pub fn lastTrayIconPath(self: *const NullPlatform) []const u8 {
3019
- return self.tray_icon_path[0..self.tray_icon_path_len];
3170
+ return self.statusItemIconPath(types.primary_status_item_id);
3020
3171
  }
3021
3172
 
3022
3173
  pub fn lastTrayTitle(self: *const NullPlatform) []const u8 {
3023
- return self.tray_title[0..self.tray_title_len];
3174
+ return self.statusItemTitle(types.primary_status_item_id);
3024
3175
  }
3025
3176
 
3026
3177
  pub fn lastTrayTooltip(self: *const NullPlatform) []const u8 {
3027
- return self.tray_tooltip[0..self.tray_tooltip_len];
3178
+ return self.statusItemTooltip(types.primary_status_item_id);
3028
3179
  }
3029
3180
 
3030
3181
  pub fn lastTrayActivationCommand(self: *const NullPlatform) []const u8 {
3031
- return self.tray_activation_command[0..self.tray_activation_command_len];
3182
+ const item = self.findStatusItemConst(types.primary_status_item_id) orelse return "";
3183
+ return item.activation_command[0..item.activation_command_len];
3032
3184
  }
3033
3185
 
3034
3186
  pub fn lastTrayAlternateActivationCommand(self: *const NullPlatform) []const u8 {
3035
- return self.tray_alternate_activation_command[0..self.tray_alternate_activation_command_len];
3187
+ const item = self.findStatusItemConst(types.primary_status_item_id) orelse return "";
3188
+ return item.alternate_activation_command[0..item.alternate_activation_command_len];
3036
3189
  }
3037
3190
 
3038
3191
  pub fn lastTrayOpenCommand(self: *const NullPlatform) []const u8 {
3039
- return self.tray_open_command[0..self.tray_open_command_len];
3192
+ const item = self.findStatusItemConst(types.primary_status_item_id) orelse return "";
3193
+ return item.open_command[0..item.open_command_len];
3040
3194
  }
3041
3195
 
3042
3196
  pub fn lastTrayPresentation(self: *const NullPlatform) TrayPresentation {
3043
- return self.tray_presentation;
3197
+ const item = self.findStatusItemConst(types.primary_status_item_id) orelse return .{};
3198
+ return item.presentation;
3044
3199
  }
3045
3200
 
3046
3201
  pub fn trayItems(self: *const NullPlatform) []const TrayMenuItem {
3047
- return self.tray_items[0..self.tray_item_count];
3202
+ return self.statusItemMenu(types.primary_status_item_id);
3203
+ }
3204
+
3205
+ pub fn statusItemCount(self: *const NullPlatform) usize {
3206
+ return self.status_item_count;
3207
+ }
3208
+
3209
+ pub fn statusItemExists(self: *const NullPlatform, status_item_id: StatusItemId) bool {
3210
+ return self.findStatusItemConst(status_item_id) != null;
3211
+ }
3212
+
3213
+ pub fn statusItemVisible(self: *const NullPlatform, status_item_id: StatusItemId) bool {
3214
+ const item = self.findStatusItemConst(status_item_id) orelse return false;
3215
+ return item.visible;
3216
+ }
3217
+
3218
+ pub fn statusItemIconPath(self: *const NullPlatform, status_item_id: StatusItemId) []const u8 {
3219
+ const item = self.findStatusItemConst(status_item_id) orelse return "";
3220
+ return item.icon_path[0..item.icon_path_len];
3221
+ }
3222
+
3223
+ pub fn statusItemTitle(self: *const NullPlatform, status_item_id: StatusItemId) []const u8 {
3224
+ const item = self.findStatusItemConst(status_item_id) orelse return "";
3225
+ return item.title[0..item.title_len];
3226
+ }
3227
+
3228
+ pub fn statusItemTooltip(self: *const NullPlatform, status_item_id: StatusItemId) []const u8 {
3229
+ const item = self.findStatusItemConst(status_item_id) orelse return "";
3230
+ return item.tooltip[0..item.tooltip_len];
3231
+ }
3232
+
3233
+ pub fn statusItemActivationCommand(self: *const NullPlatform, status_item_id: StatusItemId) []const u8 {
3234
+ const item = self.findStatusItemConst(status_item_id) orelse return "";
3235
+ return item.activation_command[0..item.activation_command_len];
3236
+ }
3237
+
3238
+ pub fn statusItemMenu(self: *const NullPlatform, status_item_id: StatusItemId) []const TrayMenuItem {
3239
+ const item = self.findStatusItemConst(status_item_id) orelse return &.{};
3240
+ return item.items[0..item.item_count];
3048
3241
  }
3049
3242
 
3050
3243
  pub fn trayCreateCount(self: *const NullPlatform) usize {
@@ -3055,6 +3248,10 @@ pub const NullPlatform = struct {
3055
3248
  return self.tray_update_count;
3056
3249
  }
3057
3250
 
3251
+ pub fn trayShellUpdateCount(self: *const NullPlatform) usize {
3252
+ return self.tray_shell_update_count;
3253
+ }
3254
+
3058
3255
  pub fn trayTitleUpdateCount(self: *const NullPlatform) usize {
3059
3256
  return self.tray_title_update_count;
3060
3257
  }
@@ -187,6 +187,59 @@ test "null platform reports hidden startup state" {
187
187
  try std.testing.expectEqual(true, recorder.startup_hidden.?);
188
188
  }
189
189
 
190
+ test "null platform captures fresh restored and explicit placement independently" {
191
+ var null_platform = NullPlatform.init(.{});
192
+ const services = null_platform.platform().services;
193
+
194
+ _ = try services.createWindow(.{
195
+ .id = 1,
196
+ .label = "fresh",
197
+ .restore_state = true,
198
+ .initial_placement = .default,
199
+ });
200
+ _ = try services.createWindow(.{
201
+ .id = 2,
202
+ .label = "restored",
203
+ .initial_placement = .restored,
204
+ });
205
+ _ = try services.createWindow(.{
206
+ .id = 3,
207
+ .label = "explicit",
208
+ .default_frame = geometry.RectF.init(80, 120, 640, 480),
209
+ .initial_placement = .explicit,
210
+ .restore_policy = .center_on_primary,
211
+ });
212
+
213
+ try std.testing.expectEqual(types.WindowInitialPlacement.default, null_platform.window_placement[0]);
214
+ try std.testing.expectEqual(types.WindowInitialPlacement.restored, null_platform.window_placement[1]);
215
+ try std.testing.expectEqual(types.WindowInitialPlacement.explicit, null_platform.window_placement[2]);
216
+ try std.testing.expectEqual(types.WindowRestorePolicy.center_on_primary, null_platform.window_restore_policy[2]);
217
+ }
218
+
219
+ test "window option conversion preserves legacy nonzero origins as explicit" {
220
+ const runtime_options: types.WindowCreateOptions = .{
221
+ .default_frame = geometry.RectF.init(32, 48, 640, 480),
222
+ };
223
+ try std.testing.expectEqual(types.WindowInitialPlacement.explicit, runtime_options.windowOptions(7, "runtime").initial_placement);
224
+
225
+ const app_info: types.AppInfo = .{
226
+ .main_window = .{ .default_frame = geometry.RectF.init(64, 96, 720, 480) },
227
+ };
228
+ try std.testing.expectEqual(types.WindowInitialPlacement.explicit, app_info.resolvedMainWindow().initial_placement);
229
+ try std.testing.expectEqual(types.WindowInitialPlacement.explicit, app_info.resolvedStartupWindow(0).initial_placement);
230
+ }
231
+
232
+ test "null platform records accessory launch presence from app info" {
233
+ const null_platform = NullPlatform.initWithOptions(.{}, .system, .{
234
+ .app_name = "Menu Bar",
235
+ .dock_visible = false,
236
+ });
237
+
238
+ try std.testing.expect(!null_platform.app_info.dock_visible);
239
+ try std.testing.expect(!null_platform.dock_visible);
240
+ try std.testing.expectEqual(@as(u32, 0), null_platform.dock_presence_count);
241
+ }
242
+
190
243
  test "null platform focus reveals a hidden window" {
191
244
  var null_platform = NullPlatform.init(.{});
192
245
  const services = null_platform.platform().services;
@@ -283,9 +336,12 @@ test "null platform records OS actions" {
283
336
  const services = null_platform.platform().services;
284
337
 
285
338
  try services.showNotification(.{
339
+ .id = "build-status",
286
340
  .title = "Build finished",
287
341
  .subtitle = "native-sdk",
288
342
  .body = "All checks passed.",
343
+ .action_label = "Open",
344
+ .action_command = "build.open",
289
345
  });
290
346
  try services.openExternalUrl("https://example.com/docs");
291
347
  try services.revealPath("/tmp/example.txt");
@@ -306,6 +362,11 @@ test "null platform records OS actions" {
306
362
  try std.testing.expectEqualStrings("Build finished", null_platform.lastNotificationTitle());
307
363
  try std.testing.expectEqualStrings("native-sdk", null_platform.lastNotificationSubtitle());
308
364
  try std.testing.expectEqualStrings("All checks passed.", null_platform.lastNotificationBody());
365
+ try std.testing.expectEqualStrings("build-status", null_platform.lastNotificationId());
366
+ try std.testing.expectEqualStrings("Open", null_platform.lastNotificationActionLabel());
367
+ try std.testing.expectEqualStrings("build.open", null_platform.lastNotificationActionCommand());
368
+ const notification_event = null_platform.activateNotification("build-status") orelse return error.TestUnexpectedResult;
369
+ try std.testing.expectEqualStrings("build.open", notification_event.notification_command.name);
309
370
  try std.testing.expectEqualStrings("https://example.com/docs", null_platform.lastExternalUrl());
310
371
  try std.testing.expectEqualStrings("/tmp/example.txt", null_platform.lastRevealedPath());
311
372
  try std.testing.expectEqualStrings("/tmp/recent.txt", null_platform.lastRecentDocumentPath());
@@ -366,6 +427,37 @@ test "null platform records OS actions" {
366
427
  try std.testing.expectEqual(@as(usize, 0), null_platform.trayItems().len);
367
428
  }
368
429
 
430
+ test "null platform notification ids replace their action binding" {
431
+ var null_platform = NullPlatform.init(.{});
432
+ defer null_platform.deinit();
433
+ const services = null_platform.platform().services;
434
+
435
+ try services.showNotification(.{
436
+ .id = "sync",
437
+ .title = "Syncing",
438
+ .action_label = "Cancel",
439
+ .action_command = "sync.cancel",
440
+ });
441
+ try services.showNotification(.{
442
+ .id = "other",
443
+ .title = "Other",
444
+ .action_label = "Open",
445
+ .action_command = "other.open",
446
+ });
447
+ try services.showNotification(.{
448
+ .id = "sync",
449
+ .title = "Synced",
450
+ .action_label = "View",
451
+ .action_command = "sync.view",
452
+ });
453
+
454
+ try std.testing.expectEqual(@as(usize, 3), null_platform.notificationCount());
455
+ try std.testing.expectEqual(@as(usize, 1), null_platform.notificationReplacementCount());
456
+ try std.testing.expectEqualStrings("sync.view", null_platform.activateNotification("sync").?.notification_command.name);
457
+ try std.testing.expectEqualStrings("other.open", null_platform.activateNotification("other").?.notification_command.name);
458
+ try std.testing.expect(null_platform.activateNotification("missing") == null);
459
+ }
460
+
369
461
  test "null platform records configured shortcuts" {
370
462
  const shortcuts = [_]Shortcut{
371
463
  .{ .id = "command.palette", .key = "p", .modifiers = .{ .primary = true, .shift = true } },
@@ -681,10 +773,11 @@ test "gpu surface image upload bounds are honest per id namespace" {
681
773
  defer std.testing.allocator.free(buffer);
682
774
  @memset(buffer, 128);
683
775
 
684
- // Ordinary registered-image ids keep the registry's avatar-scale
685
- // bound: exactly 1 MiB (512x512 RGBA8) passes, one pixel past it is
686
- // an engine bug and refuses loudly.
687
- try services.uploadGpuSurfaceImage(.{ .id = 7, .width = 512, .height = 512, .rgba8 = buffer[0..types.max_gpu_surface_image_pixel_bytes] });
776
+ // Ordinary registered-image ids accept the registry's configurable
777
+ // ceiling: exactly 8 MiB (2048x1024 RGBA8) passes, one pixel past it
778
+ // is an engine bug and refuses loudly. Apps on the default 1 MiB tier
779
+ // still refuse earlier, at registration.
780
+ try services.uploadGpuSurfaceImage(.{ .id = 7, .width = 2048, .height = 1024, .rgba8 = buffer[0..types.max_gpu_surface_image_pixel_bytes] });
688
781
  try std.testing.expectError(error.InvalidGpuSurfaceImage, services.uploadGpuSurfaceImage(.{
689
782
  .id = 7,
690
783
  .width = types.max_gpu_surface_image_pixel_bytes / 4 + 1,