@native-sdk/cli 0.9.5 → 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 (47) hide show
  1. package/build/app.zig +7 -0
  2. package/build/ts_run.mjs +1 -1
  3. package/build.zig +8 -1
  4. package/package.json +10 -10
  5. package/packages/core/package-lock.json +12 -11
  6. package/packages/core/package.json +2 -2
  7. package/packages/core/scripts/compiler_command.mjs +1 -1
  8. package/schemas/app.schema.json +12 -1
  9. package/skill-data/ts-services/references/service-surface.md +1 -1
  10. package/src/app_runner/root.zig +25 -0
  11. package/src/platform/macos/appkit_host.h +25 -0
  12. package/src/platform/macos/appkit_host.m +537 -15
  13. package/src/platform/macos/cef_host.mm +17 -0
  14. package/src/platform/macos/root.zig +95 -0
  15. package/src/platform/root.zig +3 -0
  16. package/src/platform/types.zig +15 -0
  17. package/src/primitives/app_manifest/tests.zig +19 -0
  18. package/src/primitives/app_manifest/validation.zig +14 -2
  19. package/src/primitives/canvas/font_ttf.zig +24 -0
  20. package/src/primitives/canvas/gpu.zig +5 -0
  21. package/src/primitives/canvas/reference.zig +4 -1
  22. package/src/primitives/canvas/render_tests.zig +1 -1
  23. package/src/primitives/canvas/root.zig +1 -0
  24. package/src/primitives/canvas/serialization.zig +1 -0
  25. package/src/primitives/canvas/test_support.zig +1 -0
  26. package/src/primitives/canvas/text.zig +1 -0
  27. package/src/primitives/canvas/text_layout.zig +84 -15
  28. package/src/primitives/canvas/text_layout_hash.zig +3 -1
  29. package/src/primitives/canvas/text_layout_types.zig +3 -0
  30. package/src/primitives/canvas/text_metrics.zig +28 -1
  31. package/src/primitives/canvas/text_tests.zig +61 -6
  32. package/src/primitives/canvas/widget_render.zig +6 -0
  33. package/src/primitives/canvas/widget_render_controls.zig +1 -0
  34. package/src/root.zig +2 -0
  35. package/src/runtime/canvas_fonts.zig +87 -0
  36. package/src/runtime/core.zig +1 -0
  37. package/src/runtime/flow.zig +7 -0
  38. package/src/runtime/native_command_event_tests.zig +58 -0
  39. package/src/tooling/manifest.zig +79 -2
  40. package/src/tooling/package.zig +33 -0
  41. package/src/tooling/raw_manifest.zig +7 -0
  42. package/src/tooling/root.zig +1 -0
  43. package/src/tooling/templates.zig +45 -0
  44. package/src/tooling/update.zig +576 -0
  45. package/src/updater/c_api.zig +123 -0
  46. package/src/updater/feed.zig +215 -0
  47. package/src/updater/root.zig +10 -0
@@ -10,6 +10,23 @@ const default_sans_font_id = canvas.default_sans_font_id;
10
10
  const default_mono_font_id = canvas.default_mono_font_id;
11
11
  const utf8SequenceLength = text_interaction.utf8SequenceLength;
12
12
 
13
+ /// Ink bounds for one shaped line, relative to its baseline.
14
+ pub const TextInkMetrics = struct {
15
+ min_x: f32 = 0,
16
+ max_x: f32 = 0,
17
+ min_y: f32 = 0,
18
+ max_y: f32 = 0,
19
+
20
+ pub fn valid(self: TextInkMetrics) bool {
21
+ return std.math.isFinite(self.min_x) and
22
+ std.math.isFinite(self.max_x) and
23
+ std.math.isFinite(self.min_y) and
24
+ std.math.isFinite(self.max_y) and
25
+ self.max_x >= self.min_x and
26
+ self.max_y >= self.min_y;
27
+ }
28
+ };
29
+
13
30
  /// Injected text measurement. The engine stays pure: platforms provide a
14
31
  /// context pointer plus a function that returns the width of a single-line
15
32
  /// run of `text` at `size` for `font_id`, shaped with the same font
@@ -29,6 +46,9 @@ pub const TextMeasureProvider = struct {
29
46
  /// with line breaks then derived from cumulative advances exactly as
30
47
  /// the estimator path derives them.
31
48
  measure_advances_fn: ?*const fn (context: ?*anyopaque, font_id: FontId, size: f32, text: []const u8, advances: []f32) bool = null,
49
+ /// Optional shaped ink bounds for one line, relative to its baseline.
50
+ /// Returning false keeps callers on conservative engine bounds.
51
+ measure_ink_fn: ?*const fn (context: ?*anyopaque, font_id: FontId, size: f32, text: []const u8, metrics: *TextInkMetrics) bool = null,
32
52
 
33
53
  pub fn measureWidth(self: TextMeasureProvider, font_id: FontId, size: f32, text: []const u8) f32 {
34
54
  if (text.len == 0) return 0;
@@ -48,6 +68,14 @@ pub const TextMeasureProvider = struct {
48
68
  if (advances.len < text.len) return false;
49
69
  return advances_fn(self.context, font_id, size, text, advances[0..text.len]);
50
70
  }
71
+
72
+ pub fn measureInk(self: TextMeasureProvider, font_id: FontId, size: f32, text: []const u8) ?TextInkMetrics {
73
+ const measure_ink_fn = self.measure_ink_fn orelse return null;
74
+ if (text.len == 0) return null;
75
+ var metrics: TextInkMetrics = .{};
76
+ if (!measure_ink_fn(self.context, font_id, size, text, &metrics)) return null;
77
+ return if (metrics.valid()) metrics else null;
78
+ }
51
79
  };
52
80
 
53
81
  /// Width of a text run: the provider when installed, the deterministic
@@ -306,4 +334,3 @@ fn sansVariantWidthFactor(font_id: FontId) f32 {
306
334
  pub fn estimatedGlyphAdvance(glyph: Glyph, size: f32) f32 {
307
335
  return @max(size * 0.25, glyph.advance);
308
336
  }
309
-
@@ -837,9 +837,10 @@ test "ime composition owns exact bytes when its preview completes CRLF" {
837
837
  }
838
838
 
839
839
  test "text bounds follow utf8 scalar fallback and shaped y offsets" {
840
- // Metric boxes inflate by the ink allowance (left/bottom 0.1em,
841
- // right 0.35em) so real glyph outlines never clip at the bounds.
842
- try expectRectApprox(geometry.RectF.init(1, 8, 19.47, 13.5), textBounds(.{
840
+ // Metric boxes inflate by the ink allowance (top 0.35em,
841
+ // left/bottom 0.1em, right 0.35em) so real and fallback glyph
842
+ // outlines never clip at the bounds.
843
+ try expectRectApprox(geometry.RectF.init(1, 4.5, 19.47, 17), textBounds(.{
843
844
  .font_id = 1,
844
845
  .size = 10,
845
846
  .origin = geometry.PointF.init(2, 18),
@@ -851,7 +852,7 @@ test "text bounds follow utf8 scalar fallback and shaped y offsets" {
851
852
  .{ .id = 1, .x = 0, .y = -2, .advance = 6 },
852
853
  .{ .id = 2, .x = 8, .y = 3, .advance = 5 },
853
854
  };
854
- try expectRect(geometry.RectF.init(3, 8, 17.5, 18.5), textBounds(.{
855
+ try expectRect(geometry.RectF.init(3, 4.5, 17.5, 22), textBounds(.{
855
856
  .font_id = 1,
856
857
  .size = 10,
857
858
  .origin = geometry.PointF.init(4, 20),
@@ -860,6 +861,60 @@ test "text bounds follow utf8 scalar fallback and shaped y offsets" {
860
861
  }));
861
862
  }
862
863
 
864
+ test "text bounds reserve top ink headroom for fallback glyphs" {
865
+ const text = DrawText{
866
+ .font_id = 1,
867
+ .size = 16,
868
+ .origin = geometry.PointF.init(4, 20),
869
+ .color = Color.rgb8(255, 255, 255),
870
+ .text = "😀",
871
+ };
872
+ const bounds = textBounds(text).?;
873
+ try std.testing.expect(bounds.y < text.origin.y - text.size);
874
+ try std.testing.expectEqual(@as(f32, 5.6), text.origin.y - text.size - bounds.y);
875
+ }
876
+
877
+ fn providerInkMetricsForTests(
878
+ context: ?*anyopaque,
879
+ font_id: FontId,
880
+ size: f32,
881
+ text: []const u8,
882
+ metrics: *support.TextInkMetrics,
883
+ ) bool {
884
+ _ = context;
885
+ _ = font_id;
886
+ _ = size;
887
+ _ = text;
888
+ metrics.* = .{
889
+ .min_x = -2,
890
+ .max_x = 12,
891
+ .min_y = -4,
892
+ .max_y = 18,
893
+ };
894
+ return true;
895
+ }
896
+
897
+ const provider_ink_measure = support.TextMeasureProvider{
898
+ .measure_fn = coretextLikeMeasureForTests,
899
+ .measure_ink_fn = providerInkMetricsForTests,
900
+ };
901
+
902
+ test "text bounds include provider ink metrics for standalone runs" {
903
+ const text = DrawText{
904
+ .font_id = 1,
905
+ .size = 10,
906
+ .origin = geometry.PointF.init(4, 20),
907
+ .color = Color.rgb8(255, 255, 255),
908
+ .text = "A",
909
+ .measure = &provider_ink_measure,
910
+ };
911
+ const bounds = textBounds(text).?;
912
+ try std.testing.expect(bounds.x <= 2);
913
+ try std.testing.expect(bounds.y <= 2);
914
+ try std.testing.expect(bounds.maxX() >= 16);
915
+ try std.testing.expect(bounds.maxY() >= 24);
916
+ }
917
+
863
918
  test "text bounds and reference renderer honor per-run wrapping" {
864
919
  const text = DrawText{
865
920
  .font_id = 1,
@@ -870,13 +925,13 @@ test "text bounds and reference renderer honor per-run wrapping" {
870
925
  .text_layout = .{ .max_width = 10, .line_height = 12, .wrap = .character },
871
926
  };
872
927
  // Metric box (0, 0, 7.11, 48) plus the ink allowance.
873
- try expectRectApprox(geometry.RectF.init(-1, 0, 11.61, 49), textBounds(text));
928
+ try expectRectApprox(geometry.RectF.init(-1, -3.5, 11.61, 52.5), textBounds(text));
874
929
 
875
930
  const commands = [_]CanvasCommand{.{ .draw_text = text }};
876
931
  var render_commands: [1]RenderCommand = undefined;
877
932
  const render_plan = try (DisplayList{ .commands = &commands }).renderPlan(&render_commands);
878
933
  try std.testing.expectEqual(@as(usize, 1), render_plan.commandCount());
879
- try expectRectApprox(geometry.RectF.init(-1, 0, 11.61, 49), render_plan.commands[0].bounds);
934
+ try expectRectApprox(geometry.RectF.init(-1, -3.5, 11.61, 52.5), render_plan.commands[0].bounds);
880
935
 
881
936
  var pixels: [16 * 32 * 4]u8 = [_]u8{0} ** (16 * 32 * 4);
882
937
  const surface = try ReferenceRenderSurface.init(16, 32, &pixels);
@@ -2673,6 +2673,7 @@ fn emitIconWidget(builder: *Builder, widget: Widget, tokens: DesignTokens) Error
2673
2673
  .origin = pixelSnapTextPoint(tokens, centeredTextOrigin(widget.frame, widget.text, size, tokens)),
2674
2674
  .color = widgetForegroundColor(widget, tokens, tokens.colors.text),
2675
2675
  .text = widget.text,
2676
+ .measure = tokens.text_measure,
2676
2677
  });
2677
2678
  }
2678
2679
 
@@ -3662,6 +3663,7 @@ fn emitChartAxisLabels(builder: *Builder, widget: Widget, tokens: DesignTokens,
3662
3663
  .origin = pixelSnapTextPoint(tokens, geometry.PointF.init(plot.x - chart_axis_label_gap - width, top + size)),
3663
3664
  .color = tokens.colors.text_muted,
3664
3665
  .text = text,
3666
+ .measure = tokens.text_measure,
3665
3667
  });
3666
3668
  }
3667
3669
  }
@@ -3693,6 +3695,7 @@ fn emitChartAxisLabels(builder: *Builder, widget: Widget, tokens: DesignTokens,
3693
3695
  .origin = pixelSnapTextPoint(tokens, geometry.PointF.init(x, baseline)),
3694
3696
  .color = tokens.colors.text_muted,
3695
3697
  .text = label,
3698
+ .measure = tokens.text_measure,
3696
3699
  });
3697
3700
  }
3698
3701
  }
@@ -4164,6 +4167,7 @@ fn emitChartHoverDetail(builder: *Builder, widget: Widget, tokens: DesignTokens,
4164
4167
  .origin = pixelSnapTextPoint(tokens, geometry.PointF.init(card.x + chart_detail_pad_h, row_y + size)),
4165
4168
  .color = tokens.colors.text,
4166
4169
  .text = title_text,
4170
+ .measure = tokens.text_measure,
4167
4171
  });
4168
4172
  row_y += line_height;
4169
4173
  for (data.series, 0..) |series, series_index| {
@@ -4183,6 +4187,7 @@ fn emitChartHoverDetail(builder: *Builder, widget: Widget, tokens: DesignTokens,
4183
4187
  .origin = pixelSnapTextPoint(tokens, geometry.PointF.init(card.x + chart_detail_pad_h + chart_detail_swatch + chart_detail_swatch_gap, row_y + size)),
4184
4188
  .color = tokens.colors.text_muted,
4185
4189
  .text = chartDetailRowName(series),
4190
+ .measure = tokens.text_measure,
4186
4191
  });
4187
4192
  var value_buffer: [chart_model.max_chart_value_label_bytes]u8 = undefined;
4188
4193
  const value_text = try builder.allocChartLabelBytes(chart_model.formatChartValue(&value_buffer, series.values[detail.index], decimals));
@@ -4194,6 +4199,7 @@ fn emitChartHoverDetail(builder: *Builder, widget: Widget, tokens: DesignTokens,
4194
4199
  .origin = pixelSnapTextPoint(tokens, geometry.PointF.init(card.maxX() - chart_detail_pad_h - value_width, row_y + size)),
4195
4200
  .color = tokens.colors.text,
4196
4201
  .text = value_text,
4202
+ .measure = tokens.text_measure,
4197
4203
  });
4198
4204
  row_y += line_height;
4199
4205
  }
@@ -267,6 +267,7 @@ pub fn emitIconButtonWidget(builder: *Builder, widget: Widget, tokens: DesignTok
267
267
  .origin = pixelSnapTextPoint(tokens, centeredTextOrigin(widget.frame, widget.text, size, tokens)),
268
268
  .color = buttonTextColorForWidget(widget, tokens),
269
269
  .text = widget.text,
270
+ .measure = tokens.text_measure,
270
271
  });
271
272
  }
272
273
  }
package/src/root.zig CHANGED
@@ -21,6 +21,8 @@ pub const js = @import("js/root.zig");
21
21
  pub const bridge = @import("bridge/root.zig");
22
22
  pub const frontend = @import("frontend/root.zig");
23
23
  pub const security = @import("security/root.zig");
24
+ pub const updater = @import("updater/root.zig");
25
+ pub const update_check_command = platform.update_check_command;
24
26
 
25
27
  pub const Runtime = runtime.Runtime;
26
28
  pub const RuntimeOptions = runtime.Options;
@@ -222,6 +222,7 @@ pub fn RuntimeCanvasFonts(comptime Runtime: type) type {
222
222
  .context = self,
223
223
  .measure_fn = canvasFontMeasure,
224
224
  .measure_advances_fn = canvasFontMeasureAdvances,
225
+ .measure_ink_fn = canvasFontMeasureInk,
225
226
  };
226
227
  }
227
228
  noteCanvasFontsChanged(self);
@@ -290,6 +291,92 @@ pub fn RuntimeCanvasFonts(comptime Runtime: type) type {
290
291
  return true;
291
292
  }
292
293
 
294
+ fn canvasFontMeasureInk(context: ?*anyopaque, font_id: canvas.FontId, size: f32, text: []const u8, metrics: *canvas.TextInkMetrics) bool {
295
+ const runtime: *Runtime = @ptrCast(@alignCast(context));
296
+ const index = findCanvasFontIndex(runtime, font_id) orelse return false;
297
+ const face = &runtime.canvas_font_faces[index];
298
+ const scale = size / face.units_per_em;
299
+ var pen_x: f32 = 0;
300
+ var has_ink = false;
301
+ var min_x: f32 = 0;
302
+ var max_x: f32 = 0;
303
+ var min_y: f32 = 0;
304
+ var max_y: f32 = 0;
305
+ var offset: usize = 0;
306
+ while (offset < text.len) {
307
+ const next = @min(text.len, offset + canvas.utf8SequenceLength(text[offset]));
308
+ const cluster = text[offset..next];
309
+ const cell_advance = canvas.estimateTextWidthForFace(face, cluster, size);
310
+ const is_break = text[offset] == ' ' or text[offset] == '\t' or
311
+ text[offset] == '\n' or text[offset] == '\r';
312
+
313
+ if (!is_break) {
314
+ var glyph: u16 = 0;
315
+ if (cluster.len == canvas.utf8SequenceLength(cluster[0]) and cluster.len > 1) {
316
+ if (std.unicode.utf8Decode(cluster)) |codepoint| {
317
+ glyph = face.glyphIndex(codepoint);
318
+ } else |_| {}
319
+ } else if (cluster.len == 1 and cluster[0] >= 0x20 and cluster[0] < 0x7F) {
320
+ glyph = face.glyphIndex(cluster[0]);
321
+ }
322
+
323
+ if (glyph != 0) {
324
+ const natural_advance = face.advance(glyph) * scale;
325
+ const inset = @max(0, (cell_advance - natural_advance) * 0.5);
326
+ const outline = face.glyphBounds(glyph) catch return false;
327
+ if (outline) |glyph_bounds| {
328
+ const outline_min_x = pen_x + inset + glyph_bounds.x * scale;
329
+ const outline_max_x = pen_x + inset + (glyph_bounds.x + glyph_bounds.width) * scale;
330
+ const outline_min_y = -((glyph_bounds.y + glyph_bounds.height) * scale);
331
+ const outline_max_y = -(glyph_bounds.y * scale);
332
+ if (!has_ink) {
333
+ has_ink = true;
334
+ min_x = outline_min_x;
335
+ max_x = outline_max_x;
336
+ min_y = outline_min_y;
337
+ max_y = outline_max_y;
338
+ } else {
339
+ min_x = @min(min_x, outline_min_x);
340
+ max_x = @max(max_x, outline_max_x);
341
+ min_y = @min(min_y, outline_min_y);
342
+ max_y = @max(max_y, outline_max_y);
343
+ }
344
+ }
345
+ } else {
346
+ // The reference renderer paints a solid fallback
347
+ // cell for an uncovered cluster. Keep this provider
348
+ // in lockstep with that block's actual cell bounds.
349
+ const block_min_x = pen_x;
350
+ const block_max_x = pen_x + cell_advance;
351
+ const block_min_y = -size;
352
+ const block_max_y = 0;
353
+ if (!has_ink) {
354
+ has_ink = true;
355
+ min_x = block_min_x;
356
+ max_x = block_max_x;
357
+ min_y = block_min_y;
358
+ max_y = block_max_y;
359
+ } else {
360
+ min_x = @min(min_x, block_min_x);
361
+ max_x = @max(max_x, block_max_x);
362
+ min_y = @min(min_y, block_min_y);
363
+ max_y = @max(max_y, block_max_y);
364
+ }
365
+ }
366
+ }
367
+ pen_x += cell_advance;
368
+ offset = next;
369
+ }
370
+
371
+ metrics.* = if (has_ink) .{
372
+ .min_x = min_x,
373
+ .max_x = max_x,
374
+ .min_y = min_y,
375
+ .max_y = max_y,
376
+ } else .{};
377
+ return true;
378
+ }
379
+
293
380
  fn findCanvasFontIndex(self: *const Runtime, id: canvas.FontId) ?usize {
294
381
  for (self.canvas_font_entries[0..self.canvas_font_count], 0..) |entry, index| {
295
382
  if (entry.id == id) return index;
@@ -529,6 +529,7 @@ pub const Runtime = struct {
529
529
  .context = options.platform.services.context,
530
530
  .measure_fn = measure_fn,
531
531
  .measure_advances_fn = options.platform.services.measure_text_advances_fn,
532
+ .measure_ink_fn = options.platform.services.measure_text_ink_fn,
532
533
  }
533
534
  else
534
535
  null;
@@ -573,6 +573,13 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
573
573
 
574
574
  pub fn dispatchCommand(self: *Runtime, app: App, command: CommandEvent) anyerror!void {
575
575
  try validateCommandName(command.name);
576
+ if (std.mem.eql(u8, command.name, platform.update_check_command)) {
577
+ self.options.platform.services.checkForUpdates(true) catch |err| switch (err) {
578
+ error.UnsupportedService => return dispatchEvent(self, app, .{ .command = command }),
579
+ else => return err,
580
+ };
581
+ return;
582
+ }
576
583
  try dispatchEvent(self, app, .{ .command = command });
577
584
  }
578
585
 
@@ -253,6 +253,64 @@ test "runtime dispatches menu command events" {
253
253
  try std.testing.expectEqual(@as(platform.WindowId, 1), app_state.last_window_id);
254
254
  }
255
255
 
256
+ test "runtime falls back to the app when the native update service is unavailable" {
257
+ const TestApp = struct {
258
+ command_count: u32 = 0,
259
+
260
+ fn app(self: *@This()) App {
261
+ return .{ .context = self, .name = "update-command", .source = platform.WebViewSource.html("<p>Update</p>"), .event_fn = event };
262
+ }
263
+
264
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
265
+ _ = runtime;
266
+ const self: *@This() = @ptrCast(@alignCast(context));
267
+ if (event_value == .command) self.command_count += 1;
268
+ }
269
+ };
270
+
271
+ const harness = try TestHarness().create(std.testing.allocator, .{});
272
+ defer harness.destroy(std.testing.allocator);
273
+ var app_state: TestApp = .{};
274
+ try harness.start(app_state.app());
275
+ try harness.runtime.dispatchCommand(app_state.app(), .{ .name = platform.update_check_command, .source = .menu });
276
+ try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
277
+ }
278
+
279
+ test "runtime reserves the native update command when the platform handles it" {
280
+ const UpdateService = struct {
281
+ var check_count: u32 = 0;
282
+
283
+ fn check(context: ?*anyopaque, user_initiated: bool) anyerror!void {
284
+ _ = context;
285
+ try std.testing.expect(user_initiated);
286
+ check_count += 1;
287
+ }
288
+ };
289
+ const TestApp = struct {
290
+ command_count: u32 = 0,
291
+
292
+ fn app(self: *@This()) App {
293
+ return .{ .context = self, .name = "update-command", .source = platform.WebViewSource.html("<p>Update</p>"), .event_fn = event };
294
+ }
295
+
296
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
297
+ _ = runtime;
298
+ const self: *@This() = @ptrCast(@alignCast(context));
299
+ if (event_value == .command) self.command_count += 1;
300
+ }
301
+ };
302
+
303
+ const harness = try TestHarness().create(std.testing.allocator, .{});
304
+ defer harness.destroy(std.testing.allocator);
305
+ UpdateService.check_count = 0;
306
+ harness.runtime.options.platform.services.check_for_updates_fn = UpdateService.check;
307
+ var app_state: TestApp = .{};
308
+ try harness.start(app_state.app());
309
+ try harness.runtime.dispatchCommand(app_state.app(), .{ .name = platform.update_check_command, .source = .menu });
310
+ try std.testing.expectEqual(@as(u32, 1), UpdateService.check_count);
311
+ try std.testing.expectEqual(@as(u32, 0), app_state.command_count);
312
+ }
313
+
256
314
  test "automation snapshot exposes configured app menus" {
257
315
  const items = [_]platform.MenuItem{
258
316
  .{ .label = "Refresh", .command = "app.refresh" },
@@ -63,6 +63,7 @@ pub const Metadata = struct {
63
63
  shortcuts: []const ShortcutMetadata = &.{},
64
64
  file_associations: []const FileAssociationMetadata = &.{},
65
65
  url_schemes: []const UrlSchemeMetadata = &.{},
66
+ updates: UpdateMetadata = .{},
66
67
  dmg: DmgMetadata = .{},
67
68
 
68
69
  pub fn displayName(self: Metadata) []const u8 {
@@ -209,6 +210,8 @@ pub const Metadata = struct {
209
210
  allocator.free(scheme.role);
210
211
  }
211
212
  if (self.url_schemes.len > 0) allocator.free(self.url_schemes);
213
+ if (self.updates.feed_url) |value| allocator.free(value);
214
+ if (self.updates.public_key) |value| allocator.free(value);
212
215
  if (self.dmg.volume_name) |value| allocator.free(value);
213
216
  if (self.dmg.background) |value| allocator.free(value);
214
217
  for (self.dmg.items) |item| {
@@ -416,6 +419,16 @@ pub const DmgMetadata = struct {
416
419
  items: []const DmgItemMetadata = &.{},
417
420
  };
418
421
 
422
+ pub const UpdateMetadata = struct {
423
+ feed_url: ?[]const u8 = null,
424
+ public_key: ?[]const u8 = null,
425
+ check_on_start: bool = false,
426
+
427
+ pub fn enabled(self: UpdateMetadata) bool {
428
+ return self.feed_url != null;
429
+ }
430
+ };
431
+
419
432
  pub const FrontendDevMetadata = struct {
420
433
  url: []const u8,
421
434
  command: []const []const u8 = &.{},
@@ -462,6 +475,7 @@ const RawMenuItem = raw_manifest.RawMenuItem;
462
475
  const RawShortcut = raw_manifest.RawShortcut;
463
476
  const RawFileAssociation = raw_manifest.RawFileAssociation;
464
477
  const RawUrlScheme = raw_manifest.RawUrlScheme;
478
+ const RawUpdates = raw_manifest.RawUpdates;
465
479
  const RawDmg = raw_manifest.RawDmg;
466
480
  const RawDmgItem = raw_manifest.RawDmgItem;
467
481
 
@@ -563,6 +577,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
563
577
  defer allocator.free(file_associations);
564
578
  const url_schemes = parseUrlSchemes(allocator, metadata.url_schemes) catch return .{ .ok = false, .message = "app manifest URL schemes are invalid" };
565
579
  defer allocator.free(url_schemes);
580
+ const updates = convertUpdates(metadata.updates) catch return .{ .ok = false, .message = "app manifest updates are invalid - updates require an HTTPS feed_url and a base64 Ed25519 public_key; check_on_start requires both" };
566
581
  // General manifest validation owns only values the app explicitly
567
582
  // declared. Archive-time fallbacks (notably display_name as the volume
568
583
  // name) are validated when a macOS archive is actually requested, so an
@@ -572,6 +587,10 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
572
587
  return .{ .ok = false, .message = dmg_message };
573
588
  }
574
589
  const manifest_web_engine = parseWebEngine(metadata.web_engine) catch return .{ .ok = false, .message = "app manifest web engine is invalid" };
590
+ if (metadata.updates.enabled() and manifest_web_engine == .chromium) return .{
591
+ .ok = false,
592
+ .message = "native updates currently require web_engine = \"system\" on macOS; the Chromium host does not yet provide the updater UI/install lifecycle",
593
+ };
575
594
  const manifest_webview_layer = parseWebViewLayer(metadata.webview_layer) catch return .{ .ok = false, .message = "app manifest webview_layer is invalid - expected \"auto\", \"include\", or \"exclude\"" };
576
595
  if (!std.mem.eql(u8, metadata.core_compiler, "external")) {
577
596
  if (std.mem.eql(u8, metadata.core_compiler, "transpiler")) {
@@ -601,6 +620,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
601
620
  .shortcuts = shortcuts,
602
621
  .file_associations = file_associations,
603
622
  .url_schemes = url_schemes,
623
+ .updates = updates,
604
624
  .cef = .{ .dir = metadata.cef.dir, .auto_install = metadata.cef.auto_install },
605
625
  .webview_layer = manifest_webview_layer,
606
626
  .package = .{ .web_engine = manifest_web_engine },
@@ -712,10 +732,28 @@ fn metadataFromRaw(allocator: std.mem.Allocator, raw: RawManifest) !Metadata {
712
732
  .shortcuts = try convertRawShortcuts(allocator, raw.shortcuts),
713
733
  .file_associations = try convertRawFileAssociations(allocator, raw.file_associations),
714
734
  .url_schemes = try convertRawUrlSchemes(allocator, raw.url_schemes),
735
+ .updates = try duplicateRawUpdates(allocator, raw.updates),
715
736
  .dmg = try convertRawDmg(allocator, raw.dmg),
716
737
  };
717
738
  }
718
739
 
740
+ fn duplicateRawUpdates(allocator: std.mem.Allocator, raw: RawUpdates) !UpdateMetadata {
741
+ return .{
742
+ .feed_url = try duplicateOptionalString(allocator, raw.feed_url),
743
+ .public_key = try duplicateOptionalString(allocator, raw.public_key),
744
+ .check_on_start = raw.check_on_start,
745
+ };
746
+ }
747
+
748
+ fn convertUpdates(updates: UpdateMetadata) !app_manifest.UpdateConfig {
749
+ if (updates.feed_url == null and updates.public_key == null and !updates.check_on_start) return .{};
750
+ const feed_url = updates.feed_url orelse return error.InvalidUpdates;
751
+ const public_key = updates.public_key orelse return error.InvalidUpdates;
752
+ if (!std.mem.startsWith(u8, feed_url, "https://")) return error.InvalidUpdates;
753
+ if (public_key.len == 0) return error.InvalidUpdates;
754
+ return .{ .feed_url = feed_url, .public_key = public_key, .check_on_start = updates.check_on_start };
755
+ }
756
+
719
757
  fn duplicateRawServicePackages(allocator: std.mem.Allocator, packages: []const raw_manifest.RawServicePackage) ![]const ServicePackageMetadata {
720
758
  if (packages.len == 0) return &.{};
721
759
  const out = try allocator.alloc(ServicePackageMetadata, packages.len);
@@ -2434,8 +2472,28 @@ fn validatePathSegment(segment: []const u8) !void {
2434
2472
  }
2435
2473
 
2436
2474
  fn parseVersionNumber(value: []const u8) !u32 {
2437
- if (value.len == 0) return error.InvalidVersion;
2438
- return std.fmt.parseUnsigned(u32, value, 10);
2475
+ if (value.len == 0 or (value.len > 1 and value[0] == '0')) return error.InvalidVersion;
2476
+ return std.fmt.parseUnsigned(u32, value, 10) catch error.InvalidVersion;
2477
+ }
2478
+
2479
+ test "manifest versions use canonical numeric components" {
2480
+ try std.testing.expectEqual(@as(u32, 10), (try parseVersion("1.10.0")).minor);
2481
+ try std.testing.expectError(error.InvalidVersion, parseVersion("1.010.0"));
2482
+ try std.testing.expectError(error.InvalidVersion, parseVersion("01.0.0"));
2483
+ try std.testing.expectError(error.InvalidVersion, parseVersion("1.0.00"));
2484
+ }
2485
+
2486
+ test "manifest validation rejects leading-zero versions" {
2487
+ var tmp = std.testing.tmpDir(.{});
2488
+ defer tmp.cleanup();
2489
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "app.json", .data =
2490
+ \\{ "id": "com.example.version", "name": "version", "version": "1.010.0" }
2491
+ });
2492
+ const path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/app.json", .{tmp.sub_path});
2493
+ defer std.testing.allocator.free(path);
2494
+ const result = try validateFile(std.testing.allocator, std.testing.io, path);
2495
+ try std.testing.expect(!result.ok);
2496
+ try std.testing.expectEqualStrings("app manifest version is invalid", result.message);
2439
2497
  }
2440
2498
 
2441
2499
  test "JSON manifest parser accepts schema metadata and rejects unknown fields" {
@@ -2462,6 +2520,25 @@ test "JSON manifest parser accepts schema metadata and rejects unknown fields" {
2462
2520
  ));
2463
2521
  }
2464
2522
 
2523
+ test "JSON manifest parser carries native update configuration" {
2524
+ const metadata = try parseJsonText(std.testing.allocator,
2525
+ \\{
2526
+ \\ "id": "com.example.updates",
2527
+ \\ "name": "updates",
2528
+ \\ "version": "1.2.3",
2529
+ \\ "updates": {
2530
+ \\ "feed_url": "https://example.com/native-update.json",
2531
+ \\ "public_key": "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
2532
+ \\ "check_on_start": true
2533
+ \\ }
2534
+ \\}
2535
+ );
2536
+ defer metadata.deinit(std.testing.allocator);
2537
+ try std.testing.expect(metadata.updates.enabled());
2538
+ try std.testing.expect(metadata.updates.check_on_start);
2539
+ try std.testing.expectEqualStrings("https://example.com/native-update.json", metadata.updates.feed_url.?);
2540
+ }
2541
+
2465
2542
  test "JSON file validation rejects null with a teaching diagnostic regardless of extension case" {
2466
2543
  var cwd = std.Io.Dir.cwd();
2467
2544
  const root = ".zig-cache/test-validate-json-null";
@@ -83,6 +83,9 @@ pub const PackageOptions = struct {
83
83
  cef_dir: []const u8 = web_engine_tool.default_cef_dir,
84
84
  signing: SigningConfig = .{},
85
85
  archive: bool = false,
86
+ /// Emit the ZIP consumed by the native updater. macOS only; unlike the
87
+ /// user-facing DMG, this archive contains exactly the packaged .app.
88
+ update_archive: bool = false,
86
89
  /// The process environment, when the caller has one (the CLI). The
87
90
  /// Android artifact probes it for the SDK/NDK toolchain to assemble
88
91
  /// the debug APK; without it the generated project is still complete
@@ -153,6 +156,7 @@ pub const PackageStats = struct {
153
156
  web_engine: WebEngine = .system,
154
157
  web_layer: ?manifest_tool.WebLayer = null,
155
158
  archive_path: ?[]const u8 = null,
159
+ update_archive_path: ?[]const u8 = null,
156
160
  /// The Windows subsystem verdict: `console` when the package
157
161
  /// wrapped a CONSOLE-subsystem exe (the app will flash a terminal
158
162
  /// window behind itself on every launch), `gui` for a GUI-subsystem
@@ -217,6 +221,10 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
217
221
  return err;
218
222
  };
219
223
  try validateWebEngineTarget(options.target, options.web_engine);
224
+ if (options.metadata.updates.enabled() and options.target == .macos and options.web_engine == .chromium) {
225
+ std.debug.print("error: native updates currently require the system macOS host; package with --web-engine system or remove the updates block\n", .{});
226
+ return error.UnsupportedUpdateHost;
227
+ }
220
228
  if (options.target == .macos and options.archive) {
221
229
  manifest_tool.validateDmgPackageSettings(options.metadata) catch |err| {
222
230
  std.debug.print("error: app.zon dmg settings are invalid ({s})\n", .{@errorName(err)});
@@ -239,6 +247,11 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
239
247
  stats.archive_path = path;
240
248
  }
241
249
  }
250
+ if (options.update_archive) {
251
+ if (options.target != .macos) return error.UnsupportedUpdateTarget;
252
+ if (!options.metadata.updates.enabled()) return error.UpdatesNotConfigured;
253
+ stats.update_archive_path = try createUpdateArchive(allocator, io, options);
254
+ }
242
255
  return stats;
243
256
  }
244
257
 
@@ -283,6 +296,26 @@ pub fn printDiagnostic(stats: PackageStats) void {
283
296
  if (stats.archive_path) |archive| {
284
297
  std.debug.print(" archive: {s}\n", .{archive});
285
298
  }
299
+ if (stats.update_archive_path) |archive| {
300
+ std.debug.print(" update archive: {s}\n", .{archive});
301
+ }
302
+ }
303
+
304
+ fn createUpdateArchive(allocator: std.mem.Allocator, io: std.Io, options: PackageOptions) ![]const u8 {
305
+ const parent = std.fs.path.dirname(options.output_path) orelse ".";
306
+ const archive_name = try std.fmt.allocPrint(allocator, "{s}-{s}-macos-{s}-update.zip", .{ options.metadata.name, options.metadata.version, options.optimize });
307
+ defer allocator.free(archive_name);
308
+ const archive_path = try std.fs.path.join(allocator, &.{ parent, archive_name });
309
+ errdefer allocator.free(archive_path);
310
+ const app_path = try absolutePathAlloc(allocator, io, options.output_path);
311
+ defer allocator.free(app_path);
312
+ const archive_command_path = try absolutePathAlloc(allocator, io, archive_path);
313
+ defer allocator.free(archive_command_path);
314
+ if (!runArchiveCommand(io, &.{ "/usr/bin/ditto", "-c", "-k", "--sequesterRsrc", "--keepParent", app_path, archive_command_path }, null)) {
315
+ std.debug.print("error: update archive creation failed for {s}\n", .{archive_path});
316
+ return error.UpdateArchiveFailed;
317
+ }
318
+ return archive_path;
286
319
  }
287
320
 
288
321
  pub fn createLocalPackage(io: std.Io, output_path: []const u8) !PackageStats {
@@ -48,9 +48,16 @@ pub const RawManifest = struct {
48
48
  shortcuts: []const RawShortcut = &.{},
49
49
  file_associations: []const RawFileAssociation = &.{},
50
50
  url_schemes: []const RawUrlScheme = &.{},
51
+ updates: RawUpdates = .{},
51
52
  dmg: RawDmg = .{},
52
53
  };
53
54
 
55
+ pub const RawUpdates = struct {
56
+ feed_url: ?[]const u8 = null,
57
+ public_key: ?[]const u8 = null,
58
+ check_on_start: bool = false,
59
+ };
60
+
54
61
  pub const RawImages = struct {
55
62
  max_image_pixel_bytes: usize = 1024 * 1024,
56
63
  };
@@ -20,6 +20,7 @@ pub const ios = @import("ios.zig");
20
20
  pub const android = @import("android.zig");
21
21
  pub const xcodeproj = @import("xcodeproj.zig");
22
22
  pub const db = @import("db.zig");
23
+ pub const update = @import("update.zig");
23
24
 
24
25
  test {
25
26
  @import("std").testing.refAllDecls(@This());