This commit is contained in:
2026-09-01 17:58:09 +08:00
parent 046ce2f1ab
commit 33d9bb1696
5 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ class UpdateChecker {
try {
final res = await _client
.get(Uri.parse('$baseUrl/api/v1/app/update'))
.timeout(const Duration(seconds: 8));
.timeout(const Duration(seconds: 30));
// 服务器 Content-Type 无 charsethttp 包默认按 latin1 解码会乱码 → 显式 utf8
final body =
jsonDecode(utf8.decode(res.bodyBytes)) as Map<String, dynamic>;
+7 -2
View File
@@ -98,14 +98,19 @@ class _UpdateScreenState extends State<UpdateScreen> {
});
try {
if (_apkPart.existsSync()) _apkPart.deleteSync();
final res = await _client.send(http.Request('GET', Uri.parse(widget.url)));
// 下载无总时长上限(APK 几十 MB 慢网可能数分钟);连接/响应头与
// 数据流分别做 30s 停滞判定,避免断流黑洞永久卡死
final res = await _client
.send(http.Request('GET', Uri.parse(widget.url)))
.timeout(const Duration(seconds: 30));
if (res.statusCode != 200) {
throw HttpException('HTTP ${res.statusCode}');
}
final total = res.contentLength ?? -1;
final sink = _apkPart.openWrite();
var received = 0;
await for (final chunk in res.stream) {
await for (final chunk
in res.stream.timeout(const Duration(seconds: 30))) {
sink.add(chunk);
received += chunk.length;
if (mounted && total > 0) {