@@ -179,6 +179,7 @@ pub fn runExample(comptime kind: ExampleKind, comptime RpcMethods: type) !void {
179179
180180 const allocator = gpa .allocator ();
181181 const app_options = appOptionsFor (kind );
182+ const run_mode_spec = parseRunModeSpec (webui .BuildFlags .run_mode );
182183
183184 var service = try webui .Service .init (allocator , RpcMethods , .{
184185 .app = app_options ,
@@ -205,6 +206,11 @@ pub fn runExample(comptime kind: ExampleKind, comptime RpcMethods: type) !void {
205206
206207 try service .showHtml (html );
207208 try service .run ();
209+ if (shouldAutoOpenTab (run_mode_spec )) {
210+ service .openInBrowserWithOptions (app_options .browser_launch ) catch | err | {
211+ std .debug .print ("[{s}] web-tab launch failed: {s}\n " , .{ tagFor (kind ), @errorName (err ) });
212+ };
213+ }
208214
209215 const has_frontend_rpc_demo = kind == .call_js_from_zig or kind == .call_js_oop or kind == .bidirectional_rpc ;
210216 // Keep backend->frontend RPC examples explicit here so future refactors do not
@@ -270,6 +276,13 @@ pub fn runExample(comptime kind: ExampleKind, comptime RpcMethods: type) !void {
270276 service .shutdown ();
271277}
272278
279+ fn shouldAutoOpenTab (spec : RunModeSpec ) bool {
280+ return spec .launch_policy .first == .web_url and
281+ spec .launch_policy .second == null and
282+ spec .launch_policy .third == null and
283+ spec .browser_launch_preference == .web_tab ;
284+ }
285+
273286fn onEventLog (_ : ? * anyopaque , event : * const webui.Event ) void {
274287 std .debug .print ("[event][window={d}] kind={s} name={s} payload={s}\n " , .{ event .window_id , @tagName (event .kind ), event .name , event .payload });
275288}
0 commit comments