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 io.nekohasekai.sfa.database.Settings
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -117,7 +118,7 @@ class BoxService(
|
|||||||
this.commandServer = commandServer
|
this.commandServer = commandServer
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun startService() {
|
private suspend fun startService(delayStart: Boolean = false) {
|
||||||
try {
|
try {
|
||||||
val selectedProfileId = Settings.selectedProfile
|
val selectedProfileId = Settings.selectedProfile
|
||||||
if (selectedProfileId == -1L) {
|
if (selectedProfileId == -1L) {
|
||||||
@@ -154,6 +155,10 @@ class BoxService(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (delayStart) {
|
||||||
|
delay(200L)
|
||||||
|
}
|
||||||
|
|
||||||
newService.start()
|
newService.start()
|
||||||
boxService = newService
|
boxService = newService
|
||||||
commandServer?.setService(boxService)
|
commandServer?.setService(boxService)
|
||||||
@@ -182,7 +187,7 @@ class BoxService(
|
|||||||
Seq.destroyRef(refnum)
|
Seq.destroyRef(refnum)
|
||||||
}
|
}
|
||||||
boxService = null
|
boxService = null
|
||||||
startService()
|
startService(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ class OverviewFragment : Fragment() {
|
|||||||
if (restart) {
|
if (restart) {
|
||||||
mainActivity.reconnect()
|
mainActivity.reconnect()
|
||||||
BoxService.stop()
|
BoxService.stop()
|
||||||
delay(200)
|
delay(200L)
|
||||||
mainActivity.startService()
|
mainActivity.startService()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class EditProfileActivity : AbstractActivity() {
|
|||||||
val binding = binding ?: return
|
val binding = binding ?: return
|
||||||
binding.progressView.isVisible = true
|
binding.progressView.isVisible = true
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
delay(200)
|
delay(200L)
|
||||||
try {
|
try {
|
||||||
ProfileManager.update(profile)
|
ProfileManager.update(profile)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -212,7 +212,7 @@ class EditProfileActivity : AbstractActivity() {
|
|||||||
val binding = binding ?: return
|
val binding = binding ?: return
|
||||||
binding.progressView.isVisible = true
|
binding.progressView.isVisible = true
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
delay(200)
|
delay(200L)
|
||||||
try {
|
try {
|
||||||
Libbox.checkConfig(File(profile.typed.path).readText())
|
Libbox.checkConfig(File(profile.typed.path).readText())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class EditProfileContentActivity : AbstractActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
delay(200)
|
delay(200L)
|
||||||
binding.progressView.isInvisible = true
|
binding.progressView.isInvisible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user