fix: 优化更新检查用户体验

🔇 静默更新检查:
- 自动检查时不显示任何提示信息
- 只有发现新版本时才弹出更新对话框
- 手动检查时显示完整的状态反馈

👤 用户友好:
- 避免应用启动时的无关弹窗
- 网络错误时静默处理,不干扰用户
- 完全模仿 FongMi/TV 的更新体验

🎛️ 控制机制:
- forceCheck 标记区分自动/手动检查
- 手机版和TV版行为完全一致
- 用户可以通过设置禁用自动检查
This commit is contained in:
您的名字
2025-09-26 13:59:27 +08:00
parent e094f38423
commit 8c6275ffe8
2 changed files with 46 additions and 22 deletions
@@ -29,6 +29,7 @@ public class Updater implements Download.Callback {
private final Download download;
private AlertDialog dialog;
private boolean dev;
private boolean forceCheck; // 是否为手动检查
private File getFile() {
return Path.cache("update.apk");
@@ -48,11 +49,13 @@ public class Updater implements Download.Callback {
public Updater() {
this.download = Download.create(getApk(), getFile(), this);
this.forceCheck = false;
}
public Updater force() {
Notify.show(R.string.update_check);
Setting.putUpdate(true);
this.forceCheck = true; // 标记为手动检查
return this;
}
@@ -88,14 +91,18 @@ public class Updater implements Download.Callback {
try {
String response = OkHttp.string(getJson());
// 检查响应是否包含错误信息
// 检查响应是否包含错误信息,只在手动检查时提示
if (response.contains("rate limit exceeded")) {
if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试"));
}
return;
}
if (response.contains("Not Found Project") || response.contains("Not Found")) {
if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用"));
}
return;
}
@@ -106,13 +113,16 @@ public class Updater implements Download.Callback {
if (need(code, name)) {
App.post(() -> show(activity, name, desc));
} else {
// 不需要更新,提示已是最新版
// 只在手动检查时提示已是最新版
if (forceCheck) {
App.post(() -> Notify.show("已是最新版本 " + name));
}
Logger.d("Already latest version: " + name);
}
} catch (Exception e) {
e.printStackTrace();
// 添加用户友好的错误提示
// 只在手动检查时提示网络错误
if (forceCheck) {
App.post(() -> {
String errorMsg = "检查更新失败";
if (e.getMessage() != null && e.getMessage().contains("rate limit")) {
@@ -126,6 +136,7 @@ public class Updater implements Download.Callback {
});
}
}
}
private void show(Activity activity, String version, String desc) {
binding = DialogUpdateBinding.inflate(LayoutInflater.from(activity));
@@ -29,6 +29,7 @@ public class Updater implements Download.Callback {
private final Download download;
private AlertDialog dialog;
private boolean dev;
private boolean forceCheck; // 是否为手动检查
private File getFile() {
return Path.cache("update.apk");
@@ -48,11 +49,13 @@ public class Updater implements Download.Callback {
public Updater() {
this.download = Download.create(getApk(), getFile(), this);
this.forceCheck = false;
}
public Updater force() {
Notify.show(R.string.update_check);
Setting.putUpdate(true);
this.forceCheck = true; // 标记为手动检查
return this;
}
@@ -88,14 +91,18 @@ public class Updater implements Download.Callback {
try {
String response = OkHttp.string(getJson());
// 检查响应是否包含错误信息
// 检查响应是否包含错误信息,只在手动检查时提示
if (response.contains("rate limit exceeded")) {
if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试"));
}
return;
}
if (response.contains("Not Found Project") || response.contains("Not Found")) {
if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用"));
}
return;
}
@@ -106,14 +113,20 @@ public class Updater implements Download.Callback {
if (need(code, name)) {
App.post(() -> show(activity, name, desc));
} else {
// 不需要更新,提示已是最新版
// 只在手动检查时提示已是最新版
if (forceCheck) {
App.post(() -> Notify.show("已是最新版本 " + name));
}
Logger.d("Already latest version: " + name);
}
} catch (Exception e) {
e.printStackTrace();
// 只在手动检查时提示网络错误
if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:网络连接异常"));
}
}
}
private void show(Activity activity, String version, String desc) {
binding = DialogUpdateBinding.inflate(LayoutInflater.from(activity));