Skip to content

Commit e9e6551

Browse files
committed
Add runtime content replacement
1 parent 4673098 commit e9e6551

3 files changed

Lines changed: 236 additions & 35 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The current phase provides:
1111
- one `App`, multiple isolated windows, and automatic port selection;
1212
- embedded HTML, static directories, custom resources, external URLs, and a
1313
built-in JavaScript bridge;
14+
- runtime content and resource-handler replacement through
15+
`Window.setContent()`;
1416
- explicit browser connection waiting and timeout through
1517
`Window.waitForConnection()`;
1618
- JavaScript calls to Zig bindings with return values;
@@ -109,6 +111,11 @@ Serve a directory by setting
109111
app starts and closed when it stops. Custom resources receive `webui.Request`
110112
and `webui.Response` directly.
111113

114+
`Window.setContent(&running, content)` prepares and installs new content, then
115+
navigates every connected client to it and returns the number notified. An
116+
invalid replacement leaves the current content unchanged. If client
117+
notification fails, the prepared replacement remains installed.
118+
112119
`Window.onEvent` installs one handler for browser lifecycle, click, and
113120
navigation events. `Event.data` contains the element ID for clicks, the target
114121
URL for navigation, and is empty for connected or disconnected events.

docs/PURE_ZIG_REFACTOR.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ protocol input never panics.
269269
| Old API | New direction |
270270
|---|---|
271271
| `webui.newWindow()` | `app.createWindow(options)` |
272-
| `window.show(content)` | Set content at creation, then call `window.open()` |
272+
| `window.show(content)` | Set initial content and call `window.open()`; use `window.setContent()` while running. |
273273
| `window.bind()` / `binding()` | `window.bind(name, handler, user_data)` |
274274
| `Event.get*At()` | `Call.string/int/float/bool/bytes(index)` |
275275
| `Event.return*()` | `Call.reply*()` |
276276
| `window.run()` | `Window.eval()` |
277277
| `Event.runClient()` | `Call.client.eval()` |
278-
| `setRootFolder()` | `.content = .{ .directory = dir }` |
278+
| `setRootFolder()` | Initial `.directory` content or runtime `Window.setContent()`. |
279279
| Global `setConfig()` | `App.Options` or `Window.Options` |
280280
| `wait()` / `clean()` | `Running.wait()` / `App.deinit()` |
281281
| `malloc/free/memcpy/encode/decode` | Zig allocators and standard library |
@@ -295,7 +295,6 @@ implementations.
295295

296296
| Upstream API | Current gap |
297297
|---|---|
298-
| `webui_show()`, `webui_set_root_folder()`, `webui_set_file_handler()`, `webui_set_file_handler_window()` | Content and resource handling can only be selected when creating a window; replacing them at runtime is not implemented. |
299298
| `webui_show_client()` | `Client` cannot replace the content of only one connected browser. |
300299
| `webui_is_shown()` | There is no window-level connected/shown query. |
301300
| `webui_set_config(folder_monitor)` | Directory change monitoring and automatic browser reload are not implemented. |
@@ -331,7 +330,7 @@ not implementation gaps:
331330
| Upstream API | Zig replacement |
332331
|---|---|
333332
| `webui_new_window()`, `webui_new_window_id()`, `webui_get_new_window_id()` | `App.createWindow()` and application-owned IDs. |
334-
| `webui_show()`, `webui_start_server()`, `webui_get_url()` | Initial `Content`, `App.start()`, `Window.open()`, and `Window.url()`. Runtime content replacement remains listed above. |
333+
| `webui_show()`, `webui_start_server()`, `webui_get_url()` | Initial `Content`, runtime `Window.setContent()`, `App.start()`, `Window.open()`, and `Window.url()`. |
335334
| `webui_wait()`, `webui_wait_async()` | `Running.wait()` used directly or through `std.Io` concurrency. |
336335
| `webui_close()`, `webui_destroy()`, `webui_exit()`, `webui_clean()` | `Window.close()`, `Running.stop()`, and `App.deinit()`. |
337336
| `webui_set_context()`, `webui_get_context()` | Binding and event-handler `user_data`. |
@@ -352,7 +351,7 @@ not implementation gaps:
352351
| `webui_set_public()` | `App.Options.public` permits non-loopback listening only with TLS; Origin and explicit connection and protocol limits are enforced. |
353352
| `webui_set_tls_certificate()` | `App.Options.tls` accepts caller-provided PEM certificate and private-key bytes. |
354353
| `webui_set_port()`, `webui_get_port()`, `webui_get_free_port()` | `App.Options.port`, including `0` for automatic selection, and the running window URL. |
355-
| `webui_set_root_folder()`, `webui_set_file_handler()`, `webui_set_file_handler_window()`, `webui_return_http()` | Initial `.directory` or `.custom` content and `Response`. Runtime replacement remains listed above. |
354+
| `webui_set_root_folder()`, `webui_set_file_handler()`, `webui_set_file_handler_window()`, `webui_return_http()` | Initial or runtime `.directory` and `.custom` content through `Content`, `Window.setContent()`, and `Response`. |
356355
| `webui_get_mime_type()` | Linsang resource handling. |
357356
| `webui_encode()`, `webui_decode()`, `webui_malloc()`, `webui_free()`, `webui_memcpy()` | Zig standard library and allocators. |
358357
| `webui_get_last_error_number()`, `webui_get_last_error_message()` | Zig error unions. |
@@ -390,7 +389,6 @@ connection waiting, and caller-provided logging.
390389

391390
### Dynamic content and client state
392391

393-
- Allow window content and resource handlers to be replaced safely.
394392
- Add targeted `Client.show()` behavior.
395393
- Add a window connected/shown query.
396394
- Add an application default directory.
@@ -475,19 +473,22 @@ zig build -Dtarget=aarch64-macos
475473

476474
1. **Linsang peer lifecycle:** The required primitive exists. zig-webui must
477475
pair `clone` and `deinit` and must not retain `*Connection`.
478-
2. **Strict bridge protocol lengths:** The Zig parser must treat WebSocket data
476+
2. **Linsang static-response lifecycle:** Replaced directory handles remain
477+
open until shutdown so in-flight responses stay valid. Linsang
478+
[issue #2](https://github.com/jinzhongjia/Linsang/issues/2) tracks a
479+
completion callback for earlier release.
480+
3. **Strict bridge protocol lengths:** The Zig parser must treat WebSocket data
479481
as untrusted and must not copy C's NUL-scanning behavior.
480-
3. **Cross-platform browser behavior:** Guarantee URL opening first, then add
482+
4. **Cross-platform browser behavior:** Guarantee URL opening first, then add
481483
platform-specific app-window flags.
482-
4. **WebView is outside the core rewrite:** If required later, separately
484+
5. **WebView is outside the core rewrite:** If required later, separately
483485
decide whether system framework or C ABI linking is acceptable. It must not
484486
block the pure Zig browser version.
485487

486488
## Next Implementation Work
487489

488490
Continue capability parity:
489491

490-
1. Allow runtime window content and resource handler replacement.
491-
2. Add targeted `Client.show()`.
492-
3. Add a window connected/shown query.
493-
4. Add an application default directory and window icons.
492+
1. Add targeted `Client.show()`.
493+
2. Add a window connected/shown query.
494+
3. Add an application default directory and window icons.

0 commit comments

Comments
 (0)