@@ -3,7 +3,6 @@ package com.github.jing332.tts_server_android.util
33import android.annotation.SuppressLint
44import android.app.PendingIntent
55import android.content.Context
6- import android.content.DialogInterface
76import android.content.Intent
87import android.content.pm.ShortcutInfo
98import android.content.pm.ShortcutManager
@@ -13,42 +12,33 @@ import android.os.Build
1312import android.util.Log
1413import android.widget.Toast
1514import androidx.appcompat.app.AlertDialog
15+ import com.drake.net.Net
1616import com.github.jing332.tts_server_android.App
1717import com.github.jing332.tts_server_android.R
1818import com.github.jing332.tts_server_android.bean.GithubReleaseApiBean
1919import kotlinx.coroutines.DelicateCoroutinesApi
20+ import kotlinx.coroutines.Dispatchers
2021import kotlinx.coroutines.GlobalScope
2122import kotlinx.coroutines.launch
2223import kotlinx.serialization.decodeFromString
23- import kotlinx.serialization.json.Json
24- import tts_server_lib.Tts_server_lib
24+ import okhttp3.Response
2525import java.math.BigDecimal
2626
2727
2828object MyTools {
2929 const val TAG = " MyTools"
30+ private const val GITHUB_RELEASES_LATEST_URL =
31+ " https://api.github.com/repos/jing332/tts-server-android/releases/latest"
3032 private val json by lazy { App .jsonBuilder }
3133
3234 /* 从Github检查更新*/
3335 @OptIn(DelicateCoroutinesApi ::class )
3436 fun checkUpdate (ctx : Context ) {
35- GlobalScope .launch {
37+ GlobalScope .launch( Dispatchers . IO ) {
3638 try {
37- val data = Tts_server_lib .httpGet(
38- " https://api.github.com/repos/jing332/tts-server-android/releases/latest" ,
39- " "
40- )
41- if (data == null ) {
42- ctx.toast(R .string.check_update_failed)
43- } else {
44- try {
45- checkVersionFromJson(ctx, data.decodeToString())
46- } catch (e: Exception ) {
47- e.printStackTrace()
48- ctx.toast(R .string.check_update_failed)
49- }
50- }
51-
39+ val resp: Response = Net .get(GITHUB_RELEASES_LATEST_URL ).execute()
40+ val jsonStr = resp.body?.string()
41+ checkVersionFromJson(ctx, jsonStr!! )
5242 } catch (e: Exception ) {
5343 e.printStackTrace()
5444 ctx.toast(R .string.check_update_failed)
0 commit comments