From 5aefef6171728e5c0d2846e997c1f09eda04a135 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 1 Oct 2022 10:39:40 +0200 Subject: [PATCH] Make sure update window is in foreground --- src/client/component/splash.cpp | 16 ++++++++++++++++ src/client/component/splash.hpp | 1 + src/client/component/updater.cpp | 7 +++---- src/common/utils/progress_ui.cpp | 4 ++-- src/common/utils/progress_ui.hpp | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/client/component/splash.cpp b/src/client/component/splash.cpp index 70208fd7..b1eca502 100644 --- a/src/client/component/splash.cpp +++ b/src/client/component/splash.cpp @@ -71,6 +71,11 @@ namespace splash this->destroy(); } + HWND get_window() const + { + return this->window_; + } + private: std::atomic_bool join_safe_{false}; HWND window_{}; @@ -212,6 +217,17 @@ namespace splash splash_component->hide(); } } + + HWND get_window() + { + auto* splash_component = component_loader::get(); + if (splash_component) + { + return splash_component->get_window(); + } + + return nullptr; + } } REGISTER_COMPONENT(splash::component) diff --git a/src/client/component/splash.hpp b/src/client/component/splash.hpp index 330ae8cd..4b7cf91d 100644 --- a/src/client/component/splash.hpp +++ b/src/client/component/splash.hpp @@ -3,4 +3,5 @@ namespace splash { void hide(); + HWND get_window(); } diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index aacd01c7..086a37c4 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -93,12 +93,12 @@ namespace updater } } - void perform_update() + void perform_update(HWND parent_window) { const utils::progress_ui progress_ui{}; progress_ui.set_title("Updating BOIII"); progress_ui.set_line(1, "Downloading update..."); - progress_ui.show(true); + progress_ui.show(true, parent_window); const auto update_data = download_update(); @@ -180,8 +180,7 @@ namespace updater { if (requires_update()) { - splash::hide(); - perform_update(); + perform_update(splash::get_window()); activate_update(); } } diff --git a/src/common/utils/progress_ui.cpp b/src/common/utils/progress_ui.cpp index 4f6b6ea3..5b437016 100644 --- a/src/common/utils/progress_ui.cpp +++ b/src/common/utils/progress_ui.cpp @@ -18,9 +18,9 @@ namespace utils this->dialog_->StopProgressDialog(); } - void progress_ui::show(const bool marquee) const + void progress_ui::show(const bool marquee, HWND parent) const { - this->dialog_->StartProgressDialog(nullptr, nullptr, PROGDLG_AUTOTIME | (marquee ? PROGDLG_MARQUEEPROGRESS : 0), nullptr); + this->dialog_->StartProgressDialog(parent, nullptr, PROGDLG_AUTOTIME | (marquee ? PROGDLG_MARQUEEPROGRESS : 0), nullptr); } void progress_ui::set_progress(const size_t current, const size_t max) const diff --git a/src/common/utils/progress_ui.hpp b/src/common/utils/progress_ui.hpp index 75b3de5d..944005b3 100644 --- a/src/common/utils/progress_ui.hpp +++ b/src/common/utils/progress_ui.hpp @@ -10,7 +10,7 @@ namespace utils progress_ui(); ~progress_ui(); - void show(bool marquee) const; + void show(bool marquee, HWND parent = nullptr) const; void set_progress(size_t current, size_t max) const; void set_line(int line, const std::string& text) const;