diff --git a/include/root_view.hpp b/include/root_view.hpp index c20ee6d..d325ec1 100644 --- a/include/root_view.hpp +++ b/include/root_view.hpp @@ -31,6 +31,9 @@ namespace nxdt::views class RootView: public brls::TabFrame { private: + bool applet_mode = false; + + nxdt::tasks::StatusInfoTask *status_info_task = nullptr; nxdt::tasks::GameCardTask *gc_status_task = nullptr; nxdt::tasks::TitleTask *title_task = nullptr; nxdt::tasks::UmsTask *ums_task = nullptr; diff --git a/include/tasks.hpp b/include/tasks.hpp index 949c764..41e27fe 100644 --- a/include/tasks.hpp +++ b/include/tasks.hpp @@ -44,6 +44,43 @@ namespace nxdt::tasks /* Custom vector type used to hold UMS devices. */ typedef std::vector UmsDeviceVector; + /* Status info task. */ + class StatusInfoTask: public brls::RepeatingTask + { + private: + VoidEvent status_info_event; + + std::string cur_time = ""; + + u32 charge_percentage = 0; + PsmChargerType charger_type = PsmChargerType_Unconnected; + + NifmInternetConnectionType connection_type = (NifmInternetConnectionType)0; + u32 signal_strength = 0; + NifmInternetConnectionStatus connection_status = (NifmInternetConnectionStatus)0; + + protected: + void run(retro_time_t current_time) override; + + public: + StatusInfoTask(void); + ~StatusInfoTask(void); + + std::string GetCurrentTimeString(void); + void GetBatteryStats(u32 *out_charge_percentage, PsmChargerType *out_charger_type); + void GetNetworkStats(NifmInternetConnectionType *out_connection_type, u32 *out_signal_strength, NifmInternetConnectionStatus *out_connection_status); + + ALWAYS_INLINE VoidEvent::Subscription RegisterListener(VoidEvent::Callback cb) + { + return this->status_info_event.subscribe(cb); + } + + ALWAYS_INLINE void UnregisterListener(VoidEvent::Subscription subscription) + { + this->status_info_event.unsubscribe(subscription); + } + }; + /* Gamecard task. */ class GameCardTask: public brls::RepeatingTask { diff --git a/romfs/i18n/en-US/gamecard_tab.json b/romfs/i18n/en-US/gamecard_tab.json index 7180c47..8d6c0a4 100644 --- a/romfs/i18n/en-US/gamecard_tab.json +++ b/romfs/i18n/en-US/gamecard_tab.json @@ -23,7 +23,7 @@ "dump_options": "Dump options", "dump_card_image": { - "label": "Dump gamecard image", + "label": "Dump gamecard image (XCI)", "description": "Generates a raw gamecard image. This is the option most people will want to use." }, diff --git a/source/root_view.cpp b/source/root_view.cpp index 37451d3..968185a 100644 --- a/source/root_view.cpp +++ b/source/root_view.cpp @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -#include +#include #include #include //#include @@ -33,7 +33,11 @@ namespace nxdt::views { RootView::RootView(void) : brls::TabFrame() { + /* Check if we're running under applet mode. */ + this->applet_mode = utilsAppletModeCheck(); + /* Start background tasks. */ + this->status_info_task = new nxdt::tasks::StatusInfoTask(); this->gc_status_task = new nxdt::tasks::GameCardTask(); this->title_task = new nxdt::tasks::TitleTask(); this->ums_task = new nxdt::tasks::UmsTask(); diff --git a/source/tasks.cpp b/source/tasks.cpp index e0c193a..1c191ae 100644 --- a/source/tasks.cpp +++ b/source/tasks.cpp @@ -26,6 +26,80 @@ namespace nxdt::tasks { + /* Status info task. */ + + StatusInfoTask::StatusInfoTask(void) : brls::RepeatingTask(NXDT_TASK_INTERVAL * 10) + { + brls::RepeatingTask::start(); + brls::Logger::debug("Status info task started."); + } + + StatusInfoTask::~StatusInfoTask(void) + { + /* Clear current time string. */ + this->cur_time.clear(); + + brls::Logger::debug("Status info task stopped."); + } + + void StatusInfoTask::run(retro_time_t current_time) + { + brls::RepeatingTask::run(current_time); + + /* Get current time. */ + bool is_am = true; + time_t unix_time = time(NULL); + struct tm *timeinfo = localtime(&unix_time); + + if (timeinfo->tm_hour > 12) + { + timeinfo->tm_hour -= 12; + is_am = false; + } else + if (!timeinfo->tm_hour) + { + timeinfo->tm_hour = 12; + } + + this->cur_time.clear(); + fmt::format_to(std::back_inserter(this->cur_time), "{:02d}:{:02d}:{:02d} {}", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, is_am ? "AM" : "PM"); + + /* Get battery stats. */ + psmGetBatteryChargePercentage(&(this->charge_percentage)); + psmGetChargerType(&(this->charger_type)); + + /* Get network connection status. */ + Result rc = nifmGetInternetConnectionStatus(&(this->connection_type), &(this->signal_strength), &(this->connection_status)); + if (R_FAILED(rc)) + { + this->connection_type = (NifmInternetConnectionType)0; + this->signal_strength = 0; + this->connection_status = (NifmInternetConnectionStatus)0; + } + + this->status_info_event.fire(); + } + + std::string StatusInfoTask::GetCurrentTimeString(void) + { + return this->cur_time; + } + + void StatusInfoTask::GetBatteryStats(u32 *out_charge_percentage, PsmChargerType *out_charger_type) + { + if (!out_charge_percentage || !out_charger_type) return; + *out_charge_percentage = this->charge_percentage; + *out_charger_type = this->charger_type; + } + + void StatusInfoTask::GetNetworkStats(NifmInternetConnectionType *out_connection_type, u32 *out_signal_strength, NifmInternetConnectionStatus *out_connection_status) + { + if (!out_connection_type || !out_signal_strength || !out_connection_status) return; + *out_connection_type = this->connection_type; + *out_signal_strength = this->signal_strength; + *out_connection_status = this->connection_status; + } + /* Gamecard task. */ GameCardTask::GameCardTask(void) : brls::RepeatingTask(NXDT_TASK_INTERVAL)