feat: move inventory to own view model, add signing keys
This commit is contained in:
+79
-4
@@ -17,7 +17,9 @@ class _KoolTabAppState extends State<KoolTabApp> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_checkForUpdates();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_checkForUpdates();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _checkForUpdates() async {
|
||||
@@ -27,19 +29,92 @@ class _KoolTabAppState extends State<KoolTabApp> {
|
||||
final update = await updater.checkForUpdate();
|
||||
|
||||
if (update == null) {
|
||||
debugPrint("No update available: ");
|
||||
debugPrint("No update available");
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint("Update available: ${update.version}");
|
||||
|
||||
// TODO:
|
||||
// Show update dialog here
|
||||
if (!mounted) return;
|
||||
|
||||
_showUpdateDialog(update);
|
||||
} catch (e) {
|
||||
debugPrint("Update check failed: $e");
|
||||
}
|
||||
}
|
||||
|
||||
void _showUpdateDialog(UpdateInfo update) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: !update.mandatory,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Update available"),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Version ${update.version} is available.",
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(update.notes),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (!update.mandatory)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Later"),
|
||||
),
|
||||
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
|
||||
await _downloadAndInstall(update);
|
||||
},
|
||||
child: const Text("Update"),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _downloadAndInstall(UpdateInfo update) async {
|
||||
final updater = AppUpdateUtil(
|
||||
serverUrl: "http://localhost:3000",
|
||||
);
|
||||
|
||||
try {
|
||||
final apk = await updater.downloadApk(
|
||||
update,
|
||||
onProgress: (progress) {
|
||||
debugPrint(
|
||||
"Download ${(progress * 100).toStringAsFixed(0)}%",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final valid = await updater.verifySha256(
|
||||
apk,
|
||||
update.sha256,
|
||||
);
|
||||
|
||||
if (!valid) {
|
||||
throw Exception("Invalid update file");
|
||||
}
|
||||
|
||||
await updater.installApk(apk);
|
||||
|
||||
} catch (e) {
|
||||
debugPrint("Update failed: $e");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
|
||||
Reference in New Issue
Block a user