Skip to content

Commit 5143617

Browse files
committed
Fix WebView Render Issue
1 parent 1b72afe commit 5143617

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

src/lib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ const symbols = {
451451
// bool webui_wait_async(void)
452452
parameters: [],
453453
result: "bool",
454-
nonblocking: true,
454+
nonblocking: false,
455455
},
456456
webui_get_count: {
457457
// size_t webui_get_count(webui_event_t* e)

src/webui.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,26 +1228,17 @@ export class WebUI {
12281228
*/
12291229
static async wait() {
12301230
WebUI.init();
1231-
1232-
// Run WebUI main loop and render the WebView UI
1233-
// _lib.symbols.webui_wait();
1234-
1235-
// TODO:
1236-
// We should call `_lib.symbols.webui_wait()` to render the WebView UI,
1237-
// but this blocks the Deno main thread (`callbackResource`), which
1238-
// prevents all WebUI events (clicks, calls, etc.) from being executed.
1239-
//
1240-
// As a workaround, we will use `sleep()` periodically to check if the
1241-
// application is still running. However, this workaround means the
1242-
// WebView will not render — only the browser-based window will function.
1243-
//
1244-
// In the future, we should find a way to use `_lib.symbols.webui_wait()`
1245-
// to render the WebView UI without blocking WebUI events.
1246-
12471231
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
12481232
while (1) {
1249-
await sleep(100);
1250-
if (!_lib.symbols.webui_interface_is_app_running()) {
1233+
// Sleep for a short time to avoid busy waiting and high CPU usage.
1234+
await sleep(25);
1235+
// Call `webui_wait_async()` to allow WebUI to process any pending events
1236+
// and check if windows are still open. Also, render any WebView graphics.
1237+
//
1238+
// Note: It's very important to call `webui_wait_async()` from main thread,
1239+
// otherwise WebView may not render or respond to events.
1240+
if (!_lib.symbols.webui_wait_async()) {
1241+
// No more windows are open, we can exit the loop.
12511242
break;
12521243
}
12531244
}

0 commit comments

Comments
 (0)