Skip to content

Commit 25e8142

Browse files
authored
feat(public_network_access): improve public window link display and set custom port (#100)
- 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
1 parent 193acda commit 25e8142

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

examples/public_network_access/main.zig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,23 @@ fn public_window_events(e: *webui.Event) void {
2626

2727
fn private_window_events(e: *webui.Event) void {
2828
if (e.event_type == .EVENT_CONNECTED) {
29+
30+
// get the public window URL and port
31+
const public_win_port = public_window.getPort() catch unreachable;
2932
const public_win_url: [:0]const u8 = public_window.getUrl() catch return;
33+
3034
var buf = std.mem.zeroes([1024]u8);
31-
const js = std.fmt.bufPrintZ(&buf, "document.getElementById('urlSpan').innerHTML = '{s}';", .{public_win_url}) catch unreachable;
32-
private_window.run(js);
35+
const js_1 = std.fmt.bufPrintZ(&buf, "document.getElementById('urlSpan1').innerHTML = 'http://localhost:{}';", .{public_win_port}) catch unreachable;
36+
private_window.run(js_1);
37+
const js_2 = std.fmt.bufPrintZ(&buf, "document.getElementById('urlSpan2').innerHTML = '{s}';", .{public_win_url}) catch unreachable;
38+
private_window.run(js_2);
3339
}
3440
}
3541

3642
pub fn main() !void {
3743
// Create windows
3844
private_window = webui.newWindow();
39-
public_window = webui.newWindow();
45+
public_window = webui.newWindow();
4046

4147
// App
4248
webui.setTimeout(0); // Wait forever (never timeout)
@@ -48,6 +54,8 @@ pub fn main() !void {
4854
// Bind all events
4955
_ = try public_window.bind("", public_window_events);
5056

57+
_ = try public_window.setPort(9090); // Set port for public access
58+
5159
// Set public window HTML
5260
try public_window.showBrowser(public_html, .NoBrowser);
5361

examples/public_network_access/private.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="UTF-8" />
5-
<script src="/webui.js"></script>
5+
<script src="webui.js"></script>
66
<title>Public Network Access Example</title>
77
<style>
88
body {
@@ -42,13 +42,14 @@
4242
<body>
4343
<h1>WebUI - Public Network Access Example</h1>
4444
<br />
45-
The second public window is configured to be accessible from <br />
46-
any device in the public network. <br />
45+
The public window is configured to be accessible from <br>
46+
any device in the network. <br>
4747
<br />
48-
Second public window link: <br />
49-
<h1 id="urlSpan" style="color: #c9913d">...</h1>
50-
Second public window events: <br />
51-
<textarea id="Logs" rows="4" cols="50" style="width: 80%"></textarea>
48+
Public window links: <br>
49+
<h1 id="urlSpan1" style="color:#c9913d">...</h1>
50+
<h1 id="urlSpan2" style="color:#c9913d">...</h1>
51+
Public window events: <br>
52+
<textarea id="Logs" rows="4" cols="50" style="width:60%"></textarea>
5253
<br />
5354
<button id="Exit">Exit</button>
5455
</body>

examples/public_network_access/public.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="UTF-8" />
5-
<script src="/webui.js"></script>
5+
<script src="webui.js"></script>
66
<title>Welcome to Public UI</title>
77
</head>
88
<body>

0 commit comments

Comments
 (0)