| 36 | #include <cstdio> |
| 37 | |
| 38 | UpdateOverlay::UpdateOverlay(Screen& screen, const AutoUpdater::Update& update, std::function<void()> onInstalled) |
| 39 | : Overlay(screen), mJob(std::make_shared<Job>()), mOnInstalled(std::move(onInstalled)) |
| 40 | { |
| 41 | mJob->update = update; |
| 42 | mText = i18n::t("updater.downloading", {update.version}); |
| 43 | mLayout = ModalChrome::fitText(mText, SIZE, false); |
| 44 | mPosx = ceilf((320 - StringUtils::textWidth(mText, SIZE)) / 2); |
| 45 | |
| 46 | if (!Threads::create(Threads::WORKER_STACK, [job = mJob]() { |
| 47 | const AutoUpdater::Outcome outcome = AutoUpdater::install(job->update); |
| 48 | job->outcome = outcome; |
| 49 | job->finished.store(true, std::memory_order_release); |
| 50 | })) { |
| 51 | // No worker, no transfer: report the failure through the same path the |
| 52 | // worker would have taken rather than leaving the bar up forever. |
| 53 | Logging::warning("Could not start the update worker thread."); |
| 54 | mJob->finished.store(true, std::memory_order_release); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void UpdateOverlay::drawTop(void) const |
| 59 | { |