1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-09 20:11:48 +00:00
AIO-switch-updater/source/confirm_page.cpp

118 lines
4 KiB
C++
Raw Normal View History

2020-09-20 01:21:28 +01:00
#include "confirm_page.hpp"
2021-09-11 14:48:13 +01:00
2021-02-10 16:28:47 +00:00
#include <algorithm>
#include <filesystem>
#include <string>
2021-09-11 14:48:13 +01:00
#include "fs.hpp"
#include "main_frame.hpp"
#include "utils.hpp"
namespace i18n = brls::i18n;
using namespace i18n::literals;
ConfirmPage::ConfirmPage(brls::StagedAppletFrame* frame, const std::string& text)
2020-09-20 01:21:28 +01:00
{
this->button = (new brls::Button(brls::ButtonStyle::REGULAR))->setLabel("menus/common/back"_i18n);
2020-09-20 01:21:28 +01:00
this->button->setParent(this);
this->button->getClickEvent()->subscribe([frame, this](View* view) {
if (!frame->isLastStage())
frame->nextStage();
else
2020-09-20 01:21:28 +01:00
brls::Application::pushView(new MainFrame());
});
this->label = new brls::Label(brls::LabelStyle::DIALOG, text, true);
this->label->setHorizontalAlign(NVG_ALIGN_CENTER);
this->label->setParent(this);
}
2020-09-20 01:21:28 +01:00
ConfirmPage_Done::ConfirmPage_Done(brls::StagedAppletFrame* frame, const std::string& text) : ConfirmPage(frame, text)
{
this->button->setLabel("menus/common/back"_i18n);
this->done = true;
2020-09-20 01:21:28 +01:00
}
ConfirmPage_AppUpdate::ConfirmPage_AppUpdate(brls::StagedAppletFrame* frame, const std::string& text) : ConfirmPage_Done(frame, text)
{
this->button->getClickEvent()->subscribe([](View* view) {
envSetNextLoad(FORWARDER_PATH, fmt::format("\"{}\"", FORWARDER_PATH).c_str());
romfsExit();
brls::Application::quit();
});
this->registerAction("", brls::Key::B, [this] { return true; });
}
ConfirmPage_AmsUpdate::ConfirmPage_AmsUpdate(brls::StagedAppletFrame* frame, const std::string& text, bool erista) : ConfirmPage_Done(frame, text)
{
this->button->getClickEvent()->subscribe([this, erista](View* view) {
if (erista) {
util::rebootToPayload(RCM_PAYLOAD_PATH);
}
else {
if (std::filesystem::exists(UPDATE_BIN_PATH)) {
fs::copyFile(UPDATE_BIN_PATH, MARIKO_PAYLOAD_PATH_TEMP);
}
else {
fs::copyFile(REBOOT_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH_TEMP);
}
fs::copyFile(RCM_PAYLOAD_PATH, MARIKO_PAYLOAD_PATH);
util::shutDown(true);
}
});
this->registerAction("", brls::Key::B, [this] { return true; });
};
2020-09-20 01:21:28 +01:00
void ConfirmPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
{
2021-09-11 14:48:13 +01:00
if (!this->done) {
2020-09-20 01:21:28 +01:00
auto end = std::chrono::high_resolution_clock::now();
auto missing = std::max(1l - std::chrono::duration_cast<std::chrono::seconds>(end - start).count(), 0l);
2021-09-11 14:48:13 +01:00
auto text = std::string("menus/common/continue"_i18n);
2020-09-20 01:21:28 +01:00
if (missing > 0) {
this->button->setLabel(fmt::format("{} ({})", text, missing));
2020-09-20 01:21:28 +01:00
this->button->setState(brls::ButtonState::DISABLED);
2021-09-11 14:48:13 +01:00
}
else {
2020-09-20 01:21:28 +01:00
this->button->setLabel(text);
this->button->setState(brls::ButtonState::ENABLED);
}
this->button->invalidate();
}
2021-09-11 14:48:13 +01:00
else {
this->button->setState(brls::ButtonState::ENABLED);
}
2020-09-20 01:21:28 +01:00
this->label->frame(ctx);
this->button->frame(ctx);
}
brls::View* ConfirmPage::getDefaultFocus()
{
return this->button;
}
void ConfirmPage::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash)
{
this->label->setWidth(this->width);
this->label->invalidate(true);
// this->label->setBackground(brls::ViewBackground::DEBUG);
this->label->setBoundaries(
this->x + this->width / 2 - this->label->getWidth() / 2,
2021-09-11 14:48:13 +01:00
this->y + (this->height - this->label->getHeight() - this->y - style->CrashFrame.buttonHeight) / 2,
2020-09-20 01:21:28 +01:00
this->label->getWidth(),
this->label->getHeight());
this->button->setBoundaries(
this->x + this->width / 2 - style->CrashFrame.buttonWidth / 2,
2021-09-11 14:48:13 +01:00
this->y + (this->height - style->CrashFrame.buttonHeight * 3),
2020-09-20 01:21:28 +01:00
style->CrashFrame.buttonWidth,
style->CrashFrame.buttonHeight);
this->button->invalidate();
start = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(150);
}
ConfirmPage::~ConfirmPage()
{
delete this->label;
delete this->button;
}