mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-28 14:15: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)
|
receiver, IntentFilter(STATE_INTENT)
|
||||||
)
|
)
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
|
enabledSwitch.isChecked = preferences.getBoolean(PREF_KEY_ENABLED, false)
|
||||||
val serverString = preferences.getString(KEY_DNS_SERVERS, "")
|
val serverString = preferences.getString(KEY_DNS_SERVERS, "")
|
||||||
if (serverString!!.isNotEmpty()) {
|
if (serverString!!.isNotEmpty()) {
|
||||||
val servers = serverString.split(",")
|
val servers = serverString.split(",")
|
||||||
|
@ -153,7 +154,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
when (intent.getStringExtra("type")) {
|
when (intent.getStringExtra("type")) {
|
||||||
"state" -> {
|
"state" -> {
|
||||||
enabledLabel.text = if (intent.getBooleanExtra("started", false)) {
|
enabledLabel.text = if (intent.getBooleanExtra("started", false)) {
|
||||||
enabledSwitch.isChecked = true
|
|
||||||
var count = 0
|
var count = 0
|
||||||
if (intent.hasExtra("dht")) {
|
if (intent.hasExtra("dht")) {
|
||||||
val dht = intent.getStringExtra("dht")
|
val dht = intent.getStringExtra("dht")
|
||||||
|
@ -170,7 +170,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
getString(R.string.main_enabled)
|
getString(R.string.main_enabled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enabledSwitch.isChecked = false
|
|
||||||
enabledLabel.setTextColor(Color.GRAY)
|
enabledLabel.setTextColor(Color.GRAY)
|
||||||
getString(R.string.main_disabled)
|
getString(R.string.main_disabled)
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,10 +59,7 @@ class PacketTunnelProvider: VpnService() {
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
val preferences = PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
if (!preferences.getBoolean(PREF_KEY_ENABLED, false)) {
|
val enabled = preferences.getBoolean(PREF_KEY_ENABLED, false)
|
||||||
Log.d(TAG, "Service is disabled")
|
|
||||||
return START_NOT_STICKY
|
|
||||||
}
|
|
||||||
return when (intent.action ?: ACTION_STOP) {
|
return when (intent.action ?: ACTION_STOP) {
|
||||||
ACTION_STOP -> {
|
ACTION_STOP -> {
|
||||||
Log.d(TAG, "Stopping...")
|
Log.d(TAG, "Stopping...")
|
||||||
|
@ -86,6 +83,10 @@ class PacketTunnelProvider: VpnService() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
if (!enabled) {
|
||||||
|
Log.d(TAG, "Service is disabled")
|
||||||
|
return START_NOT_STICKY
|
||||||
|
}
|
||||||
Log.d(TAG, "Starting...")
|
Log.d(TAG, "Starting...")
|
||||||
start(); START_STICKY
|
start(); START_STICKY
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue