@native-sdk/cli 0.9.4 → 0.10.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 (97) hide show
  1. package/README.md +3 -3
  2. package/build/app.zig +75 -57
  3. package/build/ts_run.mjs +1 -1
  4. package/build.zig +20 -2
  5. package/package.json +11 -10
  6. package/packages/core/package-lock.json +12 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/compiler_command.mjs +1 -1
  9. package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
  10. package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
  11. package/packages/core/scripts/vendor_service_packages.mjs +121 -8
  12. package/packages/core/sdk/events.d.ts +33 -4
  13. package/packages/core/sdk/events.ts +45 -6
  14. package/packages/core/src/checker.ts +103 -8
  15. package/packages/core/src/modules.ts +6 -2
  16. package/packages/core/src/sqlite_cli.ts +22 -2
  17. package/packages/core/src/typed_ast.ts +4 -2
  18. package/packages/core/src/types.ts +8 -8
  19. package/schemas/app.schema.json +446 -0
  20. package/skill-data/core/SKILL.md +53 -15
  21. package/skill-data/core/references/project-anatomy.md +6 -6
  22. package/skill-data/native-ui/SKILL.md +26 -5
  23. package/skill-data/ts-core/SKILL.md +6 -6
  24. package/skill-data/ts-services/references/service-surface.md +1 -1
  25. package/skills/native-sdk/SKILL.md +2 -2
  26. package/src/app_runner/root.zig +25 -0
  27. package/src/automation/snapshot.zig +91 -3
  28. package/src/platform/macos/appkit_host.h +66 -2
  29. package/src/platform/macos/appkit_host.m +735 -24
  30. package/src/platform/macos/cef_host.mm +208 -9
  31. package/src/platform/macos/root.zig +205 -3
  32. package/src/platform/null_platform.zig +50 -1
  33. package/src/platform/null_platform_tests.zig +53 -0
  34. package/src/platform/root.zig +12 -0
  35. package/src/platform/types.zig +73 -0
  36. package/src/platform/windows/root.zig +88 -15
  37. package/src/primitives/app_manifest/tests.zig +19 -0
  38. package/src/primitives/app_manifest/validation.zig +14 -2
  39. package/src/primitives/canvas/font_ttf.zig +24 -0
  40. package/src/primitives/canvas/gpu.zig +5 -0
  41. package/src/primitives/canvas/reference.zig +41 -16
  42. package/src/primitives/canvas/reference_tests.zig +63 -0
  43. package/src/primitives/canvas/render_tests.zig +1 -1
  44. package/src/primitives/canvas/root.zig +1 -0
  45. package/src/primitives/canvas/serialization.zig +1 -0
  46. package/src/primitives/canvas/test_support.zig +1 -0
  47. package/src/primitives/canvas/text.zig +1 -0
  48. package/src/primitives/canvas/text_layout.zig +84 -15
  49. package/src/primitives/canvas/text_layout_hash.zig +3 -1
  50. package/src/primitives/canvas/text_layout_types.zig +3 -0
  51. package/src/primitives/canvas/text_metrics.zig +28 -1
  52. package/src/primitives/canvas/text_tests.zig +61 -6
  53. package/src/primitives/canvas/ui.zig +9 -0
  54. package/src/primitives/canvas/ui_markup.zig +29 -0
  55. package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
  56. package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
  57. package/src/primitives/canvas/ui_markup_contract.zig +7 -0
  58. package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
  59. package/src/primitives/canvas/ui_markup_tests.zig +6 -0
  60. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  61. package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
  62. package/src/primitives/canvas/ui_schema.zig +9 -0
  63. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  64. package/src/primitives/canvas/ui_tests.zig +4 -2
  65. package/src/primitives/canvas/widget_render.zig +13 -2
  66. package/src/primitives/canvas/widget_render_controls.zig +1 -0
  67. package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
  68. package/src/root.zig +6 -0
  69. package/src/runtime/automation_snapshot.zig +3 -0
  70. package/src/runtime/canvas_fonts.zig +87 -0
  71. package/src/runtime/core.zig +1 -0
  72. package/src/runtime/flow.zig +8 -1
  73. package/src/runtime/native_command_event_tests.zig +58 -0
  74. package/src/runtime/state.zig +14 -0
  75. package/src/runtime/system_services.zig +62 -0
  76. package/src/runtime/ts_ui_app.zig +161 -33
  77. package/src/runtime/ui_app.zig +33 -1
  78. package/src/runtime/ui_app_tests.zig +63 -0
  79. package/src/runtime/validation.zig +87 -1
  80. package/src/tooling/android.zig +5 -4
  81. package/src/tooling/buildgraph.zig +24 -8
  82. package/src/tooling/db.zig +1 -1
  83. package/src/tooling/doctor.zig +1 -1
  84. package/src/tooling/ios.zig +5 -4
  85. package/src/tooling/json_to_zon.zig +136 -0
  86. package/src/tooling/manifest.zig +199 -35
  87. package/src/tooling/package.zig +33 -0
  88. package/src/tooling/raw_manifest.zig +11 -0
  89. package/src/tooling/root.zig +2 -0
  90. package/src/tooling/templates.zig +210 -116
  91. package/src/tooling/ts_core.zig +11 -7
  92. package/src/tooling/update.zig +576 -0
  93. package/src/tooling/verbs.zig +7 -6
  94. package/src/tooling/web_engine.zig +17 -1
  95. package/src/updater/c_api.zig +123 -0
  96. package/src/updater/feed.zig +215 -0
  97. package/src/updater/root.zig +10 -0
@@ -45,6 +45,10 @@ const max_tray_title_bytes = types.max_tray_title_bytes;
45
45
  const max_tray_tooltip_bytes = types.max_tray_tooltip_bytes;
46
46
  const max_tray_item_label_bytes = types.max_tray_item_label_bytes;
47
47
  const max_tray_item_command_bytes = types.max_tray_item_command_bytes;
48
+ const max_tray_segment_options = types.max_tray_segment_options;
49
+ const max_tray_segment_label_bytes = types.max_tray_segment_label_bytes;
50
+ const max_tray_chart_values = types.max_tray_chart_values;
51
+ const max_tray_chart_text_bytes = types.max_tray_chart_text_bytes;
48
52
  const max_drop_paths_bytes = types.max_drop_paths_bytes;
49
53
  const max_drop_paths = types.max_drop_paths;
50
54
  const max_window_event_name_bytes = types.max_window_event_name_bytes;
@@ -319,6 +323,16 @@ const NullStatusItem = struct {
319
323
  open_command_len: usize = 0,
320
324
  presentation: TrayPresentation = .{},
321
325
  items: [max_tray_items]TrayMenuItem = undefined,
326
+ segment_options: [max_tray_items * max_tray_segment_options]types.TraySegmentOption = undefined,
327
+ segment_option_label_storage: [max_tray_items * max_tray_segment_options][max_tray_segment_label_bytes]u8 = undefined,
328
+ segment_option_command_storage: [max_tray_items * max_tray_segment_options][max_tray_item_command_bytes]u8 = undefined,
329
+ metric_primary_storage: [max_tray_items][max_tray_item_label_bytes]u8 = undefined,
330
+ metric_secondary_storage: [max_tray_items][types.max_tray_item_detail_bytes]u8 = undefined,
331
+ metric_accessibility_storage: [max_tray_items][max_tray_chart_text_bytes]u8 = undefined,
332
+ chart_values: [max_tray_items * max_tray_chart_values]f32 = undefined,
333
+ chart_leading_caption_storage: [max_tray_items][max_tray_chart_text_bytes]u8 = undefined,
334
+ chart_trailing_summary_storage: [max_tray_items][max_tray_chart_text_bytes]u8 = undefined,
335
+ chart_accessibility_storage: [max_tray_items][max_tray_chart_text_bytes]u8 = undefined,
322
336
  item_count: usize = 0,
323
337
  };
324
338
 
@@ -1789,7 +1803,42 @@ pub const NullPlatform = struct {
1789
1803
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1790
1804
  const status_item = self.findStatusItem(status_item_id) orelse return error.InvalidTrayOptions;
1791
1805
  if (items.len > status_item.items.len) return error.InvalidTrayOptions;
1792
- for (items, 0..) |item, index| status_item.items[index] = item;
1806
+ for (items, 0..) |item, index| {
1807
+ status_item.items[index] = item;
1808
+ if (item.segmented) |segmented| {
1809
+ const start = index * max_tray_segment_options;
1810
+ for (segmented.options, 0..) |option, option_index| {
1811
+ const flat_index = start + option_index;
1812
+ status_item.segment_options[flat_index] = .{
1813
+ .id = option.id,
1814
+ .label = try copyInto(&status_item.segment_option_label_storage[flat_index], option.label),
1815
+ .command = try copyInto(&status_item.segment_option_command_storage[flat_index], option.command),
1816
+ .selected = option.selected,
1817
+ .enabled = option.enabled,
1818
+ };
1819
+ }
1820
+ status_item.items[index].segmented = .{ .options = status_item.segment_options[start .. start + segmented.options.len] };
1821
+ }
1822
+ if (item.metric) |metric| {
1823
+ status_item.items[index].metric = .{
1824
+ .primary_text = try copyInto(&status_item.metric_primary_storage[index], metric.primary_text),
1825
+ .secondary_text = try copyInto(&status_item.metric_secondary_storage[index], metric.secondary_text),
1826
+ .accessibility_label = try copyInto(&status_item.metric_accessibility_storage[index], metric.accessibility_label),
1827
+ };
1828
+ }
1829
+ if (item.chart) |chart| {
1830
+ const start = index * max_tray_chart_values;
1831
+ @memcpy(status_item.chart_values[start .. start + chart.values.len], chart.values);
1832
+ status_item.items[index].chart = .{
1833
+ .values = status_item.chart_values[start .. start + chart.values.len],
1834
+ .min_value = chart.min_value,
1835
+ .max_value = chart.max_value,
1836
+ .leading_caption = try copyInto(&status_item.chart_leading_caption_storage[index], chart.leading_caption),
1837
+ .trailing_summary = try copyInto(&status_item.chart_trailing_summary_storage[index], chart.trailing_summary),
1838
+ .accessibility_label = try copyInto(&status_item.chart_accessibility_storage[index], chart.accessibility_label),
1839
+ };
1840
+ }
1841
+ }
1793
1842
  status_item.item_count = items.len;
1794
1843
  self.tray_update_count += 1;
1795
1844
  }
@@ -330,6 +330,59 @@ test "null platform preserves the tray title when presentation styles are set" {
330
330
  try std.testing.expectEqual(types.TrayTone.warning, retitled.tone);
331
331
  }
332
332
 
333
+ test "null platform owns retained rich tray row bytes" {
334
+ var null_platform = NullPlatform.init(.{});
335
+ defer null_platform.deinit();
336
+
337
+ var segment_label = [_]u8{ 'D', 'a', 'y' };
338
+ var segment_command = [_]u8{ 'r', 'a', 'n', 'g', 'e' };
339
+ var metric_primary = [_]u8{ '2', '4', '9', '4' };
340
+ var metric_secondary = [_]u8{ 'T', 'o', 'd', 'a', 'y' };
341
+ var metric_accessibility = [_]u8{ 'M', 'e', 't', 'r', 'i', 'c' };
342
+ var chart_caption = [_]u8{ 'C', 'P', 'U' };
343
+ var chart_summary = [_]u8{ '5', '0', '%' };
344
+ var chart_accessibility = [_]u8{ 'C', 'P', 'U', ' ', '5', '0' };
345
+ const chart_values = [_]f32{0.5};
346
+
347
+ try null_platform.platform().services.createTray(.{ .items = &.{
348
+ .{ .role = .segmented, .segmented = .{ .options = &.{.{
349
+ .id = 20,
350
+ .label = &segment_label,
351
+ .command = &segment_command,
352
+ }} } },
353
+ .{ .role = .hero, .metric = .{
354
+ .primary_text = &metric_primary,
355
+ .secondary_text = &metric_secondary,
356
+ .accessibility_label = &metric_accessibility,
357
+ } },
358
+ .{ .role = .chart, .chart = .{
359
+ .values = &chart_values,
360
+ .leading_caption = &chart_caption,
361
+ .trailing_summary = &chart_summary,
362
+ .accessibility_label = &chart_accessibility,
363
+ } },
364
+ } });
365
+
366
+ @memset(&segment_label, 'X');
367
+ @memset(&segment_command, 'Y');
368
+ @memset(&metric_primary, 'P');
369
+ @memset(&metric_secondary, 'S');
370
+ @memset(&metric_accessibility, 'A');
371
+ @memset(&chart_caption, 'Z');
372
+ @memset(&chart_summary, 'W');
373
+ @memset(&chart_accessibility, 'Q');
374
+
375
+ const items = null_platform.trayItems();
376
+ try std.testing.expectEqualStrings("Day", items[0].segmented.?.options[0].label);
377
+ try std.testing.expectEqualStrings("range", items[0].segmented.?.options[0].command);
378
+ try std.testing.expectEqualStrings("2494", items[1].metric.?.primary_text);
379
+ try std.testing.expectEqualStrings("Today", items[1].metric.?.secondary_text);
380
+ try std.testing.expectEqualStrings("Metric", items[1].metric.?.accessibility_label);
381
+ try std.testing.expectEqualStrings("CPU", items[2].chart.?.leading_caption);
382
+ try std.testing.expectEqualStrings("50%", items[2].chart.?.trailing_summary);
383
+ try std.testing.expectEqualStrings("CPU 50", items[2].chart.?.accessibility_label);
384
+ }
385
+
333
386
  test "null platform records OS actions" {
334
387
  var null_platform = NullPlatform.init(.{});
335
388
  defer null_platform.deinit();
@@ -35,6 +35,9 @@ pub const max_credential_service_bytes = types.max_credential_service_bytes;
35
35
  pub const max_credential_account_bytes = types.max_credential_account_bytes;
36
36
  pub const max_credential_secret_bytes = types.max_credential_secret_bytes;
37
37
  pub const max_local_time_text_bytes = types.max_local_time_text_bytes;
38
+ pub const max_update_feed_url_bytes = types.max_update_feed_url_bytes;
39
+ pub const max_update_public_key_bytes = types.max_update_public_key_bytes;
40
+ pub const update_check_command = types.update_check_command;
38
41
  pub const max_status_items = types.max_status_items;
39
42
  pub const max_tray_items = types.max_tray_items;
40
43
  pub const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
@@ -43,6 +46,10 @@ pub const max_tray_tooltip_bytes = types.max_tray_tooltip_bytes;
43
46
  pub const max_tray_item_label_bytes = types.max_tray_item_label_bytes;
44
47
  pub const max_tray_item_command_bytes = types.max_tray_item_command_bytes;
45
48
  pub const max_tray_item_detail_bytes = types.max_tray_item_detail_bytes;
49
+ pub const max_tray_segment_options = types.max_tray_segment_options;
50
+ pub const max_tray_segment_label_bytes = types.max_tray_segment_label_bytes;
51
+ pub const max_tray_chart_values = types.max_tray_chart_values;
52
+ pub const max_tray_chart_text_bytes = types.max_tray_chart_text_bytes;
46
53
  pub const max_drop_paths_bytes = types.max_drop_paths_bytes;
47
54
  pub const max_drop_paths = types.max_drop_paths;
48
55
  pub const max_window_event_name_bytes = types.max_window_event_name_bytes;
@@ -142,8 +149,13 @@ pub const TrayShell = types.TrayShell;
142
149
  pub const trayShell = types.trayShell;
143
150
  pub const TrayTone = types.TrayTone;
144
151
  pub const TrayPresentation = types.TrayPresentation;
152
+ pub const TrayFontWeight = types.TrayFontWeight;
145
153
  pub const TrayMenuItem = types.TrayMenuItem;
146
154
  pub const TrayItemRole = types.TrayItemRole;
155
+ pub const TraySegmentOption = types.TraySegmentOption;
156
+ pub const TraySegmentedRow = types.TraySegmentedRow;
157
+ pub const TrayMetricRow = types.TrayMetricRow;
158
+ pub const TrayChartRow = types.TrayChartRow;
147
159
  pub const NativeCommandEvent = types.NativeCommandEvent;
148
160
  pub const MenuCommandEvent = types.MenuCommandEvent;
149
161
  pub const TrayCommandEvent = types.TrayCommandEvent;
@@ -255,6 +255,9 @@ pub const max_credential_account_bytes: usize = 256;
255
255
  /// Every host accepts this whole range; none silently truncates it.
256
256
  pub const max_credential_secret_bytes: usize = 5 * 512;
257
257
  pub const max_local_time_text_bytes: usize = 512;
258
+ pub const max_update_feed_url_bytes: usize = 4096;
259
+ pub const max_update_public_key_bytes: usize = 128;
260
+ pub const update_check_command = "app.check-for-updates";
258
261
  /// A desktop app may own a small bounded set of independent status items.
259
262
  /// macOS implements the whole set; hosts whose tray API is singular accept
260
263
  /// only `primary_status_item_id` and reject additional identifiers.
@@ -266,6 +269,10 @@ pub const max_tray_tooltip_bytes: usize = 256;
266
269
  pub const max_tray_item_label_bytes: usize = 256;
267
270
  pub const max_tray_item_command_bytes: usize = 128;
268
271
  pub const max_tray_item_detail_bytes: usize = 256;
272
+ pub const max_tray_segment_options: usize = 8;
273
+ pub const max_tray_segment_label_bytes: usize = 64;
274
+ pub const max_tray_chart_values: usize = 32;
275
+ pub const max_tray_chart_text_bytes: usize = 128;
269
276
  pub const max_drop_paths_bytes: usize = 8192;
270
277
  pub const max_drop_paths: usize = max_drop_paths_bytes / 2 + 1;
271
278
  pub const max_window_event_name_bytes: usize = 64;
@@ -1301,6 +1308,9 @@ pub const AppInfo = struct {
1301
1308
  window_title: []const u8 = "",
1302
1309
  bundle_id: []const u8 = "dev.native_sdk.app",
1303
1310
  icon_path: []const u8 = "",
1311
+ update_feed_url: []const u8 = "",
1312
+ update_public_key: []const u8 = "",
1313
+ update_check_on_start: bool = false,
1304
1314
  main_window: WindowOptions = .{},
1305
1315
  windows: []const WindowOptions = &.{},
1306
1316
 
@@ -1466,6 +1476,13 @@ pub const TrayTone = enum(u8) {
1466
1476
  critical,
1467
1477
  };
1468
1478
 
1479
+ pub const TrayFontWeight = enum(u8) {
1480
+ regular,
1481
+ medium,
1482
+ semibold,
1483
+ bold,
1484
+ };
1485
+
1469
1486
  /// The model-derived part of a status item. Keeping this separate from
1470
1487
  /// icon/tooltip/activation options lets UiApp patch presentation without
1471
1488
  /// recreating the native item.
@@ -1477,6 +1494,9 @@ pub const TrayPresentation = struct {
1477
1494
  tone: TrayTone = .normal,
1478
1495
  icon_opacity: f32 = 1,
1479
1496
  monospaced: bool = false,
1497
+ /// Explicit title size in points; zero keeps the host's menu-bar default.
1498
+ font_size: f32 = 0,
1499
+ font_weight: TrayFontWeight = .regular,
1480
1500
  };
1481
1501
 
1482
1502
  pub const TrayOptions = struct {
@@ -1531,6 +1551,45 @@ pub const TrayItemRole = enum(u8) {
1531
1551
  hero,
1532
1552
  agent,
1533
1553
  context,
1554
+ segmented,
1555
+ chart,
1556
+ };
1557
+
1558
+ /// One choice inside a typed segmented tray row. Its stable id and command
1559
+ /// participate in the same namespace and dispatch route as an ordinary tray
1560
+ /// command row; the containing row itself is display structure, not an
1561
+ /// action. At most one option in a row may be selected.
1562
+ pub const TraySegmentOption = struct {
1563
+ id: TrayItemId,
1564
+ label: []const u8,
1565
+ command: []const u8,
1566
+ selected: bool = false,
1567
+ enabled: bool = true,
1568
+ };
1569
+
1570
+ pub const TraySegmentedRow = struct {
1571
+ options: []const TraySegmentOption = &.{},
1572
+ };
1573
+
1574
+ /// A prominent two-line metric block inside a tray menu. This is semantic
1575
+ /// dropdown content, distinct from the persistent menu-bar title.
1576
+ pub const TrayMetricRow = struct {
1577
+ primary_text: []const u8,
1578
+ secondary_text: []const u8 = "",
1579
+ accessibility_label: []const u8,
1580
+ };
1581
+
1582
+ /// A bounded bar-chart/sparkline readout. Values are finite and must fall in
1583
+ /// the explicit `min_value...max_value` domain. The text fields remain
1584
+ /// semantic data on every host; capable macOS hosts place them around a
1585
+ /// native AppKit-drawn bar chart.
1586
+ pub const TrayChartRow = struct {
1587
+ values: []const f32 = &.{},
1588
+ min_value: f32 = 0,
1589
+ max_value: f32 = 1,
1590
+ leading_caption: []const u8 = "",
1591
+ trailing_summary: []const u8 = "",
1592
+ accessibility_label: []const u8 = "",
1534
1593
  };
1535
1594
 
1536
1595
  pub const TrayMenuItem = struct {
@@ -1543,6 +1602,11 @@ pub const TrayMenuItem = struct {
1543
1602
  role: TrayItemRole = .command,
1544
1603
  key: []const u8 = "",
1545
1604
  modifiers: ShortcutModifiers = .{},
1605
+ /// Typed rich-row payloads. Exactly one is present for its matching role;
1606
+ /// both stay null for every existing command/readout row.
1607
+ segmented: ?TraySegmentedRow = null,
1608
+ metric: ?TrayMetricRow = null,
1609
+ chart: ?TrayChartRow = null,
1546
1610
  };
1547
1611
 
1548
1612
  pub const NativeCommandEvent = struct {
@@ -2717,6 +2781,7 @@ pub const PlatformServices = struct {
2717
2781
  reveal_path_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2718
2782
  add_recent_document_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2719
2783
  clear_recent_documents_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2784
+ check_for_updates_fn: ?*const fn (context: ?*anyopaque, user_initiated: bool) anyerror!void = null,
2720
2785
  create_tray_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, options: TrayOptions) anyerror!void = null,
2721
2786
  update_tray_shell_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, shell: TrayShell) anyerror!void = null,
2722
2787
  update_tray_menu_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, items: []const TrayMenuItem) anyerror!void = null,
@@ -2986,6 +3051,9 @@ pub const PlatformServices = struct {
2986
3051
  /// engine-side registered-face provider — both batch engine-side
2987
3052
  /// without any platform seam.
2988
3053
  measure_text_advances_fn: ?*const fn (context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, advances: []f32) bool = null,
3054
+ /// Shaped glyph-path bounds for one single-line run, relative to its
3055
+ /// baseline. Null on platforms without host-side text metrics.
3056
+ measure_text_ink_fn: ?*const fn (context: ?*anyopaque, font_id: u64, size: f32, text: []const u8, metrics: *canvas.TextInkMetrics) bool = null,
2989
3057
  /// Decode encoded image bytes (PNG, JPEG, ... — whatever the platform
2990
3058
  /// codec supports) into tightly packed, row-major, straight-alpha
2991
3059
  /// (non-premultiplied) RGBA8 written into `buffer`, returning the
@@ -3290,6 +3358,11 @@ pub const PlatformServices = struct {
3290
3358
  return clear_fn(self.context);
3291
3359
  }
3292
3360
 
3361
+ pub fn checkForUpdates(self: PlatformServices, user_initiated: bool) anyerror!void {
3362
+ const check_fn = self.check_for_updates_fn orelse return error.UnsupportedService;
3363
+ return check_fn(self.context, user_initiated);
3364
+ }
3365
+
3293
3366
  pub fn createStatusItem(self: PlatformServices, status_item_id: StatusItemId, options: TrayOptions) anyerror!void {
3294
3367
  const tray_fn = self.create_tray_fn orelse return error.UnsupportedService;
3295
3368
  return tray_fn(self.context, status_item_id, options);
@@ -1519,6 +1519,34 @@ fn showNotification(context: ?*anyopaque, options: platform_mod.NotificationOpti
1519
1519
 
1520
1520
  const max_tray_items: usize = 32;
1521
1521
 
1522
+ const TrayFallbackText = struct {
1523
+ label: []const u8,
1524
+ detail: []const u8,
1525
+ };
1526
+
1527
+ /// Project a rich row onto Win32's plain label/detail menu surface. Chart
1528
+ /// captions are optional, but the accessibility label is required, so a
1529
+ /// captionless chart must still remain visible instead of becoming a blank
1530
+ /// disabled row.
1531
+ fn trayFallbackText(item: platform_mod.TrayMenuItem) TrayFallbackText {
1532
+ if (item.metric) |metric| return .{
1533
+ .label = metric.primary_text,
1534
+ .detail = metric.secondary_text,
1535
+ };
1536
+ if (item.chart) |chart| {
1537
+ if (chart.leading_caption.len > 0) return .{
1538
+ .label = chart.leading_caption,
1539
+ .detail = chart.trailing_summary,
1540
+ };
1541
+ if (chart.trailing_summary.len > 0) return .{
1542
+ .label = chart.trailing_summary,
1543
+ .detail = "",
1544
+ };
1545
+ return .{ .label = chart.accessibility_label, .detail = "" };
1546
+ }
1547
+ return .{ .label = item.label, .detail = item.detail };
1548
+ }
1549
+
1522
1550
  fn createTray(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId, options: platform_mod.TrayOptions) anyerror!void {
1523
1551
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1524
1552
  if (status_item_id != platform_mod.primary_status_item_id) return error.UnsupportedService;
@@ -1545,7 +1573,7 @@ fn updateTrayMenu(context: ?*anyopaque, status_item_id: platform_mod.StatusItemI
1545
1573
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1546
1574
  if (status_item_id != platform_mod.primary_status_item_id) return error.UnsupportedService;
1547
1575
  if (self.web_engine != .system) return error.UnsupportedService;
1548
- const count = @min(items.len, max_tray_items);
1576
+ var count: usize = 0;
1549
1577
  var ids: [max_tray_items]u32 = undefined;
1550
1578
  var labels: [max_tray_items][*]const u8 = undefined;
1551
1579
  var label_lens: [max_tray_items]usize = undefined;
@@ -1563,23 +1591,44 @@ fn updateTrayMenu(context: ?*anyopaque, status_item_id: platform_mod.StatusItemI
1563
1591
  // returning). Doubling covers the all-ampersands worst case.
1564
1592
  var label_pool: [max_tray_items * (platform_mod.max_tray_item_label_bytes + platform_mod.max_tray_item_detail_bytes) * 2]u8 = undefined;
1565
1593
  var pool_used: usize = 0;
1566
- for (items[0..count], 0..) |item, index| {
1567
- const label = escapeMenuLabelAmpersands(item.label, &label_pool, &pool_used);
1568
- const detail = escapeMenuLabelAmpersands(item.detail, &label_pool, &pool_used);
1569
- ids[index] = item.id;
1570
- labels[index] = label.ptr;
1571
- label_lens[index] = label.len;
1572
- separators[index] = if (item.separator) 1 else 0;
1594
+ for (items) |item| {
1595
+ if (item.segmented) |segmented| {
1596
+ for (segmented.options) |option| {
1597
+ const label = escapeMenuLabelAmpersands(option.label, &label_pool, &pool_used);
1598
+ ids[count] = option.id;
1599
+ labels[count] = label.ptr;
1600
+ label_lens[count] = label.len;
1601
+ separators[count] = 0;
1602
+ enabled_flags[count] = if (option.enabled) 1 else 0;
1603
+ const selected_detail = if (option.selected) "Selected" else "";
1604
+ details[count] = selected_detail.ptr;
1605
+ detail_lens[count] = selected_detail.len;
1606
+ roles[count] = @intFromEnum(platform_mod.TrayItemRole.command);
1607
+ keys[count] = "".ptr;
1608
+ key_lens[count] = 0;
1609
+ modifiers[count] = 0;
1610
+ count += 1;
1611
+ }
1612
+ continue;
1613
+ }
1614
+ const fallback = trayFallbackText(item);
1615
+ const label = escapeMenuLabelAmpersands(fallback.label, &label_pool, &pool_used);
1616
+ const detail = escapeMenuLabelAmpersands(fallback.detail, &label_pool, &pool_used);
1617
+ ids[count] = item.id;
1618
+ labels[count] = label.ptr;
1619
+ label_lens[count] = label.len;
1620
+ separators[count] = if (item.separator) 1 else 0;
1573
1621
  // Windows has no custom status-menu row seam. Preserve semantic
1574
1622
  // readouts as visible detail text, while only command/agent rows can
1575
1623
  // become actions.
1576
- enabled_flags[index] = if (item.enabled and (item.role == .command or item.role == .agent)) 1 else 0;
1577
- details[index] = detail.ptr;
1578
- detail_lens[index] = detail.len;
1579
- roles[index] = @intFromEnum(item.role);
1580
- keys[index] = item.key.ptr;
1581
- key_lens[index] = item.key.len;
1582
- modifiers[index] = shortcutModifierFlags(item.modifiers);
1624
+ enabled_flags[count] = if (item.enabled and (item.role == .command or item.role == .agent)) 1 else 0;
1625
+ details[count] = detail.ptr;
1626
+ detail_lens[count] = detail.len;
1627
+ roles[count] = @intFromEnum(item.role);
1628
+ keys[count] = item.key.ptr;
1629
+ key_lens[count] = item.key.len;
1630
+ modifiers[count] = shortcutModifierFlags(item.modifiers);
1631
+ count += 1;
1583
1632
  }
1584
1633
  if (native_sdk_windows_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, &details, &detail_lens, &roles, &keys, &key_lens, &modifiers, count) == 0) return error.UnsupportedService;
1585
1634
  }
@@ -2183,6 +2232,30 @@ test "windows tray carries lifecycle commands rich rows and key equivalents into
2183
2232
  try std.testing.expect(std.mem.indexOf(u8, host_source, "tray_event == NIN_SELECT || tray_event == NIN_KEYSELECT || tray_event == WM_LBUTTONUP") != null);
2184
2233
  }
2185
2234
 
2235
+ test "windows chart fallback uses accessibility text when captions are absent" {
2236
+ const values = [_]f32{0.5};
2237
+ const fallback = trayFallbackText(.{
2238
+ .role = .chart,
2239
+ .chart = .{
2240
+ .values = &values,
2241
+ .accessibility_label = "CPU history, 50 percent",
2242
+ },
2243
+ });
2244
+ try std.testing.expectEqualStrings("CPU history, 50 percent", fallback.label);
2245
+ try std.testing.expectEqualStrings("", fallback.detail);
2246
+
2247
+ const summarized = trayFallbackText(.{
2248
+ .role = .chart,
2249
+ .chart = .{
2250
+ .values = &values,
2251
+ .trailing_summary = "50%",
2252
+ .accessibility_label = "CPU history, 50 percent",
2253
+ },
2254
+ });
2255
+ try std.testing.expectEqualStrings("50%", summarized.label);
2256
+ try std.testing.expectEqualStrings("", summarized.detail);
2257
+ }
2258
+
2186
2259
  test "windows refuses a tray-less .hide main window at platform init instead of stranding it hidden" {
2187
2260
  // The pre-created MAIN window never passes through the runtime's
2188
2261
  // create gate, so the platform's init gate must hold the same line
@@ -106,6 +106,25 @@ test "valid minimal manifest" {
106
106
  try validateManifest(manifest);
107
107
  }
108
108
 
109
+ test "updates require paired HTTPS feed and Ed25519 public key" {
110
+ try validateUpdates(.{
111
+ .feed_url = "https://example.com/native-update.json",
112
+ .public_key = "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
113
+ .check_on_start = true,
114
+ });
115
+ try std.testing.expectError(error.MissingRequiredField, validateUpdates(.{
116
+ .feed_url = "https://example.com/native-update.json",
117
+ }));
118
+ try std.testing.expectError(error.InvalidUrl, validateUpdates(.{
119
+ .feed_url = "http://example.com/native-update.json",
120
+ .public_key = "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
121
+ }));
122
+ try std.testing.expectError(error.MissingRequiredField, validateUpdates(.{
123
+ .feed_url = "https://example.com/native-update.json",
124
+ .public_key = "not-a-public-key",
125
+ }));
126
+ }
127
+
109
128
  test "accessory startup requires the tray capability" {
110
129
  const tray_capabilities = [_]Capability{.tray};
111
130
  try validateManifest(.{
@@ -654,8 +654,20 @@ pub fn validateSecurity(security: SecurityConfig) ValidationError!void {
654
654
  }
655
655
 
656
656
  pub fn validateUpdates(updates: UpdateConfig) ValidationError!void {
657
- if (updates.feed_url) |url| try validateExternalUrlPattern(url);
658
- if (updates.public_key) |key| if (key.len == 0) return error.MissingRequiredField;
657
+ if ((updates.feed_url == null) != (updates.public_key == null)) return error.MissingRequiredField;
658
+ if (updates.check_on_start and updates.feed_url == null) return error.MissingRequiredField;
659
+ if (updates.feed_url) |url| {
660
+ if (url.len > 4096) return error.InvalidUrl;
661
+ if (!std.mem.startsWith(u8, url, "https://")) return error.InvalidUrl;
662
+ try validateUrl(url);
663
+ }
664
+ if (updates.public_key) |key| {
665
+ var decoded: [std.crypto.sign.Ed25519.PublicKey.encoded_length]u8 = undefined;
666
+ const decoded_len = std.base64.standard.Decoder.calcSizeForSlice(key) catch return error.MissingRequiredField;
667
+ if (decoded_len != decoded.len) return error.MissingRequiredField;
668
+ std.base64.standard.Decoder.decode(&decoded, key) catch return error.MissingRequiredField;
669
+ _ = std.crypto.sign.Ed25519.PublicKey.fromBytes(decoded) catch return error.MissingRequiredField;
670
+ }
659
671
  }
660
672
 
661
673
  fn validateExternalUrlPattern(url: []const u8) ValidationError!void {
@@ -260,6 +260,30 @@ pub const Face = struct {
260
260
  return @floatFromInt(value);
261
261
  }
262
262
 
263
+ /// The glyph's TrueType bounding box in font units, or null for an
264
+ /// intentionally empty glyph such as space. The bbox is stored in the
265
+ /// `glyf` header for both simple and composite glyphs, so this answers
266
+ /// without replaying the outline into a path builder.
267
+ pub fn glyphBounds(self: *const Face, glyph: u16) Error!?geometry.RectF {
268
+ if (glyph >= self.num_glyphs) return error.FontParseFailed;
269
+ const range = try self.glyphRange(glyph);
270
+ if (range.len == 0) return null;
271
+ if (range.len < 10) return error.FontParseFailed;
272
+ const offset = self.glyf_offset + range.offset;
273
+ const min_x = try readI16(self.bytes, offset + 2);
274
+ const min_y = try readI16(self.bytes, offset + 4);
275
+ const max_x = try readI16(self.bytes, offset + 6);
276
+ const max_y = try readI16(self.bytes, offset + 8);
277
+ if (max_x < min_x or max_y < min_y) return error.FontParseFailed;
278
+ if (max_x == min_x or max_y == min_y) return null;
279
+ return geometry.RectF.init(
280
+ @floatFromInt(min_x),
281
+ @floatFromInt(min_y),
282
+ @as(f32, @floatFromInt(max_x - min_x)),
283
+ @as(f32, @floatFromInt(max_y - min_y)),
284
+ );
285
+ }
286
+
263
287
  /// Emit the glyph outline through `transform` into `sink`
264
288
  /// (`moveTo`/`lineTo`/`quadTo`/`close`). Coordinates handed to the
265
289
  /// transform are raw font units (y-up); bake the y-flip and em
@@ -2,6 +2,7 @@ const geometry = @import("geometry");
2
2
  const canvas = @import("root.zig");
3
3
  const drawing_model = @import("drawing.zig");
4
4
  const text_model = @import("text.zig");
5
+ const text_metrics = @import("text_metrics.zig");
5
6
  const render_model = @import("render.zig");
6
7
 
7
8
  const Error = canvas.Error;
@@ -170,6 +171,9 @@ pub const CanvasGpuText = struct {
170
171
  color: Color = .{},
171
172
  text: []const u8 = "",
172
173
  glyphs: []const Glyph = &.{},
174
+ /// Process-local measurement context used while deriving packet lines.
175
+ /// It never crosses the wire.
176
+ measure: ?*const text_metrics.TextMeasureProvider = null,
173
177
  text_layout: ?TextLayoutOptions = null,
174
178
  };
175
179
 
@@ -568,6 +572,7 @@ pub fn canvasGpuCommandFromRenderCommand(command: RenderCommand, command_index:
568
572
  .color = value.color,
569
573
  .text = value.text,
570
574
  .glyphs = value.glyphs,
575
+ .measure = value.measure,
571
576
  .text_layout = value.text_layout,
572
577
  };
573
578
  packet_command.uses_resource = true;