From bc842d8905e135d71e5fa1436b5a2af5dc4adffd Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Thu, 29 Jul 2021 15:55:31 -0400 Subject: [PATCH] OptionsTab: check if an Internet connection is available before starting an update. --- include/options_tab.hpp | 6 ++++-- include/tasks.hpp | 3 +++ romfs/i18n/en-US/options_tab.json | 7 ++++--- source/options_tab.cpp | 17 +++++++++++++++-- source/root_view.cpp | 2 +- source/tasks.cpp | 5 +++++ 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/options_tab.hpp b/include/options_tab.hpp index ee2736c..c407773 100644 --- a/include/options_tab.hpp +++ b/include/options_tab.hpp @@ -26,7 +26,7 @@ #include -#include "download_task.hpp" +#include "tasks.hpp" namespace nxdt::views { @@ -70,13 +70,15 @@ namespace nxdt::views class OptionsTab: public brls::List { private: + nxdt::tasks::StatusInfoTask *status_info_task = nullptr; + bool display_notification = true; brls::menu_timer_t notification_timer = 0.0f; brls::menu_timer_ctx_entry_t notification_timer_ctx = {0}; void DisplayNotification(std::string str); public: - OptionsTab(void); + OptionsTab(nxdt::tasks::StatusInfoTask *status_info_task); ~OptionsTab(void); }; } diff --git a/include/tasks.hpp b/include/tasks.hpp index f04af59..e7a1f77 100644 --- a/include/tasks.hpp +++ b/include/tasks.hpp @@ -31,6 +31,7 @@ #include "core/title.h" #include "core/ums.h" #include "core/usb.h" +#include "download_task.hpp" namespace nxdt::tasks { @@ -71,6 +72,8 @@ namespace nxdt::tasks StatusInfoTask(void); ~StatusInfoTask(void); + const StatusInfoData* GetStatusInfoData(void); + ALWAYS_INLINE StatusInfoEvent::Subscription RegisterListener(StatusInfoEvent::Callback cb) { return this->status_info_event.subscribe(cb); diff --git a/romfs/i18n/en-US/options_tab.json b/romfs/i18n/en-US/options_tab.json index 820c5a5..0d3d347 100644 --- a/romfs/i18n/en-US/options_tab.json +++ b/romfs/i18n/en-US/options_tab.json @@ -31,9 +31,10 @@ }, "notifications": { - "is_nso": "The application is running as an NSO. Unable to update.", - "already_updated": "The application has already been updated. Please reload.", + "no_internet_connection": "Internet connection unavailable. Unable to update.", "update_failed": "Update failed! For more information, please check the logfile.", - "nswdb_xml_updated": "NSWDB XML successfully updated!" + "nswdb_xml_updated": "NSWDB XML successfully updated!", + "is_nso": "The application is running as an NSO. Unable to update.", + "already_updated": "The application has already been updated. Please reload." } } diff --git a/source/options_tab.cpp b/source/options_tab.cpp index 413702c..1d49cf7 100644 --- a/source/options_tab.cpp +++ b/source/options_tab.cpp @@ -185,7 +185,7 @@ namespace nxdt::views return true; } - OptionsTab::OptionsTab(void) : brls::List() + OptionsTab::OptionsTab(nxdt::tasks::StatusInfoTask *status_info_task) : brls::List(), status_info_task(status_info_task) { /* Set custom spacing. */ this->setSpacing(this->getSpacing() / 2); @@ -241,6 +241,13 @@ namespace nxdt::views brls::ListItem *update_nswdb_xml = new brls::ListItem("options_tab/update_nswdb_xml/label"_i18n, "options_tab/update_nswdb_xml/description"_i18n); update_nswdb_xml->getClickEvent()->subscribe([this](brls::View* view) { + if (!this->status_info_task->GetStatusInfoData()->ip_addr) + { + /* Display a notification if no Internet connection is available. */ + this->DisplayNotification("options_tab/notifications/no_internet_connection"_i18n); + return; + } + OptionsTabUpdateFileDialog *dialog = new OptionsTabUpdateFileDialog(NSWDB_XML_PATH, NSWDB_XML_URL, false, "options_tab/notifications/nswdb_xml_updated"_i18n); dialog->open(false); }); @@ -257,7 +264,13 @@ namespace nxdt::views this->DisplayNotification("options_tab/notifications/is_nso"_i18n); return; } else - if (false) + if (!this->status_info_task->GetStatusInfoData()->ip_addr) + { + /* Display a notification if no Internet connection is available. */ + this->DisplayNotification("options_tab/notifications/no_internet_connection"_i18n); + return; + } else + if (false) /// TODO: add a proper check here { /* Display a notification if the application has already been updated. */ this->DisplayNotification("options_tab/notifications/already_updated"_i18n); diff --git a/source/root_view.cpp b/source/root_view.cpp index 6bb97a3..e730cb1 100644 --- a/source/root_view.cpp +++ b/source/root_view.cpp @@ -111,7 +111,7 @@ namespace nxdt::views this->addSeparator(); - this->addTab("root_view/tabs/options"_i18n, new OptionsTab()); + this->addTab("root_view/tabs/options"_i18n, new OptionsTab(this->status_info_task)); this->addSeparator(); diff --git a/source/tasks.cpp b/source/tasks.cpp index 87268cc..d288847 100644 --- a/source/tasks.cpp +++ b/source/tasks.cpp @@ -42,6 +42,11 @@ namespace nxdt::tasks brls::Logger::debug("Status info task stopped."); } + const StatusInfoData* StatusInfoTask::GetStatusInfoData(void) + { + return &(this->status_info_data); + } + void StatusInfoTask::run(retro_time_t current_time) { brls::RepeatingTask::run(current_time);