mirror of
https://github.com/SagerNet/sing-box-for-android.git
synced 2025-04-03 20:07:38 +03:00
Fix service reload
This commit is contained in:
parent
141eff8841
commit
cb06973881
4 changed files with 11 additions and 6 deletions
|
@ -28,6 +28,7 @@ import io.nekohasekai.sfa.database.ProfileManager
|
|||
import io.nekohasekai.sfa.database.Settings
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@ -117,7 +118,7 @@ class BoxService(
|
|||
this.commandServer = commandServer
|
||||
}
|
||||
|
||||
private suspend fun startService() {
|
||||
private suspend fun startService(delayStart: Boolean = false) {
|
||||
try {
|
||||
val selectedProfileId = Settings.selectedProfile
|
||||
if (selectedProfileId == -1L) {
|
||||
|
@ -154,6 +155,10 @@ class BoxService(
|
|||
return
|
||||
}
|
||||
|
||||
if (delayStart) {
|
||||
delay(200L)
|
||||
}
|
||||
|
||||
newService.start()
|
||||
boxService = newService
|
||||
commandServer?.setService(boxService)
|
||||
|
@ -182,7 +187,7 @@ class BoxService(
|
|||
Seq.destroyRef(refnum)
|
||||
}
|
||||
boxService = null
|
||||
startService()
|
||||
startService(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ class OverviewFragment : Fragment() {
|
|||
if (restart) {
|
||||
mainActivity.reconnect()
|
||||
BoxService.stop()
|
||||
delay(200)
|
||||
delay(200L)
|
||||
mainActivity.startService()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ class EditProfileActivity : AbstractActivity() {
|
|||
val binding = binding ?: return
|
||||
binding.progressView.isVisible = true
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
delay(200)
|
||||
delay(200L)
|
||||
try {
|
||||
ProfileManager.update(profile)
|
||||
} catch (e: Exception) {
|
||||
|
@ -212,7 +212,7 @@ class EditProfileActivity : AbstractActivity() {
|
|||
val binding = binding ?: return
|
||||
binding.progressView.isVisible = true
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
delay(200)
|
||||
delay(200L)
|
||||
try {
|
||||
Libbox.checkConfig(File(profile.typed.path).readText())
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -138,7 +138,7 @@ class EditProfileContentActivity : AbstractActivity() {
|
|||
}
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
delay(200)
|
||||
delay(200L)
|
||||
binding.progressView.isInvisible = true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue