From b0ce6fc618f280cf78578a4a34bd9dd0ec577cda Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Fri, 10 May 2024 12:18:57 +0200 Subject: [PATCH] LayeredErrorFrame: use focus stack references Other changes include: * Codebase: remove `_i18n` operators from strings used in brls::i18n::getStr() calls. * GameCardStatusTask: rename first_notification -> skip_notification. * GameCardStatusTask: fire event before displaying a notification. * libs: update borealis fork. * TitlesTab: store application metadata pointer array and size into local variables. --- include/tasks/gamecard_status_task.hpp | 2 +- libs/borealis | 2 +- source/main.cpp | 2 +- source/tasks/gamecard_status_task.cpp | 14 +++++++------- source/utils/exception_handler.cpp | 4 ++-- source/views/about_tab.cpp | 14 +++++++------- source/views/gamecard_tab.cpp | 4 ++-- source/views/layered_error_frame.cpp | 17 ++++++++--------- source/views/options_tab.cpp | 4 ++-- source/views/root_view.cpp | 8 ++++---- source/views/titles_tab.cpp | 12 +++++++----- 11 files changed, 42 insertions(+), 41 deletions(-) diff --git a/include/tasks/gamecard_status_task.hpp b/include/tasks/gamecard_status_task.hpp index fef198a..dca155b 100644 --- a/include/tasks/gamecard_status_task.hpp +++ b/include/tasks/gamecard_status_task.hpp @@ -42,7 +42,7 @@ namespace nxdt::tasks GameCardStatusEvent gc_status_event; GameCardStatus cur_gc_status = GameCardStatus_NotInserted; GameCardStatus prev_gc_status = GameCardStatus_NotInserted; - bool first_notification = true; + bool skip_notification = true; protected: void run(retro_time_t current_time) override; diff --git a/libs/borealis b/libs/borealis index 1a69955..a4eaaf4 160000 --- a/libs/borealis +++ b/libs/borealis @@ -1 +1 @@ -Subproject commit 1a69955c64f72a48342abce317a75998ffac3f9d +Subproject commit a4eaaf45824f1407b2a85e02d3ab8e47a83378e3 diff --git a/source/main.cpp b/source/main.cpp index a807c4b..25e71c1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) } catch (...) { std::exception_ptr p = std::current_exception(); LOG_MSG_ERROR("Exception caught! (%s).", p ? p.__cxa_exception_type()->name() : "unknown"); - brls::Application::crash(i18n::getStr("generic/exception_caught"_i18n, p ? p.__cxa_exception_type()->name() : "generic/unknown_exception"_i18n)); + brls::Application::crash(i18n::getStr("generic/exception_caught", p ? p.__cxa_exception_type()->name() : "generic/unknown_exception"_i18n)); while(brls::Application::mainLoop()); } diff --git a/source/tasks/gamecard_status_task.cpp b/source/tasks/gamecard_status_task.cpp index b6ba5c6..98efdd3 100644 --- a/source/tasks/gamecard_status_task.cpp +++ b/source/tasks/gamecard_status_task.cpp @@ -29,9 +29,9 @@ namespace nxdt::tasks { brls::RepeatingTask::start(); - this->first_notification = (gamecardGetStatus() != GameCardStatus_NotInserted); + this->skip_notification = (gamecardGetStatus() != GameCardStatus_NotInserted); - LOG_MSG_DEBUG("Gamecard task started with first_notification = %u.", this->first_notification); + LOG_MSG_DEBUG("Gamecard task started with skip_notification = %u.", this->skip_notification); } GameCardStatusTask::~GameCardStatusTask() @@ -48,7 +48,10 @@ namespace nxdt::tasks { LOG_MSG_DEBUG("Gamecard status change triggered: %u.", this->cur_gc_status); - if (!this->first_notification) + /* Fire task event. */ + this->gc_status_event.fire(this->cur_gc_status); + + if (!this->skip_notification) { if (this->prev_gc_status == GameCardStatus_NotInserted && this->cur_gc_status == GameCardStatus_Processing) { @@ -63,14 +66,11 @@ namespace nxdt::tasks brls::Application::notify("tasks/notifications/gamecard_ejected"_i18n); } } else { - this->first_notification = false; + this->skip_notification = false; } /* Update previous gamecard status. */ this->prev_gc_status = this->cur_gc_status; - - /* Fire task event. */ - this->gc_status_event.fire(this->cur_gc_status); } } } diff --git a/source/utils/exception_handler.cpp b/source/utils/exception_handler.cpp index 4be6f1b..9c91738 100644 --- a/source/utils/exception_handler.cpp +++ b/source/utils/exception_handler.cpp @@ -123,7 +123,7 @@ extern "C" { LOG_MSG_ERROR("*** libnx aborted with error code: 0x%X ***", res); /* Abort program execution. */ - std::string crash_str = (g_borealisInitialized ? i18n::getStr("utils/exception_handler/libnx_abort"_i18n, res) : fmt::format("Fatal error triggered in libnx!\nError code: 0x{:08X}.", res)); + std::string crash_str = (g_borealisInitialized ? i18n::getStr("utils/exception_handler/libnx_abort", res) : fmt::format("Fatal error triggered in libnx!\nError code: 0x{:08X}.", res)); nxdt::utils::AbortProgramExecution(crash_str); } @@ -223,7 +223,7 @@ extern "C" { #endif /* LOG_LEVEL < LOG_LEVEL_NONE */ /* Abort program execution. */ - crash_str = (g_borealisInitialized ? i18n::getStr("utils/exception_handler/exception_triggered"_i18n, error_desc_str, ctx->error_desc) : \ + crash_str = (g_borealisInitialized ? i18n::getStr("utils/exception_handler/exception_triggered", error_desc_str, ctx->error_desc) : \ fmt::format("Fatal exception triggered!\nReason: {} (0x{:X}).", error_desc_str, ctx->error_desc)); crash_str += (fmt::format("\nPC: 0x{:X}", ctx->pc.x) + (IS_HB_ADDR(ctx->pc.x) ? fmt::format(" (BASE + 0x{:X}).", ctx->pc.x - info.addr) : ".")); nxdt::utils::AbortProgramExecution(crash_str); diff --git a/source/views/about_tab.cpp b/source/views/about_tab.cpp index 3ed621d..8496efa 100644 --- a/source/views/about_tab.cpp +++ b/source/views/about_tab.cpp @@ -47,17 +47,17 @@ namespace nxdt::views this->addView(new AboutTabLabel(brls::LabelStyle::CRASH, "about_tab/description"_i18n, true)); /* Copyright. */ - brls::Label *copyright = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("about_tab/copyright"_i18n, APP_AUTHOR, GITHUB_REPOSITORY_URL), true); + brls::Label *copyright = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("about_tab/copyright", APP_AUTHOR, GITHUB_REPOSITORY_URL), true); copyright->setHorizontalAlign(NVG_ALIGN_CENTER); this->addView(copyright); /* Dependencies. */ this->addView(new brls::Header("about_tab/dependencies/header"_i18n)); - this->addView(new brls::Label(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_00"_i18n, APP_TITLE, BOREALIS_URL), true)); - this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_01"_i18n, LIBUSBHSFS_URL))); - this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_02"_i18n, FATFS_URL))); - this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_03"_i18n, LZ4_URL))); - this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_04"_i18n, JSON_C_URL))); + this->addView(new brls::Label(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_00", APP_TITLE, BOREALIS_URL), true)); + this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_01", LIBUSBHSFS_URL))); + this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_02", FATFS_URL))); + this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_03", LZ4_URL))); + this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/dependencies/line_04", JSON_C_URL))); /* Acknowledgments. */ this->addView(new brls::Header("about_tab/acknowledgments/header"_i18n)); @@ -66,7 +66,7 @@ namespace nxdt::views /* Additional links and resources. */ this->addView(new brls::Header("about_tab/links/header"_i18n)); - this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/links/line_00"_i18n, DISCORD_SERVER_URL))); + this->addView(new AboutTabLabel(brls::LabelStyle::SMALL, i18n::getStr("about_tab/links/line_00", DISCORD_SERVER_URL))); } AboutTab::~AboutTab() diff --git a/source/views/gamecard_tab.cpp b/source/views/gamecard_tab.cpp index ca455ae..3578ad8 100644 --- a/source/views/gamecard_tab.cpp +++ b/source/views/gamecard_tab.cpp @@ -83,7 +83,7 @@ namespace nxdt::views this->error_frame->SetMessage("gamecard_tab/error_frame/lafw_update_required"_i18n); break; case GameCardStatus_InsertedAndInfoNotLoaded: - this->error_frame->SetMessage(i18n::getStr("gamecard_tab/error_frame/info_not_loaded"_i18n, GITHUB_NEW_ISSUE_URL)); + this->error_frame->SetMessage(i18n::getStr("gamecard_tab/error_frame/info_not_loaded", GITHUB_NEW_ISSUE_URL)); break; case GameCardStatus_InsertedAndInfoLoaded: /* Update list and switch to it. */ @@ -176,7 +176,7 @@ namespace nxdt::views this->list->addView(new brls::Header("gamecard_tab/list/user_titles/header"_i18n)); /* Add information about how to work with individual user titles. */ - brls::Label *user_titles_info = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("gamecard_tab/list/user_titles/info"_i18n, \ + brls::Label *user_titles_info = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("gamecard_tab/list/user_titles/info", \ "root_view/tabs/user_titles"_i18n), true); user_titles_info->setHorizontalAlign(NVG_ALIGN_CENTER); this->list->addView(user_titles_info); diff --git a/source/views/layered_error_frame.cpp b/source/views/layered_error_frame.cpp index cade26a..eb21e42 100644 --- a/source/views/layered_error_frame.cpp +++ b/source/views/layered_error_frame.cpp @@ -59,17 +59,17 @@ namespace nxdt::views int LayeredErrorFrame::GetFocusStackViewIndex(void) { size_t cur_list_count = this->list->getViewsCount(); - std::vector *focus_stack = brls::Application::getFocusStack(); + std::vector& focus_stack = brls::Application::getFocusStack(); - if (cur_list_count && focus_stack) + if (cur_list_count) { - size_t focus_stack_size = focus_stack->size(); + size_t focus_stack_size = focus_stack.size(); for(size_t i = 0; i < focus_stack_size; i++) { for(size_t j = 0; j < cur_list_count; j++) { - if (this->list->getChild(j) == focus_stack->at(i)) return static_cast(i); + if (this->list->getChild(j) == focus_stack.at(i)) return static_cast(i); } } } @@ -79,13 +79,12 @@ namespace nxdt::views bool LayeredErrorFrame::UpdateFocusStackViewAtIndex(int index, brls::View *view) { - std::vector *focus_stack = brls::Application::getFocusStack(); - if (!focus_stack || index < 0 || !view) return false; + std::vector& focus_stack = brls::Application::getFocusStack(); + size_t focus_stack_size = focus_stack.size(); - size_t focus_stack_size = focus_stack->size(); - if (index >= static_cast(focus_stack_size)) return false; + if (index < 0 || index >= static_cast(focus_stack_size) || !view) return false; - focus_stack->at(index) = view; + focus_stack.at(index) = view; LOG_MSG_DEBUG("Focus stack updated."); return true; diff --git a/source/views/options_tab.cpp b/source/views/options_tab.cpp index 28affb0..97de3b8 100644 --- a/source/views/options_tab.cpp +++ b/source/views/options_tab.cpp @@ -144,7 +144,7 @@ namespace nxdt::views this->changelog_list->addView(version_lbl); /* Display release date and commit hash. */ - brls::Label *release_details_lbl = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("options_tab/update_app/frame/release_details"_i18n, \ + brls::Label *release_details_lbl = new brls::Label(brls::LabelStyle::DESCRIPTION, i18n::getStr("options_tab/update_app/frame/release_details", \ this->json_data.commit_hash, RootView::GetFormattedDateString(this->json_data.date)), true); release_details_lbl->setHorizontalAlign(NVG_ALIGN_CENTER); this->changelog_list->addView(release_details_lbl); @@ -286,7 +286,7 @@ namespace nxdt::views /* 2. Generate the string vector required by the dropdown. */ /* 3. Initialize the dropdown and pass a custom callback that will take care of unmounting the selected device. */ brls::SelectListItem *unmount_ums_device = new brls::SelectListItem("options_tab/unmount_ums_device/label"_i18n, { "dummy" }, 0, - i18n::getStr("options_tab/unmount_ums_device/description"_i18n, APP_TITLE), false); + i18n::getStr("options_tab/unmount_ums_device/description", APP_TITLE), false); unmount_ums_device->getClickEvent()->unsubscribeAll(); diff --git a/source/views/root_view.cpp b/source/views/root_view.cpp index 2e1ba84..fce89c4 100644 --- a/source/views/root_view.cpp +++ b/source/views/root_view.cpp @@ -84,7 +84,7 @@ namespace nxdt::views this->usb_icon->setVerticalAlign(NVG_ALIGN_TOP); this->usb_icon->setParent(this); - this->ums_counter_lbl = new brls::Label(brls::LabelStyle::SMALL, i18n::getStr("root_view/ums_counter"_i18n, usbHsFsGetPhysicalDeviceCount())); + this->ums_counter_lbl = new brls::Label(brls::LabelStyle::SMALL, i18n::getStr("root_view/ums_counter", usbHsFsGetPhysicalDeviceCount())); this->ums_counter_lbl->setHorizontalAlign(NVG_ALIGN_RIGHT); this->ums_counter_lbl->setVerticalAlign(NVG_ALIGN_TOP); this->ums_counter_lbl->setParent(this); @@ -161,7 +161,7 @@ namespace nxdt::views /* Subscribe to UMS event. */ this->ums_task_sub = this->ums_task->RegisterListener([this](const nxdt::tasks::UmsDeviceVector& ums_devices) { /* Update UMS counter label. */ - this->ums_counter_lbl->setText(i18n::getStr("root_view/ums_counter"_i18n, usbHsFsGetPhysicalDeviceCount())); + this->ums_counter_lbl->setText(i18n::getStr("root_view/ums_counter", usbHsFsGetPhysicalDeviceCount())); /* Update cached output storage value, if needed. */ if (this->output_storage > ConfigOutputStorage_UsbHost) this->output_storage = ConfigOutputStorage_SdCard; @@ -170,7 +170,7 @@ namespace nxdt::views /* Subscribe to USB host event. */ this->usb_host_task_sub = this->usb_host_task->RegisterListener([this](UsbHostSpeed usb_host_speed) { /* Update USB host speed label. */ - this->usb_host_speed_lbl->setText(usb_host_speed ? i18n::getStr("root_view/usb_host_speed"_i18n, usb_host_speed) : "root_view/usb_host_not_connected"_i18n); + this->usb_host_speed_lbl->setText(usb_host_speed ? i18n::getStr("root_view/usb_host_speed", usb_host_speed) : "root_view/usb_host_not_connected"_i18n); }); } @@ -224,7 +224,7 @@ namespace nxdt::views } } - return i18n::getStr("generic/date"_i18n, ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, is_am ? "AM" : "PM"); + return i18n::getStr("generic/date", ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec, is_am ? "AM" : "PM"); } void RootView::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) diff --git a/source/views/titles_tab.cpp b/source/views/titles_tab.cpp index d3bd046..8325f06 100644 --- a/source/views/titles_tab.cpp +++ b/source/views/titles_tab.cpp @@ -106,29 +106,31 @@ namespace nxdt::views brls::Application::blockInputs(); /* Populate variables. */ + TitleApplicationMetadata **app_metadata = app_metadata_info.app_metadata; + const u32 app_metadata_count = app_metadata_info.app_metadata_count; + bool update_focused_view = this->IsListItemFocused(); int focus_stack_index = this->GetFocusStackViewIndex(); /* If needed, switch to the error frame *before* cleaning up our list. */ - if (!app_metadata_info.app_metadata_count) this->SwitchLayerView(true); + if (!app_metadata_count) this->SwitchLayerView(true); /* Clear list. */ this->list->clear(); this->list->invalidate(true); /* Return immediately if we have no application metadata. */ - if (!app_metadata_info.app_metadata_count) + if (!app_metadata_count) { brls::Application::unblockInputs(); return; } /* Populate list. */ - for(u32 i = 0; i < app_metadata_info.app_metadata_count; i++) + for(u32 i = 0; i < app_metadata_count; i++) { /* Create list item. */ - const TitleApplicationMetadata *cur_app_metadata = app_metadata_info.app_metadata[i]; - TitlesTabItem *item = new TitlesTabItem(cur_app_metadata, this->is_system); + TitlesTabItem *item = new TitlesTabItem(app_metadata[i], this->is_system); /* Register click event. */ item->getClickEvent()->subscribe([](brls::View *view) {