@native-sdk/cli 0.4.1 → 0.4.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.
- package/assets/native-sdk.manifest +17 -1
- package/build/app.zig +40 -1
- package/build.zig +49 -3
- package/package.json +10 -9
- package/src/platform/macos/appkit_host.m +21 -6
- package/src/platform/windows/webview2_host.cpp +377 -72
- package/src/primitives/canvas/chart.zig +8 -7
- package/src/primitives/canvas/chart_tests.zig +2 -2
- package/src/primitives/canvas/commands.zig +27 -0
- package/src/primitives/canvas/gpu.zig +8 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -1
- package/src/primitives/canvas/reference.zig +82 -3
- package/src/primitives/canvas/reference_tests.zig +155 -1
- package/src/primitives/canvas/serialization.zig +16 -3
- package/src/primitives/canvas/themes/geist.zig +6 -0
- package/src/primitives/canvas/tokens.zig +7 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +191 -0
- package/src/primitives/canvas/widget_render.zig +29 -41
- package/src/primitives/canvas/widget_render_controls.zig +55 -42
- package/src/primitives/canvas/widget_render_style.zig +53 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
- package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
- package/src/runtime/canvas_frame_packet_tests.zig +9 -1
- package/src/runtime/canvas_frame_patch_tests.zig +39 -1
- package/src/runtime/canvas_widget_control_tests.zig +4 -4
- package/src/runtime/ui_app.zig +78 -10
- package/src/runtime/ui_app_tests.zig +109 -0
- package/src/runtime/ui_app_window_tests.zig +93 -0
- package/src/tooling/package.zig +45 -0
- package/src/tooling/templates.zig +42 -1
- package/third_party/webview2/LICENSE.txt +27 -0
- package/third_party/webview2/README.md +19 -0
- package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
- package/third_party/webview2/include/EventToken.h +12 -0
- package/third_party/webview2/include/WebView2.h +60636 -0
- package/third_party/webview2/x64/WebView2Loader.dll +0 -0
|
@@ -180,7 +180,7 @@ const BinaryCursor = struct {
|
|
|
180
180
|
const start = self.offset;
|
|
181
181
|
_ = try self.readU8(); // kind
|
|
182
182
|
const flags = try self.readU8();
|
|
183
|
-
try self.skip(16 + 4 + 4); // bounds + opacity + stroke_width
|
|
183
|
+
try self.skip(16 + 4 + 4 + 1); // bounds + opacity + stroke_width + cap
|
|
184
184
|
if (flags & 0x01 != 0) try self.skip(8); // id
|
|
185
185
|
if (flags & 0x02 != 0) try self.skip(16); // clip
|
|
186
186
|
if (flags & 0x04 != 0) try self.skip(24); // transform
|
|
@@ -929,6 +929,9 @@ test "command fingerprints cover every encoded field" {
|
|
|
929
929
|
changed.stroke_width = 3;
|
|
930
930
|
try std.testing.expect(canvas.canvasGpuCommandFingerprint(changed) != base_fingerprint);
|
|
931
931
|
changed = base;
|
|
932
|
+
changed.cap = .round;
|
|
933
|
+
try std.testing.expect(canvas.canvasGpuCommandFingerprint(changed) != base_fingerprint);
|
|
934
|
+
changed = base;
|
|
932
935
|
changed.id = 42;
|
|
933
936
|
try std.testing.expect(canvas.canvasGpuCommandFingerprint(changed) != base_fingerprint);
|
|
934
937
|
changed = base;
|
|
@@ -975,6 +978,41 @@ test "command fingerprints cover every encoded field" {
|
|
|
975
978
|
try std.testing.expect(canvas.canvasGpuPacketCommandKey(moved, unkeyed_fingerprint) != synthetic);
|
|
976
979
|
}
|
|
977
980
|
|
|
981
|
+
test "the stroke end-cap rides the binary command encoding" {
|
|
982
|
+
// The command model's cap channel must survive the wire: the host
|
|
983
|
+
// strokes the checkbox mark's open polyline with the caps the
|
|
984
|
+
// reference renderer rasterizes, so a dropped byte here is silent
|
|
985
|
+
// cross-engine divergence. The cap sits at a fixed offset — key u64,
|
|
986
|
+
// kind u8, flags u8, bounds f32[4], opacity f32, stroke_width f32 —
|
|
987
|
+
// pinned against the host decoder's layout.
|
|
988
|
+
const elements = [_]canvas.PathElement{
|
|
989
|
+
.{ .verb = .move_to, .points = .{ geometry.PointF.init(4, 8), geometry.PointF.zero(), geometry.PointF.zero() } },
|
|
990
|
+
.{ .verb = .line_to, .points = .{ geometry.PointF.init(7, 11), geometry.PointF.zero(), geometry.PointF.zero() } },
|
|
991
|
+
.{ .verb = .line_to, .points = .{ geometry.PointF.init(12, 5), geometry.PointF.zero(), geometry.PointF.zero() } },
|
|
992
|
+
};
|
|
993
|
+
var command = canvas.CanvasGpuCommand{
|
|
994
|
+
.command_index = 0,
|
|
995
|
+
.id = 7,
|
|
996
|
+
.kind = .stroke_path,
|
|
997
|
+
.bounds = geometry.RectF.init(4, 5, 8, 6),
|
|
998
|
+
.shape = .{ .path = &elements },
|
|
999
|
+
.paint = .{ .color = canvas.Color.rgb8(255, 255, 255) },
|
|
1000
|
+
.stroke_width = 2,
|
|
1001
|
+
.cap = .round,
|
|
1002
|
+
};
|
|
1003
|
+
const cap_offset = 8 + 1 + 1 + 16 + 4 + 4;
|
|
1004
|
+
|
|
1005
|
+
var buffer: [512]u8 = undefined;
|
|
1006
|
+
var writer = std.Io.Writer.fixed(&buffer);
|
|
1007
|
+
try canvas.writeCanvasGpuCommandBinaryKeyed(7, command, &writer);
|
|
1008
|
+
try std.testing.expectEqual(@as(u8, 1), writer.buffered()[cap_offset]);
|
|
1009
|
+
|
|
1010
|
+
command.cap = .butt;
|
|
1011
|
+
var butt_writer = std.Io.Writer.fixed(&buffer);
|
|
1012
|
+
try canvas.writeCanvasGpuCommandBinaryKeyed(7, command, &butt_writer);
|
|
1013
|
+
try std.testing.expectEqual(@as(u8, 0), butt_writer.buffered()[cap_offset]);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
978
1016
|
test "pixel presents adopt a dirty-refinement baseline only for opted-in hosts and never feed patches" {
|
|
979
1017
|
// The mobile embed host presents through the CPU pixel path only and
|
|
980
1018
|
// opts in (`Options.pixel_present_retained_baseline`): pixel presents
|
|
@@ -191,8 +191,8 @@ test "runtime applies pointer values to canvas controls" {
|
|
|
191
191
|
var saw_empty_slider_active = false;
|
|
192
192
|
for (display_list.commands) |command| {
|
|
193
193
|
switch (command) {
|
|
194
|
-
.
|
|
195
|
-
if (
|
|
194
|
+
.stroke_path => |stroke| {
|
|
195
|
+
if (stroke.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
|
|
196
196
|
},
|
|
197
197
|
.fill_rounded_rect => |fill| {
|
|
198
198
|
if (fill.id == testCanvasWidgetPartId(4, 2)) {
|
|
@@ -1328,8 +1328,8 @@ test "runtime refreshes widget owned display list from canvas input" {
|
|
|
1328
1328
|
var saw_checkbox_check = false;
|
|
1329
1329
|
for (display_list.commands) |command| {
|
|
1330
1330
|
switch (command) {
|
|
1331
|
-
.
|
|
1332
|
-
if (
|
|
1331
|
+
.stroke_path => |stroke| {
|
|
1332
|
+
if (stroke.id == testCanvasWidgetPartId(2, 4)) saw_checkbox_check = true;
|
|
1333
1333
|
},
|
|
1334
1334
|
else => {},
|
|
1335
1335
|
}
|
package/src/runtime/ui_app.zig
CHANGED
|
@@ -659,6 +659,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
659
659
|
on_close: ?MsgT = null,
|
|
660
660
|
installed: bool = false,
|
|
661
661
|
canvas_size: geometry.SizeF = .{ .width = 1, .height = 1 },
|
|
662
|
+
/// The device scale of THIS window's surface, adopted from
|
|
663
|
+
/// its own frame and resize events. Secondary windows can sit
|
|
664
|
+
/// on a different-density monitor than the main canvas, so
|
|
665
|
+
/// the scale is per-window state: the app owns ONE appearance,
|
|
666
|
+
/// but each slot's rebuild stamps its own scale into
|
|
667
|
+
/// `pixel_snap.scale` (`slotEffectiveTokens`) so this window's
|
|
668
|
+
/// hairlines snap against the grid it actually renders on.
|
|
669
|
+
/// The main canvas keeps its scale in `Self.pixel_snap_scale`.
|
|
670
|
+
pixel_snap_scale: f32 = 1,
|
|
662
671
|
tree: ?Ui.Tree = null,
|
|
663
672
|
arena_index: usize = 0,
|
|
664
673
|
arenas: [2]std.heap.ArenaAllocator,
|
|
@@ -1131,15 +1140,21 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1131
1140
|
/// `tokens_fn`, explicit static `tokens`, or — the default — the
|
|
1132
1141
|
/// stock theme derived from the SYSTEM appearance the runtime
|
|
1133
1142
|
/// tracks (scheme, contrast, reduced motion), so an unthemed app
|
|
1134
|
-
/// honors the OS light/dark setting live.
|
|
1135
|
-
///
|
|
1143
|
+
/// honors the OS light/dark setting live. Every path carries the
|
|
1144
|
+
/// surface scale in `pixel_snap.scale` — the app owns the
|
|
1145
|
+
/// appearance, the runtime owns the device scale — so static
|
|
1146
|
+
/// tokens snap hairlines against the real surface density too.
|
|
1136
1147
|
pub fn effectiveTokens(self: *const Self) canvas.DesignTokens {
|
|
1137
1148
|
if (self.options.tokens_fn) |tokens_fn| {
|
|
1138
1149
|
var tokens = tokens_fn(&self.model);
|
|
1139
1150
|
tokens.pixel_snap.scale = self.pixel_snap_scale;
|
|
1140
1151
|
return tokens;
|
|
1141
1152
|
}
|
|
1142
|
-
if (self.options.tokens) |static_tokens|
|
|
1153
|
+
if (self.options.tokens) |static_tokens| {
|
|
1154
|
+
var tokens = static_tokens;
|
|
1155
|
+
tokens.pixel_snap.scale = self.pixel_snap_scale;
|
|
1156
|
+
return tokens;
|
|
1157
|
+
}
|
|
1143
1158
|
var tokens = canvas.DesignTokens.theme(.{
|
|
1144
1159
|
.color_scheme = switch (self.system_appearance.color_scheme) {
|
|
1145
1160
|
.light => .light,
|
|
@@ -1153,10 +1168,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1153
1168
|
return tokens;
|
|
1154
1169
|
}
|
|
1155
1170
|
|
|
1171
|
+
/// The design tokens for a secondary window's rebuild: the same
|
|
1172
|
+
/// app-owned appearance as `effectiveTokens`, restamped with the
|
|
1173
|
+
/// SLOT's device scale. Each window snaps hairlines against its
|
|
1174
|
+
/// own monitor's grid — only the scale differs per window, never
|
|
1175
|
+
/// the appearance.
|
|
1176
|
+
fn slotEffectiveTokens(self: *const Self, slot: *const WindowSlot) canvas.DesignTokens {
|
|
1177
|
+
var tokens = self.effectiveTokens();
|
|
1178
|
+
tokens.pixel_snap.scale = slot.pixel_snap_scale;
|
|
1179
|
+
return tokens;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1156
1182
|
/// Whether the stock tokens derive from the system appearance:
|
|
1157
1183
|
/// true only when the app claims neither token override, so an
|
|
1158
|
-
/// appearance flip
|
|
1159
|
-
/// and re-render.
|
|
1184
|
+
/// appearance flip must re-derive and re-render.
|
|
1160
1185
|
fn followsSystemAppearance(self: *const Self) bool {
|
|
1161
1186
|
return self.options.tokens_fn == null and self.options.tokens == null;
|
|
1162
1187
|
}
|
|
@@ -1167,6 +1192,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1167
1192
|
return self.options.tokens_fn != null or self.followsSystemAppearance();
|
|
1168
1193
|
}
|
|
1169
1194
|
|
|
1195
|
+
/// Whether a rebuild must push its tokens into the runtime's
|
|
1196
|
+
/// stored copy. Derived tokens can change with any model or
|
|
1197
|
+
/// appearance input, so they always re-emit. Static tokens are
|
|
1198
|
+
/// fixed by the app, but the runtime stamps the surface scale
|
|
1199
|
+
/// onto them (`effectiveTokens`), so a stored copy holding a
|
|
1200
|
+
/// stale scale re-emits too — hairlines re-snap after a move
|
|
1201
|
+
/// between monitors — while ordinary rebuilds keep skipping the
|
|
1202
|
+
/// redundant emission.
|
|
1203
|
+
fn rebuildEmitsTokens(self: *const Self, runtime: *Runtime, window_id: platform.WindowId, canvas_label: []const u8, tokens: canvas.DesignTokens) bool {
|
|
1204
|
+
if (self.derivesTokens()) return true;
|
|
1205
|
+
const stored = runtime.canvasWidgetDesignTokens(window_id, canvas_label) catch return true;
|
|
1206
|
+
return stored.pixel_snap.scale != tokens.pixel_snap.scale;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1170
1209
|
/// Read runtime-owned widget state back into the model through the
|
|
1171
1210
|
/// optional `sync` hook.
|
|
1172
1211
|
fn syncModel(self: *Self, runtime: *Runtime, window_id: platform.WindowId) void {
|
|
@@ -1279,7 +1318,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1279
1318
|
try self.installChromeDisplayList(runtime, window_id, chrome, layout, tokens);
|
|
1280
1319
|
} else {
|
|
1281
1320
|
_ = try runtime.setCanvasWidgetLayout(window_id, self.options.canvas_label, layout);
|
|
1282
|
-
if (self.installed and self.
|
|
1321
|
+
if (self.installed and self.rebuildEmitsTokens(runtime, window_id, self.options.canvas_label, tokens)) {
|
|
1283
1322
|
_ = try runtime.emitCanvasWidgetDisplayList(window_id, self.options.canvas_label, tokens);
|
|
1284
1323
|
}
|
|
1285
1324
|
}
|
|
@@ -1732,6 +1771,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1732
1771
|
slot.on_close = descriptor.on_close;
|
|
1733
1772
|
slot.installed = false;
|
|
1734
1773
|
slot.canvas_size = .{ .width = descriptor.width, .height = descriptor.height };
|
|
1774
|
+
// Until this window's first frame reports its real density,
|
|
1775
|
+
// assume the main canvas's — new windows usually open on the
|
|
1776
|
+
// same monitor, and the installing frame corrects the guess.
|
|
1777
|
+
slot.pixel_snap_scale = self.pixel_snap_scale;
|
|
1735
1778
|
slot.tree = null;
|
|
1736
1779
|
slot.arena_index = 0;
|
|
1737
1780
|
self.window_slot_count += 1;
|
|
@@ -1808,7 +1851,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1808
1851
|
|
|
1809
1852
|
fn rebuildWindowSlot(self: *Self, runtime: *Runtime, slot: *WindowSlot) anyerror!void {
|
|
1810
1853
|
const window_view = self.options.window_view orelse return;
|
|
1811
|
-
const tokens = runtime.tokensWithTextMeasure(self.
|
|
1854
|
+
const tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
|
|
1812
1855
|
const next_index = slot.arena_index ^ 1;
|
|
1813
1856
|
_ = slot.arenas[next_index].reset(.retain_capacity);
|
|
1814
1857
|
var ui = Ui.init(slot.arenas[next_index].allocator());
|
|
@@ -1827,7 +1870,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1827
1870
|
return err;
|
|
1828
1871
|
};
|
|
1829
1872
|
_ = try runtime.setCanvasWidgetLayout(slot.window_id, slot.canvasLabel(), layout);
|
|
1830
|
-
if (slot.installed and self.
|
|
1873
|
+
if (slot.installed and self.rebuildEmitsTokens(runtime, slot.window_id, slot.canvasLabel(), tokens)) {
|
|
1831
1874
|
_ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), tokens);
|
|
1832
1875
|
}
|
|
1833
1876
|
slot.tree = tree;
|
|
@@ -2749,7 +2792,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2749
2792
|
self.installed = true;
|
|
2750
2793
|
self.startMarkupWatch(runtime);
|
|
2751
2794
|
self.installStatusItem(runtime);
|
|
2752
|
-
} else if (
|
|
2795
|
+
} else if (@abs(self.pixel_snap_scale - scale) > 0.001) {
|
|
2796
|
+
// The surface moved to a different density (a drag between
|
|
2797
|
+
// monitors): EVERY token path carries the scale in
|
|
2798
|
+
// `pixel_snap.scale`, so static-token apps rebuild here
|
|
2799
|
+
// too — the re-emit inside `rebuild` re-snaps hairlines
|
|
2800
|
+
// against the new grid.
|
|
2753
2801
|
self.pixel_snap_scale = scale;
|
|
2754
2802
|
try self.rebuild(runtime, frame_event.window_id);
|
|
2755
2803
|
} else if (self.options.web_panes != null) {
|
|
@@ -2778,13 +2826,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2778
2826
|
fn handleWindowSlotFrame(self: *Self, runtime: *Runtime, frame_event: platform.GpuSurfaceFrameEvent) anyerror!void {
|
|
2779
2827
|
const slot = self.windowSlotByCanvasLabel(frame_event.label) orelse return;
|
|
2780
2828
|
slot.window_id = frame_event.window_id;
|
|
2829
|
+
const scale = normalizedSurfaceScale(frame_event.scale_factor);
|
|
2781
2830
|
var installing = false;
|
|
2782
2831
|
if (!slot.installed) {
|
|
2783
2832
|
installing = true;
|
|
2784
2833
|
slot.canvas_size = frame_event.size;
|
|
2834
|
+
slot.pixel_snap_scale = scale;
|
|
2785
2835
|
try self.rebuildWindowSlot(runtime, slot);
|
|
2786
|
-
_ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), runtime.tokensWithTextMeasure(self.
|
|
2836
|
+
_ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot)));
|
|
2787
2837
|
slot.installed = true;
|
|
2838
|
+
} else if (@abs(slot.pixel_snap_scale - scale) > 0.001) {
|
|
2839
|
+
// THIS window moved to a different density (the main
|
|
2840
|
+
// canvas may still be on its old monitor): adopt the
|
|
2841
|
+
// slot's scale and rebuild so the re-emit inside
|
|
2842
|
+
// `rebuildWindowSlot` re-snaps this window's hairlines —
|
|
2843
|
+
// static-token apps included, because the stored copy
|
|
2844
|
+
// holds the stale scale (`rebuildEmitsTokens`).
|
|
2845
|
+
slot.pixel_snap_scale = scale;
|
|
2846
|
+
try self.rebuildWindowSlot(runtime, slot);
|
|
2788
2847
|
}
|
|
2789
2848
|
try self.presentFrame(runtime, frame_event, slot.canvasLabel(), installing);
|
|
2790
2849
|
}
|
|
@@ -2897,13 +2956,22 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2897
2956
|
}
|
|
2898
2957
|
|
|
2899
2958
|
fn handleResize(self: *Self, runtime: *Runtime, resize_event: platform.GpuSurfaceResizeEvent) anyerror!void {
|
|
2959
|
+
// Resize events carry the surface density alongside the frame:
|
|
2960
|
+
// a move to a different-DPI monitor can arrive as a resize
|
|
2961
|
+
// whose LOGICAL size is unchanged (the OS rescales the frame),
|
|
2962
|
+
// so the scale must be adopted BEFORE the rebuild below — the
|
|
2963
|
+
// rebuild's re-emit then stamps freshly-snapped tokens, and
|
|
2964
|
+
// `rebuildEmitsTokens` sees the stored copy's stale scale and
|
|
2965
|
+
// forces the emission even when nothing else changed.
|
|
2900
2966
|
if (!std.mem.eql(u8, resize_event.label, self.options.canvas_label)) {
|
|
2901
2967
|
const slot = self.windowSlotByCanvasLabel(resize_event.label) orelse return;
|
|
2902
2968
|
slot.canvas_size = .{ .width = resize_event.frame.width, .height = resize_event.frame.height };
|
|
2969
|
+
slot.pixel_snap_scale = normalizedSurfaceScale(resize_event.scale_factor);
|
|
2903
2970
|
if (slot.installed) try self.rebuildWindowSlot(runtime, slot);
|
|
2904
2971
|
return;
|
|
2905
2972
|
}
|
|
2906
2973
|
self.canvas_size = .{ .width = resize_event.frame.width, .height = resize_event.frame.height };
|
|
2974
|
+
self.pixel_snap_scale = normalizedSurfaceScale(resize_event.scale_factor);
|
|
2907
2975
|
if (!self.installed) return;
|
|
2908
2976
|
// Fullscreen transitions resize the canvas AND flip the
|
|
2909
2977
|
// chrome overlay insets (macOS hides the titlebar band and
|
|
@@ -1044,6 +1044,115 @@ test "unthemed apps follow the system appearance live; explicit tokens opt out"
|
|
|
1044
1044
|
try std.testing.expectEqualDeep(light.colors.background, fixed_state.effectiveTokens().colors.background);
|
|
1045
1045
|
}
|
|
1046
1046
|
|
|
1047
|
+
test "static tokens carry the surface scale and re-snap on a scale change" {
|
|
1048
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1049
|
+
defer harness.destroy(std.testing.allocator);
|
|
1050
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1051
|
+
|
|
1052
|
+
// The app pins its look with static tokens (geometry snapping on,
|
|
1053
|
+
// scale 1 inside — the app never knows the monitor).
|
|
1054
|
+
var options = counterOptions();
|
|
1055
|
+
var static_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .light });
|
|
1056
|
+
static_tokens.pixel_snap = .{ .geometry = true, .text = true };
|
|
1057
|
+
options.tokens = static_tokens;
|
|
1058
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
1059
|
+
defer std.testing.allocator.destroy(app_state);
|
|
1060
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
|
|
1061
|
+
defer app_state.deinit();
|
|
1062
|
+
const app = app_state.app();
|
|
1063
|
+
try harness.start(app);
|
|
1064
|
+
|
|
1065
|
+
// Install on a 2x surface: the effective tokens are a stamped COPY —
|
|
1066
|
+
// the app owns the appearance, the runtime owns the device scale —
|
|
1067
|
+
// and the stored tokens carry the real density, so hairlines snap
|
|
1068
|
+
// against the physical grid instead of scale 1.
|
|
1069
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
1070
|
+
.label = canvas_label,
|
|
1071
|
+
.size = geometry.SizeF.init(400, 300),
|
|
1072
|
+
.scale_factor = 2,
|
|
1073
|
+
.frame_index = 1,
|
|
1074
|
+
.timestamp_ns = 1_000_000,
|
|
1075
|
+
.nonblank = true,
|
|
1076
|
+
} });
|
|
1077
|
+
try std.testing.expect(app_state.installed);
|
|
1078
|
+
try std.testing.expectEqual(@as(f32, 2), app_state.effectiveTokens().pixel_snap.scale);
|
|
1079
|
+
var stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
1080
|
+
try std.testing.expectEqual(@as(f32, 2), stored.pixel_snap.scale);
|
|
1081
|
+
try std.testing.expectEqualDeep(static_tokens.colors.background, stored.colors.background);
|
|
1082
|
+
|
|
1083
|
+
// A frame at a new density (the window dragged to a 1x monitor)
|
|
1084
|
+
// rebuilds and re-emits for a static-token app too: the stored
|
|
1085
|
+
// tokens re-snap to the new grid without any app involvement. The
|
|
1086
|
+
// model is poked directly (no dispatch) so the refreshed retained
|
|
1087
|
+
// text proves the FRAME triggered the rebuild.
|
|
1088
|
+
app_state.model.count = 5;
|
|
1089
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
1090
|
+
.label = canvas_label,
|
|
1091
|
+
.size = geometry.SizeF.init(400, 300),
|
|
1092
|
+
.scale_factor = 1,
|
|
1093
|
+
.frame_index = 2,
|
|
1094
|
+
.timestamp_ns = 2_000_000,
|
|
1095
|
+
.nonblank = true,
|
|
1096
|
+
} });
|
|
1097
|
+
try std.testing.expect(try retainedTextExists(&harness.runtime, "Count 5"));
|
|
1098
|
+
try std.testing.expectEqual(@as(f32, 1), app_state.effectiveTokens().pixel_snap.scale);
|
|
1099
|
+
stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
1100
|
+
try std.testing.expectEqual(@as(f32, 1), stored.pixel_snap.scale);
|
|
1101
|
+
try std.testing.expectEqualDeep(static_tokens.colors.background, stored.colors.background);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
test "a resize carrying a new density re-stamps and re-emits at the unchanged logical size" {
|
|
1105
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1106
|
+
defer harness.destroy(std.testing.allocator);
|
|
1107
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1108
|
+
|
|
1109
|
+
// Static tokens make this the strict case: ordinary rebuilds skip
|
|
1110
|
+
// the redundant emission, so a re-stamped stored copy below proves
|
|
1111
|
+
// the stale-scale re-emit fired.
|
|
1112
|
+
var options = counterOptions();
|
|
1113
|
+
var static_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .light });
|
|
1114
|
+
static_tokens.pixel_snap = .{ .geometry = true, .text = true };
|
|
1115
|
+
options.tokens = static_tokens;
|
|
1116
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
1117
|
+
defer std.testing.allocator.destroy(app_state);
|
|
1118
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
|
|
1119
|
+
defer app_state.deinit();
|
|
1120
|
+
const app = app_state.app();
|
|
1121
|
+
try harness.start(app);
|
|
1122
|
+
|
|
1123
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
1124
|
+
.label = canvas_label,
|
|
1125
|
+
.size = geometry.SizeF.init(400, 300),
|
|
1126
|
+
.scale_factor = 2,
|
|
1127
|
+
.frame_index = 1,
|
|
1128
|
+
.timestamp_ns = 1_000_000,
|
|
1129
|
+
.nonblank = true,
|
|
1130
|
+
} });
|
|
1131
|
+
try std.testing.expect(app_state.installed);
|
|
1132
|
+
var stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
1133
|
+
try std.testing.expectEqual(@as(f32, 2), stored.pixel_snap.scale);
|
|
1134
|
+
|
|
1135
|
+
// A DPI-only monitor move arrives as a resize whose LOGICAL size is
|
|
1136
|
+
// unchanged — only the event's scale differs. The resize path must
|
|
1137
|
+
// adopt the density before rebuilding, and the rebuild must re-emit
|
|
1138
|
+
// even though the layout inputs are identical: without both, the
|
|
1139
|
+
// stored tokens keep snapping against the old grid until the next
|
|
1140
|
+
// input. The model is poked directly (no dispatch) so the refreshed
|
|
1141
|
+
// retained text proves the RESIZE triggered the rebuild.
|
|
1142
|
+
app_state.model.count = 7;
|
|
1143
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_resized = .{
|
|
1144
|
+
.window_id = 1,
|
|
1145
|
+
.label = canvas_label,
|
|
1146
|
+
.frame = geometry.RectF.init(0, 0, 400, 300),
|
|
1147
|
+
.scale_factor = 1,
|
|
1148
|
+
} });
|
|
1149
|
+
try std.testing.expect(try retainedTextExists(&harness.runtime, "Count 7"));
|
|
1150
|
+
try std.testing.expectEqual(@as(f32, 1), app_state.effectiveTokens().pixel_snap.scale);
|
|
1151
|
+
stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
1152
|
+
try std.testing.expectEqual(@as(f32, 1), stored.pixel_snap.scale);
|
|
1153
|
+
try std.testing.expectEqualDeep(static_tokens.colors.background, stored.colors.background);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1047
1156
|
test "markup watch polls from the reserved runtime timer" {
|
|
1048
1157
|
const io = std.testing.io;
|
|
1049
1158
|
const watch_path = ".zig-cache/ui-app-markup-watch-test.native";
|
|
@@ -309,6 +309,99 @@ test "input from the secondary window dispatches through its own tree with its w
|
|
|
309
309
|
try std.testing.expectEqual(@as(u32, 1), fixture.app_state.model.bumps);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
test "each window's tokens carry its own surface density, not the main canvas's" {
|
|
313
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
314
|
+
defer harness.destroy(std.testing.allocator);
|
|
315
|
+
harness.null_platform.gpu_surfaces = true;
|
|
316
|
+
|
|
317
|
+
// Static tokens make this the strict case: ordinary slot rebuilds
|
|
318
|
+
// skip the redundant emission, so every re-stamped stored copy below
|
|
319
|
+
// proves the stale-scale re-emit fired for THAT window.
|
|
320
|
+
var static_tokens = canvas.DesignTokens.theme(.{ .color_scheme = .light });
|
|
321
|
+
static_tokens.pixel_snap = .{ .geometry = true, .text = true };
|
|
322
|
+
const app_state = try PanelApp.create(std.heap.page_allocator, .{
|
|
323
|
+
.name = "ui-app-panel-density",
|
|
324
|
+
.scene = panel_scene,
|
|
325
|
+
.canvas_label = canvas_label,
|
|
326
|
+
.tokens = static_tokens,
|
|
327
|
+
.update = panelUpdate,
|
|
328
|
+
.view = panelView,
|
|
329
|
+
.windows_fn = panelWindows,
|
|
330
|
+
.window_view = panelWindowView,
|
|
331
|
+
});
|
|
332
|
+
defer app_state.destroy();
|
|
333
|
+
const app = app_state.app();
|
|
334
|
+
try harness.start(app);
|
|
335
|
+
|
|
336
|
+
// Main canvas installs on a 1x monitor; the model already declares
|
|
337
|
+
// the settings window, so the installing rebuild creates it.
|
|
338
|
+
app_state.model.settings_open = true;
|
|
339
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
340
|
+
.label = canvas_label,
|
|
341
|
+
.size = geometry.SizeF.init(400, 300),
|
|
342
|
+
.scale_factor = 1,
|
|
343
|
+
.frame_index = 1,
|
|
344
|
+
.timestamp_ns = 1_000_000,
|
|
345
|
+
.nonblank = true,
|
|
346
|
+
} });
|
|
347
|
+
var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
|
|
348
|
+
var settings_id: support.platform.WindowId = 0;
|
|
349
|
+
for (harness.runtime.listWindows(&buffer)) |info| {
|
|
350
|
+
if (std.mem.eql(u8, info.label, settings_window_label)) settings_id = info.id;
|
|
351
|
+
}
|
|
352
|
+
try std.testing.expect(settings_id != 0);
|
|
353
|
+
|
|
354
|
+
// The settings window installs on a 2x monitor: ITS stored tokens
|
|
355
|
+
// carry 2 while the main canvas keeps 1 — the scale is per-window
|
|
356
|
+
// state, the appearance is still the app's single set.
|
|
357
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
358
|
+
.window_id = settings_id,
|
|
359
|
+
.label = settings_canvas_label,
|
|
360
|
+
.size = geometry.SizeF.init(320, 240),
|
|
361
|
+
.scale_factor = 2,
|
|
362
|
+
.frame_index = 1,
|
|
363
|
+
.timestamp_ns = 2_000_000,
|
|
364
|
+
.nonblank = true,
|
|
365
|
+
} });
|
|
366
|
+
const main_stored = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
367
|
+
try std.testing.expectEqual(@as(f32, 1), main_stored.pixel_snap.scale);
|
|
368
|
+
var slot_stored = try harness.runtime.canvasWidgetDesignTokens(settings_id, settings_canvas_label);
|
|
369
|
+
try std.testing.expectEqual(@as(f32, 2), slot_stored.pixel_snap.scale);
|
|
370
|
+
try std.testing.expectEqualDeep(static_tokens.colors.background, slot_stored.colors.background);
|
|
371
|
+
|
|
372
|
+
// Dragging the SECONDARY window to a 1x monitor re-stamps only its
|
|
373
|
+
// own tokens. The model is poked directly (no dispatch) so the
|
|
374
|
+
// refreshed slot text proves the frame triggered the slot rebuild.
|
|
375
|
+
app_state.model.bumps = 3;
|
|
376
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
377
|
+
.window_id = settings_id,
|
|
378
|
+
.label = settings_canvas_label,
|
|
379
|
+
.size = geometry.SizeF.init(320, 240),
|
|
380
|
+
.scale_factor = 1,
|
|
381
|
+
.frame_index = 2,
|
|
382
|
+
.timestamp_ns = 3_000_000,
|
|
383
|
+
.nonblank = true,
|
|
384
|
+
} });
|
|
385
|
+
const rebuilt = try harness.runtime.canvasWidgetLayout(settings_id, settings_canvas_label);
|
|
386
|
+
try std.testing.expect(widgetIdByText(rebuilt, .text, "bumped 3") != null);
|
|
387
|
+
slot_stored = try harness.runtime.canvasWidgetDesignTokens(settings_id, settings_canvas_label);
|
|
388
|
+
try std.testing.expectEqual(@as(f32, 1), slot_stored.pixel_snap.scale);
|
|
389
|
+
|
|
390
|
+
// A density-carrying RESIZE (the DPI-change channel on hosts that
|
|
391
|
+
// rescale the frame in place) re-stamps the slot's tokens too, even
|
|
392
|
+
// at an unchanged logical size.
|
|
393
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_resized = .{
|
|
394
|
+
.window_id = settings_id,
|
|
395
|
+
.label = settings_canvas_label,
|
|
396
|
+
.frame = geometry.RectF.init(0, 0, 320, 240),
|
|
397
|
+
.scale_factor = 2,
|
|
398
|
+
} });
|
|
399
|
+
slot_stored = try harness.runtime.canvasWidgetDesignTokens(settings_id, settings_canvas_label);
|
|
400
|
+
try std.testing.expectEqual(@as(f32, 2), slot_stored.pixel_snap.scale);
|
|
401
|
+
const main_after = try harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
|
|
402
|
+
try std.testing.expectEqual(@as(f32, 1), main_after.pixel_snap.scale);
|
|
403
|
+
}
|
|
404
|
+
|
|
312
405
|
// ------------------------------------------------- window-action effects
|
|
313
406
|
|
|
314
407
|
const VerbModel = struct {
|
package/src/tooling/package.zig
CHANGED
|
@@ -2,6 +2,7 @@ const std = @import("std");
|
|
|
2
2
|
const android_tool = @import("android.zig");
|
|
3
3
|
const app_icon_tool = @import("app_icon");
|
|
4
4
|
const assets_tool = @import("assets.zig");
|
|
5
|
+
const buildgraph = @import("buildgraph.zig");
|
|
5
6
|
const cef = @import("cef.zig");
|
|
6
7
|
const codesign = @import("codesign.zig");
|
|
7
8
|
const diagnostics = @import("diagnostics");
|
|
@@ -212,6 +213,11 @@ fn createDesktopArtifact(allocator: std.mem.Allocator, io: std.Io, options: Pack
|
|
|
212
213
|
const binary_subpath = try std.fmt.allocPrint(allocator, "bin/{s}", .{executable_name});
|
|
213
214
|
defer allocator.free(binary_subpath);
|
|
214
215
|
try copyFileToDir(allocator, io, dir, binary_path, binary_subpath);
|
|
216
|
+
if (options.target == .windows and options.web_engine == .system) {
|
|
217
|
+
try copyWindowsWebView2Loader(allocator, io, dir, options, binary_path);
|
|
218
|
+
}
|
|
219
|
+
} else if (options.target == .windows and options.web_engine == .system) {
|
|
220
|
+
try writeFile(dir, io, "bin/README.txt", "Build the app binary separately and place it here for this target, together with the WebView2Loader.dll for its architecture (vendored in the SDK under third_party/webview2/).\n");
|
|
215
221
|
} else {
|
|
216
222
|
try writeFile(dir, io, "bin/README.txt", "Build the app binary separately and place it here for this target.\n");
|
|
217
223
|
}
|
|
@@ -934,6 +940,45 @@ fn zonStringAlloc(allocator: std.mem.Allocator, value: []const u8) ![]const u8 {
|
|
|
934
940
|
return out.toOwnedSlice(allocator);
|
|
935
941
|
}
|
|
936
942
|
|
|
943
|
+
/// The Windows system engine discovers the machine's WebView2 runtime
|
|
944
|
+
/// through WebView2Loader.dll, which the host loads from the executable's
|
|
945
|
+
/// directory — the vendored copy ships inside every packaged app. The
|
|
946
|
+
/// architecture comes from the packaged binary's PE header so an arm64
|
|
947
|
+
/// build gets the arm64 loader.
|
|
948
|
+
fn copyWindowsWebView2Loader(allocator: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, options: PackageOptions, binary_path: []const u8) !void {
|
|
949
|
+
const framework_root = blk: {
|
|
950
|
+
if (options.env_map) |env_map| {
|
|
951
|
+
if (try buildgraph.resolveFrameworkRoot(allocator, io, env_map)) |root| break :blk root;
|
|
952
|
+
} else if (try buildgraph.frameworkRootFromExecutable(allocator, io)) |root| {
|
|
953
|
+
break :blk root;
|
|
954
|
+
}
|
|
955
|
+
return error.MissingFramework;
|
|
956
|
+
};
|
|
957
|
+
defer allocator.free(framework_root);
|
|
958
|
+
const arch_dir: []const u8 = if (try peExecutableIsArm64(io, binary_path)) "arm64" else "x64";
|
|
959
|
+
const loader_path = try std.fs.path.join(allocator, &.{ framework_root, "third_party", "webview2", arch_dir, "WebView2Loader.dll" });
|
|
960
|
+
defer allocator.free(loader_path);
|
|
961
|
+
try copyFileToDir(allocator, io, dir, loader_path, "bin/WebView2Loader.dll");
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/// Whether a PE executable targets arm64, read from the COFF machine
|
|
965
|
+
/// field. Anything unrecognized falls back to x64, the default Windows
|
|
966
|
+
/// build target.
|
|
967
|
+
fn peExecutableIsArm64(io: std.Io, path: []const u8) !bool {
|
|
968
|
+
var file = try std.Io.Dir.cwd().openFile(io, path, .{});
|
|
969
|
+
defer file.close(io);
|
|
970
|
+
var read_buffer: [4096]u8 = undefined;
|
|
971
|
+
var reader = file.reader(io, &read_buffer);
|
|
972
|
+
var header: [4096]u8 = undefined;
|
|
973
|
+
const len = try reader.interface.readSliceShort(&header);
|
|
974
|
+
if (len < 0x40 or header[0] != 'M' or header[1] != 'Z') return false;
|
|
975
|
+
const pe_offset: usize = std.mem.readInt(u32, header[0x3c..0x40], .little);
|
|
976
|
+
if (pe_offset + 6 > len) return false;
|
|
977
|
+
if (!std.mem.eql(u8, header[pe_offset..][0..4], "PE\x00\x00")) return false;
|
|
978
|
+
const machine = std.mem.readInt(u16, header[pe_offset + 4 ..][0..2], .little);
|
|
979
|
+
return machine == 0xaa64;
|
|
980
|
+
}
|
|
981
|
+
|
|
937
982
|
fn copyFileToDir(allocator: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, source_path: []const u8, dest_subpath: []const u8) !void {
|
|
938
983
|
_ = allocator;
|
|
939
984
|
try std.Io.Dir.copyFile(std.Io.Dir.cwd(), source_path, dir, dest_subpath, io, .{ .make_path = true, .replace = true });
|
|
@@ -944,11 +944,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
944
944
|
\\ const run = b.addRunArtifact(exe);
|
|
945
945
|
\\ run.step.dependOn(&frontend_build.step);
|
|
946
946
|
\\ addCefRuntimeRunFiles(b, target, run, exe, web_engine, cef_dir);
|
|
947
|
+
\\ addWebView2RuntimeRunFiles(b, target, run, web_engine, native_sdk_path);
|
|
947
948
|
\\ const run_step = b.step("run", "Run the app");
|
|
948
949
|
\\ run_step.dependOn(&run.step);
|
|
949
950
|
\\
|
|
950
951
|
\\ const dev = b.addSystemCommand(&.{ "native", "dev", "--manifest", "app.zon", "--binary" });
|
|
951
952
|
\\ dev.addFileArg(exe.getEmittedBin());
|
|
953
|
+
\\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path);
|
|
952
954
|
\\ dev.step.dependOn(&exe.step);
|
|
953
955
|
\\ dev.step.dependOn(&frontend_install.step);
|
|
954
956
|
\\ const dev_step = b.step("dev", "Run the frontend dev server and native shell");
|
|
@@ -972,6 +974,11 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
972
974
|
\\ b.fmt("zig-out/package/{s}-0.1.0-{s}-{s}{s}", .{ app_exe_name, @tagName(package_target), optimize_name, packageSuffix(package_target) }),
|
|
973
975
|
\\ "--binary",
|
|
974
976
|
\\ });
|
|
977
|
+
\\ // The CLI resolves SDK-owned package inputs (the vendored WebView2
|
|
978
|
+
\\ // loader) from the framework root; a PATH-resolved `native` could
|
|
979
|
+
\\ // belong to a different checkout than the one this build compiled
|
|
980
|
+
\\ // against, so hand the same root over explicitly.
|
|
981
|
+
\\ package.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot(native_sdk_path));
|
|
975
982
|
\\ package.addFileArg(exe.getEmittedBin());
|
|
976
983
|
\\ package.addArgs(&.{ "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
|
|
977
984
|
\\ if (cef_auto_install) package.addArg("--cef-auto-install");
|
|
@@ -1139,7 +1146,19 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1139
1146
|
\\ if (web_engine == .chromium) app_mod.linkSystemLibrary("stdc++", .{});
|
|
1140
1147
|
\\ } else if (platform == .windows) {
|
|
1141
1148
|
\\ switch (web_engine) {
|
|
1142
|
-
\\ .system =>
|
|
1149
|
+
\\ .system => {
|
|
1150
|
+
\\ // The vendored WebView2 SDK header (third_party/webview2)
|
|
1151
|
+
\\ // turns on the host's embedded-WebView layer; the host
|
|
1152
|
+
\\ // fails the compile by design if it cannot be found.
|
|
1153
|
+
\\ app_mod.addIncludePath(nativeSdkPath(b, native_sdk_path, "third_party/webview2/include"));
|
|
1154
|
+
\\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17" } });
|
|
1155
|
+
\\ // WebView2Loader.dll rides next to the installed app
|
|
1156
|
+
\\ // executable: the host loads it at runtime to discover
|
|
1157
|
+
\\ // the machine's WebView2 runtime. Canvas apps never
|
|
1158
|
+
\\ // touch it.
|
|
1159
|
+
\\ const loader = b.addInstallBinFile(nativeSdkPath(b, native_sdk_path, webView2LoaderSubPath(target)), "WebView2Loader.dll");
|
|
1160
|
+
\\ b.getInstallStep().dependOn(&loader.step);
|
|
1161
|
+
\\ },
|
|
1143
1162
|
\\ .chromium => {
|
|
1144
1163
|
\\ const cef_check = addCefCheck(b, target, cef_dir);
|
|
1145
1164
|
\\ if (cef_auto_install) {
|
|
@@ -1172,6 +1191,26 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1172
1191
|
\\ }
|
|
1173
1192
|
\\}
|
|
1174
1193
|
\\
|
|
1194
|
+
\\/// The vendored WebView2Loader.dll for the target architecture, relative
|
|
1195
|
+
\\/// to the framework root.
|
|
1196
|
+
\\fn webView2LoaderSubPath(target: std.Build.ResolvedTarget) []const u8 {
|
|
1197
|
+
\\ return if (target.result.cpu.arch == .aarch64)
|
|
1198
|
+
\\ "third_party/webview2/arm64/WebView2Loader.dll"
|
|
1199
|
+
\\ else
|
|
1200
|
+
\\ "third_party/webview2/x64/WebView2Loader.dll";
|
|
1201
|
+
\\}
|
|
1202
|
+
\\
|
|
1203
|
+
\\/// `zig build run` and `zig build dev` execute the cached artifact, which
|
|
1204
|
+
\\/// has no installed WebView2Loader.dll beside it; the vendored loader's
|
|
1205
|
+
\\/// directory goes on the step's PATH so the host's LoadLibrary resolves it
|
|
1206
|
+
\\/// (`native dev` passes its environment on to the app it spawns).
|
|
1207
|
+
\\fn addWebView2RuntimeRunFiles(b: *std.Build, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, web_engine: WebEngineOption, native_sdk_path: []const u8) void {
|
|
1208
|
+
\\ if (web_engine != .system) return;
|
|
1209
|
+
\\ if (target.result.os.tag != .windows) return;
|
|
1210
|
+
\\ const loader_dir = std.fs.path.dirname(webView2LoaderSubPath(target)).?;
|
|
1211
|
+
\\ run.addPathDir(b.pathFromRoot(b.pathJoin(&.{ native_sdk_path, loader_dir })));
|
|
1212
|
+
\\}
|
|
1213
|
+
\\
|
|
1175
1214
|
\\fn addCefRuntimeRunFiles(b: *std.Build, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, exe: *std.Build.Step.Compile, web_engine: WebEngineOption, cef_dir: []const u8) void {
|
|
1176
1215
|
\\ if (web_engine != .chromium) return;
|
|
1177
1216
|
\\ if (target.result.os.tag != .macos) return;
|
|
@@ -2835,6 +2874,8 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
2835
2874
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.step.dependOn(&frontend_install.step)") != null);
|
|
2836
2875
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"native\", \"dev\"") != null);
|
|
2837
2876
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "dev.step.dependOn(&frontend_install.step)") != null);
|
|
2877
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path)") != null);
|
|
2878
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.setEnvironmentVariable(\"NATIVE_SDK_PATH\", b.pathFromRoot(native_sdk_path))") != null);
|
|
2838
2879
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "chromium") != null);
|
|
2839
2880
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "cef-dir") != null);
|
|
2840
2881
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "src/platform/macos/cef_host.mm") != null);
|