Skip to content

Commit 01301a6

Browse files
singaraionaclaude
andcommitted
fix(startup): signal ready before loading script to prevent UI freeze
Reorder startup sequence to signal ready and start UI loop before loading the script file. Previously, slow script operations (like synchronous IPC calls) would block the main thread, causing the window manager to report "not responding". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dbcad0a commit 01301a6

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

src/rayforce_thread.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,24 @@ void* rfui_rayforce_thread(void* arg) {
589589
// Step 4: Register rayforce-ui functions (widget, draw)
590590
register_rfui_functions();
591591

592-
// Step 5: Load script file if provided via command line
592+
// Step 5: Create poll waker for UI messages
593+
waker = poll_waker_create(runtime->poll, on_ui_message, ctx);
594+
if (!waker) {
595+
g_ctx = NULL;
596+
runtime_destroy();
597+
rfui_ctx_set_quit(ctx, B8_TRUE);
598+
rfui_ctx_signal_ready(ctx);
599+
return NULL;
600+
}
601+
602+
// Step 6: Store waker in context and signal ready
603+
// Signal ready BEFORE loading script so UI loop can start
604+
// while potentially slow script operations (IPC, file I/O) execute
605+
rfui_ctx_set_waker(ctx, waker);
606+
rfui_ctx_signal_ready(ctx);
607+
608+
// Step 7: Load script file if provided via command line
609+
// This may take time (e.g., synchronous IPC calls) but UI is now responsive
593610
{
594611
obj_p file_arg = runtime_get_arg("file");
595612
if (!is_null(file_arg)) {
@@ -607,23 +624,7 @@ void* rfui_rayforce_thread(void* arg) {
607624
}
608625
}
609626

610-
// Step 6: Create poll waker for UI messages
611-
waker = poll_waker_create(runtime->poll, on_ui_message, ctx);
612-
if (!waker) {
613-
g_ctx = NULL;
614-
runtime_destroy();
615-
rfui_ctx_set_quit(ctx, B8_TRUE);
616-
rfui_ctx_signal_ready(ctx);
617-
return NULL;
618-
}
619-
620-
// Step 7: Store waker in context
621-
rfui_ctx_set_waker(ctx, waker);
622-
623-
// Step 8: Signal ready
624-
rfui_ctx_signal_ready(ctx);
625-
626-
// Step 9: Run poll loop (blocks until exit)
627+
// Step 8: Run poll loop (blocks until exit)
627628
runtime_run();
628629

629630
// Cleanup

0 commit comments

Comments
 (0)