e3eb3fd415
- MCP 3.3K LOC: McpSystem 1899 + McpHandler 1029 + McpScreensaver + 2 apps
- Uses native tactility/log.h TAG macros, no old Logger.h
- DisplaySettings McpScreen enum, WebServer coexistence (MCP enabled starts HTTP)
- DisplayIdle: startMcpScreensaver + isDeviceCharging + lock inversion fix 3629ffef
- LVGL 512K PSRAM cache retained from previous perf patch
- Audio kept upstream es8311-module per note we might not need custom
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
#include <Tactility/settings/McpSettings.h>
|
|
#include <Tactility/file/PropertiesFile.h>
|
|
#include <Tactility/file/File.h>
|
|
#include <tactility/log.h>
|
|
|
|
constexpr auto* TAG = "McpSettings";
|
|
#include <Tactility/Paths.h>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
namespace tt::settings::mcp {
|
|
|
|
|
|
static std::string getSettingsFilePath() {
|
|
return getUserDataPath() + "/settings/mcp.properties";
|
|
}
|
|
|
|
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
|