diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt index b1df39a..8070450 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt @@ -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 } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt index 38bac86..18acd24 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/AppViewModel.kt @@ -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 diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt index d0d3321..f8477b2 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt @@ -215,4 +215,9 @@ class MainActivity : AppCompatActivity() { } } } + override fun onDestroy() { + super.onDestroy() + // save battery by not polling stats while app is closed + tunnelService.cancelStatsJob() + } } diff --git a/logcatter/src/main/java/com/zaneschepke/logcatter/LogcatCollector.kt b/logcatter/src/main/java/com/zaneschepke/logcatter/LogcatCollector.kt index bbefde2..ad5316a 100644 --- a/logcatter/src/main/java/com/zaneschepke/logcatter/LogcatCollector.kt +++ b/logcatter/src/main/java/com/zaneschepke/logcatter/LogcatCollector.kt @@ -182,8 +182,7 @@ object LogcatCollector { clear() logcatProc = Runtime.getRuntime().exec(command) reader = BufferedReader(InputStreamReader(logcatProc!!.inputStream), 1024) - var line: String? = null - + var line: String? while (!stopped) { if (paused) continue line = reader?.readLine()