mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-26 21:13:01 +00:00
exception test 3
This commit is contained in:
parent
2f191bbb7e
commit
a9da78ff71
3 changed files with 26 additions and 23 deletions
|
@ -3,7 +3,6 @@ package com.vanced.manager.core.downloader
|
|||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.widget.Toast
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
|
@ -19,17 +18,11 @@ import com.vanced.manager.utils.InternetTools.getFileNameFromUrl
|
|||
import com.vanced.manager.utils.NotificationHelper
|
||||
import com.vanced.manager.utils.NotificationHelper.cancelNotif
|
||||
import com.vanced.manager.utils.NotificationHelper.createBasicNotif
|
||||
import java.lang.IllegalStateException
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
class MicrogDownloadService: Service() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
try {
|
||||
downloadMicrog()
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(this, "Unable to download MicroG", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
stopSelf()
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
@ -37,10 +30,18 @@ class MicrogDownloadService: Service() {
|
|||
private fun downloadMicrog() {
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
|
||||
val apkUrl = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json")
|
||||
val dwnldUrl = apkUrl.get("url").asString
|
||||
val apkUrl =
|
||||
if(GetJson().isConnected(this))
|
||||
try {
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/microg.json").get("url").asString
|
||||
} catch (e: Exception) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/microg.json").get("url").asString
|
||||
}
|
||||
else
|
||||
""
|
||||
|
||||
val channel = 420
|
||||
PRDownloader.download(dwnldUrl, filesDir.path, "microg.apk")
|
||||
PRDownloader.download(apkUrl, filesDir.path, "microg.apk")
|
||||
.build()
|
||||
.setOnStartOrResumeListener { OnStartOrResumeListener { prefs?.edit()?.putBoolean("isMicrogDownloading", true)?.apply() } }
|
||||
.setOnProgressListener { progress ->
|
||||
|
@ -48,7 +49,7 @@ class MicrogDownloadService: Service() {
|
|||
NotificationHelper.displayDownloadNotif(
|
||||
channel,
|
||||
mProgress.toInt(),
|
||||
getFileNameFromUrl(dwnldUrl),
|
||||
getFileNameFromUrl(apkUrl),
|
||||
this
|
||||
)
|
||||
}
|
||||
|
|
|
@ -41,7 +41,15 @@ class VancedDownloadService: Service() {
|
|||
type: String = "arch"
|
||||
) {
|
||||
val baseUrl = PreferenceManager.getDefaultSharedPreferences(this).getString("install_url", baseUrl)
|
||||
val vancedVer = GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("version").asString
|
||||
val vancedVer =
|
||||
if(GetJson().isConnected(this))
|
||||
try {
|
||||
GetJson().AsJSONObject("https://vanced.app/api/v1/vanced.json").get("vanced").asString
|
||||
} catch (e: Exception) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/vanced.json").get("vanced").asString
|
||||
}
|
||||
else
|
||||
""
|
||||
val prefs = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
val variant = PreferenceManager.getDefaultSharedPreferences(this).getString("vanced_variant", "nonroot")
|
||||
val lang = prefs?.getString("lang", "en")
|
||||
|
|
|
@ -26,14 +26,10 @@ object InternetTools {
|
|||
fun displayJsonString(json: String, obj: String, context: Context): String {
|
||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||
return if (GetJson().isConnected(context)) {
|
||||
try {
|
||||
return try {
|
||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asString
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is InterruptedException, is ExecutionException -> GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
||||
else -> throw e
|
||||
}
|
||||
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asString
|
||||
}
|
||||
} else {
|
||||
context.getString(R.string.unavailable)
|
||||
|
@ -43,7 +39,7 @@ object InternetTools {
|
|||
fun displayJsonInt(json: String, obj: String, context: Context): Int {
|
||||
val installUrl = PreferenceManager.getDefaultSharedPreferences(context).getString("install_url", baseUrl)
|
||||
return if (GetJson().isConnected(context)) {
|
||||
try {
|
||||
return try {
|
||||
GetJson().AsJSONObject("$installUrl/$json").get(obj).asInt
|
||||
} catch (e: Exception) {
|
||||
GetJson().AsJSONObject("https://x1nto.github.io/VancedFiles/$json").get(obj).asInt
|
||||
|
@ -60,6 +56,4 @@ object InternetTools {
|
|||
|
||||
const val baseUrl = "https://vanced.app/api/v1"
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue