@native-sdk/cli 0.9.5 → 0.10.1
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.
- package/build/app.zig +7 -0
- package/build/ts_run.mjs +1 -1
- package/build.zig +30 -5
- package/package.json +10 -10
- package/packages/core/package-lock.json +12 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_command.mjs +1 -1
- package/schemas/app.schema.json +12 -1
- package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/src/app_runner/root.zig +25 -0
- package/src/platform/macos/appkit_host.h +25 -0
- package/src/platform/macos/appkit_host.m +537 -15
- package/src/platform/macos/cef_host.mm +17 -0
- package/src/platform/macos/root.zig +95 -0
- package/src/platform/root.zig +3 -0
- package/src/platform/types.zig +15 -0
- package/src/primitives/app_manifest/tests.zig +19 -0
- package/src/primitives/app_manifest/validation.zig +14 -2
- package/src/primitives/canvas/font_ttf.zig +24 -0
- package/src/primitives/canvas/gpu.zig +5 -0
- package/src/primitives/canvas/reference.zig +4 -1
- package/src/primitives/canvas/render_tests.zig +1 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/serialization.zig +1 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_layout.zig +84 -15
- package/src/primitives/canvas/text_layout_hash.zig +3 -1
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_metrics.zig +28 -1
- package/src/primitives/canvas/text_tests.zig +61 -6
- package/src/primitives/canvas/widget_render.zig +6 -0
- package/src/primitives/canvas/widget_render_controls.zig +1 -0
- package/src/root.zig +2 -0
- package/src/runtime/canvas_fonts.zig +87 -0
- package/src/runtime/core.zig +1 -0
- package/src/runtime/flow.zig +7 -0
- package/src/runtime/native_command_event_tests.zig +58 -0
- package/src/tooling/codesign.zig +125 -74
- package/src/tooling/manifest.zig +79 -2
- package/src/tooling/package.zig +118 -1
- package/src/tooling/raw_manifest.zig +7 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +45 -0
- package/src/tooling/update.zig +576 -0
- package/src/updater/c_api.zig +123 -0
- package/src/updater/feed.zig +215 -0
- 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 (
|
|
841
|
-
// right 0.35em) so real
|
|
842
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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;
|
package/src/runtime/core.zig
CHANGED
|
@@ -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;
|
package/src/runtime/flow.zig
CHANGED
|
@@ -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" },
|