Skip to content

Conversation

@vide
Copy link
Owner

@vide vide commented Jan 19, 2026

Summary

  • Adds ServerHealthMonitor that periodically pings both servers every 10 seconds
  • App now proactively knows which server is available, eliminating timeout waits
  • When primary is unavailable (e.g., VPN scenario), secondary is tried first immediately

How it works

  1. ServerHealthMonitor runs in background when app is in foreground
  2. Pings both servers and tracks availability via StateFlow<ServerPreference>
  3. TeslamateRepository observes this preference to decide server order
  4. When settings change, cache is invalidated and health check runs immediately

Changes

  • New ServerHealthMonitor class with lifecycle awareness
  • Updated TeslamateRepository to use health monitor for server selection
  • Updated SettingsViewModel to trigger health check on settings save
  • Added lifecycle-process dependency for ProcessLifecycleOwner

Test plan

  • Configure primary and secondary servers
  • Verify app works normally when both are available
  • Disconnect from primary server network (VPN off)
  • Verify data loads immediately via secondary (no 1s timeout wait)
  • Reconnect to primary network (VPN on)
  • Verify app switches back to primary within ~10 seconds

🤖 Generated with Claude Code

Adds a ServerHealthMonitor that periodically checks the availability
of primary and secondary servers. This allows the app to proactively
switch to the available server without waiting for connection timeouts.

- Runs health checks every 10 seconds when app is in foreground
- Uses ProcessLifecycleOwner to detect app foreground/background state
- TeslamateRepository now uses health status to choose server order
- Settings changes trigger immediate health check
- Added lifecycle-process dependency

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants