Skip to content

Added proper serialization of modal popups#13

Merged
nefarius merged 4 commits into
masterfrom
ui-refactor
Mar 21, 2026
Merged

Added proper serialization of modal popups#13
nefarius merged 4 commits into
masterfrom
ui-refactor

Conversation

@nefarius

@nefarius nefarius commented Mar 21, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Refactor

    • Startup probing moved to background workers with asynchronous shutdown for non-blocking startup.
    • System dialogs unified into a priority-aware queue for serialized, reliable notifications.
  • New Features

    • Single centered modal renderer for consistent dialog presentation and dismissal.
    • About/Preferences now enqueue as system dialogs and are greyed out while a system modal is active.

@coderabbitai

coderabbitai Bot commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a17eb234-2a0b-4ef8-b2f3-c1e5a2345fa7

📥 Commits

Reviewing files that changed from the base of the PR and between d5c8333 and fe40e3a.

📒 Files selected for processing (2)
  • src/startup_probe.cpp
  • src/startup_probe.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/startup_probe.cpp

📝 Walkthrough

Walkthrough

Replaces multiple boolean-driven modals with a priority-aware SystemDialog queue, adds async startup probing via StartupProbeSession (HidHide and libwdi workers) that posts completion messages to the UI, and introduces a centered ImGui modal helper used to render queued system dialogs.

Changes

Cohort / File(s) Summary
Main Application Logic
src/main.cpp
Replaced boolean modal flags with a SystemDialog queue (g_systemDialogQueue), enqueued About/Preferences/menu actions, handle WM_HIDHIDE_PROBE_READY / WM_LIBWDI_PROBE_READY by queuing results, removed synchronous startup probes, added async startup session creation/shutdown, and unified ImGui modal rendering to show queue front.
Modal Helper
src/modal_helpers.h, src/modal_helpers.cpp
Added BeginCenteredModal declaration and implementation to center and size ImGui popup-modals and return an active/begin state for popup rendering.
Startup Probe System
src/startup_probe.h, src/startup_probe.cpp
Added StartupProbeSession managing two background probe threads with an atomic notify HWND, mutex-protected pending results, UI pop APIs (HidHideProbe_PopResultForUi, LibwdiProbe_PopResultForUi), WM_*_PROBE_READY constants, and StartupProbeSession_ShutdownAsync for async teardown.

Sequence Diagram

sequenceDiagram
    participant UI as Main Window (UI thread)
    participant Session as StartupProbeSession
    participant Hid as HidHide Worker
    participant Lib as Libwdi Worker
    participant Queue as SystemDialog Queue
    participant ImGui as ImGui Renderer

    UI->>Session: StartupProbeSession(hwnd)
    activate Session
    Session->>Hid: start thread
    Session->>Lib: start thread
    deactivate Session

    par HidHide probe
        Hid->>Hid: GetHidHideStatus()
        Hid->>UI: PostMessage(WM_HIDHIDE_PROBE_READY)
    and libwdi probe
        Lib->>Lib: ProbeLibwdiUsbDevices()
        Lib->>UI: PostMessage(WM_LIBWDI_PROBE_READY)
    end

    UI->>UI: WndProc receives WM_*_PROBE_READY
    UI->>Queue: Enqueue corresponding SystemDialog
    UI->>ImGui: OpenPopup(front) if queue not empty
    ImGui->>ImGui: BeginCenteredModal(SystemDialogPopupId(front))
    ImGui->>ImGui: Render dialog content (switch on front)
    ImGui->>Queue: On dismiss -> Pop front
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through threads both near and far,

probes tapped my paw and sent a little star.
Modals line up, polite in a queue,
centered and cozy, showing what’s new.
Hooray—async carrots for me and you!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: introducing a queue-based system for serializing modal dialogs instead of concurrent popups, which is the central refactoring visible across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ui-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main.cpp`:
- Around line 430-445: The current handling of WM_SYSCOMMAND sets separate flags
(g_pendingAbout, g_showAbout, g_pendingPreferences, g_showPreferences) which
allows out-of-order/reentrant modal presentation; instead consolidate modal
requests into a single serialized queue/state machine (e.g., push a ModalRequest
{type: ABOUT|PREFERENCES} into g_systemDialogQueue) and replace the separate
pending/show booleans with a single “current modal active” check before
dequeuing or setting any show flag; update the replay/renderer paths to always
pop from g_systemDialogQueue only when no modal is active (or consult the single
current-modal state) so About and Preferences respect request order and cannot
be displayed on consecutive frames while one is open (also apply same change
where similar modal handling exists around lines 743-910).
- Around line 265-276: EnqueueSystemDialog currently runs std::lower_bound
across the entire g_systemDialogQueue which allows a later high-priority dialog
to be inserted before the active front; change the insertion range so the
existing front remains fixed: if g_systemDialogQueue is non-empty, run the
lower_bound and insert only into the tail range (begin()+1 to end()) so you
preserve the current front, otherwise insert into the empty queue as before;
update EnqueueSystemDialog (referencing SystemDialogQueueContains,
SystemDialogPriority and g_systemDialogQueue) to search/insert starting from the
second element (or alternatively track the active dialog separately and only
priority-sort pending entries).

In `@src/startup_probe.cpp`:
- Around line 28-94: The shutdown hang is caused by std::jthread joins running
on the UI thread when g_startupProbeSession.reset() is called; instead, avoid
joining on the UI thread by performing the jthread teardown off-thread:
implement a ShutdownAsync helper that captures/moves g_startupProbeSession into
a background std::thread (or threadpool task) and calls reset() there, then make
the WM_DESTROY path call ShutdownAsync rather than resetting directly; keep
RunHidHideWorker and RunLibwdiWorker unchanged except ensure they respect
stop_token (they already do) and reference g_startupProbeSession, std::jthread,
RunHidHideWorker, RunLibwdiWorker, and the WM_DESTROY shutdown call when
locating where to change the reset to an asynchronous teardown.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3cbe859c-7910-423a-876c-b62ffa6e4e70

📥 Commits

Reviewing files that changed from the base of the PR and between 3acabf6 and b34b261.

📒 Files selected for processing (5)
  • src/main.cpp
  • src/modal_helpers.cpp
  • src/modal_helpers.h
  • src/startup_probe.cpp
  • src/startup_probe.h

Comment thread src/main.cpp
Comment thread src/main.cpp
Comment thread src/startup_probe.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/startup_probe.cpp`:
- Around line 102-115: The catch path can block trying to join partially-started
std::jthread workers; to fix, publish hwnd_.store(nullptr,
std::memory_order_release) before touching threads so
RunHidHideWorker/RunLibwdiWorker see the invalidated handle and exit quickly,
then reset hidThread_ and libwdiThread_; ensure the code sets hwnd_ to nullptr
as the very first action in the catch block (reference symbols: hidThread_,
libwdiThread_, hwnd_, RunHidHideWorker, RunLibwdiWorker).
- Around line 147-156: In StartupProbeSession_ShutdownAsync, invalidate the
notify handle and request stop synchronously before handing the unique_ptr off
to a detached thread: call the session's stop/request method and set its hwnd_
(or notify handle) to nullptr immediately, then attempt to construct the
std::thread that takes the moved session only for the join/cleanup work; wrap
thread construction in a try/catch (catch std::system_error) and if thread
construction fails, synchronously reset the moved session to ensure teardown
happens immediately. Ensure all references to hwnd_ and the stop request happen
on the session object before moving it into the thread.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e3ff9dc-3b52-4e5f-9cff-cd4bde6cd8af

📥 Commits

Reviewing files that changed from the base of the PR and between b34b261 and d5c8333.

📒 Files selected for processing (3)
  • src/main.cpp
  • src/startup_probe.cpp
  • src/startup_probe.h

Comment thread src/startup_probe.cpp Outdated
Comment thread src/startup_probe.cpp Outdated
@nefarius nefarius merged commit ead096f into master Mar 21, 2026
2 checks passed
@nefarius nefarius deleted the ui-refactor branch March 21, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant