Skip to content

Commit

Permalink
Fix update dialog
Browse files Browse the repository at this point in the history
* Show "Fetching metadata" while updateManager is checking http responses and downloading checksums
* Fix progressIndicator not working
* Show "Installing update..." while waiting for system update prompt
  • Loading branch information
Hedon-dev committed Jan 19, 2025
1 parent 727b54a commit 0aa7e13
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ class ViewerAppState extends State<ViewerApp> with WidgetsBindingObserver {
}

void performUpdate() async {
// This is for showing the download progress
updateManager.addListener(() => setState(() {}));
try {
List<String?> updateFuture = await updateManager.checkForUpdate();
latestTag = updateFuture[0];
Expand Down Expand Up @@ -227,7 +225,7 @@ class ViewerAppState extends State<ViewerApp> with WidgetsBindingObserver {

Widget buildRealApp() {
return updateAvailable
? buildUpdateDialogue()
? buildUpdateDialog()
: Scaffold(
bottomNavigationBar: NavigationBar(
destinations: <Widget>[
Expand Down Expand Up @@ -265,8 +263,10 @@ class ViewerAppState extends State<ViewerApp> with WidgetsBindingObserver {
body: screenList.elementAt(_selectedIndex));
}

Widget buildUpdateDialogue() {
return Builder(builder: (context) {
Widget buildUpdateDialog() {
return StatefulBuilder(builder: (context, setState) {
// This is for showing the download progress
updateManager.addListener(() => setState(() {}));
return Scaffold(
body: AlertDialog(
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
Expand All @@ -280,7 +280,11 @@ class ViewerAppState extends State<ViewerApp> with WidgetsBindingObserver {
updateFailed
? "Update failed due to $failReason\n\nPlease try again later."
: isDownloadingUpdate
? "Downloading update..."
? updateManager.downloadProgress == 0.0
? "Fetching update metadata..."
: updateManager.downloadProgress == 1.0
? "Installing update..."
: "Downloading update..."
: "Please install the update to continue",
style: Theme.of(context).textTheme.titleMedium)),
if (latestChangeLog != null &&
Expand Down

0 comments on commit 0aa7e13

Please sign in to comment.