feat: fix debug updater

This commit is contained in:
2026-07-30 04:46:03 +02:00
parent 715aa529d4
commit 217be08231
9 changed files with 616 additions and 91 deletions
+6 -50
View File
@@ -1,9 +1,8 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:kooltab2/utils/app_update_util.dart';
import 'package:ota_update/ota_update.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'app_config.dart';
@@ -43,7 +42,7 @@ class UpdateChecker {
showDialog(
context: context,
barrierDismissible: !update.mandatory,
builder: (_) => AlertDialog(
builder: (dialogContext) => AlertDialog(
title: const Text("Update available"),
content: Column(
mainAxisSize: MainAxisSize.min,
@@ -57,14 +56,13 @@ class UpdateChecker {
actions: [
if (!update.mandatory)
TextButton(
onPressed: () => Navigator.pop(context),
onPressed: () => Navigator.pop(dialogContext),
child: const Text("Later"),
),
FilledButton(
onPressed: () async {
Navigator.pop(context);
await _downloadAndInstall(update);
onPressed: () {
Navigator.pop(dialogContext);
context.push('/update-progress', extra: update);
},
child: const Text("Update"),
),
@@ -73,45 +71,3 @@ class UpdateChecker {
);
}
}
Future<void> _downloadAndInstall(UpdateInfo update) async {
try {
final url = update.download.startsWith("http")
? update.download
: "$kUpdateServerUrl${update.download}";
OtaUpdate()
.execute(
url,
destinationFilename: "update.apk",
sha256checksum: update.sha256,
)
.listen((OtaEvent event) {
debugPrint("OTA status: ${event.status}");
debugPrint("OTA value: ${event.value}");
switch (event.status) {
case OtaStatus.DOWNLOADING:
final progress = double.tryParse(event.value ?? "0") ?? 0;
debugPrint("Downloading ${progress.toStringAsFixed(0)}%");
break;
case OtaStatus.INSTALLING:
debugPrint("Installing update");
break;
case OtaStatus.INSTALLATION_ERROR:
debugPrint("Installation error: ${event.value}");
break;
case OtaStatus.DOWNLOAD_ERROR:
debugPrint("Download error: ${event.value}");
break;
default:
break;
}
}, onError: (e, stack) {
debugPrint("OTA stream error: $e");
Sentry.captureException(e, stackTrace: stack);
});
} catch (e, stack) {
debugPrint("OTA update failed: $e");
Sentry.captureException(e, stackTrace: stack);
}
}