Skip to content

Commit 81d56a2

Browse files
committed
Add window shown state query
1 parent 9c46b43 commit 81d56a2

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The current phase provides:
1616
- targeted runtime content replacement through `Client.show()`;
1717
- explicit browser connection waiting and timeout through
1818
`Window.waitForConnection()`;
19+
- window connected/shown state through `Window.isShown()`;
1920
- JavaScript calls to Zig bindings with return values;
2021
- typed integer, float, and boolean call arguments and replies;
2122
- owned one-shot delayed binding replies through `Call.deferReply()`;

docs/PURE_ZIG_REFACTOR.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ implementations.
295295

296296
| Upstream API | Current gap |
297297
|---|---|
298-
| `webui_is_shown()` | There is no window-level connected/shown query. |
299298
| `webui_set_config(folder_monitor)` | Directory change monitoring and automatic browser reload are not implemented. |
300299
| `webui_set_default_root_folder()` | There is no application-wide default directory content setting. |
301300
| `webui_set_icon()`, `webui_set_icon_file()` | Window icon configuration is not implemented. |
@@ -331,6 +330,7 @@ not implementation gaps:
331330
| `webui_new_window()`, `webui_new_window_id()`, `webui_get_new_window_id()` | `App.createWindow()` and application-owned IDs. |
332331
| `webui_show()`, `webui_start_server()`, `webui_get_url()` | Initial `Content`, runtime `Window.setContent()`, `App.start()`, `Window.open()`, and `Window.url()`. |
333332
| `webui_show_client()` | `Client.show()` replaces the window content and navigates only the selected client. |
333+
| `webui_is_shown()` | `Window.isShown()` reports whether the window has at least one connected browser client. |
334334
| `webui_wait()`, `webui_wait_async()` | `Running.wait()` used directly or through `std.Io` concurrency. |
335335
| `webui_close()`, `webui_destroy()`, `webui_exit()`, `webui_clean()` | `Window.close()`, `Running.stop()`, and `App.deinit()`. |
336336
| `webui_set_context()`, `webui_get_context()` | Binding and event-handler `user_data`. |
@@ -389,7 +389,6 @@ connection waiting, and caller-provided logging.
389389

390390
### Dynamic content and client state
391391

392-
- Add a window connected/shown query.
393392
- Add an application default directory.
394393
- Add inline and file-backed window icons.
395394

@@ -484,5 +483,4 @@ zig build -Dtarget=aarch64-macos
484483

485484
Continue capability parity:
486485

487-
1. Add a window connected/shown query.
488-
2. Add an application default directory and window icons.
486+
1. Add an application default directory and window icons.

src/app.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,11 @@ pub const Window = struct {
13181318
try browser.open(self.state.gpa, io, page_url);
13191319
}
13201320

1321+
/// Return whether at least one browser client is connected.
1322+
pub fn isShown(self: Window, io: std.Io) bool {
1323+
return self.state.hasClients(io);
1324+
}
1325+
13211326
/// Wait for at least one browser connection and return the first client.
13221327
pub fn waitForConnection(
13231328
self: Window,
@@ -2790,6 +2795,7 @@ test "window connection waiting observes clients and timeouts" {
27902795
const window = try app.createWindow(.{
27912796
.content = .{ .html = "connection wait test" },
27922797
});
2798+
try std.testing.expect(!window.isShown(io));
27932799
var running = try app.start(io);
27942800
defer running.stop() catch {};
27952801

@@ -2821,6 +2827,7 @@ test "window connection waiting observes clients and timeouts" {
28212827
));
28222828

28232829
const delayed = try waiting.await(io);
2830+
try std.testing.expect(window.isShown(io));
28242831
try std.testing.expect(delayed.isConnected(io));
28252832
const immediate = try window.waitForConnection(io, .zero);
28262833
try std.testing.expectEqual(delayed.id(), immediate.id());
@@ -2831,6 +2838,7 @@ test "window connection waiting observes clients and timeouts" {
28312838
try std.Io.sleep(io, .fromMilliseconds(1), .awake);
28322839
}
28332840
try std.testing.expect(!delayed.isConnected(io));
2841+
try std.testing.expect(!window.isShown(io));
28342842
try std.testing.expectError(
28352843
error.Timeout,
28362844
window.waitForConnection(io, .fromMilliseconds(5)),
@@ -3654,6 +3662,7 @@ test "multi-client limits, targeting, and disconnect lifecycle" {
36543662
try window.bind("greet", integrationHandler, &called_client_id);
36553663
var running = try app.start(io);
36563664
defer running.stop() catch {};
3665+
try std.testing.expect(!window.isShown(io));
36573666

36583667
const first_stream = try connectTestWebSocket(
36593668
running.inner.address,
@@ -3670,6 +3679,7 @@ test "multi-client limits, targeting, and disconnect lifecycle" {
36703679
&window.state.capability,
36713680
&first_response,
36723681
));
3682+
try std.testing.expect(window.isShown(io));
36733683

36743684
var packet: std.ArrayList(u8) = .empty;
36753685
defer packet.deinit(gpa);
@@ -3705,6 +3715,7 @@ test "multi-client limits, targeting, and disconnect lifecycle" {
37053715
&window.state.capability,
37063716
&second_response,
37073717
));
3718+
try std.testing.expect(window.isShown(io));
37083719
packet.clearRetainingCapacity();
37093720
try protocol.append(&packet, gpa, .{
37103721
.token = window.state.token,
@@ -4074,6 +4085,7 @@ test "multi-client limits, targeting, and disconnect lifecycle" {
40744085
}
40754086
try std.testing.expect(first_disconnected);
40764087
try std.testing.expect(second.isConnected(io));
4088+
try std.testing.expect(window.isShown(io));
40774089
try std.testing.expect(!app.closed.load(.acquire));
40784090
try std.testing.expectError(error.ConnectionClosed, first_eval.await(io));
40794091
try std.testing.expectError(
@@ -4115,4 +4127,5 @@ test "multi-client limits, targeting, and disconnect lifecycle" {
41154127
try std.testing.expectEqual(protocol.Command.close, second_close.header.command);
41164128
try second_stream.shutdown(io, .both);
41174129
try running.wait();
4130+
try std.testing.expect(!window.isShown(io));
41184131
}

0 commit comments

Comments
 (0)