Skip to content

Commit

Permalink
chore(config): Switch to string_view for translated strings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ashquarky committed Aug 4, 2024
1 parent c6d80bd commit aedd02b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
4 changes: 1 addition & 3 deletions src/Notification.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#include <string_view>

void ShowNotification(std::string_view notification);
void ShowNotification(const char* notification);
20 changes: 14 additions & 6 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
};
Expand Down
16 changes: 9 additions & 7 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef INKAY_CONFIG_H
#define INKAY_CONFIG_H

#include <string_view>

class Config {
public:
static void Init();
Expand All @@ -23,13 +25,13 @@ class Config {

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

0 comments on commit aedd02b

Please sign in to comment.