Skip to content

Commit f7a32cc

Browse files
committed
Split RPC files and add docs
1 parent 1cb64c2 commit f7a32cc

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

build.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ pub fn build(b: *Build) void {
145145
const minify_embedded_js = b.option(bool, "minify-embedded-js", "Minify embedded JS helpers with pure Zig asset processing (default: true)") orelse true;
146146
const minify_written_js = b.option(bool, "minify-written-js", "Minify written JS helper assets with pure Zig asset processing (default: false)") orelse false;
147147
const selected_example = b.option(ExampleChoice, "example", "Example to run with `zig build run` (default: all)") orelse .all;
148-
const run_mode = b.option([]const u8, "run-mode", "Runtime launch order for examples. Presets: `webview`, `browser` (app-window), `web-tab`, `web-url`. Or ordered tokens (`webview,browser,web-url`, `browser,webview`, etc). Default: webview,browser,web-url") orelse "webview,browser,web-url";
148+
const run_mode_option = b.option([]const u8, "run-mode", "Runtime launch order for examples. Presets: `webview`, `browser` (app-window), `web-tab`, `web-url`. Or ordered tokens (`webview,browser,web-url`, `browser,webview`, etc). Default: webview,browser,web-url");
149+
const run_mode = run_mode_option orelse "webview,browser,web-url";
150+
const run_mode_explicit = run_mode_option != null;
149151
const linux_webview_target = b.option([]const u8, "linux-webview-target", "Linux native webview runtime target for examples: `webview` (WebKit2GTK 4.1/4.0, default) or `webkitgtk-6`") orelse "webview";
150152
if (!isValidRunMode(run_mode)) {
151153
@panic("invalid -Drun-mode value: use `webview`, `browser`, `web-tab`, `web-url`, or an ordered comma-separated combination");
@@ -161,6 +163,7 @@ pub fn build(b: *Build) void {
161163
build_opts.addOption(bool, "enable_tls", enable_tls);
162164
build_opts.addOption(bool, "enable_webui_log", enable_webui_log);
163165
build_opts.addOption([]const u8, "run_mode", run_mode);
166+
build_opts.addOption(bool, "run_mode_explicit", run_mode_explicit);
164167
build_opts.addOption([]const u8, "linux_webview_target", linux_webview_target);
165168
build_opts.addOption([]const u8, "runtime_helpers_embed_path", runtime_helpers_assets.embed_path);
166169
build_opts.addOption([]const u8, "runtime_helpers_written_path", runtime_helpers_assets.written_path);

examples/shared/demo_runner.zig

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ fn parseRunModeSpec(mode: []const u8) RunModeSpec {
165165
};
166166
}
167167

168+
fn effectiveRunModeSpec(run_mode: []const u8, run_mode_explicit: bool, darling_runtime: bool) RunModeSpec {
169+
if (darling_runtime and !run_mode_explicit) {
170+
return parseRunModeSpec("web-tab");
171+
}
172+
return parseRunModeSpec(run_mode);
173+
}
174+
168175
fn surfaceName(surface: webui.LaunchSurface) []const u8 {
169176
return switch (surface) {
170177
.native_webview => "native webview",
@@ -179,7 +186,11 @@ pub fn runExample(comptime kind: ExampleKind, comptime RpcMethods: type) !void {
179186

180187
const allocator = gpa.allocator();
181188
const app_options = appOptionsFor(kind);
182-
const run_mode_spec = parseRunModeSpec(webui.BuildFlags.run_mode);
189+
const run_mode_spec = effectiveRunModeSpec(
190+
webui.BuildFlags.run_mode,
191+
webui.BuildFlags.run_mode_explicit,
192+
webui.isDarlingRuntime(),
193+
);
183194

184195
var service = try webui.Service.init(allocator, RpcMethods, .{
185196
.app = app_options,
@@ -352,8 +363,11 @@ fn tagFor(comptime kind: ExampleKind) []const u8 {
352363
}
353364

354365
fn appOptionsFor(comptime kind: ExampleKind) webui.AppOptions {
355-
const run_mode = webui.BuildFlags.run_mode;
356-
const run_mode_spec = parseRunModeSpec(run_mode);
366+
const run_mode_spec = effectiveRunModeSpec(
367+
webui.BuildFlags.run_mode,
368+
webui.BuildFlags.run_mode_explicit,
369+
webui.isDarlingRuntime(),
370+
);
357371
const launch_policy = run_mode_spec.launch_policy;
358372
const launch_pref = run_mode_spec.browser_launch_preference;
359373
const native_first = launch_policy.first == .native_webview;
@@ -404,6 +418,18 @@ test "run-mode browser launch preference parser supports web-tab" {
404418
try std.testing.expectEqual(BrowserLaunchPreference.auto, parseRunModeSpec("web-url").browser_launch_preference);
405419
}
406420

421+
test "darling default example mode switches to web-tab when run-mode was not explicit" {
422+
const spec = effectiveRunModeSpec("webview,browser,web-url", false, true);
423+
try std.testing.expectEqual(BrowserLaunchPreference.web_tab, spec.browser_launch_preference);
424+
try std.testing.expectEqual(@as(webui.LaunchSurface, .web_url), spec.launch_policy.first);
425+
}
426+
427+
test "explicit run-mode wins over darling default override" {
428+
const spec = effectiveRunModeSpec("webview", true, true);
429+
try std.testing.expectEqual(BrowserLaunchPreference.auto, spec.browser_launch_preference);
430+
try std.testing.expectEqual(@as(webui.LaunchSurface, .native_webview), spec.launch_policy.first);
431+
}
432+
407433
test "web-tab auto-open intent survives mixed fallback run-modes" {
408434
try std.testing.expect(shouldAutoOpenTab(parseRunModeSpec("web-tab")));
409435
try std.testing.expect(shouldAutoOpenTab(parseRunModeSpec("webview,web-tab,web-url")));

src/root.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const std = @import("std");
22

33
const bridge_runtime_helpers = @import("bridge/runtime_helpers.zig");
44
const core_runtime = @import("ported/webui.zig");
5+
const runtime_env = @import("ported/runtime_env.zig");
56
const civetweb = @import("network/civetweb.zig");
67
const tls_runtime = @import("network/tls_runtime.zig");
78
const api_types = @import("root/api_types.zig");
@@ -52,6 +53,11 @@ pub fn defaultWebviewProfilePath(allocator: std.mem.Allocator) ![]u8 {
5253
return core_runtime.defaultWebviewProfilePath(allocator);
5354
}
5455

56+
/// Returns whether a macOS-targeted binary is currently running under Darling.
57+
pub fn isDarlingRuntime() bool {
58+
return runtime_env.isDarlingRuntime();
59+
}
60+
5561
pub const Size = window_style_types.Size;
5662
pub const Point = window_style_types.Point;
5763
pub const WindowIcon = window_style_types.WindowIcon;

src/root/api_types.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub const BuildFlags = struct {
1212
pub const enable_tls = build_options.enable_tls;
1313
pub const enable_webui_log = build_options.enable_webui_log;
1414
pub const run_mode = build_options.run_mode;
15+
pub const run_mode_explicit = build_options.run_mode_explicit;
1516
pub const linux_webview_target = build_options.linux_webview_target;
1617
};
1718

0 commit comments

Comments
 (0)