Skip to content

refactor(core): Phase 5 — introduce MonitoringState machine and decouple lifecycle from window close #1408

@shm11C3

Description

@shm11C3

Parent

Part of #1402. Depends on Phase 4.

Goal

Introduce a MonitoringState machine (Running / Paused / Stopped) inside the root-level core crate and stop tying the app process lifecycle to the main window's close event.

Workspace Context

core::monitoring lives at core/src/monitoring/ in the workspace core crate; lifecycle wiring lives at src-tauri/src/app/lifecycle.rs and depends on the core crate.

Scope

  • Add core::monitoring::MonitoringState with explicit transitions in core/src/monitoring/.
  • Move start/stop wiring into app::lifecycle (src-tauri/src/app/lifecycle.rs).
  • on_window_event(CloseRequested) no longer calls WorkersState::terminate_all() and no longer calls app.exit(0). It hides the window instead.
  • An explicit Quit action (initially behind a debug flag or hidden setting) stops Core cleanly: state machine → Stopped, persistence flush, then app.exit(0).
  • Existing release behavior (closing the window quits the app) is preserved for end-users in this phase by gating the new behavior. The user-facing change ships with feat: add background monitoring mode with system tray support #1275.

Out of Scope

Definition of Done

  • With the debug flag enabled, the app keeps running with no visible window; collector and persistence continue.
  • Quit exits cleanly with no orphaned tasks and DB writes flushed.
  • MonitoringState transitions have unit tests covering all valid and invalid transitions, runnable via cargo test -p <core-crate> without a Tauri runtime.
  • Default release behavior is unchanged for users until feat: add background monitoring mode with system tray support #1275 lands.

Notes

This phase is intentionally invisible to end users. The visible UX changes (tray menu, "close to tray" setting, first-run dialog) are owned by #1275.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions