Fix service reload
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user