@@ -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