Skip to content

Commit

Permalink
add a time remaining indication (#262)
Browse files Browse the repository at this point in the history
* add a time remaining indication

* fixed text pos and add translation
  • Loading branch information
PoloNX authored Jul 11, 2023
1 parent 7270c84 commit 42b7be7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions resources/i18n/en-US/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,12 @@
"insufficient_storage": "There isn't enough space available on your SD card to perform this operation.",
"error_message": "{}\nPlease try again in a little while. If the problem persists, open an issue on GitHub.",
"mariko_payload_missing": "In order to update Atmosphère on patched Switches, your payload needs to be named \"payload.bin\" and should be at the root of your SD card."
},
"worker": {
"of": "of",
"remaining": "Time remaining",
"hours": "hours",
"minutes": "minutes",
"seconds": "seconds"
}
}
29 changes: 27 additions & 2 deletions source/worker_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ WorkerPage::WorkerPage(brls::StagedAppletFrame* frame, const std::string& text,
this->registerAction("", brls::Key::PLUS, [this] { return true; });
}

std::string formatLabelText( double speed, double fileSizeCurrent, double fileSizeFinal)
{
double fileSizeCurrentMB = fileSizeCurrent / 0x100000;
double fileSizeFinalMB = fileSizeFinal / 0x100000;
double speedMB = speed / 0x100000;

// Calcul du temps restant
double timeRemaining = (fileSizeFinal - fileSizeCurrent) / speed;
int hours = static_cast<int>(timeRemaining / 3600);
int minutes = static_cast<int>((timeRemaining - hours * 3600) / 60);
int seconds = static_cast<int>(timeRemaining - hours * 3600 - minutes * 60);

std::string labelText = fmt::format("({:.1f} MB {} {:.1f} MB - {:.1f} MB/s) - {}: ",
fileSizeCurrentMB, "menus/worker/of"_i18n, fileSizeFinalMB, speedMB, "menus/worker/remaining"_i18n);

if (hours > 0)
labelText += fmt::format("{}{} ", hours, "menus/worker/hours"_i18n);
if (minutes > 0)
labelText += fmt::format("{}{} ", minutes, "menus/worker/minutes"_i18n);

labelText += fmt::format("{}{}", seconds, "menus/worker/seconds"_i18n);

return labelText;
}

void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
{
if (this->draw_page) {
Expand Down Expand Up @@ -62,7 +87,7 @@ void WorkerPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned hei
this->progressDisp->setProgress(ProgressEvent::instance().getStep(), ProgressEvent::instance().getMax());
this->progressDisp->frame(ctx);
if (ProgressEvent::instance().getTotal()) {
this->label->setText(fmt::format("{0} ({1:.1f} MB of {2:.1f} MB - {3:.1f} MB/s)", text, ProgressEvent::instance().getNow() / 0x100000, ProgressEvent::instance().getTotal() / 0x100000, ProgressEvent::instance().getSpeed() / 0x100000));
this->label->setText(formatLabelText(ProgressEvent::instance().getSpeed(), ProgressEvent::instance().getNow(), ProgressEvent::instance().getTotal()));
}
this->label->frame(ctx);
}
Expand All @@ -75,7 +100,7 @@ void WorkerPage::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* sta

this->label->setBoundaries(
this->x + this->width / 2 - this->label->getWidth() / 2,
this->y + (this->height - style->AppletFrame.footerHeight) / 2,
this->y + (this->height - style->AppletFrame.footerHeight) / 2 - 30,
this->label->getWidth(),
this->label->getHeight());

Expand Down

0 comments on commit 42b7be7

Please sign in to comment.