Skip to content

refactor(core): Phase 2 — introduce in-process EventBus for metric snapshots (#1404)#1413

Merged
shm11C3 merged 2 commits into
developfrom
refactor/#1404
Apr 29, 2026
Merged

refactor(core): Phase 2 — introduce in-process EventBus for metric snapshots (#1404)#1413
shm11C3 merged 2 commits into
developfrom
refactor/#1404

Conversation

@shm11C3

@shm11C3 shm11C3 commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 2 of #1402. Introduce hwviz_core::event_bus::EventBus, a Tauri-independent in-process broadcast channel for MetricsSnapshot. The collector no longer emits Tauri events directly; the new adapters::window::WindowAdapter is the sole place that translates a Core snapshot into the existing HardwareMonitorUpdate Tauri event. The wire format is unchanged.

This PR also drops the src-tauri/src/app/ namespace introduced as a placeholder in #1411 — with Core promoted to a workspace crate, the entire src-tauri/ crate is Tauri-aware by construction, so adapters/ lives directly under src-tauri/src/. See the discussion on #1402.

Closes #1404. Refs #1402.

Changes

core/

  • core::event_bus::EventBus — wraps tokio::sync::broadcast::Sender<MetricsSnapshot>. publish / subscribe / subscriber_count, default capacity 16. Clone so it can be cheaply handed to multiple producers.
  • core::models::{MetricsSnapshot, GpuMetric} — Tauri-independent data shape mirroring the existing wire payload. No serde / specta derives; that ceremony stays App-side.
  • tokio dep — added to core/Cargo.toml with only the sync feature in [dependencies]; ["macros", "rt"] in [dev-dependencies] for #[tokio::test]. Verified cargo tree -p hwviz-core | grep -ic tauri == 0.

src-tauri/

  • workers::system_monitorpayload.emit(app_handle) becomes bus.publish(snapshot). SystemMonitorController::setup now takes an EventBus. The GPU payload builder is renamed build_gpu_metrics and returns Vec<GpuMetric>. The app_handle parameter is retained this phase only for the temperature_unit lookup; Phase 3.5 moves that to the adapter.
  • adapters::window::WindowAdapter — long-running tokio task that subscribes to the bus and emits HardwareMonitorUpdate. Handles Lagged (warn + skip) and Closed (exit). terminate() uses the same watch::Sender<bool> pattern as the collector.
  • WorkersState — gains a window_adapter slot. terminate_all order: collector first (stop sources) → adapter (drain consumer) → archive worker.
  • run() wiring — creates the bus, starts WindowAdapter with bus.subscribe(), then starts the collector with bus.
  • Drop src-tauri/src/app/ placeholder — empty Phase 1 module deleted; mod app; replaced by mod adapters; in lib.rs.

Notable choices

  • MetricsSnapshot is a fresh Core type rather than re-exporting HardwareMonitorUpdate. Sharing the type would force core to depend on serde / specta (and through specta, on Tauri-adjacent crates). The 1:1 field translation lives in WindowAdapter and is unit-tested.
  • app_handle stays on the collector to read temperature_unit. Removing it (and pushing °C-only snapshots through the bus, with adapter-side conversion) is explicitly Phase 3.5 — keeping it here avoids changing wire-format-relevant behavior in this PR.
  • WorkersState ownership of the adapter keeps the existing shutdown path unchanged for callers; on_window_event(CloseRequested) still calls terminate_all and the adapter is now part of that.
  • No bus exposed via app.manage(...) yet. Phase 4 (persistence) is the natural place to make the bus shared state; until then, scoping it to setup() keeps the surface minimal.
  • No app/ namespace — see Epic: split backend into Tauri-independent Core and thin App adapters #1402 (Change Log entry).

Test plan

  • cargo build --workspace succeeds
  • cargo tauri-lint succeeds
  • cargo tauri-fmt -- --check succeeds
  • cargo llvm-cov --workspace --no-report -- --test-threads=1 --nocapture: 279 src-tauri tests + 6 hwviz-core tests pass (was 276 + 0 before this PR)
  • cargo test -p hwviz-core runs without a Tauri runtime
  • cargo tree -p hwviz-core | grep -ic tauri returns 0
  • No .emit( / Emitter::emit / AppHandle::emit remains in workers/system_monitor.rs
  • tauri dev: dashboard updates indistinguishably from develop (please verify on Windows during review — host platform dictates which sensors are exercised)
  • CI green across lint-backend / test-backend / test-build

Out of scope (later phases)

Summary by CodeRabbit

  • New Features

    • Real-time metrics broadcasting enabling live delivery of CPU, memory, and GPU snapshots to the UI.
  • Refactor

    • Reworked monitoring pipeline to publish snapshots internally and subscribe from the window adapter for smoother, more reliable updates.
    • Added GPU metrics support (per-GPU usage, temperature, memory, cooler level) in reported snapshots.

Copilot AI review requested due to automatic review settings April 29, 2026 20:12
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 217c6211-0290-4792-99a3-219f497da05c

📥 Commits

Reviewing files that changed from the base of the PR and between ad676f4 and 921ab88.

📒 Files selected for processing (3)
  • core/src/event_bus.rs
  • src-tauri/src/adapters/window.rs
  • src-tauri/src/workers/system_monitor.rs
✅ Files skipped from review due to trivial changes (2)
  • core/src/event_bus.rs
  • src-tauri/src/workers/system_monitor.rs

📝 Walkthrough

Walkthrough

This PR introduces an in-process EventBus in the core crate (tokio broadcast) and payload models (MetricsSnapshot, GpuMetric), switches SystemMonitorController to publish snapshots to the bus, and adds a WindowAdapter that subscribes and emits HardwareMonitorUpdate to the Tauri window. Module wiring and worker lifecycle were updated to instantiate and manage the adapter and bus.

Changes

Cohort / File(s) Summary
Dependencies
core/Cargo.toml
Added tokio as a production dependency (with sync feature) and added a [dev-dependencies] entry for tokio with macros and rt features for tests.
Core Event Bus & Models
core/src/event_bus.rs, core/src/models/metrics.rs, core/src/models/mod.rs
Added EventBus (tokio::sync::broadcast) with capacity, publish/subscribe, subscriber_count, and Default. Added MetricsSnapshot and GpuMetric model structs and public re-exports. Includes unit tests for fan-out, late subscribers, and preservation of GPU fields.
Core Module Organization
core/src/lib.rs
Switched event_bus and models module declarations from inline blocks to file-based modules; updated crate-level doc comment.
Tauri Setup & Wiring
src-tauri/src/lib.rs, src-tauri/src/workers/mod.rs
Instantiated EventBus in Tauri setup, wired it into SystemMonitorController::setup and WindowAdapter::setup. Added WorkersState.window_adapter: Mutex<Option<WindowAdapter>> and updated terminate_all() to stop the adapter as part of shutdown.
System Monitor Refactor
src-tauri/src/workers/system_monitor.rs
Replaced payload construction with build_gpu_metrics() producing Vec<GpuMetric>. Replaced direct Tauri emits with bus.publish(snapshot); updated SystemMonitorController::setup() signature to accept EventBus. Tests updated accordingly.
Tauri Adapter
src-tauri/src/adapters/mod.rs, src-tauri/src/adapters/window.rs
Added adapters::window module and WindowAdapter that subscribes to the broadcast receiver, converts MetricsSnapshotHardwareMonitorUpdate, emits to Tauri window, handles lag/backpressure and termination; includes unit tests for translation and optional GPU fields.
Documentation Cleanup
src-tauri/src/app/mod.rs
Removed a module-level documentation block (doc-only deletion).

Sequence Diagram(s)

sequenceDiagram
    participant Monitor as SystemMonitorController
    participant Bus as EventBus
    participant Adapter as WindowAdapter
    participant Tauri as Tauri AppHandle
    participant Frontend as Frontend Window

    Monitor->>Monitor: collect metrics (CPU, memory, GPUs)
    Monitor->>Monitor: build MetricsSnapshot
    Monitor->>Bus: publish(snapshot)
    Bus->>Adapter: broadcast snapshot to subscribers
    Adapter->>Adapter: convert snapshot → HardwareMonitorUpdate
    Adapter->>Tauri: emit("hardware-monitor-update", payload)
    Tauri->>Frontend: deliver event to frontend
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Poem

🐰
Metrics hop in tidy rows,
Broadcast whispers where the data goes,
A window listens, then it sings,
Tauri wakes and dashboard springs,
Hoppity-hop — pub, subscribe, and pose.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately and concisely describes the main change: introducing an in-process EventBus for metric snapshots in the core crate as Phase 2 of issue #1402.
Description check ✅ Passed The PR description is comprehensive and covers all template sections: Summary clearly explains the changes, Related Issues lists #1404 and refs #1402, Type of Change is marked as refactoring, Test Plan is detailed with specific commands run, and Checklist items are addressed (self-review, linting, testing, no warnings).
Linked Issues check ✅ Passed The PR fully implements the objectives from #1404: EventBus with tokio::sync::broadcast is implemented; MetricsSnapshot and GpuMetric models added to core; system_monitor publishes snapshots via the bus; WindowAdapter subscribes and emits HardwareMonitorUpdate; wire format unchanged; EventBus is tested without Tauri; cargo tree confirms zero Tauri dependencies in core.
Out of Scope Changes check ✅ Passed All code changes are directly aligned with the Phase 2 objectives: EventBus implementation, MetricsSnapshot/GpuMetric models, system_monitor refactoring to use the bus, WindowAdapter addition, WorkersState extension, and removal of the src-tauri/src/app/ placeholder namespace. No unrelated or speculative changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 refactor/#1404

Review rate limit: 3/5 reviews remaining, refill in 17 minutes and 8 seconds.

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

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file rust Pull requests that update Rust code configuration labels Apr 29, 2026
@shm11C3 shm11C3 enabled auto-merge (squash) April 29, 2026 20:14

Copilot AI 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.

Pull request overview

Introduces a Tauri-independent in-process EventBus in the new core/ crate and refactors the real-time monitoring pipeline so the collector publishes MetricsSnapshot to the bus, while a new Tauri-side WindowAdapter is solely responsible for translating snapshots into the existing HardwareMonitorUpdate event (wire format unchanged).

Changes:

  • Added hwviz_core::event_bus::EventBus (tokio broadcast) and Tauri-independent snapshot models (MetricsSnapshot, GpuMetric) in core/.
  • Refactored SystemMonitorController to publish snapshots to the bus instead of emitting Tauri events directly.
  • Added app::adapters::window::WindowAdapter to subscribe to the bus and emit the existing HardwareMonitorUpdate, and wired it into startup/shutdown via WorkersState.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src-tauri/src/workers/system_monitor.rs Collector now builds MetricsSnapshot + publishes to EventBus; GPU builder renamed to return Core metrics type.
src-tauri/src/workers/mod.rs WorkersState now owns a WindowAdapter and terminates it during shutdown.
src-tauri/src/lib.rs Wires up the bus, starts WindowAdapter, then starts the monitor with the bus and stores both in WorkersState.
src-tauri/src/app/mod.rs Makes app::adapters a real module (Phase 2 population).
src-tauri/src/app/adapters/window.rs New adapter task subscribing to bus and emitting HardwareMonitorUpdate; includes translation unit tests.
src-tauri/src/app/adapters/mod.rs Exposes the window adapter module.
core/src/models/mod.rs New Core models module exporting metric snapshot types.
core/src/models/metrics.rs Defines GpuMetric + MetricsSnapshot as Tauri-independent shapes.
core/src/lib.rs Exposes the new event_bus and models modules from the core crate.
core/src/event_bus.rs Implements EventBus wrapper around tokio::sync::broadcast with unit tests.
core/Cargo.toml Adds tokio dependency (sync) + dev-dependency (macros/rt) for core tests.
Cargo.lock Updates lockfile for core’s new tokio dependency.

Comment thread src-tauri/src/workers/system_monitor.rs
Comment thread src-tauri/src/adapters/window.rs
Comment thread core/src/event_bus.rs
Comment thread src-tauri/src/adapters/window.rs Outdated
@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Rust Backend Coverage Report

Coverage Details
Filename                                                       Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
core/src/event_bus.rs                                              166                 3    98.19%          19                 1    94.74%         106                 3    97.17%           0                 0         -
src-tauri/src/_tests/commands/background_image_test.rs              39                 0   100.00%           6                 0   100.00%          21                 0   100.00%           0                 0         -
src-tauri/src/_tests/commands/settings_test.rs                     220                 0   100.00%          18                 0   100.00%         167                 0   100.00%           0                 0         -
src-tauri/src/adapters/window.rs                                   152                50    67.11%          11                 5    54.55%         117                32    72.65%           0                 0         -
src-tauri/src/commands/background_image.rs                          22                 7    68.18%          11                 5    54.55%          19                 7    63.16%           0                 0         -
src-tauri/src/commands/hardware.rs                                  66                66     0.00%          20                20     0.00%          66                66     0.00%           0                 0         -
src-tauri/src/commands/settings.rs                                 544               544     0.00%          97                97     0.00%         463               463     0.00%           0                 0         -
src-tauri/src/commands/system.rs                                     6                 6     0.00%           3                 3     0.00%           5                 5     0.00%           0                 0         -
src-tauri/src/commands/ui.rs                                        17                17     0.00%           2                 2     0.00%          13                13     0.00%           0                 0         -
src-tauri/src/commands/updater.rs                                   97                97     0.00%          15                15     0.00%          66                66     0.00%           0                 0         -
src-tauri/src/enums/error.rs                                       105                 0   100.00%           8                 0   100.00%          89                 0   100.00%           0                 0         -
src-tauri/src/enums/hardware.rs                                    188                 1    99.47%          15                 0   100.00%         114                 0   100.00%           0                 0         -
src-tauri/src/enums/settings.rs                                    415                 6    98.55%          24                 0   100.00%         279                 0   100.00%           0                 0         -
src-tauri/src/infrastructure/database/db.rs                         21                21     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
src-tauri/src/infrastructure/database/gpu_archive.rs                51                51     0.00%           4                 4     0.00%          18                18     0.00%           0                 0         -
src-tauri/src/infrastructure/database/hardware_archive.rs           41                41     0.00%           4                 4     0.00%          21                21     0.00%           0                 0         -
src-tauri/src/infrastructure/database/migration.rs                  66                 1    98.48%          10                 0   100.00%          86                 0   100.00%           0                 0         -
src-tauri/src/infrastructure/database/preflight.rs                 288                13    95.49%          28                 1    96.43%         179                 7    96.09%           0                 0         -
src-tauri/src/infrastructure/database/process_stats.rs              41                41     0.00%           4                 4     0.00%          29                29     0.00%           0                 0         -
src-tauri/src/infrastructure/providers/linux/dmidecode.rs          229                15    93.45%          16                 3    81.25%         319                14    95.61%           0                 0         -
src-tauri/src/infrastructure/providers/linux/drm_sys.rs            205               156    23.90%          21                14    33.33%         126                93    26.19%           0                 0         -
src-tauri/src/infrastructure/providers/linux/hwmon.rs              119                94    21.01%           8                 6    25.00%          68                56    17.65%           0                 0         -
src-tauri/src/infrastructure/providers/linux/kernel.rs             165                22    86.67%          19                 2    89.47%         161                 8    95.03%           0                 0         -
src-tauri/src/infrastructure/providers/linux/lspci.rs               83                20    75.90%           8                 2    75.00%          50                11    78.00%           0                 0         -
src-tauri/src/infrastructure/providers/linux/net_sys.rs            171               171     0.00%          13                13     0.00%          93                93     0.00%           0                 0         -
src-tauri/src/infrastructure/providers/linux/procfs.rs             261                24    90.80%          25                 3    88.00%         222                19    91.44%           0                 0         -
src-tauri/src/infrastructure/providers/sysinfo_provider.rs          54                54     0.00%           2                 2     0.00%          45                45     0.00%           0                 0         -
src-tauri/src/lib.rs                                               259               259     0.00%           6                 6     0.00%         143               143     0.00%           0                 0         -
src-tauri/src/main.rs                                                3                 3     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
src-tauri/src/models/hardware.rs                                   292                 0   100.00%          19                 0   100.00%         175                 0   100.00%           0                 0         -
src-tauri/src/models/hardware_archive.rs                             3                 0   100.00%           1                 0   100.00%           7                 0   100.00%           0                 0         -
src-tauri/src/models/settings.rs                                   301                 0   100.00%          17                 0   100.00%         264                 0   100.00%           0                 0         -
src-tauri/src/platform/factory.rs                                   18                18     0.00%           4                 4     0.00%          15                15     0.00%           0                 0         -
src-tauri/src/platform/linux/cache.rs                               53                53     0.00%           4                 4     0.00%          38                38     0.00%           0                 0         -
src-tauri/src/platform/linux/gpu.rs                                143               143     0.00%          14                14     0.00%         105               105     0.00%           0                 0         -
src-tauri/src/platform/linux/memory.rs                              43                43     0.00%           6                 6     0.00%          41                41     0.00%           0                 0         -
src-tauri/src/platform/linux/mod.rs                                 34                34     0.00%          11                11     0.00%          70                70     0.00%           0                 0         -
src-tauri/src/platform/linux/network.rs                              4                 4     0.00%           1                 1     0.00%           4                 4     0.00%           0                 0         -
src-tauri/src/services/archive_service.rs                         1230               155    87.40%          93                15    83.87%         694               135    80.55%           0                 0         -
src-tauri/src/services/background_image_service.rs                 165                96    41.82%          16                10    37.50%          93                59    36.56%           0                 0         -
src-tauri/src/services/cpu_service.rs                               32                32     0.00%           4                 4     0.00%          15                15     0.00%           0                 0         -
src-tauri/src/services/db_startup_service.rs                       188                87    53.72%          10                 3    70.00%         114                58    49.12%           0                 0         -
src-tauri/src/services/gpu_service.rs                               37                37     0.00%          10                10     0.00%          31                31     0.00%           0                 0         -
src-tauri/src/services/hardware_service.rs                          67                67     0.00%           5                 5     0.00%          43                43     0.00%           0                 0         -
src-tauri/src/services/language_service.rs                         101                 0   100.00%          18                 0   100.00%          57                 0   100.00%           0                 0         -
src-tauri/src/services/memory_service.rs                            22                22     0.00%           4                 4     0.00%          15                15     0.00%           0                 0         -
src-tauri/src/services/monitoring_service.rs                      1114               161    85.55%          75                19    74.67%         574               104    81.88%           0                 0         -
src-tauri/src/services/motherboard_service.rs                       10                10     0.00%           3                 3     0.00%           7                 7     0.00%           0                 0         -
src-tauri/src/services/network_service.rs                            9                 9     0.00%           1                 1     0.00%           7                 7     0.00%           0                 0         -
src-tauri/src/services/process_service.rs                           86                86     0.00%           5                 5     0.00%          50                50     0.00%           0                 0         -
src-tauri/src/services/settings_service.rs                         338               158    53.25%          34                16    52.94%         288               148    48.61%           0                 0         -
src-tauri/src/services/system_service.rs                            22                22     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
src-tauri/src/services/ui_service.rs                                45                45     0.00%           8                 8     0.00%          36                36     0.00%           0                 0         -
src-tauri/src/utils/color.rs                                        66                 1    98.48%           4                 0   100.00%          26                 0   100.00%           0                 0         -
src-tauri/src/utils/file.rs                                        224                 5    97.77%          14                 0   100.00%         144                 4    97.22%           0                 0         -
src-tauri/src/utils/formatter.rs                                   195                 8    95.90%          16                 0   100.00%         160                12    92.50%           0                 0         -
src-tauri/src/utils/ip.rs                                           65                 0   100.00%           5                 0   100.00%          33                 0   100.00%           0                 0         -
src-tauri/src/utils/logger.rs                                       71                71     0.00%           1                 1     0.00%          38                38     0.00%           0                 0         -
src-tauri/src/utils/rounding.rs                                     68                 0   100.00%           7                 0   100.00%          41                 0   100.00%           0                 0         -
src-tauri/src/utils/tauri.rs                                       138                 0   100.00%          17                 0   100.00%          82                 0   100.00%           0                 0         -
src-tauri/src/workers/hardware_archive.rs                           52                52     0.00%           6                 6     0.00%          36                36     0.00%           0                 0         -
src-tauri/src/workers/mod.rs                                        32                32     0.00%           2                 2     0.00%          20                20     0.00%           0                 0         -
src-tauri/src/workers/system_monitor.rs                            257                93    63.81%          18                 6    66.67%         147                63    57.14%           0                 0         -
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                             9619              3327    65.41%         875               375    57.14%        6582              2393    63.64%           0                 0         -

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

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

Inline comments:
In `@core/src/event_bus.rs`:
- Around line 27-29: The constructor with_capacity should guard against zero to
avoid tokio::sync::broadcast::channel(0) panicking; update the with_capacity
function to check if capacity == 0 and replace it with 1 (or otherwise coerce to
a non-zero value) before calling broadcast::channel, e.g. compute let cap = if
capacity == 0 { 1 } else { capacity } and then call broadcast::channel(cap) and
construct Self { tx } as before.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f9aed0ad-dfb2-44c5-ac1e-dfe7936a9fbe

📥 Commits

Reviewing files that changed from the base of the PR and between d224788 and 52e74df.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • core/Cargo.toml
  • core/src/event_bus.rs
  • core/src/lib.rs
  • core/src/models/metrics.rs
  • core/src/models/mod.rs
  • src-tauri/src/app/adapters/mod.rs
  • src-tauri/src/app/adapters/window.rs
  • src-tauri/src/app/mod.rs
  • src-tauri/src/lib.rs
  • src-tauri/src/workers/mod.rs
  • src-tauri/src/workers/system_monitor.rs

Comment thread core/src/event_bus.rs
@shm11C3 shm11C3 disabled auto-merge April 29, 2026 20:20
coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 29, 2026
@shm11C3

shm11C3 commented Apr 29, 2026

Copy link
Copy Markdown
Owner Author

Force-pushing this branch shortly to drop the app/ namespace per discussion on #1402:

  • src-tauri/src/app/adapters/window.rssrc-tauri/src/adapters/window.rs
  • src-tauri/src/app/mod.rs (the empty Phase 1 placeholder) is deleted
  • mod app; is removed from src-tauri/src/lib.rs; mod adapters; is added in its place
  • crate::app::adapters::window::WindowAdaptercrate::adapters::window::WindowAdapter in workers/mod.rs and lib.rs

WindowAdapter logic, EventBus, MetricsSnapshot, the core crate, and all tests are unchanged. Build/lint/cargo llvm-cov --workspace results stay identical to the previous push.

Rationale: with Core promoted to a workspace crate in #1411, the entire src-tauri/ crate is Tauri-aware by construction, so an extra app/ layer inside it just nests for the sake of nesting. Detail in the #1402 comment.

Phase 2 of #1402. Introduce a Tauri-independent
`hwviz_core::event_bus::EventBus` that fans out a `MetricsSnapshot`
to every in-process subscriber. The collector no longer emits Tauri
events directly; the new `adapters::window::WindowAdapter` is the
sole place that translates a Core snapshot into the existing
`HardwareMonitorUpdate` Tauri event. The wire format stays unchanged.

- Add `core::event_bus::EventBus` over `tokio::sync::broadcast` and
  `core::models::{MetricsSnapshot, GpuMetric}`. `core` gains a `tokio`
  dependency with the `sync` feature; the dep graph still has no Tauri.
- Replace `payload.emit(app_handle)` inside
  `workers::system_monitor::SystemMonitorController` with
  `bus.publish(snapshot)`. Rename the GPU payload builder to
  `build_gpu_metrics`. The collector still consults `AppState` for the
  user's `temperature_unit`; that lookup moves to the adapter in
  Phase 3.5.
- Add `adapters::window::WindowAdapter`, a long-running task that
  subscribes to the bus and emits `HardwareMonitorUpdate` per snapshot.
  Logs and skips on `Lagged`; exits cleanly on `Closed` or stop signal.
- Track the adapter in `WorkersState`; `terminate_all` stops the
  collector first (no further publishes), then drains the adapter,
  then the archive worker.
- Unit tests under `core/` exercise EventBus fan-out, late-subscriber
  semantics, and zero-subscriber publish without a Tauri runtime.
- Drop the `src-tauri/src/app/` namespace introduced as a placeholder in
  #1411. With Core promoted to a workspace crate, the entire
  `src-tauri/` crate is Tauri-aware by construction, so `adapters/`
  lives directly under `src-tauri/src/`. See discussion on #1402.

Refs #1402, closes #1404

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

🤖 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-tauri/src/workers/system_monitor.rs`:
- Around line 71-78: The doc comment in system_monitor.rs references the old
module path app::adapters::window::WindowAdapter; update that reference to the
new path crate::adapters::window::WindowAdapter in the setup/docs block (the
parameter list describing `bus` and translation to `HardwareMonitorUpdate`) so
the documentation points to the relocated adapter symbol.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3110e110-0063-4284-ae30-2fd6b1457b18

📥 Commits

Reviewing files that changed from the base of the PR and between 52e74df and ad676f4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • core/Cargo.toml
  • core/src/event_bus.rs
  • core/src/lib.rs
  • core/src/models/metrics.rs
  • core/src/models/mod.rs
  • src-tauri/src/adapters/mod.rs
  • src-tauri/src/adapters/window.rs
  • src-tauri/src/app/mod.rs
  • src-tauri/src/lib.rs
  • src-tauri/src/workers/mod.rs
  • src-tauri/src/workers/system_monitor.rs
💤 Files with no reviewable changes (1)
  • src-tauri/src/app/mod.rs
✅ Files skipped from review due to trivial changes (2)
  • core/src/models/mod.rs
  • core/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (5)
  • core/src/lib.rs
  • core/src/models/metrics.rs
  • src-tauri/src/lib.rs
  • src-tauri/src/workers/mod.rs
  • core/src/event_bus.rs

Comment thread src-tauri/src/workers/system_monitor.rs
- core::event_bus: document the zero-capacity panic on
  `EventBus::with_capacity` and add an explicit assert with a clearer
  message. Add a `#[should_panic]` test pinning the contract.
- adapters::window: drop a redundant `continue;` in the `Lagged` arm.
  The select! arm naturally falls through to the next loop iteration.
- adapters::window / workers::system_monitor: refresh stale
  `app::adapters::window::*` references in log labels and a doc comment
  to match the post-rename `crate::adapters::window::*` namespace.
@shm11C3 shm11C3 enabled auto-merge (squash) April 29, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration dependencies Pull requests that update a dependency file rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(core): Phase 2 — introduce in-process EventBus for metric snapshots

2 participants