feat: restore MCP settings and board customizations
This commit is contained in:
@@ -20,6 +20,7 @@ static std::string getSettingsFilePath() {
|
||||
}
|
||||
|
||||
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
|
||||
constexpr auto* SETTINGS_KEY_FONT_SIZE = "fontSize";
|
||||
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
|
||||
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
|
||||
constexpr auto* SETTINGS_KEY_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
|
||||
@@ -73,6 +74,34 @@ static bool fromString(const std::string& str, Orientation& orientation) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::string toString(FontSize font_size) {
|
||||
switch (font_size) {
|
||||
using enum FontSize;
|
||||
case Small:
|
||||
return "Small";
|
||||
case Default:
|
||||
return "Default";
|
||||
case Large:
|
||||
return "Large";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
static bool fromString(const std::string& str, FontSize& font_size) {
|
||||
if (str == "Small") {
|
||||
font_size = FontSize::Small;
|
||||
return true;
|
||||
} else if (str == "Default") {
|
||||
font_size = FontSize::Default;
|
||||
return true;
|
||||
} else if (str == "Large") {
|
||||
font_size = FontSize::Large;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::string toString(ScreensaverType type) {
|
||||
switch (type) {
|
||||
using enum ScreensaverType;
|
||||
@@ -86,6 +115,8 @@ static std::string toString(ScreensaverType type) {
|
||||
return "MatrixRain";
|
||||
case StackChan:
|
||||
return "StackChan";
|
||||
case McpScreen:
|
||||
return "McpScreen";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
@@ -107,6 +138,9 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
|
||||
} else if (str == "StackChan") {
|
||||
type = ScreensaverType::StackChan;
|
||||
return true;
|
||||
} else if (str == "McpScreen") {
|
||||
type = ScreensaverType::McpScreen;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -129,6 +163,12 @@ bool load(DisplaySettings& settings) {
|
||||
orientation = getDefaultOrientation();
|
||||
}
|
||||
|
||||
auto font_size_entry = map.find(SETTINGS_KEY_FONT_SIZE);
|
||||
FontSize font_size = FontSize::Default;
|
||||
if (font_size_entry != map.end()) {
|
||||
fromString(font_size_entry->second, font_size);
|
||||
}
|
||||
|
||||
auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
|
||||
int gamma_curve = 0;
|
||||
if (gamma_entry != map.end()) {
|
||||
@@ -163,6 +203,7 @@ bool load(DisplaySettings& settings) {
|
||||
}
|
||||
|
||||
settings.orientation = orientation;
|
||||
settings.fontSize = font_size;
|
||||
settings.gammaCurve = gamma_curve;
|
||||
settings.backlightDuty = backlight_duty;
|
||||
settings.backlightTimeoutEnabled = timeout_enabled;
|
||||
@@ -175,6 +216,7 @@ bool load(DisplaySettings& settings) {
|
||||
DisplaySettings getDefault() {
|
||||
return DisplaySettings {
|
||||
.orientation = getDefaultOrientation(),
|
||||
.fontSize = FontSize::Default,
|
||||
.gammaCurve = 1,
|
||||
.backlightDuty = 200,
|
||||
.backlightTimeoutEnabled = false,
|
||||
@@ -196,6 +238,7 @@ bool save(const DisplaySettings& settings) {
|
||||
map[SETTINGS_KEY_BACKLIGHT_DUTY] = std::to_string(settings.backlightDuty);
|
||||
map[SETTINGS_KEY_GAMMA_CURVE] = std::to_string(settings.gammaCurve);
|
||||
map[SETTINGS_KEY_ORIENTATION] = toString(settings.orientation);
|
||||
map[SETTINGS_KEY_FONT_SIZE] = toString(settings.fontSize);
|
||||
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
|
||||
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
|
||||
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <tactility/log.h>
|
||||
#include <app/paths.h>
|
||||
|
||||
constexpr auto* TAG = "McpSettings";
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace tt::settings::mcp {
|
||||
|
||||
|
||||
static std::string getSettingsFilePath() {
|
||||
char path[256];
|
||||
if (app_paths_get_user_data_path("tactility.mcpsettings", "mcp.properties", path, sizeof(path)) != ERROR_NONE) {
|
||||
return "";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
constexpr auto* KEY_MCP_ENABLED = "mcpEnabled";
|
||||
|
||||
bool load(McpSettings& settings) {
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::isFile(settings_path)) {
|
||||
return false;
|
||||
}
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(settings_path, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mcp_enabled = map.find(KEY_MCP_ENABLED);
|
||||
settings.mcpEnabled = (mcp_enabled != map.end())
|
||||
? (mcp_enabled->second == "1" || mcp_enabled->second == "true")
|
||||
: false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
McpSettings getDefault() {
|
||||
return McpSettings{
|
||||
.mcpEnabled = false
|
||||
};
|
||||
}
|
||||
|
||||
McpSettings loadOrGetDefault() {
|
||||
McpSettings settings;
|
||||
if (!load(settings)) {
|
||||
settings = getDefault();
|
||||
if (!save(settings)) {
|
||||
LOG_W(TAG, "Failed to save default MCP settings");
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool save(const McpSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
map[KEY_MCP_ENABLED] = settings.mcpEnabled ? "true" : "false";
|
||||
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||
LOG_E(TAG, "Failed to create parent dir for %s", settings_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file::savePropertiesFile(settings_path, map)) {
|
||||
LOG_E(TAG, "Failed to save MCP settings to %s", settings_path.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user