minor: disable stats job when app is closed

Adds a slight battery performance improvement

#437
This commit is contained in:
Zane Schepke
2024-11-23 15:00:06 -05:00
parent f79f922838
commit 9a2d77c8bf
4 changed files with 8 additions and 3 deletions
@@ -273,7 +273,7 @@ constructor(
}
companion object {
const val STATS_START_DELAY = 5_000L
const val STATS_START_DELAY = 1_000L
const val VPN_STATISTIC_CHECK_INTERVAL = 1_000L
const val VPN_RESTART_DELAY = 1_000L
}
@@ -94,6 +94,7 @@ constructor(
}
private suspend fun initTunnel() {
if (tunnelService.get().getState() == TunnelState.UP) tunnelService.get().startStatsJob()
val activeTunnels = appDataRepository.tunnels.getActive()
if (activeTunnels.isNotEmpty() &&
tunnelService.get().getState() == TunnelState.DOWN
@@ -215,4 +215,9 @@ class MainActivity : AppCompatActivity() {
}
}
}
override fun onDestroy() {
super.onDestroy()
// save battery by not polling stats while app is closed
tunnelService.cancelStatsJob()
}
}