mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-28 06:05:08 +03:00
Fixed a bug with turning on/off the VPN.
This commit is contained in:
parent
631d321206
commit
4b8e6cf922
2 changed files with 6 additions and 6 deletions
|
@ -128,6 +128,7 @@ class MainActivity : AppCompatActivity() {
|
|||
receiver, IntentFilter(STATE_INTENT)
|
||||
)
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
enabledSwitch.isChecked = preferences.getBoolean(PREF_KEY_ENABLED, false)
|
||||
val serverString = preferences.getString(KEY_DNS_SERVERS, "")
|
||||
if (serverString!!.isNotEmpty()) {
|
||||
val servers = serverString.split(",")
|
||||
|
@ -153,7 +154,6 @@ class MainActivity : AppCompatActivity() {
|
|||
when (intent.getStringExtra("type")) {
|
||||
"state" -> {
|
||||
enabledLabel.text = if (intent.getBooleanExtra("started", false)) {
|
||||
enabledSwitch.isChecked = true
|
||||
var count = 0
|
||||
if (intent.hasExtra("dht")) {
|
||||
val dht = intent.getStringExtra("dht")
|
||||
|
@ -170,7 +170,6 @@ class MainActivity : AppCompatActivity() {
|
|||
getString(R.string.main_enabled)
|
||||
}
|
||||
} else {
|
||||
enabledSwitch.isChecked = false
|
||||
enabledLabel.setTextColor(Color.GRAY)
|
||||
getString(R.string.main_disabled)
|
||||
}
|
||||
|
|
|
@ -59,10 +59,7 @@ class PacketTunnelProvider: VpnService() {
|
|||
return START_NOT_STICKY
|
||||
}
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||
if (!preferences.getBoolean(PREF_KEY_ENABLED, false)) {
|
||||
Log.d(TAG, "Service is disabled")
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
val enabled = preferences.getBoolean(PREF_KEY_ENABLED, false)
|
||||
return when (intent.action ?: ACTION_STOP) {
|
||||
ACTION_STOP -> {
|
||||
Log.d(TAG, "Stopping...")
|
||||
|
@ -86,6 +83,10 @@ class PacketTunnelProvider: VpnService() {
|
|||
}
|
||||
}
|
||||
else -> {
|
||||
if (!enabled) {
|
||||
Log.d(TAG, "Service is disabled")
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
Log.d(TAG, "Starting...")
|
||||
start(); START_STICKY
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue