| Crates.io | os-monitor-service |
| lib.rs | os-monitor-service |
| version | 0.5.0 |
| created_at | 2025-01-31 21:43:57.56837+00 |
| updated_at | 2025-06-04 01:35:27.08585+00 |
| description | OS level monitor for recording window focus and input events from os_monitor |
| homepage | |
| repository | https://github.com/CodeClimbersIO/os-monitor-service |
| max_upload_size | |
| id | 1537858 |
| size | 273,965 |
The monitoring service is a Rust application that runs as a background service to record user activity data. It works in conjunction with the os-monitor crate to track and store activity metrics while maintaining user privacy.
The monitoring service:
cargo install sqlx-cli
DATABASE_URL=sqlite:/{home_dir}/.codeclimbers/codeclimbers-desktop.sqlite
sqlx database create
# Run all pending migrations
sqlx migrate run
cargo sqlx prepare
cargo build
cargo watch -x run
Refer to main.rs for more information on how the service is run.
The service will create a SQLite database at ~/.codeclimbers/codeclimbers-desktop.sqlite
ActivityService receives events via callbacksActivity Service (services/activities_service.rs)
EventCallback trait from the monitor crateApp Switch Tracking (services/app_switch.rs)
Database Layer (db/)
ActivityRepo: Handles storage of individual activitiesActivityStateRepo: Manages activity state recordsActivityFlowPeriodRepo: Manages activity flow period recordsActivity (db/models/activity.rs)
Activity State (db/models/activity_state.rs)
Activity Flow Period (db/models/activity_flow_period.rs)
Records 10-minute activity periods
Provides a score for the period based on activity states and app switches
Maintains start/end times
The project uses SQLx for type-safe database operations. When making changes to queries:
Ensure the database is running with the latest migrations
Update or create new queries in the code
Run SQLx prepare to check query compatibility: cargo sqlx prepare -- --lib ```bash
This will verify all SQL queries at compile time and update sqlx-data.json.
Migrations are stored in migrations/ and follow the format:
-- Add migration script here
CREATE TABLE activity (
id INTEGER PRIMARY KEY,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
timestamp DATETIME,
activity_type TEXT,
app_name TEXT,
app_window_title TEXT
);
To create a new migration:
sqlx migrate add to create the filecargo sqlx prepare --database-url sqlite:/{home_dir}/.codeclimbers/codeclimbers-desktop.sqlite to update the query type checking.sqlx/query-*.jsonThe project includes unit tests, integration tests, and database tests. It is not comprehensive. To run them:
# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_name
# Run tests in a specific module
cargo test module_name::
Unit Tests: Located alongside the code they test
#[cfg(test)]
mod tests {
use super::*;
// test cases...
}
Database Tests: Use in-memory SQLite database
db/ modulesActivity Tests
#[tokio::test]
async fn test_activity_creation() {
let pool = create_test_db().await;
let activity_service = ActivityService::new(pool);
// Test logic...
}