/** * @file rex/ui/overlay/acquire_wizard_overlay.h * * @brief Generic pre-runtime acquisition dialog: install a payload either * by fetching it automatically (e.g. a download) or from a * user-selected source file. */ #pragma once #include #include #include #include #include #include namespace rex::ui { class AcquireWizardDialog final : public ImGuiDialog { public: struct Options { std::string title; std::string intro; std::string target_directory; std::string initial_status; // Leave a label empty to hide the corresponding button. std::string fetch_button_label; std::string pick_button_label; // Shown while a fetch is in progress but no bytes have arrived yet (e.g. // waiting on the server's first byte). Falls back to fetch_working_status // if empty. std::string fetch_connecting_status; std::string fetch_working_status; std::string install_working_status; std::string done_status; std::string done_button_label; }; using PickSourceCallback = std::function; using InstallCallback = std::function& copied_bytes, std::atomic& total_bytes, std::string& error)>; using FetchCallback = std::function& copied_bytes, std::atomic& total_bytes, std::string& error)>; using CompleteCallback = std::function; AcquireWizardDialog(ImGuiDrawer* drawer, Options options, FetchCallback fetch, PickSourceCallback pick_source, InstallCallback install, CompleteCallback complete); protected: void OnClose() override; void OnDraw(ImGuiIO& io) override; private: enum class State { kWaitingForChoice, kWorking, kDone, kFailed, }; void StartWork(std::function work, std::string busy_status); void StartFetch(); void PickSourceAndInstall(); void FinishWorkIfNeeded(); const std::string& WorkingStatus() const; Options options_; FetchCallback fetch_; PickSourceCallback pick_source_; InstallCallback install_; CompleteCallback complete_; std::thread work_thread_; std::atomic work_done_{false}; std::atomic work_ok_{false}; std::atomic copied_bytes_{0}; std::atomic total_bytes_{0}; State state_ = State::kWaitingForChoice; bool working_is_fetch_ = false; std::filesystem::path source_path_; std::string status_; std::string error_; }; } // namespace rex::ui