How menndouyukkuri/explorer_ghost_cleaner works
Project Type and Purpose
• This is a standalone, full-client desktop (Windows) “tray” application written in Rust.
• Its sole responsibility is to monitor and clean up idle “ghost” explorer.exe processes.
• There is no remote server, database, or network layer—everything runs locally.
File Structure
Top-level files & directories:
• Cargo.toml / build.rs – Rust project metadata and build script.
• config/config.toml – Runtime configuration file (scan interval, thresholds).
• src/
– main.rs: application entrypoint; initializes components.
– lib.rs: core library exports.
– worker.rs: scheduling and orchestration of scan/cleanup tasks.
– system_ext.rs: high-level wrappers around OS process enumeration and metrics.
– format.rs: formatting utilities (e.g., logs, status messages).
– src/worker/os.rs: OS-specific implementations (Windows API calls for process stats and termination).
• docs/: documentation, including Japanese README.
README for Insights
• Single executable, zero dependencies beyond Windows.
• Configurable via config.toml (scan interval, CPU/disk thresholds).
• Monitors CPU & disk I/O metrics to decide idleness.
Main Components and Their Interactions
a. Configuration Loader
– Reads config/config.toml on startup.
– Passes parameters (interval_seconds, cpu_threshold, disk_threshold_bytes) to the scheduler.
b. Scheduler / Worker Orchestrator
– In worker.rs: kicks off periodic “scan” jobs per interval.
c. Process Scanner & Analyzer
– Uses system_ext.rs to enumerate all explorer.exe processes.
– For each, gathers CPU and disk I/O metrics via OS API in worker/os.rs.
d. Decision Engine
– Compares metrics against thresholds.
– Flags truly idle “ghost” processes.
e. Cleaner
– Invokes Windows API calls (TerminateProcess or equivalent) via worker/os.rs.
f. UI Layer
– Sends status updates (optional) or logs to the tray tooltip or log file.
g. Logging / Formatting
– format.rs for human‐readable messages; could be written to stdout, a file, or shown in the tray.
Architectural Patterns & Principles
• Layered Architecture:
– Presentation (UI)
– Application (Scheduler + Decision Engine)
– Domain services (Process scanning, metrics)
– Infrastructure (OS bindings)
• Separation of Concerns:
– UI code lives entirely in ui.rs.
– OS‐specific code isolated in worker/os.rs.
– Shared logic in lib.rs, worker.rs, system_ext.rs.
• Configuration-driven Behavior: simple config file drives runtime.