Skip to content

Commit

Permalink
feat:蒲公英需要app完成备案才能调用api,去除它并仅使用github进行更新
Browse files Browse the repository at this point in the history
  • Loading branch information
nestor committed Feb 29, 2024
1 parent c131c38 commit 8858b0c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 61 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ android {

val NESTOR_KEYSTORE_PASSWORD = System.getenv("NESTOR_KEYSTORE_PASSWORD")
val NESTOR_KEYSTORE_ALIAS = System.getenv("NESTOR_KEYSTORE_ALIAS")
val PGY_API_KEY = System.getenv("PGY_API_KEY")
// val PGY_API_KEY = System.getenv("PGY_API_KEY")

signingConfigs {
create("release") {
Expand All @@ -83,13 +83,13 @@ android {
buildTypes {
named("debug").configure {
signingConfig = signingConfigs.getByName("release")
manifestPlaceholders["pgy_api_key"] = PGY_API_KEY
//manifestPlaceholders["pgy_api_key"] = PGY_API_KEY
}
named("release").configure {
isDebuggable = false
isJniDebuggable = false
signingConfig = signingConfigs.getByName("release")
manifestPlaceholders["pgy_api_key"] = PGY_API_KEY
// manifestPlaceholders["pgy_api_key"] = PGY_API_KEY
}
}
flavorDimensions.add("version")
Expand Down
4 changes: 0 additions & 4 deletions app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
android:resource="@color/colorPrimary" />

<!-- io.homeassistant.companion.android-->
<meta-data
android:name="pgy_api_key"
android:value="${pgy_api_key}" />


<meta-data
android:name="androidx.car.app.minCarApiLevel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import android.view.View
import android.widget.Toast
import androidx.core.content.FileProvider
import io.homeassistant.companion.android.BuildConfig
import io.homeassistant.companion.android.util.getAppMetaDataString
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import okhttp3.*
import org.json.JSONObject
import java.io.File
import java.io.IOException
import java.util.*
Expand Down Expand Up @@ -47,55 +45,55 @@ object UpdateUtil {
return
}

try {
val formBody: RequestBody = FormBody.Builder()
.add("_api_key", context.getAppMetaDataString("pgy_api_key"))
.add("appKey", "8a601dcac3098f0d5c89fa9fe416ca94")
.add("buildVersion", BuildConfig.VERSION_CODE.toString())
.build()
val request = Request.Builder().apply {
url("https://www.pgyer.com/apiv2/app/check")
post(formBody)
}.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
Log.e("checkNew==>", e.toString())
githubCheckNew(context, okHttpClient)
}

override fun onResponse(call: Call, response: Response) {
val res = response.body?.string()
if (res.isNullOrEmpty()) {
githubCheckNew(context, okHttpClient)
return
}
//Log.e("onResponse==>", res)
val jsonObject = JSONObject(res)
if (jsonObject.getInt("code") != 0) {
githubCheckNew(context, okHttpClient)
return
}
val dataObject = jsonObject.getJSONObject("data")
val buildHaveNewVersion = dataObject.getBoolean("buildHaveNewVersion")
if (!buildHaveNewVersion) return
val downloadURL = dataObject.getString("downloadURL")
val ver = dataObject.getString("buildVersion")
val desc = try {
dataObject.getString("buildUpdateDescription")
} catch (e: Exception) {
"有新版本了!"
}
val updateInfo = UpdateInfo(ver, desc, downloadURL)
val intent = Intent(context, UpdateActivity::class.java)
intent.putExtra(UpdateActivity.UPDATE_INFO, updateInfo)
context.startActivity(intent)
context.overridePendingTransition(0, 0)
}

})
} catch (e: Exception) {
githubCheckNew(context, okHttpClient)
}
// try {
// val formBody: RequestBody = FormBody.Builder()
// .add("_api_key", context.getAppMetaDataString("pgy_api_key"))
// .add("appKey", "8a601dcac3098f0d5c89fa9fe416ca94")
// .add("buildVersion", BuildConfig.VERSION_CODE.toString())
// .build()
// val request = Request.Builder().apply {
// url("https://www.pgyer.com/apiv2/app/check")
// post(formBody)
// }.build()
// okHttpClient.newCall(request).enqueue(object : Callback {
// override fun onFailure(call: Call, e: IOException) {
// Log.e("checkNew==>", e.toString())
// githubCheckNew(context, okHttpClient)
// }
//
// override fun onResponse(call: Call, response: Response) {
// val res = response.body?.string()
// if (res.isNullOrEmpty()) {
// githubCheckNew(context, okHttpClient)
// return
// }
// //Log.e("onResponse==>", res)
// val jsonObject = JSONObject(res)
// if (jsonObject.getInt("code") != 0) {
// githubCheckNew(context, okHttpClient)
// return
// }
// val dataObject = jsonObject.getJSONObject("data")
// val buildHaveNewVersion = dataObject.getBoolean("buildHaveNewVersion")
// if (!buildHaveNewVersion) return
// val downloadURL = dataObject.getString("downloadURL")
// val ver = dataObject.getString("buildVersion")
// val desc = try {
// dataObject.getString("buildUpdateDescription")
// } catch (e: Exception) {
// "有新版本了!"
// }
// val updateInfo = UpdateInfo(ver, desc, downloadURL)
// val intent = Intent(context, UpdateActivity::class.java)
// intent.putExtra(UpdateActivity.UPDATE_INFO, updateInfo)
// context.startActivity(intent)
// context.overridePendingTransition(0, 0)
// }
//
// })
// } catch (e: Exception) {
githubCheckNew(context, okHttpClient)
// }
}

private fun githubCheckNew(context: Activity, okHttpClient: OkHttpClient) {
Expand All @@ -109,7 +107,7 @@ object UpdateUtil {
runBlocking(Dispatchers.Main) {
Toast.makeText(
context,
"有新版本了!",
"获取版本信息失败,您可能无法访问github。",
Toast.LENGTH_SHORT
).show()
}
Expand All @@ -125,8 +123,8 @@ object UpdateUtil {
Log.d("checkNew==>apkUrl:", apkUrl)
val updateInfo = UpdateInfo(
ver, "如果无法直接更新,可以关注公众号进行更新!\n" +
"公众号:UnknownExceptions 回复 最新版 获取新版本\n" +
"也可回复HA获取全新Flutter版本", apkUrl
"公众号:UnknownExceptions 回复 最新版 获取新版本\n" +
"也可回复HA获取全新Flutter版本", apkUrl
)
val intent = Intent(context, UpdateActivity::class.java)
intent.putExtra(UpdateActivity.UPDATE_INFO, updateInfo)
Expand Down

0 comments on commit 8858b0c

Please sign in to comment.