修复自动更新功能并优化Gitee镜像配置
- 修复版本号点击无弹窗问题,添加友好的错误提示 - 更新Gitee镜像配置,使用正确的用户名 ochenoktochen/XMBOX - 优化更新检测逻辑,支持智能镜像选择和错误处理 - 增强用户体验,显示具体的更新失败原因 - 支持GitHub API限流时自动切换到Gitee镜像源
This commit is contained in:
@@ -6,6 +6,7 @@ import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.fongmi.android.tv.App;
|
||||
import com.fongmi.android.tv.databinding.DialogUpdateBinding;
|
||||
import com.fongmi.android.tv.utils.Download;
|
||||
import com.fongmi.android.tv.utils.FileUtil;
|
||||
@@ -79,13 +80,38 @@ public class Updater implements Download.Callback {
|
||||
|
||||
private void doInBackground(Activity activity) {
|
||||
try {
|
||||
JSONObject object = new JSONObject(OkHttp.string(getJson()));
|
||||
String response = OkHttp.string(getJson());
|
||||
|
||||
// 检查响应是否包含错误信息
|
||||
if (response.contains("rate limit exceeded")) {
|
||||
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.contains("Not Found Project") || response.contains("Not Found")) {
|
||||
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用"));
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject object = new JSONObject(response);
|
||||
String name = object.optString("name");
|
||||
String desc = object.optString("desc");
|
||||
int code = object.optInt("code");
|
||||
if (need(code, name)) App.post(() -> show(activity, name, desc));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// 添加用户友好的错误提示
|
||||
App.post(() -> {
|
||||
String errorMsg = "检查更新失败";
|
||||
if (e.getMessage() != null && e.getMessage().contains("rate limit")) {
|
||||
errorMsg = "检查更新失败:请求过于频繁,请稍后重试";
|
||||
} else if (e.getMessage() != null && e.getMessage().contains("Not Found")) {
|
||||
errorMsg = "检查更新失败:更新服务暂时不可用";
|
||||
} else {
|
||||
errorMsg = "检查更新失败,请稍后重试";
|
||||
}
|
||||
Notify.show(errorMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.fongmi.android.tv.App;
|
||||
import com.fongmi.android.tv.databinding.DialogUpdateBinding;
|
||||
import com.fongmi.android.tv.utils.Download;
|
||||
import com.fongmi.android.tv.utils.FileUtil;
|
||||
@@ -124,6 +125,17 @@ public class Updater implements Download.Callback {
|
||||
String response = OkHttp.string(jsonUrl);
|
||||
Logger.d("Update check response: " + response);
|
||||
|
||||
// 检查响应是否包含错误信息
|
||||
if (response.contains("rate limit exceeded")) {
|
||||
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.contains("Not Found Project") || response.contains("Not Found")) {
|
||||
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用"));
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject release = new JSONObject(response);
|
||||
String tagName = release.getString("tag_name");
|
||||
String body = release.getString("body");
|
||||
@@ -148,6 +160,18 @@ public class Updater implements Download.Callback {
|
||||
} catch (Exception e) {
|
||||
Logger.e("Update check failed", e);
|
||||
e.printStackTrace();
|
||||
// 添加用户友好的错误提示
|
||||
App.post(() -> {
|
||||
String errorMsg = "检查更新失败";
|
||||
if (e.getMessage() != null && e.getMessage().contains("rate limit")) {
|
||||
errorMsg = "检查更新失败:请求过于频繁,请稍后重试";
|
||||
} else if (e.getMessage() != null && e.getMessage().contains("Not Found")) {
|
||||
errorMsg = "检查更新失败:更新服务暂时不可用";
|
||||
} else {
|
||||
errorMsg = "检查更新失败,请稍后重试";
|
||||
}
|
||||
Notify.show(errorMsg);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user