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 final Download download;
private AlertDialog dialog; private AlertDialog dialog;
private boolean dev; private boolean dev;
private boolean forceCheck; // 是否为手动检查
private File getFile() { private File getFile() {
return Path.cache("update.apk"); return Path.cache("update.apk");
@@ -48,11 +49,13 @@ public class Updater implements Download.Callback {
public Updater() { public Updater() {
this.download = Download.create(getApk(), getFile(), this); this.download = Download.create(getApk(), getFile(), this);
this.forceCheck = false;
} }
public Updater force() { public Updater force() {
Notify.show(R.string.update_check); Notify.show(R.string.update_check);
Setting.putUpdate(true); Setting.putUpdate(true);
this.forceCheck = true; // 标记为手动检查
return this; return this;
} }
@@ -88,14 +91,18 @@ public class Updater implements Download.Callback {
try { try {
String response = OkHttp.string(getJson()); String response = OkHttp.string(getJson());
// 检查响应是否包含错误信息 // 检查响应是否包含错误信息,只在手动检查时提示
if (response.contains("rate limit exceeded")) { if (response.contains("rate limit exceeded")) {
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试")); if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试"));
}
return; return;
} }
if (response.contains("Not Found Project") || response.contains("Not Found")) { if (response.contains("Not Found Project") || response.contains("Not Found")) {
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用")); if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用"));
}
return; return;
} }
@@ -106,24 +113,28 @@ public class Updater implements Download.Callback {
if (need(code, name)) { if (need(code, name)) {
App.post(() -> show(activity, name, desc)); App.post(() -> show(activity, name, desc));
} else { } else {
// 不需要更新,提示已是最新版 // 只在手动检查时提示已是最新版
App.post(() -> Notify.show("已是最新版本 " + name)); if (forceCheck) {
App.post(() -> Notify.show("已是最新版本 " + name));
}
Logger.d("Already latest version: " + name); Logger.d("Already latest version: " + name);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
// 添加用户友好的错误提示 // 只在手动检查时提示网络错误
App.post(() -> { if (forceCheck) {
String errorMsg = "检查更新失败"; App.post(() -> {
if (e.getMessage() != null && e.getMessage().contains("rate limit")) { String errorMsg = "检查更新失败";
errorMsg = "检查更新失败:请求过于频繁,请稍后重试"; if (e.getMessage() != null && e.getMessage().contains("rate limit")) {
} else if (e.getMessage() != null && e.getMessage().contains("Not Found")) { errorMsg = "检查更新失败:请求过于频繁,请稍后重试";
errorMsg = "检查更新失败:更新服务暂时不可用"; } else if (e.getMessage() != null && e.getMessage().contains("Not Found")) {
} else { errorMsg = "检查更新失败:更新服务暂时不可用";
errorMsg = "检查更新失败,请稍后重试"; } else {
} errorMsg = "检查更新失败,请稍后重试";
Notify.show(errorMsg); }
}); Notify.show(errorMsg);
});
}
} }
} }
@@ -29,6 +29,7 @@ public class Updater implements Download.Callback {
private final Download download; private final Download download;
private AlertDialog dialog; private AlertDialog dialog;
private boolean dev; private boolean dev;
private boolean forceCheck; // 是否为手动检查
private File getFile() { private File getFile() {
return Path.cache("update.apk"); return Path.cache("update.apk");
@@ -48,11 +49,13 @@ public class Updater implements Download.Callback {
public Updater() { public Updater() {
this.download = Download.create(getApk(), getFile(), this); this.download = Download.create(getApk(), getFile(), this);
this.forceCheck = false;
} }
public Updater force() { public Updater force() {
Notify.show(R.string.update_check); Notify.show(R.string.update_check);
Setting.putUpdate(true); Setting.putUpdate(true);
this.forceCheck = true; // 标记为手动检查
return this; return this;
} }
@@ -88,14 +91,18 @@ public class Updater implements Download.Callback {
try { try {
String response = OkHttp.string(getJson()); String response = OkHttp.string(getJson());
// 检查响应是否包含错误信息 // 检查响应是否包含错误信息,只在手动检查时提示
if (response.contains("rate limit exceeded")) { if (response.contains("rate limit exceeded")) {
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试")); if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:API请求过于频繁,请稍后重试"));
}
return; return;
} }
if (response.contains("Not Found Project") || response.contains("Not Found")) { if (response.contains("Not Found Project") || response.contains("Not Found")) {
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用")); if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:更新服务暂时不可用"));
}
return; return;
} }
@@ -106,12 +113,18 @@ public class Updater implements Download.Callback {
if (need(code, name)) { if (need(code, name)) {
App.post(() -> show(activity, name, desc)); App.post(() -> show(activity, name, desc));
} else { } else {
// 不需要更新,提示已是最新版 // 只在手动检查时提示已是最新版
if (forceCheck) {
App.post(() -> Notify.show("已是最新版本 " + name));
}
Logger.d("Already latest version: " + name); Logger.d("Already latest version: " + name);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
App.post(() -> Notify.show("检查更新失败:网络连接异常")); // 只在手动检查时提示网络错误
if (forceCheck) {
App.post(() -> Notify.show("检查更新失败:网络连接异常"));
}
} }
} }