Files
tactility/Tactility/Source/settings/McpSettings.cpp
Adolfo Reyna 620d56e19a feat(ui): simplify family UI - hide advanced settings/apps, sane defaults
Hide from Settings: Bluetooth, Development, MCP Screen, Power,
Region & Language, Time & Date (APP_MANIFEST_FLAG_HIDDEN).

Hide from Apps list: App Hub, Chat, I2C Scanner, Notes,
Screenshot, System Info, Web Server.

Defaults: MCP on, WebServer on, America/New_York timezone,
12-hour time format.
2026-09-12 19:45:13 -04:00

77 lines
1.9 KiB
C++

#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")
: true;
return true;
}
McpSettings getDefault() {
return McpSettings{
.mcpEnabled = true
};
}
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