Tockler's backend is built on Electron and provides core functionality for tracking computer usage, application activities, and system state changes. The backend handles data collection, storage, analysis, and maintains the application state.
Tockler's backend is structured into several key components:
- Main Process (
index.ts) - Entry point that initializes the application, sets up windows, and manages power monitor events. - Window Manager (
window-manager.ts) - Handles the creation and management of application windows. - State Manager (
state-manager.ts) - Maintains the current state of tracking items and system state. - Background Service (
background-service.ts) - Core service for handling track item creation, updates, and system state transitions. - App Manager (
app-manager.ts) - Manages application lifecycle and initialization.
- TrackItem - The primary data model representing a tracked activity with the following properties:
id: Unique identifierapp: Application nametaskName: Type of track item (LogTrackItem, AppTrackItem, StatusTrackItem)title: Window title or descriptionurl: URL (if applicable)color: Color for visualizationbeginDate: Start time of the tracked itemendDate: End time of the tracked item
Tockler has three main tracking jobs that run at regular intervals:
-
AppTrackItemJob - Tracks active applications and window titles
- Captures the current active window
- Creates or updates AppTrackItem records
- Analyzes window titles for task identification
-
StatusTrackItemJob - Monitors system status
- Tracks whether the system is Online, Offline, or Idle
- Manages transitions between different states
- Creates StatusTrackItem records
-
LogTrackItemJob - Handles manual time logging
- Manages user-defined tracking items
- Records intentional activities logged by the user
-
TrackItemService - Handles CRUD operations for track items
- Creating new track items
- Querying track items for various time ranges
- Exporting track items
- Updating and deleting track items
-
AppSettingService - Manages application settings
- Storing and retrieving app colors
- Managing app-specific settings
-
SettingsService - Handles global application settings
- Timer settings
- UI preferences
- Background job intervals
The application tracks three main states:
- ONLINE - Computer is active and being used
- IDLE - Computer is on but not being used (idle timeout)
- OFFLINE - Computer is sleeping or powered off
Three primary tracking types are defined:
- AppTrackItem - Records application usage (which apps were open and active)
- StatusTrackItem - Records system status (online, idle, offline)
- LogTrackItem - Records manual time entries created by the user
The AppTrackItemJob runs at regular intervals (default: every few seconds) and:
- Queries the OS for the currently active window
- Creates a new AppTrackItem or updates an existing one
- Stores details like app name, window title, start time, and end time
The StatusTrackItemJob:
- Monitors for system idle state
- Creates StatusTrackItem records when state changes
- Handles transitions between Online, Idle, and Offline states
The backend responds to system sleep and wake events:
- When the system sleeps, the current state is saved
- When the system wakes, an Offline period is recorded for the sleep duration
- Tracking resumes with the current state
The TaskAnalyzer:
- Examines window titles and application names
- Identifies potential tasks based on patterns
- Can notify users about recognized tasks
Tockler uses an Objection.js ORM with SQL database to store:
- Track items (application usage, system state, manual logs)
- Application settings (colors, preferences)
- Global settings
The backend has special handling for activities that span midnight:
- TrackItems that cross midnight are split into separate day chunks
- This ensures accurate daily reporting
The backend implements robust error handling:
- Logging errors with detailed context
- Graceful degradation when tracking encounters issues
- Recovery mechanisms after system sleep or crashes
Background jobs are managed with:
- Configurable intervals
- Automatic retries
- Error logging and recovery
The backend exposes functionality to the frontend through:
- IPC (Inter-Process Communication) channels
- Shared data models
- Event emitters for real-time updates
The backend can be configured through:
- Environment variables
- User settings (stored in the database)
- Default configurations in code
This document provides an overview of Tockler's backend architecture and main components. For specific implementation details, refer to the corresponding source files.
There should be system state events. Online, Offline, Idle. There is a thread that checks for Idle state. If state changes event is fired.
Other parts are listening to those events.
In active application tracking, there is a thread that in every 3 seconds checks the active window. If system is Idle or Offline, the thread is ended. It will start if it gets event Online. It keeps current state in memory, and changes endDate if needed or saves state to sqllite db