1.7 KiB
1.7 KiB
Idle Detection for WindowWatcher
Summary
Add idle detection to WindowWatcher so it automatically pauses the active TaskTracker task when the user is away, and resumes it when they return.
Behavior
- Detection method:
GetLastInputInfoWin32 API — returns time of last keyboard/mouse input - Idle threshold: Configurable via
IdleTimeoutMs(default: 300,000ms = 5 minutes) - Checked on existing poll cycle — no new timers or threads
State Machine
ACTIVE ──(idle > threshold)──► IDLE
▲ │
└──(input detected)──────────────┘
On Idle Transition
GET /api/tasks/activeto find the current taskPUT /api/tasks/{id}/pausewith note "Auto-paused: idle timeout"- Store paused task ID locally
On Resume Transition
- Check if stored task ID is still in Paused status
- If yes:
PUT /api/tasks/{id}/resumewith note "Auto-resumed: user returned" - Clear stored task ID
Files Changed
| File | Change |
|---|---|
NativeMethods.cs |
Add GetLastInputInfo + LASTINPUTINFO struct |
Worker.cs |
Add idle state tracking, check idle time each poll, call pause/resume APIs |
WindowWatcherOptions.cs |
Add IdleTimeoutMs (default: 300000) |
appsettings.json |
Add IdleTimeoutMs setting |
Edge Cases
- No active task when idle fires: Log, skip pause, don't store task ID
- Task manually changed while idle: On resume, verify stored task is still paused before resuming
- API unreachable: Log warning, retry on next poll cycle. Maintain idle state locally
Out of Scope
- Session lock/unlock detection
- New context event types
- Tray menu UI changes