chore(config): Switch to string_view for translated strings

Elides about 100 strlen calls by allowing the length to be calculated at compile time

ofc the WUPS backend doesn't USE this info but, y'know.
This commit is contained in:
Ash Logan 2024-08-04 18:15:16 +10:00
parent c6d80bd550
commit aedd02b0d1
4 changed files with 26 additions and 18 deletions

View File

@ -18,7 +18,7 @@
#include <notifications/notification_defines.h>
#include <notifications/notifications.h>
void ShowNotification(std::string_view notification) {
void ShowNotification(const char* notification) {
auto err1 = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO,
NOTIFICATION_MODULE_DEFAULT_OPTION_KEEP_UNTIL_SHOWN, true);
auto err2 = NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_INFO,
@ -27,5 +27,5 @@ void ShowNotification(std::string_view notification) {
if (err1 != NOTIFICATION_MODULE_RESULT_SUCCESS || err2 != NOTIFICATION_MODULE_RESULT_SUCCESS) return;
NotificationModule_AddInfoNotification(notification.data());
NotificationModule_AddInfoNotification(notification);
}

View File

@ -1,5 +1,3 @@
#pragma once
#include <string_view>
void ShowNotification(std::string_view notification);
void ShowNotification(const char* notification);

View File

@ -37,7 +37,7 @@ bool Config::need_relaunch = false;
bool Config::unregister_task_item_pressed = false;
bool Config::is_wiiu_menu = false;
config_strings strings;
static config_strings strings;
constexpr config_strings get_config_strings(nn::swkbd::LanguageType language) {
switch (language) {
@ -232,10 +232,18 @@ static void unregister_task_item_on_input_cb(void *context, WUPSConfigSimplePadD
}
static int32_t unregister_task_item_get_display_value(void *context, char *out_buf, int32_t out_size) {
if (!Config::is_wiiu_menu)
strncpy(out_buf, strings.need_menu_action, out_size);
else
strncpy(out_buf, Config::unregister_task_item_pressed ? strings.restart_to_apply_action : strings.press_a_action, out_size);
auto string = strings.need_menu_action;
if (Config::is_wiiu_menu) {
if (Config::unregister_task_item_pressed) {
string = strings.restart_to_apply_action;
} else {
string = strings.press_a_action;
}
}
if ((int)string.length() > out_size - 1) return -1;
string.copy(out_buf, string.length());
out_buf[string.length()] = '\0';
return 0;
}
@ -283,7 +291,7 @@ static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHa
};
WUPSConfigAPIItemOptionsV2 unregisterTasksItemOptions = {
.displayName = strings.reset_wwp_setting,
.displayName = strings.reset_wwp_setting.data(),
.context = nullptr,
.callbacks = unregisterTasksItemCallbacks,
};

View File

@ -5,6 +5,8 @@
#ifndef INKAY_CONFIG_H
#define INKAY_CONFIG_H
#include <string_view>
class Config {
public:
static void Init();
@ -23,13 +25,13 @@ public:
struct config_strings {
const char *plugin_name;
const char *network_category;
const char *connect_to_network_setting;
const char *other_category;
const char *reset_wwp_setting;
const char *press_a_action;
const char *restart_to_apply_action;
const char *need_menu_action;
std::string_view network_category;
std::string_view connect_to_network_setting;
std::string_view other_category;
std::string_view reset_wwp_setting;
std::string_view press_a_action;
std::string_view restart_to_apply_action;
std::string_view need_menu_action;
};
#endif //INKAY_CONFIG_H