From fd834d125cd7039b609720c6d21e160a5b526d2d Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Sun, 22 Jun 2025 01:16:16 +0800 Subject: [PATCH] feat(public_network_access): improve public window link display and set custom port - set public window port to 9090 for network access - display both localhost and full URL in private window - update private.html to show two URL spans for public window - fix script src path in private.html and public.html --- examples/public_network_access/main.zig | 14 +++++++++++--- examples/public_network_access/private.html | 15 ++++++++------- examples/public_network_access/public.html | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/examples/public_network_access/main.zig b/examples/public_network_access/main.zig index f734626..f538c3b 100644 --- a/examples/public_network_access/main.zig +++ b/examples/public_network_access/main.zig @@ -26,17 +26,23 @@ fn public_window_events(e: *webui.Event) void { fn private_window_events(e: *webui.Event) void { if (e.event_type == .EVENT_CONNECTED) { + + // get the public window URL and port + const public_win_port = public_window.getPort() catch unreachable; const public_win_url: [:0]const u8 = public_window.getUrl() catch return; + var buf = std.mem.zeroes([1024]u8); - const js = std.fmt.bufPrintZ(&buf, "document.getElementById('urlSpan').innerHTML = '{s}';", .{public_win_url}) catch unreachable; - private_window.run(js); + const js_1 = std.fmt.bufPrintZ(&buf, "document.getElementById('urlSpan1').innerHTML = 'http://localhost:{}';", .{public_win_port}) catch unreachable; + private_window.run(js_1); + const js_2 = std.fmt.bufPrintZ(&buf, "document.getElementById('urlSpan2').innerHTML = '{s}';", .{public_win_url}) catch unreachable; + private_window.run(js_2); } } pub fn main() !void { // Create windows private_window = webui.newWindow(); - public_window = webui.newWindow(); + public_window = webui.newWindow(); // App webui.setTimeout(0); // Wait forever (never timeout) @@ -48,6 +54,8 @@ pub fn main() !void { // Bind all events _ = try public_window.bind("", public_window_events); + _ = try public_window.setPort(9090); // Set port for public access + // Set public window HTML try public_window.showBrowser(public_html, .NoBrowser); diff --git a/examples/public_network_access/private.html b/examples/public_network_access/private.html index ad814b0..410daa3 100644 --- a/examples/public_network_access/private.html +++ b/examples/public_network_access/private.html @@ -2,7 +2,7 @@ - + Public Network Access Example