Skip to content

Commit

Permalink
Check new version in individual coroutine scope and IO context
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZong committed Dec 30, 2024
1 parent 4e71604 commit 963dc40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/moe/nemesiss/hostman/HostmanActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ class HostmanActivity : ComponentActivity(), ServiceConnection {
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {

checkUpdateModel.checkNewVersionAvailable()
// Check new version in individual coroutine scope.
lifecycleScope.launch {
checkUpdateModel.checkNewVersionAvailable()
}

ShizukuStateModel
.state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.alibaba.fastjson2.to
import com.alibaba.fastjson2.toJSONString
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import moe.nemesiss.hostman.BuildConfig
import moe.nemesiss.hostman.boost.EasyDebug
import moe.nemesiss.hostman.model.*
Expand Down Expand Up @@ -34,8 +36,9 @@ object CheckUpdateService {
}

suspend fun checkNewVersionAvailable(): CheckVersionResult {

try {
val latestVersion = getLatestAppVersion() ?: return NoNewVersionResult
val latestVersion = withContext(Dispatchers.IO) { getLatestAppVersion() } ?: return NoNewVersionResult
val currentVersion = BuildConfig.VERSION_NAME.replace(".debug", "")
if (latestVersion > AppVersion(currentVersion)) {
EasyDebug.info(TAG) { "New version available: $latestVersion, current version: $currentVersion" }
Expand Down

0 comments on commit 963dc40

Please sign in to comment.