From 07ceff9721af4024dd691742641b6766a0be66f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Mon, 22 Aug 2016 10:25:55 +0200 Subject: [PATCH] Display a global progress for self update --- .../clients/inst_update_installer.rb | 35 +++++++++++++++++++ src/lib/installation/update_repository.rb | 35 ++----------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/lib/installation/clients/inst_update_installer.rb b/src/lib/installation/clients/inst_update_installer.rb index f34555da7..3a9c0630f 100644 --- a/src/lib/installation/clients/inst_update_installer.rb +++ b/src/lib/installation/clients/inst_update_installer.rb @@ -56,6 +56,35 @@ def main # shortcut - already updated return :next if installer_updated? + # open a new wizard dialog with title on the top + # (the default dialog with title on the left looks ugly with the + # Progress dialog) + Yast::Wizard.CreateDialog + @wizard_open = true + + Yast::Progress.New( + # TRANSLATORS: dialog title + _("Updating the Installer..."), + # TRANSLATORS: progress title + _("Updating the Installer..."), + # max is 100% + 100, + # stages + [ + # TRANSLATORS: progress label + _("Add Update Repository"), + _("Download the Packages"), + _("Restart") + ], + # steps + [], + # help text + "" + ) + + # mark the first stage active + Yast::Progress.NextStage + # initialize packager, we need to load the base product name # to properly obtain the update URL from the registration server return :abort unless initialize_packager @@ -71,10 +100,16 @@ def main if installer_updated # Indicates that the installer was updated. ::FileUtils.touch(update_flag_file) + Yast::Progress.NextStage Installation.restart! else :next end + ensure + if @wizard_open + Yast::Progress.Finish + Yast::Wizard.CloseDialog + end end # Tries to update the installer diff --git a/src/lib/installation/update_repository.rb b/src/lib/installation/update_repository.rb index 1ea112bb5..ab10a3657 100644 --- a/src/lib/installation/update_repository.rb +++ b/src/lib/installation/update_repository.rb @@ -148,15 +148,13 @@ def fetch(path = Pathname("/download")) init_progress packages.each_with_object(update_files).with_index do |(package, files), index| - update_progress(index) + update_progress(100 * index / packages.size) files << fetch_package(package, path) end rescue PackageNotFound, CouldNotExtractPackage, CouldNotSquashPackage => e log.error("Could not fetch update: #{e.inspect}. Rolling back.") remove_update_files raise CouldNotFetchUpdate - ensure - finish_progress end # Remove fetched packages @@ -383,30 +381,9 @@ def update_instsys_parts(path, mountpoint) end end - # Initialize the progress if it is enabled. + # Initialize the progress def init_progress - # open a new wizard window for the progress (only when Progress is enabled) - # to not mess the current dialog - Yast::Wizard.CreateDialog if Yast::Progress.status - Yast::Progress.New( - # TRANSLATORS: dialog title - _("Updating..."), - # TRANSLATORS: progress title - _("Downloading Packages..."), - # size - packages.size, - # stages - [ - # TRANSLATORS: progress label - _("Downloading the Installer Updates...") - ], - # steps - [], - # help text - "" - ) - - # mark the first stage active + # mark the next stage active Yast::Progress.NextStage end @@ -415,11 +392,5 @@ def init_progress def update_progress(percent) Yast::Progress.Step(percent) end - - # Close the progress if it is enabled - def finish_progress - Yast::Progress.Finish - Yast::Wizard.CloseDialog if Yast::Progress.status - end end end