diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt index 1cc7adf..de74202 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/MainActivity.kt @@ -148,16 +148,20 @@ class MainActivity : AppCompatActivity() { connectivityManager?.let { it.registerDefaultNetworkCallback(object : ConnectivityManager.NetworkCallback() { override fun onAvailable(network: Network) { - showToast("network on") - stopVpn() - Thread.sleep(1000) - startVpn() + if(isStarted) { + showToast("network on") + stopVpn() + Thread.sleep(1000) + startVpn() + } } override fun onLost(network: Network?) { - showToast("network off") - stopVpn() - Thread.sleep(1000) - startVpn() + if(isStarted) { + showToast("network off") + stopVpn() + Thread.sleep(1000) + startVpn() + } } }) } @@ -168,11 +172,19 @@ class MainActivity : AppCompatActivity() { Log.i(TAG, "Network state has been changed") if ("android.net.conn.CONNECTIVITY_CHANGE" == intent.action) { if (status == NetworkUtils.NETWORK_STATUS_NOT_CONNECTED) { - showToast("network on") - stopVpn() + if(isStarted) { + showToast("network on") + stopVpn() + Thread.sleep(1000) + startVpn() + } } else { - showToast("network of") - startVpn() + if(isStarted) { + showToast("network off") + stopVpn() + Thread.sleep(1000) + startVpn() + } } } }