An Electron desktop application with MediaPipe face and iris tracking that automatically switches Windows OS application window focus based on your gaze.
-
MediaPipe FaceMesh & Iris Tracking (478 Landmarks):
- GPU-accelerated tracking running at >30 FPS with offline bundled model (
public/models/face_landmarker.task) and local WebAssembly binaries (public/wasm/). - Automatic 4-tier fallback: local GPU -> local CPU -> CDN GPU -> CDN CPU.
- Eye Aspect Ratio (EAR) blink detection with a 300ms grace period to prevent accidental focus switching during blinks.
- Normalized pupil coordinates fused with head-pose yaw and pitch compensation.
- GPU-accelerated tracking running at >30 FPS with offline bundled model (
-
Webcam Selection & Contention Handling:
- Enumerates video devices via
navigator.mediaDevices.enumerateDeviceswith hot-plug support. - Gracefully handles camera contention (
NotReadableError,TrackStartError) with diagnostic guidance and one-click camera re-query. - Built-in simulation mode for testing gaze tracking without an active camera.
- Enumerates video devices via
-
Gaze Calibration & Screen Mapping:
- 5-point calibration wizard (Center, Left, Right, Top, Bottom) that saves boundary boxes to
localStorage. - Pupil coordinates map to physical screen space: looking left targets Window 1 (0.0 to 0.50), looking right targets Window 2 (0.50 to 1.0).
- Instant
invertXtoggle.
- 5-point calibration wizard (Center, Left, Right, Top, Bottom) that saves boundary boxes to
-
Debounced Dwell Time Tracking:
- Configurable dwell threshold (default 300ms) with visual progress ring/bar feedback.
- Natural blink rejection preserves dwell progress without triggering while eyes are closed.
- Cooldown period prevents rapid back-and-forth window switching.
-
Windows OS Window Enumeration & Focus Activation:
scripts/get-desktop-windows.ps1enumerates top-level windows with screen bounds (X,Y,Width,Height), filtering system noise (explorer,TextInputHost,Antigravity, background tool windows).- Open windows are sorted left-to-right to bind to Window 1 and Window 2.
scripts/focus-window.ps1bypasses WindowsLockSetForegroundWindowrestrictions viaAttachThreadInput, simulated keyboard events,ShowWindow(SW_RESTORE),BringWindowToTop, andSetForegroundWindow.- Supports focus matching by PID first, then title substring, then process name, with a retry loop for minimized windows.
-
Display Mirroring UI:
- Numbered display monitor badges matching Microsoft Display Settings:
[ 1 ] Window 1and[ 2 ] Window 2. - Secondary badges showing connected applications (
App: chrome,App: slack). - One-click "Auto-Assign by Screen Position" and "⇄ Swap Window 1 & 2" controls.
- Web Audio API chime on successful focus switch.
- Numbered display monitor badges matching Microsoft Display Settings:
-
Multi-Environment Support:
- Electron Desktop: Native IPC via
contextBridge. - Browser Dev Server: Custom Vite middleware endpoints (
/api/windowsand/api/focus) for browser development without launch errors.
- Electron Desktop: Native IPC via
- Node.js 18+
- Windows 10 or 11 (for native Win32 window switching)
npm installnpm run devOpen http://localhost:5173.
npm run electronnpm run buildRun unit tests via Vitest:
npm testtests/gazeEngine.test.ts: EAR calculation, iris ratio bounds, exponential moving average smoothing, head pose estimation, physical screen orientation mapping, andinvertXtoggling.tests/dwellTracker.test.ts: Debounce timing, threshold triggers, cooldown windows, natural blink preservation (150-250ms), and expired grace period cleanup.tests/calibration.test.ts: Screen coordinate mapping, dual/triple zone classification, sample statistics, calibration bounding box finalization, and horizontal window sorting (including negative multi-monitor coordinates).
FocusTracker/
├── electron/
│ ├── main.ts # Electron process, IPC handlers, local server
│ ├── preload.ts # Context bridge exposing electronAPI
│ └── windowManager.ts # OS window enumeration & focus activation
├── scripts/
│ ├── get-desktop-windows.ps1 # Win32 window enumeration with true screen coordinates
│ ├── focus-window.ps1 # Win32 foreground activation & LockSetForeground bypass
│ └── build-electron.mjs # esbuild bundler for main and preload scripts
├── src/
│ ├── components/
│ │ ├── CameraSelector.tsx # Device selection, contention banner, simulator
│ │ ├── VideoCanvas.tsx # Video feed and MediaPipe landmark canvas overlay
│ │ ├── FocusHUD.tsx # Display monitor badges & dwell progress
│ │ ├── WindowConfig.tsx # Window assignment & Microsoft display simulator
│ │ ├── CalibrationWizard.tsx # 5-point calibration wizard
│ │ └── SettingsModal.tsx # Dwell, EAR, and smoothing settings
│ ├── core/
│ │ ├── gazeEngine.ts # Eye geometry, EAR, iris ratios, smoothing
│ │ ├── dwellTracker.ts # Debounce and dwell state machine
│ │ ├── calibration.ts # Calibration bounds, zone detection, window sorting
│ │ ├── mediapipeManager.ts # 4-tier model initialization fallback
│ │ ├── windowBridge.ts # IPC / Vite HTTP bridge for window operations
│ │ └── audioFeedback.ts # Web Audio synthesized chime feedback
│ ├── App.tsx # Main dashboard component
│ └── types/ # Shared TypeScript interfaces
├── tests/ # Vitest test suite
└── public/
├── models/face_landmarker.task # Offline MediaPipe model
└── wasm/ # Offline WASM binaries