mirror of
https://github.com/2dust/v2rayNG.git
synced 2025-06-28 12:19:52 +00:00
Improved update checking and prompts in case of abnormality
This commit is contained in:
parent
1a5e105212
commit
e077c18108
2 changed files with 12 additions and 10 deletions
|
@ -17,7 +17,6 @@ import java.io.FileOutputStream
|
||||||
|
|
||||||
object UpdateCheckerManager {
|
object UpdateCheckerManager {
|
||||||
suspend fun checkForUpdate(includePreRelease: Boolean = false): CheckUpdateResult = withContext(Dispatchers.IO) {
|
suspend fun checkForUpdate(includePreRelease: Boolean = false): CheckUpdateResult = withContext(Dispatchers.IO) {
|
||||||
try {
|
|
||||||
val url = if (includePreRelease) {
|
val url = if (includePreRelease) {
|
||||||
AppConfig.APP_API_URL
|
AppConfig.APP_API_URL
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,10 +52,6 @@ object UpdateCheckerManager {
|
||||||
} else {
|
} else {
|
||||||
CheckUpdateResult(hasUpdate = false)
|
CheckUpdateResult(hasUpdate = false)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(AppConfig.TAG, "Failed to check for updates: ${e.message}")
|
|
||||||
return@withContext CheckUpdateResult(hasUpdate = false, error = e.message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun downloadApk(context: Context, downloadUrl: String): File? = withContext(Dispatchers.IO) {
|
suspend fun downloadApk(context: Context, downloadUrl: String): File? = withContext(Dispatchers.IO) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.v2ray.ang.ui
|
package com.v2ray.ang.ui
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.v2ray.ang.AppConfig
|
import com.v2ray.ang.AppConfig
|
||||||
|
@ -9,6 +10,7 @@ import com.v2ray.ang.R
|
||||||
import com.v2ray.ang.databinding.ActivityCheckUpdateBinding
|
import com.v2ray.ang.databinding.ActivityCheckUpdateBinding
|
||||||
import com.v2ray.ang.dto.CheckUpdateResult
|
import com.v2ray.ang.dto.CheckUpdateResult
|
||||||
import com.v2ray.ang.extension.toast
|
import com.v2ray.ang.extension.toast
|
||||||
|
import com.v2ray.ang.extension.toastError
|
||||||
import com.v2ray.ang.extension.toastSuccess
|
import com.v2ray.ang.extension.toastSuccess
|
||||||
import com.v2ray.ang.handler.MmkvManager
|
import com.v2ray.ang.handler.MmkvManager
|
||||||
import com.v2ray.ang.handler.SpeedtestManager
|
import com.v2ray.ang.handler.SpeedtestManager
|
||||||
|
@ -46,11 +48,16 @@ class CheckUpdateActivity : BaseActivity() {
|
||||||
toast(R.string.update_checking_for_update)
|
toast(R.string.update_checking_for_update)
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val result = UpdateCheckerManager.checkForUpdate(includePreRelease)
|
try {
|
||||||
if (result.hasUpdate) {
|
val result = UpdateCheckerManager.checkForUpdate(includePreRelease)
|
||||||
showUpdateDialog(result)
|
if (result.hasUpdate) {
|
||||||
} else {
|
showUpdateDialog(result)
|
||||||
toastSuccess(R.string.update_already_latest_version)
|
} else {
|
||||||
|
toastSuccess(R.string.update_already_latest_version)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(AppConfig.TAG, "Failed to check for updates: ${e.message}")
|
||||||
|
toastError(e.message ?: getString(R.string.toast_failure))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue