How bariskisir/sessionlens works
Session Lens is an Electron desktop app for monitoring AI-provider usage limits. Its main workflow is: the main process loads settings, periodically queries enabled providers, aggregates quota windows, then updates the tray icon and tooltip, emits snapshots, and checks notification thresholds. Users configure providers and display behavior in the renderer; settings cross a limited preload IPC bridge and persist as validated JSON. The README also documents reset-window warm starts, update checks, and multiple notification channels. Wiring beyond the sampled excerpts is shown only where the tree or documentation supports the subsystem; those paths identify enclosing directories.
Main entry points: UsageRefreshService.ts Refresh service · main/index.ts App lifecycle · ipc.ts IPC handlers · preload/index.ts Preload API
Components 22
Desktop runtime
- App lifecycle
src/main/index.ts - Window service
src/main/services/WindowService.ts - IPC handlers
src/main/ipc.ts - Preload API
src/preload/index.ts - Tray and tooltip
src/main/services/TrayService.ts
Usage monitoring
- Refresh service
src/main/services/usage/UsageRefreshService.ts - Usage aggregator
src/main/services/usage/UsageAggregator.ts - Usage providers
src/main/services/usage/providers - Auth readers
src/main/services/usage - Usage presentation
src/main/services/usage - Threshold notifications
src/main/services/usage/NotificationDispatcher.ts - Window warm starts
src/main/services/usage/UsageWindowStartService.ts
Renderer interface
- Settings interface
src/renderer/src/App.tsx - Settings actions
src/renderer/src/hooks/useSettingsActions.ts - Renderer state
src/renderer/src/store
Settings and state
- Settings storage
src/main/services/StorageService.ts
External integrations
- Update service
src/main/services/AppUpdater.ts - Telemetry service
src/main/services/TelemetryService.ts - Provider APIs
- Notification channels
- GitHub Releases
Other components
- Desktop user
Connections 28
- Desktop user → Settings interface: configures
- App lifecycle → Settings storage: loads settings
- App lifecycle → Window service: creates window
- App lifecycle → Refresh service: starts loop
- App lifecycle → IPC handlers: registers handlers
- App lifecycle → Telemetry service: tracks startup
- Settings interface → Preload API: calls API
- Preload API → IPC handlers: invokes channels
- IPC handlers → Settings storage: reads and saves
- IPC handlers → Refresh service: requests refresh
- Refresh service → Settings storage: loads settings
- Refresh service → Usage aggregator: queries usage
- Usage aggregator → Usage providers: dispatches queries
- Usage providers → Provider APIs: requests quotas
- Usage aggregator → Auth readers: uses credentials
- Refresh service → Tray and tooltip: sets usage display
- Refresh service → Usage presentation: builds display data
- Refresh service → Threshold notifications: checks thresholds
- Threshold notifications → Notification channels: sends alerts
- Refresh service → Window warm starts: observes windows
- Tray and tooltip → Desktop user: shows status
- Refresh service → IPC handlers: emits snapshots
- IPC handlers → Preload API: forwards events
- Preload API → Settings interface: delivers updates
- Settings actions → Preload API: saves settings
- Settings actions → Renderer state: updates state
- App lifecycle → Update service: creates service
- Update service → GitHub Releases: checks releases